plugin: new simple findptr plugin
[ia32rtools.git] / ida / findptr / findptr.cpp
1 /*
2  * ia32rtools
3  * (C) notaz, 2015
4  *
5  * This work is licensed under the terms of 3-clause BSD license.
6  * See COPYING file in the top-level directory.
7  */
8
9 #define NO_OBSOLETE_FUNCS
10 #include <ida.hpp>
11 #include <idp.hpp>
12 #include <bytes.hpp>
13 #include <loader.hpp>
14 #include <kernwin.hpp>
15
16 //--------------------------------------------------------------------------
17 static int idaapi init(void)
18 {
19   return PLUGIN_OK;
20 }
21
22 //--------------------------------------------------------------------------
23 static void idaapi term(void)
24 {
25 }
26
27 //--------------------------------------------------------------------------
28
29 static void idaapi run(int /*arg*/)
30 {
31   bool found = false;
32   flags_t ea_flags;
33   uint32 val;
34   ea_t ea;
35
36   ea = get_screen_ea();
37   // msg("range: %x/%x-%x\n", ea, inf.minEA, inf.maxEA);
38
39   ea = next_unknown(ea, inf.maxEA);
40   for (; ea != BADADDR; ea = next_unknown(ea, inf.maxEA))
41   {
42     segment_t *seg = getseg(ea);
43     if (!seg)
44       break;
45     if (seg->type != SEG_DATA)
46       continue;
47
48     ea_flags = getFlags(ea);
49     if (!hasValue(ea_flags))
50       continue;
51     val = get_long(ea);
52     if (inf.minEA <= val && val < inf.maxEA) {
53       found = 1;
54       break;
55     }
56   }
57
58   if (found) {
59     // msg("%x: jmp\n", ea);
60     jumpto(ea);
61   }
62   else
63     msg("end reached.\n");
64 }
65
66 //--------------------------------------------------------------------------
67
68 static const char comment[] = "Find next pointer-like data";
69 static const char help[] = "Find next pointer-like data\n";
70 static const char wanted_name[] = "Find next ptr-like";
71 static const char wanted_hotkey[] = "Shift-N";
72
73 //--------------------------------------------------------------------------
74 //
75 //      PLUGIN DESCRIPTION BLOCK
76 //
77 //--------------------------------------------------------------------------
78 plugin_t PLUGIN =
79 {
80   IDP_INTERFACE_VERSION,
81   0,                    // plugin flags
82   init,                 // initialize
83   term,                 // terminate. this pointer may be NULL.
84   run,                  // invoke plugin
85   comment,              // long comment about the plugin
86                         // it could appear in the status line
87                         // or as a hint
88   help,                 // multiline help about the plugin
89   wanted_name,          // the preferred short name of the plugin
90   wanted_hotkey         // the preferred hotkey to run the plugin
91 };
92
93 // vim:ts=2:shiftwidth=2:expandtab