1+ #include < windows.h>
2+
3+ #include < ida.hpp>
4+ #include < idp.hpp>
5+ #include < loader.hpp>
6+ #include < diskio.hpp>
7+ #include < graph.hpp>
8+ #include < kernwin.hpp>
9+
10+ #include < string>
11+ #include < iostream>
12+ #include < fstream>
13+
14+ #include < boost/regex.hpp>
15+
16+ using namespace std ;
17+
18+ int IDAP_init (void )
19+ {
20+ // Do checks here to ensure your plug-in is being used within
21+ // an environment it was written for. Return PLUGIN_SKIP if the
22+ // checks fail, otherwise return PLUGIN_KEEP.
23+ return PLUGIN_KEEP;
24+ }
25+ void IDAP_term (void )
26+ {
27+ // Stuff to do when exiting, generally you'd put any sort
28+ // of clean-up jobs here.
29+ return ;
30+ }
31+
32+ // The plugin can be passed an integer argumenct from the plugins.cfg
33+ // file. This can be useful when you want the one plug-in to do
34+ // something different depending on the hot-key pressed or menu
35+ // item selected.
36+ void IDAP_run (int arg)
37+ {
38+ // The "meat" of your plug-in
39+ ea_t cur_ea;
40+ char * trace_name = NULL ;
41+ FILE* fin;
42+ string cur_line, instruction, annotation;
43+ ifstream trace_file;
44+ unsigned int annotation_pos = 0 ;
45+ boost::regex trace_re (" ((?:\\ d|\\ w)+)\\ : \\ w+\\ s+.+\\ # ((?:\\ w+: (?:\\ w|\\ d)+(?:\\ s,\\ s)*)*)" );
46+ boost::regex instruction_re (" ((?:[0-9]|[a-f])+)" );
47+ boost::cmatch instruction_matches;
48+
49+ msg (" Annotated Tracing Plugin 1.0\n " );
50+ // cur_ea = get_screen_ea();
51+ // describe(cur_ea, 0, "test comment!");
52+ // set_cmt(cur_ea, "test comment!", false);
53+ trace_name = askfile_c (0 ," instrtrace.trace" ," Select the instruction trace file" );
54+ msg (" Selected file: %s\n " , trace_name);
55+
56+ if (trace_name)
57+ {
58+ trace_file.open (trace_name);
59+ while (!trace_file.eof ())
60+ {
61+ annotation_pos = 0 ;
62+ getline (trace_file, cur_line);
63+
64+ // if (!boost::regex_search(cur_line, trace_re))
65+ {
66+ // continue;
67+ }
68+
69+ /* boost::regex_search(cur_line.c_str(), instruction_matches, instruction_re);
70+
71+ if(!instruction_matches.empty())
72+ {
73+ instruction = string(instruction_matches[1].first, instruction_matches[1].second);
74+ }*/
75+
76+ // msg(instruction.c_str());
77+
78+ instruction = cur_line.substr (0 , 7 );
79+ cur_ea = strtol (instruction.c_str (), NULL , 16 );
80+
81+ annotation_pos = cur_line.find (" #" );
82+ // set_cmt(strtol(instruction.c_str(), NULL, 16), "TEST!", false);
83+ set_item_color (cur_ea, 0x32CD32 );
84+ if (annotation_pos != 0 )
85+ {
86+ annotation = cur_line.substr (annotation_pos+1 );
87+ set_cmt (cur_ea, annotation.c_str (), false );
88+ }
89+ // msg(cur_line.c_str());
90+ }
91+ }
92+
93+ /* for annotation in annotations.split(", "):
94+ if len(annotation.split("ptr_val[]:")) == 2:
95+ if cmt_tbl.has_key(instruction):
96+ cmt_tbl[instruction] += ', ' + annotation.split("ptr_val[]:")[1].strip()#annotation.split("ptr_val[]:")[0].strip() + ' "' + annotation.split("ptr_val[]:")[1].strip() + '"'
97+ else:
98+ cmt_tbl[instruction] = annotation.split("ptr_val[]:")[1].strip()#annotation.split("ptr_val[]:")[0].strip() + ' "' + annotation.split("ptr_val[]:")[1].strip() + '"'
99+
100+ original_cmt = GetCommentEx(int(instruction,16), 0)
101+ if original_cmt == None:
102+ original_cmt = ''
103+ MakeComm(int(instruction, 16), str(original_cmt) + annotation.split("ptr_val[]:")[1].strip())
104+
105+ SetColor(int(instruction, 16), CIC_ITEM, 0x32CD32)*/
106+
107+ return ;
108+ }
109+ // There isn't much use for these yet, but I set them anyway.
110+ char IDAP_comment[] = " This is my test plug-in" ;
111+ char IDAP_help[] = " My plugin" ;
112+ // The name of the plug-in displayed in the Edit->Plugins menu. It
113+ // can be overridden in the user's plugins.cfg file.
114+ char IDAP_name[] = " Annotated Tracing" ;
115+ // The hot-key the user can use to run your plug-in.
116+ char IDAP_hotkey[] = " Alt-1" ;
117+ // The all-important exported PLUGIN object
118+ plugin_t PLUGIN =
119+ {
120+ IDP_INTERFACE_VERSION, // IDA version plug-in is written for
121+ 0 , // Flags (see below)
122+ IDAP_init, // Initialisation function
123+ IDAP_term, // Clean-up function
124+ IDAP_run, // Main plug-in body
125+ IDAP_comment, // Comment – unused
126+ IDAP_help, // As above – unused
127+ IDAP_name, // Plug-in name shown in
128+ // Edit->Plugins menu
129+ IDAP_hotkey // Hot key to run the plug-in
130+ };
0 commit comments