Results 1 to 3 of 3

Thread: How to extract resources from compiled Qt4 programm?

  1. #1
    Join Date
    Sep 2011
    Location
    Mannheim, Germany
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to extract resources from compiled Qt4 programm?

    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

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to extract resources from compiled Qt4 programm?

    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."), 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:
    Qt Code:
    1. #include <stdio.h>
    2.  
    3. // opened few png files with hex editor, those bytes were common for all of them
    4. static const char png_head[] = { 0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0 };
    5. static const size_t png_head_size = 17;
    6. static const char png_end[] = { 0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 };
    7. static const size_t png_end_size = 8;
    8.  
    9. size_t buffer_compare( const char * buff, size_t start_pos, size_t total, const char * to_compare, size_t to_compare_size ){
    10. if(!buff || !to_compare){ return -1; }
    11. size_t found = -1;
    12. while( start_pos < total ){
    13. if( 0 == memcmp( (buff+start_pos), to_compare, to_compare_size) ){
    14. found = start_pos;
    15. break;
    16. } else{
    17. ++start_pos;
    18. }
    19. }
    20. return found;
    21. }
    22.  
    23. size_t seek_png_start( const char * buff, size_t start_pos, size_t total ){
    24. return buffer_compare(buff, start_pos, total, png_head, png_head_size );
    25. }
    26.  
    27. size_t seek_png_end( const char * buff, size_t start_pos, size_t total ){
    28. return buffer_compare(buff, start_pos, total, png_end, png_end_size );
    29. }
    30.  
    31. int main( int argc, char ** argv ){
    32. if( argc > 1 ){
    33. FILE * f = fopen(argv[1], "rb");
    34. if( f ){
    35. fseek(f,0,SEEK_END);
    36. const long size = ftell(f);
    37. rewind(f);
    38. char * buff = (char*)malloc(size);
    39. size_t size_read = fread( (void*)buff, 1, size, f );
    40. if( size_read != size ){
    41. puts("cannot read file!");
    42. } else{
    43. puts("file opened ok.");
    44. int found = 0;
    45. size_t pos = 0, end = 0;
    46. char tmp[256];
    47. while(1){
    48. pos = seek_png_start( buff, end, size );
    49. end = seek_png_end( buff, pos+1, size );
    50. if( pos == -1 || end == -1 ){ break; }
    51. sprintf(tmp,"file_%i.png",found++);
    52. FILE * out = fopen(tmp,"wb");
    53. if( out ){
    54. fwrite( buff+pos, 1, end-pos+png_end_size, out );
    55. fclose(out);
    56. }
    57. };
    58. printf("\nfound %i png files.\n",found);
    59. }
    60. free(buff);
    61. fclose(f);
    62. } else{
    63. puts("cannot open file!");
    64. }
    65. }
    66. return 0;
    67. }
    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.
    Last edited by stampede; 28th September 2011 at 09:03.

  3. The following user says thank you to stampede for this useful post:

    tenggui_fu (26th December 2013)

  4. #3
    Join Date
    Sep 2011
    Location
    Mannheim, Germany
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extract resources from compiled Qt4 programm?

    Thank alot ! I will try it.

Similar Threads

  1. Replies: 3
    Last Post: 20th September 2010, 22:36
  2. How can i add a ProgressIndicator to my programm?
    By Bong.Da.City in forum Qt Programming
    Replies: 1
    Last Post: 23rd August 2010, 21:36
  3. Why my programm is asking for libssl.so.7?
    By gboelter in forum Newbie
    Replies: 2
    Last Post: 29th September 2009, 12:23
  4. Compiled resources in shared library
    By magland in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2007, 04:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.