mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-24 17:58:22 +00:00
Merge pull request #218 from gaffe23/master
add assertion to callback-PC test to make it clear what the correct behavior should be (issue #210)
This commit is contained in:
commit
92f7e2e156
1 changed files with 37 additions and 11 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# reg_write() can't modify PC from within trace callbacks
|
# reg_write() can't modify PC from within trace callbacks
|
||||||
# Pull Request #4
|
# issue #210
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from unicorn import *
|
from unicorn import *
|
||||||
|
@ -30,11 +30,7 @@ def hook_block(uc, address, size, user_data):
|
||||||
|
|
||||||
class CallBackPCTest(regress.RegressTest):
|
class CallBackPCTest(regress.RegressTest):
|
||||||
|
|
||||||
def runTest(self):
|
def test_instruction_trace(self):
|
||||||
self.instruction_trace_test()
|
|
||||||
|
|
||||||
# set up emulation
|
|
||||||
def instruction_trace_test(self):
|
|
||||||
try:
|
try:
|
||||||
# initialize emulator in ARM's Thumb mode
|
# initialize emulator in ARM's Thumb mode
|
||||||
mu = Uc(UC_ARCH_ARM, UC_MODE_THUMB)
|
mu = Uc(UC_ARCH_ARM, UC_MODE_THUMB)
|
||||||
|
@ -51,14 +47,44 @@ class CallBackPCTest(regress.RegressTest):
|
||||||
# tracing all instructions with customized callback
|
# tracing all instructions with customized callback
|
||||||
mu.hook_add(UC_HOOK_CODE, hook_code, user_data=mu)
|
mu.hook_add(UC_HOOK_CODE, hook_code, user_data=mu)
|
||||||
|
|
||||||
# tracing all basic blocks with customized callback
|
# emulate one instruction
|
||||||
mu.hook_add(UC_HOOK_BLOCK, hook_block, user_data=mu)
|
mu.emu_start(BASE_ADDRESS, BASE_ADDRESS + len(THUMB_CODE), count=1)
|
||||||
|
|
||||||
# emulate machine code in infinite time
|
# the instruction trace callback set PC to 0xffffffff, so at this
|
||||||
mu.emu_start(BASE_ADDRESS, BASE_ADDRESS + len(THUMB_CODE))
|
# point, the PC value should be 0xffffffff.
|
||||||
|
pc = mu.reg_read(UC_ARM_REG_PC)
|
||||||
|
self.assertEqual(pc, 0xffffffff, "PC not set to 0xffffffff by instruction trace callback")
|
||||||
|
|
||||||
except UcError as e:
|
except UcError as e:
|
||||||
assertFalse(0, "ERROR: %s" % e)
|
self.assertFalse(0, "ERROR: %s" % e)
|
||||||
|
|
||||||
|
def test_block_trace(self):
|
||||||
|
try:
|
||||||
|
# initialize emulator in ARM's Thumb mode
|
||||||
|
mu = Uc(UC_ARCH_ARM, UC_MODE_THUMB)
|
||||||
|
|
||||||
|
# map some memory
|
||||||
|
mu.mem_map(BASE_ADDRESS, 2 * 1024 * 1024)
|
||||||
|
|
||||||
|
# write machine code to be emulated to memory
|
||||||
|
mu.mem_write(BASE_ADDRESS, THUMB_CODE)
|
||||||
|
|
||||||
|
# setup stack
|
||||||
|
mu.reg_write(UC_ARM_REG_SP, BASE_ADDRESS + 2 * 1024 * 1024)
|
||||||
|
|
||||||
|
# trace blocks with customized callback
|
||||||
|
mu.hook_add(UC_HOOK_BLOCK, hook_block, user_data=mu)
|
||||||
|
|
||||||
|
# emulate one instruction
|
||||||
|
mu.emu_start(BASE_ADDRESS, BASE_ADDRESS + len(THUMB_CODE), count=1)
|
||||||
|
|
||||||
|
# the block callback set PC to 0xffffffff, so at this point, the PC
|
||||||
|
# value should be 0xffffffff.
|
||||||
|
pc = mu.reg_read(UC_ARM_REG_PC)
|
||||||
|
self.assertEqual(pc, 0xffffffff, "PC not set to 0xffffffff by block callback")
|
||||||
|
|
||||||
|
except UcError as e:
|
||||||
|
self.assertFalse(0, "ERROR: %s" % e)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
regress.main()
|
regress.main()
|
||||||
|
|
Loading…
Reference in a new issue