-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.py
71 lines (48 loc) · 1.37 KB
/
test.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import tty
import sys
def clear_line(msg=""):
sys.stdout.write("\x1b[0K%s" % msg)
sys.stdout.flush()
def rewind_line():
sys.stdout.write("\r")
sys.stdout.flush()
def do_test(target, data):
data = bytearray(data)
if sys.version_info[0] == 2:
data = ''.join(map(chr, data))
else:
rep = data = bytes(data)
target.sendbinline(data)
clear_line("Waiting for %r" % data[:32])
target.expect_exact(data)
rewind_line()
def run_tests(target):
print("[-] Starting tests.")
clear_line("[x] Testing simple strings.\n")
do_test(target, b"abcd")
do_test(target, b"abcd" * 1000)
clear_line("[x] Testing single bytes.\n")
for x in range(256):
do_test(target, (x,))
clear_line("[x] Testing single bytes in context.\n")
for x in range(256):
do_test(target, (61, x, 61))
clear_line("[x] Testing multiple bytes in context.\n")
for x in range(256):
for y in range(256):
do_test(target, (61, x, y, 61))
clear_line()
if __name__ == '__main__':
import binexpect
setup = binexpect.setup("cat")
target = setup.target()
target.setecho(False)
try:
os.system('setterm -cursor off')
run_tests(target)
finally:
os.system('setterm -cursor on')
print("[-] Tests done.")