home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ida35bc.zip / RESOURCE.IDC < prev    next >
Text File  |  1996-01-29  |  10KB  |  321 lines

  1. //
  2. //    This is an example how New Executable Format resources can be
  3. //    analysed. In this example we analyse Version Information resource
  4. //    type only.
  5. //    You can write functions to analyse other types too.
  6. //
  7. //    P.S. I don't think that this way of analysing is useful.
  8. //    Better if you use some other program to analyse resources.
  9. //    I myself never wrote programs for MS Windows and never disassembled
  10. //    them. If you feel that IDA should disassemble resources too,
  11. //    please let me know. If many people will ask me to do it, I'll
  12. //    implement it.
  13. //
  14. //            Ilfak Guilfanov, 24.02.94
  15. //
  16.  
  17. //-------------------------------------------------------------------
  18. static nextResource(ea) {    // find next resource
  19.   auto next;
  20.   auto name;
  21.  
  22.   next = ea;
  23.   while ( (next=NextSeg(next)) != -1 ) {
  24.     name = SegName(next);
  25.     if ( substr(name,0,3) == "res" ) break;    // Yes, this is a resource
  26.   }
  27.   return next;
  28. }
  29.  
  30. //-------------------------------------------------------------------
  31. static getResourceType(cmt) {
  32.   auto i;
  33.   i = strstr(cmt,"(");
  34.   if ( i != -1 ) {
  35.     i = i + 1;
  36.     return xtol(substr(cmt,i,i+4));    // get type of the resource
  37.   }
  38.   return 0;                // couldn't determine rsc type
  39. }
  40.  
  41. //-------------------------------------------------------------------
  42. static getResourceID(cmt) {
  43.   auto i;
  44.   i = strstr(cmt,":");
  45.   if ( i != -1 ) {
  46.     i = i + 1;
  47.     return long(substr(cmt,i,-1));    // get ID of the resource
  48.   }
  49.   return 0;                // couldn't determine rsc ID
  50. }
  51.  
  52. //-------------------------------------------------------------------
  53. static ResourceCursor(ea,id) {
  54.   Message(form("Cursor, id: %ld\n",id));
  55. }
  56.  
  57. //-------------------------------------------------------------------
  58. static ResourceBitmap(ea,id) {
  59.   Message(form("Bitmap, id: %ld\n",id));
  60. }
  61.  
  62. //-------------------------------------------------------------------
  63. static ResourceIcon(ea,id) {
  64.   Message(form("Icon, id: %ld\n",id));
  65. }
  66.  
  67. //-------------------------------------------------------------------
  68. static ResourceMenu(ea,id) {
  69.   Message(form("Menu, id: %ld\n",id));
  70. }
  71.  
  72. //-------------------------------------------------------------------
  73. static ResourceDbox(ea,id) {
  74.   Message(form("Dbox, id: %ld\n",id));
  75. }
  76.  
  77. //-------------------------------------------------------------------
  78. static ResourceStrT(ea,id) {
  79.   Message(form("String Table, id: %ld\n",id));
  80. }
  81.  
  82. //-------------------------------------------------------------------
  83. static ResourceFontDir(ea,id) {
  84.   Message(form("FontDir, id: %ld\n",id));
  85. }
  86.  
  87. //-------------------------------------------------------------------
  88. static ResourceFont(ea,id) {
  89.   Message(form("Font, id: %ld\n",id));
  90. }
  91.  
  92. //-------------------------------------------------------------------
  93. static ResourceAccl(ea,id) {
  94.   Message(form("Accelerator, id: %ld\n",id));
  95. }
  96.  
  97. //-------------------------------------------------------------------
  98. static ResourceData(ea,id) {
  99.   Message(form("Resource Data, id: %ld\n",id));
  100. }
  101.  
  102. //-------------------------------------------------------------------
  103. static ResourceCurDir(ea,id) {
  104.   Message(form("Cursor Dir, id: %ld\n",id));
  105. }
  106.  
  107. //-------------------------------------------------------------------
  108. static ResourceIconDir(ea,id) {
  109.   Message(form("Icon Dir, id: %ld\n",id));
  110. }
  111.  
  112. //-------------------------------------------------------------------
  113. static ResourceName(ea,id) {
  114.   Message(form("Cursor, id: %ld\n",id));
  115. }
  116.  
  117. //-------------------------------------------------------------------
  118. static ResourceVersion(ea,id) {
  119.  
  120.   Message(form("Version info, id: %ld\n",id));
  121.  
  122.   ea = AnalyseVBlock(ea,0);
  123. }
  124.  
  125. //-------------------------------------------------------------------
  126. static ConvertToStr(vea,len) {
  127.   auto ea;
  128.   auto slen;
  129.   ea = vea;
  130.   for ( ea=vea; len > 0; vea = ea ) {
  131.     while ( Byte(ea) != 0 ) ea = ea + 1;
  132.     ea = ea + 1;
  133.     slen = ea - vea;
  134.     MakeStr(vea,slen);
  135.     len = len - slen;
  136.   }
  137. }
  138.  
  139. //-------------------------------------------------------------------
  140. static Pad32(ea) {
  141.   auto vea;
  142.   vea = (ea + 3) & ~3;            // align to 32-bit boundary
  143.   if ( vea != ea ) {            // extra bytes found
  144.     MakeArray(ea,vea-ea);
  145.     MakeComm(ea,"Padding bytes");
  146.   }
  147.   return vea;
  148. }
  149.  
  150. //-------------------------------------------------------------------
  151. static AnalyseVBlock(ea,blnum) {
  152.   auto key,block,vsize,x,vea,keyea;
  153.   auto blstart,blend;
  154.  
  155.   blstart = ea;                // save block start
  156.  
  157.   block = Word(ea);
  158.   MakeName(ea,form("rscVinfoBlSize_%ld",blnum));
  159.   MakeWord(ea);
  160.   OpNum(ea);
  161.  
  162.   ea = ea + 2;
  163.   vsize = Word(ea);
  164.   MakeName(ea,form("rscVinfoValSize_%ld",blnum));
  165.   MakeWord(ea);
  166.   OpNum(ea);
  167.  
  168.   ea = ea + 2;
  169.   keyea = ea;
  170.   MakeName(key,form("rscVinfoKey_%ld",blnum));
  171.   key = "";
  172.   while ( Byte(ea) != 0 ) {
  173.     key = key + char(Byte(ea));
  174.     ea = ea + 1;
  175.   }
  176.   ea = ea + 1;
  177.   MakeStr(keyea,ea-keyea);
  178.  
  179.   vea = Pad32(ea);
  180.  
  181.   MakeName(vea, form("rscVinfoValue_%ld",blnum));
  182.  
  183.   blend = vea + vsize;            // find block end
  184.  
  185. //  Message(form("At %lX key is: ",keyea) + key + "\n");
  186.  
  187.   if      ( key == "VS_VERSION_INFO" ) {
  188.  
  189.       ;    // nothing to do
  190.  
  191.   } else if ( key == "VarFileInfo"     ) {
  192.  
  193.       ;    // nothing to do
  194.  
  195.   } else if ( key == "Translation"     ) {
  196.  
  197.     for ( ea=vea; ea < blend; ea=ea+4 ) {
  198.       auto lang,charset;
  199.  
  200.       lang = Word(ea);
  201.       charset = Word(ea+2);
  202.  
  203.     if      ( lang == 0x0401 ) lang = "Arabic";
  204.     else if ( lang == 0x0402 ) lang = "Bulgarian";
  205.     else if ( lang == 0x0403 ) lang = "Catalan";
  206.     else if ( lang == 0x0404 ) lang = "Traditional Chinese";
  207.     else if ( lang == 0x0405 ) lang = "Czech";
  208.     else if ( lang == 0x0406 ) lang = "Danish";
  209.     else if ( lang == 0x0407 ) lang = "German";
  210.     else if ( lang == 0x0408 ) lang = "Greek";
  211.     else if ( lang == 0x0409 ) lang = "U.S. English";
  212.     else if ( lang == 0x040A ) lang = "Castilian Spanish";
  213.     else if ( lang == 0x040B ) lang = "Finnish";
  214.     else if ( lang == 0x040C ) lang = "French";
  215.     else if ( lang == 0x040D ) lang = "Hebrew";
  216.     else if ( lang == 0x040E ) lang = "Hungarian";
  217.     else if ( lang == 0x040F ) lang = "Icelandic";
  218.     else if ( lang == 0x0410 ) lang = "Italian";
  219.     else if ( lang == 0x0411 ) lang = "Japanese";
  220.     else if ( lang == 0x0412 ) lang = "Korean";
  221.     else if ( lang == 0x0413 ) lang = "Dutch";
  222.     else if ( lang == 0x0414 ) lang = "Norwegian - Bokmal";
  223.     else if ( lang == 0x0415 ) lang = "Polish";
  224.     else if ( lang == 0x0416 ) lang = "Brazilian Portuguese";
  225.     else if ( lang == 0x0417 ) lang = "Rhaeto-Romanic";
  226.     else if ( lang == 0x0418 ) lang = "Romanian";
  227.     else if ( lang == 0x0419 ) lang = "Russian";
  228.     else if ( lang == 0x041A ) lang = "Croato-Serbian (Latin)";
  229.     else if ( lang == 0x041B ) lang = "Slovak";
  230.     else if ( lang == 0x041C ) lang = "Albanian";
  231.     else if ( lang == 0x041D ) lang = "Swedish";
  232.     else if ( lang == 0x041E ) lang = "Thai";
  233.     else if ( lang == 0x041F ) lang = "Turkish";
  234.     else if ( lang == 0x0420 ) lang = "Urdu";
  235.     else if ( lang == 0x0421 ) lang = "Bahasa";
  236.     else if ( lang == 0x0804 ) lang = "Simplified Chinese";
  237.     else if ( lang == 0x0807 ) lang = "Swiss German";
  238.     else if ( lang == 0x0809 ) lang = "U.K. English";
  239.     else if ( lang == 0x080A ) lang = "Mexican Spanish";
  240.     else if ( lang == 0x080C ) lang = "Belgian French";
  241.     else if ( lang == 0x0810 ) lang = "Swiss Italian";
  242.     else if ( lang == 0x0813 ) lang = "Belgian Dutch";
  243.     else if ( lang == 0x0814 ) lang = "Norwegian - Nynorsk";
  244.     else if ( lang == 0x0816 ) lang = "Portuguese";
  245.     else if ( lang == 0x081A ) lang = "Serbo-Croatian (Cyrillic)";
  246.     else if ( lang == 0x0C0C ) lang = "Canadian French";
  247.     else if ( lang == 0x100C ) lang = "Swiss French";
  248.  
  249.     if      ( charset == 0    ) charset = "7-bit ASCII";
  250.     else if ( charset == 932  ) charset = "Windows, Japan (Shift - JIS X-0208)";
  251.     else if ( charset == 949  ) charset = "Windows, Korea (Shift - KSC 5601)";
  252.     else if ( charset == 950  ) charset = "Windows, Taiwan (GB5)";
  253.     else if ( charset == 1200 ) charset = "Unicode";
  254.     else if ( charset == 1250 ) charset = "Windows, Latin-2 (Eastern European)";
  255.     else if ( charset == 1251 ) charset = "Windows, Cyrillic";
  256.     else if ( charset == 1252 ) charset = "Windows, Multilingual";
  257.     else if ( charset == 1253 ) charset = "Windows, Greek";
  258.     else if ( charset == 1254 ) charset = "Windows, Turkish";
  259.     else if ( charset == 1255 ) charset = "Windows, Hebrew";
  260.     else if ( charset == 1256 ) charset = "Windows, Arabic";
  261.  
  262.     MakeComm(ea,"Language: " + lang);
  263.     MakeWord(ea);
  264.     OpNum(ea);
  265.     MakeComm(ea+2,"Character set: " + charset);
  266.     MakeWord(ea+2);
  267.     OpNum(ea+2);
  268.  
  269.     }
  270.   } else if ( key == "StringFileInfo"  ) {
  271.  
  272.       ConvertToStr(vea,vsize);
  273.  
  274.   } else {
  275.       ConvertToStr(vea,vsize);
  276.   }
  277.  
  278.   blend = Pad32(blend);
  279.   ExtLinB(blend,0,";------------------------------------------------------");
  280.   blnum = (blnum+1) * 10;        // nested block number
  281.   while ( (blend-blstart) < block ) {    // nested block exist
  282.     Message(form("Nested block at %lX\n",blend));
  283.     MakeComm(blend,form("Nested block...%ld",blnum));
  284.     blend = AnalyseVBlock(blend,blnum);
  285.     blnum = blnum + 1;
  286.   }
  287.   return blend;
  288. }
  289.  
  290. //-------------------------------------------------------------------
  291. static main(void) {
  292.   auto ea;
  293.   auto type,id;
  294.  
  295.   Message("Searching for resources...\n");
  296.   ea = FirstSeg();
  297.   while ( (ea=nextResource(ea)) != -1 ) {
  298.     Message(form("Found a resource at %08lX, name: ",ea) + SegName(ea) + "\n");
  299.     type = getResourceType(LineA(ea,0));    // get rsc type
  300.     id   = getResourceID(LineA(ea,3));        // get rsc id
  301.     if      ( type == 0x8001 )    ResourceCursor(ea,id);
  302.     else if ( type == 0x8002 )    ResourceBitmap(ea,id);
  303.     else if ( type == 0x8003 )    ResourceIcon(ea,id);
  304.     else if ( type == 0x8004 )    ResourceMenu(ea,id);
  305.     else if ( type == 0x8005 )    ResourceDbox(ea,id);
  306.     else if ( type == 0x8006 )    ResourceStrT(ea,id);
  307.     else if ( type == 0x8007 )    ResourceFontDir(ea,id);
  308.     else if ( type == 0x8008 )    ResourceFont(ea,id);
  309.     else if ( type == 0x8009 )    ResourceAccl(ea,id);
  310.     else if ( type == 0x800A )    ResourceData(ea,id);
  311.  
  312.     else if ( type == 0x800C )    ResourceCurDir(ea,id);
  313.  
  314.     else if ( type == 0x800E )    ResourceIconDir(ea,id);
  315.     else if ( type == 0x800F )    ResourceName(ea,id);
  316.     else if ( type == 0x8010 )    ResourceVersion(ea,id);
  317.     else Message(form("Unknown resource type %04lX\n",type));
  318.   }
  319.   Message("Done.\n");
  320. }
  321.