forked from F8LEFT/DecLLVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbgEngine.py
74 lines (57 loc) · 1.79 KB
/
dbgEngine.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
__author__ = 'F8LEFT'
#for ida debug loop
#collect breakpoint
# from python import *
from idaapi import *
from idautils import *
from idc import *
from logEngine import *
from regHelper import ArmReg
class InstructionHelp:
def __init__(self):
self.saveBp = {}
for i in range(0, GetBptQty()):
bptea = GetBptEA(i)
self.saveBp[bptea] = GetBptAttr(bptea, BPTATTR_FLAGS)
for bp in self.saveBp:
EnableBpt(bp, 0)
def __del__(self):
for bp in self.saveBp:
SetBptAttr(bp, BPTATTR_FLAGS, self.saveBp[bp])
def get_next_instruction(self, regObj):
StepInto()
return 0
class DbgEngine:
def __init__(self, regHelper, insObj):
self.addr = 0
regHelper.dumpReg()
self.tracer = LogEngine()
self.ins = insObj
self.regis = regHelper
def start_run(self, startAddr, count, logfd):
GetDebuggerEvent(WFNE_SUSP, -1)
pc = GetRegValue("PC")
if pc != startAddr:
RunTo(startAddr)
GetDebuggerEvent(WFNE_SUSP, -1)
self.regis.dumpReg()
self.tracer.log_start(self.regis, logfd)
self.tracer.log_trace(self.regis, logfd)
while count > 0:
nextReg = self.ins.get_next_instruction(self.regis)
if nextReg != 0:
RunTo(nextReg)
GetDebuggerEvent(WFNE_SUSP, -1)
if not isCode(getFlags(nextReg)):
MakeCode(nextReg)
self.regis.dumpReg()
self.tracer.log_trace(self.regis, logfd)
count -= 1
return True
if __name__ == "__main__":
ins = InstructionHelp()
reg = ArmReg()
dbgEng = DbgEngine(reg, ins)
fd = open("F:/trace.log", "w+")
dbgEng.start_run(GetRegValue("PC"), 2, fd)
fd.close()