Quantcast
Channel: Python extension for WinDbg
Viewing all articles
Browse latest Browse all 1625

Created Issue: [0.3.x] windbg crash with unicorn module [14018]

$
0
0
Try run this script in windbg:

```
from __future__ import print_function
from unicorn import *
from unicorn.x86_const import *

# code to be emulated
X86_CODE32 = b"\x41\x4a" # INC ecx; DEC edx

# memory address where emulation starts
ADDRESS = 0x1000000

print("Emulate i386 code")
try:
# Initialize emulator in X86-32bit mode
mu = Uc(UC_ARCH_X86, UC_MODE_32)

# map 2MB memory for this emulation
mu.mem_map(ADDRESS, 2 * 1024 * 1024)

# write machine code to be emulated to memory
mu.mem_write(ADDRESS, X86_CODE32)

# initialize machine registers
mu.reg_write(UC_X86_REG_ECX, 0x1234)
mu.reg_write(UC_X86_REG_EDX, 0x7890)

# emulate code in infinite time & unlimited instructions
mu.emu_start(ADDRESS, ADDRESS + len(X86_CODE32)) # this line crashes windbg

# now print out some registers
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)

except UcError as e:
print("ERROR: %s" % e)
```

Expected result: output "Emulation done"
In fact: crash windbg with stack:

00 msvcrt!_except_validate_jump_buffer
01 msvcrt!longjmp
02 unicorn!cpu_loop_exit_x86_64
03 unicorn!helper_rdmsr
04 unicorn!helper_hlt
05 unicorn!have_bmi1_x86_64

Viewing all articles
Browse latest Browse all 1625

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>