#include <stdio.h>
// opened few png files with hex editor, those bytes were common for all of them
static const char png_head[] = { 0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0 };
static const size_t png_head_size = 17;
static const char png_end[] = { 0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 };
static const size_t png_end_size = 8;
size_t buffer_compare( const char * buff, size_t start_pos, size_t total, const char * to_compare, size_t to_compare_size ){
if(!buff || !to_compare){ return -1; }
size_t found = -1;
while( start_pos < total ){
if( 0 == memcmp( (buff+start_pos), to_compare, to_compare_size) ){
found = start_pos;
break;
} else{
++start_pos;
}
}
return found;
}
size_t seek_png_start( const char * buff, size_t start_pos, size_t total ){
return buffer_compare(buff, start_pos, total, png_head, png_head_size );
}
size_t seek_png_end( const char * buff, size_t start_pos, size_t total ){
return buffer_compare(buff, start_pos, total, png_end, png_end_size );
}
int main( int argc, char ** argv ){
if( argc > 1 ){
FILE * f = fopen(argv[1], "rb");
if( f ){
fseek(f,0,SEEK_END);
const long size = ftell(f);
rewind(f);
char * buff = (char*)malloc(size);
size_t size_read = fread( (void*)buff, 1, size, f );
if( size_read != size ){
puts("cannot read file!");
} else{
puts("file opened ok.");
int found = 0;
size_t pos = 0, end = 0;
char tmp[256];
while(1){
pos = seek_png_start( buff, end, size );
end = seek_png_end( buff, pos+1, size );
if( pos == -1 || end == -1 ){ break; }
sprintf(tmp,"file_%i.png",found++);
FILE * out = fopen(tmp,"wb");
if( out ){
fwrite( buff+pos, 1, end-pos+png_end_size, out );
fclose(out);
}
};
printf("\nfound %i png files.\n",found);
}
free(buff);
fclose(f);
} else{
puts("cannot open file!");
}
}
return 0;
}
#include <stdio.h>
// opened few png files with hex editor, those bytes were common for all of them
static const char png_head[] = { 0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0 };
static const size_t png_head_size = 17;
static const char png_end[] = { 0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 };
static const size_t png_end_size = 8;
size_t buffer_compare( const char * buff, size_t start_pos, size_t total, const char * to_compare, size_t to_compare_size ){
if(!buff || !to_compare){ return -1; }
size_t found = -1;
while( start_pos < total ){
if( 0 == memcmp( (buff+start_pos), to_compare, to_compare_size) ){
found = start_pos;
break;
} else{
++start_pos;
}
}
return found;
}
size_t seek_png_start( const char * buff, size_t start_pos, size_t total ){
return buffer_compare(buff, start_pos, total, png_head, png_head_size );
}
size_t seek_png_end( const char * buff, size_t start_pos, size_t total ){
return buffer_compare(buff, start_pos, total, png_end, png_end_size );
}
int main( int argc, char ** argv ){
if( argc > 1 ){
FILE * f = fopen(argv[1], "rb");
if( f ){
fseek(f,0,SEEK_END);
const long size = ftell(f);
rewind(f);
char * buff = (char*)malloc(size);
size_t size_read = fread( (void*)buff, 1, size, f );
if( size_read != size ){
puts("cannot read file!");
} else{
puts("file opened ok.");
int found = 0;
size_t pos = 0, end = 0;
char tmp[256];
while(1){
pos = seek_png_start( buff, end, size );
end = seek_png_end( buff, pos+1, size );
if( pos == -1 || end == -1 ){ break; }
sprintf(tmp,"file_%i.png",found++);
FILE * out = fopen(tmp,"wb");
if( out ){
fwrite( buff+pos, 1, end-pos+png_end_size, out );
fclose(out);
}
};
printf("\nfound %i png files.\n",found);
}
free(buff);
fclose(f);
} else{
puts("cannot open file!");
}
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Its just "quick and dirty" solution, but it works ( tested on few exe files with png compiled in ). Maybe you can adapt it to extract your .mng file.
Bookmarks