PDA

View Full Version : How to extract resources from compiled Qt4 programm?



dennis81
27th September 2011, 12:19
Hello community,

is it possible to extract resources from a compiled Qt4 project?
I have got an .exe with an MNG-video file in it and lost the original file :-(

The Knut resource extractor works only for Qt3 binaries.

greets,
Dennis

stampede
28th September 2011, 08:43
I don't know about any resource extractor available, but you can try to extract it yourself - there is a big chance that this file was compiled "as is" into the exe - by simply putting each byte, one by one, into .exe.
.mng format is closely related to .png ("MNG (pronounced "ming") is a format for storing multiple bitmaps and animations and is a close cousin of the PNG format. (http://www.graphicsacademy.com/format_mng.php)"), which will make things easier - you can try to search the .exe for the .mng file header, and specific "footer" bytes (each .png file is like that, so maybe .mng too, I'm not sure), then simply copy every byte starting at the beginning of header and end at the "footer".
It works well for .png files (and .jpgs too). I can give you sample code for extracting .png files, if you want, but you should be able to write it without problems (no more than 50 lines of code in pure C).
I guess its better than nothing.
-----
edit:
I could not find my old code (It worked for jpg and avi files too), so I've made this:


#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,0 xd,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;
}

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.

dennis81
28th September 2011, 12:17
Thank alot ! I will try it.