-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkallsyms_to_makecode.py
60 lines (40 loc) · 1.03 KB
/
kallsyms_to_makecode.py
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
import re
import os
import sys
# thanks to Maciej Klimas
def usage():
print("%s <path to kallsyms>" % sys.argv[0] )
print("%s /proc/kallsyms" % sys.argv[0] )
def main():
prefix = """
#define UNLOADED_FILE 1
#include <idc.idc>
static main(void)
{
"""
suffix = '}'
format = '\tMakeCode\t (0x%s);'
regex = re.compile( r'([a-fA-Z0-9]+) \w (\w+)' )
#if( len(sys.argv) != 2 ):
# return usage()
kallsymsPath = "kallsyms.txt"
f = open( kallsymsPath, "r" )
if None == f:
print("Unable to open %s.\n", kallsymsPath )
return -3
f1 = open( "code.idc", "w")
f1.write( "// Enabling addresses...")
#cmd = 'echo 1 > /proc/sys/kernel/kptr_restrict'
#os.system( cmd )
f1.write(prefix)
lines = f.readlines()
for line in lines:
match = regex.match(line)
if( match != None ):
f1.write( format % (match.group(1)) )
f.close()
f1.write(suffix)
f1.close()
return 0
if __name__ == '__main__':
main()