-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkallsyms_loader.idc
107 lines (92 loc) · 2.2 KB
/
kallsyms_loader.idc
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
/* kallsyms loader */
/* by goroh_kun */
/* modified from H2enum Version 1.09 */
#include <idc.idc>
// returns -1 if symbol is NOT 'space'
static is_space(c)
{
return strstr(" \t\r\n\b",c);
}
// strip leading blank characters from string.
static ltrim(str)
{
auto pos,c,l;
l = strlen(str);
pos = 0;
while (pos < l)
{
c = substr(str,pos,pos+1);
if (is_space(c) == -1) break;
pos++;
}
return substr(str,pos,-1);
}
// strip trailing blank characters from string.
static rtrim(str)
{
auto pos,c;
pos = strlen(str);
while (pos > 0)
{
c = substr(str,pos-1,pos);
if (is_space(c) == -1) break;
pos--;
}
return substr(str,0,pos);
}
// Find first delimiter position in string (SPACE or TAB).
static FindDelim(str)
{
auto pos1,pos2;
pos1 = strstr(str," ");
pos2 = strstr(str,"\t");
if (pos1 == -1) return pos2;
if (pos2 == -1) return pos1;
if (pos1 < pos2) return pos1;
else return pos2;
}
// Main conversion routine
static load_kallsyms(fname)
{
auto def_addr, def_name, def_type;
auto hFile,in_str,pos,str_no,c;
if ((hFile=fopen(fname,"r")) == 0)
{
Warning("Couldn't open file '%s'!",fname);
return -1;
}
Message("Conversion started...\n");
str_no = 0;
while ((in_str=readstr(hFile)) != -1)
{
str_no++;
pos = FindDelim(in_str);
def_addr = xtol(substr(in_str, 0, pos));
in_str = substr(in_str, pos + 1, -1);
pos = FindDelim(in_str);
def_type = substr(in_str, 0, pos);
in_str = substr(in_str, pos + 1, -1);
def_name = trim(in_str);
if (def_type == 'T' || def_type == 't') MakeCode(def_addr);
if(0 == MakeNameEx(def_addr, def_name, SN_NOCHECK | SN_NOWARN | SN_AUTO)){
auto i;
for(i=1; i<100; i++){
def_name = def_name + "_" + ltoa(i, 10);
if(0 != MakeNameEx(def_addr, def_name, SN_NOCHECK | SN_NOWARN | SN_AUTO)){
break;
}
}
}
Message("name %s = '%08x'(%s)\n", def_name, def_addr, def_type);
}
fclose(hFile);
Message("Successful %d elements imported.\n", str_no);
return 0;
}
static main()
{
auto fname;
fname = AskFile(0,"*.txt","Choose a kallsyms file to parse:");
if (fname == "") return;
load_kallsyms(fname);
}