-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgenerate_symbol_idc.idc
More file actions
172 lines (131 loc) · 3.83 KB
/
Copy pathgenerate_symbol_idc.idc
File metadata and controls
172 lines (131 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
//Symbol dump Script
//by tomsons26
//Writes symbols to a runnable idc script
//
//PROBABLY_TODO
//hhmmmm
#include <idc.idc>
#include "badnames.idc"
#define Script_Version "0.58.0"
//Binary alignment thats typically between functions
#define Alignment 4
static main()
{
auto Just_Functions, SpecificString, Filter;
auto Segment_Start, Segment_End;
auto Path, Handle;
auto IDB_Path, Input_Filename, Checksum;
//Check if currently read segment has good start and end addresses
Segment_Start = FirstSeg();
Segment_End = SegEnd(Segment_Start);
if (Segment_Start == BADADDR || Segment_End == BADADDR)
{
return;
}
//Ask should only function names be written excluding data
Just_Functions = AskYN(0, "Write only function names?");
//If got -1(Cancel) stop execution
if(Just_Functions == -1)
{
return;
}
//Show Save as dialog
Filter = AskYN(0, "Write only symbols with a specific string?");
//If got -1(Cancel) stop execution
if(Filter == -1)
{
return;
}
SpecificString = "";
if (Filter){
SpecificString = AskStr("", "Type In string to filter.\nCase Sensitive!\nLeave black for all");
}
//Show Save as dialog
Path = AskFile(1, "*.idc", "Save idc script");
if (Path == "")
{
return;
}
Handle = fopen(Path, "wb");
if (!Handle)
{
return;
}
fprintf(Handle,"//\n" "//Symbol Name Script V%s\n", Script_Version);
fprintf(Handle,"//\n//Alignment set in script was %d dwords\n", Alignment);
//Get info
IDB_Path = GetIdbPath();
// Instead of full Path could get just filename, might be useful for public dumps.
//Input_Filename = GetInputFile()
Checksum = GetInputMD5();
//Print db Path and MD5 as a comment for safety sake to confirm its the correct IDB
//fprintf(Handle,"//\n//IDB Path for this IDB was %s\n", IDB_Path);
//Message("//Filename for the binary was %s\n", Input_Filename );
//Print Checksum definition
fprintf(Handle,"\n#define Checksum \"%s\"\n\n", Checksum);
//Print idc headers
fprintf(Handle,"#include <idc.idc>\n\n""static main(void)\n");
//Print symbol frame start
fprintf(Handle,"{\n");
//Print Checksum check function
fprintf(Handle," if (GetInputMD5() != Checksum)\n {\n");
fprintf(Handle," Message(\"Checksum does not match current IDB!\\n\");\n");
fprintf(Handle," return;\n }\n");
//Start dumping symbol names
Print_Symbol_Info(Handle, Just_Functions, SpecificString);
//Print symbol frame start
fprintf(Handle,"}");
//Close file
fclose(Handle);
}
static String_Is_Present(check, string)
{
if (strstr(check, string) != -1) {
return 1;
}
return 0;
}
static Print_Symbol_Info(Handle, Is_Just_Functions, SpecificString)
{
auto Segment_Start, Segment_End;
auto Symbol_Address, Item_Flags, String;
auto process;
do
{
Segment_Start = NextSeg(Segment_Start);
Segment_End = SegEnd(Segment_Start);
}
while (Segment_Start != BADADDR && Segment_End != BADADDR);
Segment_Start = FirstSeg();
Segment_End = SegEnd(Segment_Start);
while(1)
{
if (Segment_Start == BADADDR || Segment_End == BADADDR) {
break;
}
Symbol_Address = Segment_Start;
while (Symbol_Address < Segment_End)
{
String = GetTrueNameEx(BADADDR, Symbol_Address);
process = 1;
if (SpecificString != "") {
process = String_Is_Present(String, SpecificString);
}
if (process && Check_For_Bad_Name(String) == 0)
{
Item_Flags = GetFlags(Symbol_Address);
if (!Is_Just_Functions || (Item_Flags & FF_CODE) == FF_CODE)
{
fprintf(Handle, " MakeName (0x%X, \"%s\");\n", Symbol_Address, String);
}
}
//Check for valid symbols within defined Alignment dword boundries
//4 bytes is typically the alignment before functions
//Extend if needed for binary
Symbol_Address = Symbol_Address + Alignment;
}
Segment_Start = NextSeg(Segment_Start);
Segment_End = SegEnd(Segment_Start);
}
}