arm64eb: arm64 big endian also using little endian instructions. (#816)

* arm64eb: arm64 big endian also using little endian instructions.

* arm64: using another example that depends on endians.

example:
1. store a word: 0x12345678
2. load a byte:
   * little endian : 0x78
   * big endian    : 0x12
This commit is contained in:
zhangwm
2017-05-04 20:00:48 +08:00
committed by Nguyen Anh Quynh
parent 1b00d3f89a
commit 4a62409949
5 changed files with 32 additions and 25 deletions

View File

@ -8,7 +8,7 @@ from unicorn.arm64_const import *
# code to be emulated
ARM64_CODE = b"\xab\x01\x0f\x8b" #add x11, x13, x15
ARM64_CODE = b"\xab\x05\x00\xb8\xaf\x05\x40\x38" # str x11, [x13]; ldrb x15, [x13]
# memory address where emulation starts
ADDRESS = 0x10000
@ -38,26 +38,27 @@ def test_arm64():
mu.mem_write(ADDRESS, ARM64_CODE)
# initialize machine registers
mu.reg_write(UC_ARM64_REG_X11, 0x1234)
mu.reg_write(UC_ARM64_REG_X13, 0x6789)
mu.reg_write(UC_ARM64_REG_X15, 0x3333)
mu.reg_write(UC_ARM64_REG_X11, 0x12345678)
mu.reg_write(UC_ARM64_REG_X13, 0x10008)
mu.reg_write(UC_ARM64_REG_X15, 0x33)
# tracing all basic blocks with customized callback
mu.hook_add(UC_HOOK_BLOCK, hook_block)
# tracing all instructions with customized callback
mu.hook_add(UC_HOOK_CODE, hook_code)
mu.hook_add(UC_HOOK_CODE, hook_code, begin=ADDRESS, end=ADDRESS)
# emulate machine code in infinite time
mu.emu_start(ADDRESS, ADDRESS + len(ARM64_CODE))
# now print out some registers
print(">>> Emulation done. Below is the CPU context")
print(">>> As little endian, X15 should be 0x78:");
x11 = mu.reg_read(UC_ARM64_REG_X11)
x13 = mu.reg_read(UC_ARM64_REG_X13)
x15 = mu.reg_read(UC_ARM64_REG_X15)
print(">>> X11 = 0x%x" %x11)
print(">>> X15 = 0x%x" %x15)
except UcError as e:
print("ERROR: %s" % e)