-
Notifications
You must be signed in to change notification settings - Fork 9
/
kprofile.py
executable file
·86 lines (61 loc) · 2.39 KB
/
kprofile.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
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
fileList = ['disasm.lst', 'disacpica.txt', 'disclipdraw.txt', 'dissys.txt', 'disvesa.txt', 'disvga.txt', 'dislegacy.txt']
driverList = ['', 'acpica', 'clipdraw', 'system', 'vesa', 'vga', 'legacy']
lines = open('C:/Users/Alex/Desktop/banana-os/log3.txt').read().split('\n')
def getDriverBaseAddr(name):
global lines
for line in lines:
try:
if line.startswith('@<<: '):
filepath = line.split(' ')[1].split('/')[-1].split('.')[0].strip()
if filepath == name:
return int(line.split(' ')[2], 16)
except Exception as e:
print(e)
pass
return 0
addrLookupMap = dict()
funcName = ''
print('Building function map...')
for i, j in zip(fileList, driverList):
additionalAddr = 0x0
if i != 'disasm.lst':
additionalAddr = getDriverBaseAddr(i.split('.')[0].split('dis')[1]) - 0x10000000
if additionalAddr == -0x10000000:
continue
disasm = open('C:/Users/Alex/Desktop/Banana/disasms/' + i).readlines()
for line in disasm:
try:
addr = int(line[0:8], 16)
if line[8] == ' ':
funcName = line.split('<')[1].split('>')[0]
addrLookupMap[addr + additionalAddr] = funcName
except Exception as e:
pass
print('Scanning logs...')
counterDict = dict()
totalLines = len(lines)
currentLine = 0
prevPercent = 0
for line in lines:
percentComplete = currentLine / totalLines * 100
if int(percentComplete) != int(prevPercent):
prevPercent = percentComplete
print('{:.1f}% complete'.format(prevPercent))
if line.startswith('@:> '):
try:
addr = int(line.split(' ')[1], 16)
funcName = addrLookupMap[addr]
if funcName in counterDict:
counterDict[funcName] += 1
else:
counterDict[funcName] = 1
prevAddr = addr
except:
pass
currentLine += 1
print('100% complete')
print('Sorting {} items...'.format(len(counterDict)))
sortedDict = sorted(counterDict.items(), key=lambda kv: kv[1], reverse=True)
for k, v in sortedDict:
print('{:9d} '.format(v) + k)
input()