home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Quines / files / search.cpp < prev   
Encoding:
C/C++ Source or Header  |  2000-05-25  |  3.6 KB  |  135 lines

  1. // Search v0.5 beta
  2. // Plugin module for IDA Pro v3.84
  3. // written by Quine (quine@blacksun.res.cmu.edu)
  4. // visit Quine's IDA Page at http://surf.to/quine_ida
  5.  
  6. #include <ida.hpp>
  7. #include <idp.hpp>
  8. #include <loader.hpp>
  9. #include <kernwin.hpp>
  10. #include <bytes.hpp>
  11. #include <ua.hpp>
  12. #include <nalt.hpp>
  13. #include <funcs.hpp>
  14. #include <enum.hpp>
  15.  
  16. ulong prev_imm;
  17. int imm_opn = -1;
  18.  
  19. int init(void)
  20. {
  21.   return PLUGIN_OK;
  22. }
  23.  
  24. void term(void)
  25. {
  26. }
  27.  
  28. ea_t find_code_imm(ea_t start_ea, ulong imm_val) {
  29.     ea_t ea = start_ea;
  30.     ea_t found_ea = BADADDR;
  31.     func_t *pfn;
  32.  
  33.     do {
  34.  
  35.         // skip over any hidden functions
  36.         if ( pfn = get_func(ea) ) {
  37.             if ( !is_visible_func(pfn) ) {
  38.                 continue;
  39.             }
  40.         }
  41.  
  42.         // disassemble the current instruction
  43.         ua_ana0(ea);
  44.  
  45.         // loop through all the operands in current insn to see if they
  46.         // contain an immediate op with the value we're looking for
  47.         for ( int i = 0; i<3; i++ ) {
  48.             if ( cmd.Operands[i].type == o_imm ) {
  49.                 if ( cmd.Operands[i].value == imm_val ) {
  50.                     found_ea = ea;
  51.                     imm_opn = i;
  52.                 }
  53.             }
  54.         }
  55.  
  56.     } while ( (found_ea == BADADDR) && ((ea = nextThat(ea, isCode)) != BADADDR) );
  57.  
  58.     return found_ea;
  59. }
  60.  
  61. void run(int arg)
  62. {
  63.     ulong imm = 0;
  64.     imm_opn = -1;
  65.     msg("arg: %i\n", arg);
  66.     if ( arg == 0 ) {
  67.         callui(ui_asklong, &imm, "Enter the immediate value to search for:");
  68.         prev_imm = imm;
  69.     } else if (arg == 1 ) {
  70.         imm = prev_imm;
  71.     } else {
  72.         return;
  73.     }
  74.     ea_t ea = find_code_imm(nextThat(get_screen_ea(), isCode), imm);
  75.     if ( ea != BADADDR ) {
  76.         jumpto(ea, imm_opn);
  77.         msg("Found immediate value 0x%x at %08X.\n", imm, ea);
  78.     } else {
  79.         beep();
  80.         msg("Immediate value 0x%x not found.\n", imm);
  81.     }
  82. }
  83.  
  84. //--------------------------------------------------------------------------
  85. char comment[] = "This implements some new search functions.";
  86.  
  87. char help[] =
  88.         "A sample plugin module\n"
  89.         "\n"
  90.         "This module shows you how to create plugin modules.\n"
  91.         "\n"
  92.         "It does nothing useful - just prints a message that is was called\n"
  93.         "and shows the current address.\n";
  94.  
  95.  
  96. //--------------------------------------------------------------------------
  97. // This is the preferred name of the plugin module in the menu system
  98. // The preferred name may be overriden in plugins.cfg file
  99.  
  100. char wanted_name[] = "Search plugin";
  101.  
  102.  
  103. // This is the preferred hotkey for the plugin module
  104. // The preferred hotkey may be overriden in plugins.cfg file
  105. // Note: IDA won't tell you if the hotkey is not correct
  106. //       It will just disable the hotkey.
  107.  
  108. char wanted_hotkey[] = "Alt-F7";
  109.  
  110.  
  111. //--------------------------------------------------------------------------
  112. //
  113. //      PLUGIN DESCRIPTION BLOCK
  114. //
  115. //--------------------------------------------------------------------------
  116.  
  117. extern "C" plugin_t PLUGIN = {
  118.   IDP_INTERFACE_VERSION,
  119.   0,                    // plugin flags
  120.   init,                 // initialize
  121.  
  122.   term,                 // terminate. this pointer may be NULL.
  123.  
  124.   run,                  // invoke plugin
  125.  
  126.   comment,              // long comment about the plugin
  127.                         // it could appear in the status line
  128.                         // or as a hint
  129.  
  130.   help,                 // multiline help about the plugin
  131.  
  132.   wanted_name,          // the preferred short name of the plugin
  133.   wanted_hotkey         // the preferred hotkey to run the plugin
  134. };
  135.