Revamp Python regression tests suite (#2022)

* Fix Python regression test suite (partial)

* Fix Python regression test suite

* Add a test for mapping at high addresses

* Add ctl tests
This commit is contained in:
Eli
2024-10-13 08:14:10 +03:00
committed by GitHub
parent 78580ca8f9
commit 9f578946d5
58 changed files with 1903 additions and 1455 deletions

View File

@@ -1,21 +1,38 @@
import regress
from unicorn import *
from unicorn.x86_const import *
count = 0
def cb(uc, addr, sz, data):
global count
count += 1
print(f"addr: {hex(addr)} count: {count}")
if count == 5:
uc.emu_stop()
else:
uc.reg_write(UC_X86_REG_RIP, 0x2000)
NOPSLED = b"\x90" * 5
mu = Uc(UC_ARCH_X86, UC_MODE_64)
mu.mem_map(0x1000, 0x4000)
mu.mem_write(0x1000, b"\x90" * 5)
mu.mem_write(0x2000, b"\x90" * 5)
mu.hook_add(UC_HOOK_CODE, cb)
mu.emu_start(0x1000, 0x2000+1, 0, 0)
class TestSetIP(regress.RegressTest):
def runTest(self):
# execution history
history = []
def __code_hook(uc, addr, size, ud):
# track execution history
history.append(addr)
if len(history) == 5:
uc.emu_stop()
else:
uc.reg_write(UC_X86_REG_RIP, 0x1800)
mu = Uc(UC_ARCH_X86, UC_MODE_64)
mu.mem_map(0x1000, 0x1000)
mu.mem_write(0x1000, NOPSLED)
mu.mem_write(0x1800, NOPSLED)
mu.hook_add(UC_HOOK_CODE, __code_hook)
mu.emu_start(0x1000, 0x1800 + 1)
self.assertListEqual([0x1000] + [0x1800] * 4, history)
if __name__ == '__main__':
regress.main()