forked from qilingframework/qiling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_windows_debugger.py
84 lines (71 loc) · 2.58 KB
/
test_windows_debugger.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
#!/usr/bin/env python3
#
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
#
import sys, subprocess, threading, unittest, socket, time
from binascii import unhexlify
sys.path.append("..")
from qiling import *
from qiling.exception import *
from qiling.const import QL_VERBOSE
DELAY = 1
def checksum(data):
checksum = 0
for c in data:
if type(c) == str:
checksum += (ord(c))
else:
checksum += c
return checksum & 0xff
def send_raw(netout, r):
netout.write(r)
netout.flush()
def send(netout, msg):
time.sleep(DELAY)
send_raw(netout, '$%s#%.2x' % (msg, checksum(msg)))
class DebuggerTest(unittest.TestCase):
def test_pe_gdbdebug(self):
ql = Qiling(["../examples/rootfs/x86_windows/bin/x86_hello.exe"], "../examples/rootfs/x86_windows/", verbose=QL_VERBOSE.DEBUG)
ql.debugger = "127.0.0.1:9996"
# some random command test just to make sure we covered most of the command
def gdb_test_client():
time.sleep(DELAY)
gdb_client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
netout = gdb_client.makefile('w')
gdb_client.connect(('127.0.0.1',9996))
time.sleep(DELAY)
send(netout, "qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;fork-events+;vfork-events+;exec-events+;vContSupported+;QThreadEvents+;no-resumed+;xmlRegisters=i386")
time.sleep(DELAY)
send(netout, "vMustReplyEmpty")
time.sleep(DELAY)
send(netout, "QStartNoAckMode")
time.sleep(DELAY)
send(netout, "Hgp0.0")
time.sleep(DELAY)
send(netout, "qXfer:auxv:read::0, 1000")
time.sleep(DELAY)
send(netout, "?")
time.sleep(DELAY)
send(netout, "qXfer:threads:read::0,fff")
time.sleep(DELAY)
send(netout, "qAttached:"+ str(ql.os.pid))
time.sleep(DELAY)
send(netout, "qC")
time.sleep(DELAY)
send(netout, "g")
time.sleep(DELAY)
send(netout, "m200, 100")
time.sleep(DELAY)
send(netout, "p10")
time.sleep(DELAY)
send(netout, "c")
time.sleep(DELAY)
send(netout, "k")
time.sleep(DELAY)
gdb_client.close()
debugger_file_therad = threading.Thread(target=gdb_test_client, daemon=True)
debugger_file_therad.start()
ql.run()
del ql
if __name__ == "__main__":
unittest.main()