From 80a286cf8a18ea1883286cb276b86cb19e826dd4 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Tue, 14 Jan 2020 09:53:04 -0500 Subject: [PATCH] python: handle UC_ERR_TIMEOUT, so sample_x86.py behaves like sample_x86.c Backports commit 810bd34eef41078ca840be2e2ad82d762cb26fa5 from unicorn --- bindings/python/sample_x86.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bindings/python/sample_x86.py b/bindings/python/sample_x86.py index 25c63ea5..eeb64dd9 100755 --- a/bindings/python/sample_x86.py +++ b/bindings/python/sample_x86.py @@ -383,9 +383,16 @@ def test_i386_loop(): print(">>> ECX = 0x%x" %r_ecx) print(">>> EDX = 0x%x" %r_edx) - except UcError as e: - print("ERROR: %s" % e) + # timeout is acceptable in this case + if e.errno == UC_ERR_TIMEOUT: + print(">>> Emulation done. Below is the CPU context") + r_ecx = mu.reg_read(UC_X86_REG_ECX) + r_edx = mu.reg_read(UC_X86_REG_EDX) + print(">>> ECX = 0x%x" %r_ecx) + print(">>> EDX = 0x%x" %r_edx) + else: + print("ERROR: %s" % e) # Test X86 32 bit with IN/OUT instruction def test_i386_inout():