#include #include // list of tags: https://exiftool.org/TagNames/JPEG.html int main(int argc,char*argv[]){ FILE*fi; int c,oldc; int ischunk=0; int isdata=0; int chunklen=0; int chunkpos=0; int readoffs=0; fi=stdin; ischunk=0; while(!feof(fi)){ oldc=c; c=fgetc(fi);readoffs++; // printf("%02x ",c); if(!isdata) if(!ischunk)if(oldc==0xff){ ischunk=1; chunkpos=0; printf("\nChunk: %02x%02x offs: %6d ",oldc,c,readoffs-2); if(c==0xc0){printf(" [SOF] ");ischunk=0;chunkpos=0;}else if(c==0xc4){printf(" [HUFFT]");ischunk=0;chunkpos=0;}else if(c==0xd8){printf(" [START]");ischunk=0;chunkpos=0;}else if(c==0xdb){printf(" [QUANT]");ischunk=0;chunkpos=0;}else if(c==0xe0){printf(" [APP0] ");ischunk=0;chunkpos=0;}else // if(c==0xe1){printf(" [EXIF] ");ischunk=0;chunkpos=0;}else if(c==0xe1){printf(" [APP1] ");ischunk=0;chunkpos=0;}else if(c==0xe2){printf(" [APP2] ");ischunk=0;chunkpos=0;}else if(c==0xe3){printf(" [APP3] ");ischunk=0;chunkpos=0;}else if(c==0xe4){printf(" [APP4] ");ischunk=0;chunkpos=0;}else if(c==0xe5){printf(" [APP5] ");ischunk=0;chunkpos=0;}else if(c==0xe6){printf(" [APP6] ");ischunk=0;chunkpos=0;}else if(c==0xe7){printf(" [APP7] ");ischunk=0;chunkpos=0;}else if(c==0xe8){printf(" [APP8] ");ischunk=0;chunkpos=0;}else if(c==0xe9){printf(" [APP9] ");ischunk=0;chunkpos=0;}else if(c==0xea){printf(" [APP10]");ischunk=0;chunkpos=0;}else if(c==0xeb){printf(" [APP11]");ischunk=0;chunkpos=0;}else if(c==0xec){printf(" [APP12]");ischunk=0;chunkpos=0;}else if(c==0xed){printf(" [APP13]");ischunk=0;chunkpos=0;}else if(c==0xee){printf(" [APP14]");ischunk=0;chunkpos=0;}else if(c==0xef){printf(" [APP15]");ischunk=0;chunkpos=0;}else if(c==0xda){printf(" [data] ");isdata=1;}else if(c==0xfe){printf(" [COMMT]");ischunk=0;chunkpos=0;}else if(c==0x00){printf(" ");ischunk=0;chunkpos=0;}else {printf(" [?%02x%02x]",oldc,c);ischunk=0;chunkpos=0;} continue; } if(isdata){ if(oldc==0xff)if(c==0xd9){ printf("\nChunk: %02x%02x offs: %6d [END] len=%d\n",oldc,c,chunkpos,readoffs-2);ischunk=0;isdata=0;continue;} } if(feof(fi))break; // if(isdata){}//printf(".%02x",c); // else if(!ischunk){if(chunkpos>2)printf("_%02x",c);} // else {}// printf(" %02x",c); chunkpos++; if(chunkpos==2){ chunklen=(oldc<<8)+c; printf(" len:%d",chunklen); } if(ischunk)if(chunklen==chunkpos){ ischunk=0; } } printf("\n"); return 0; }