ctf-tools/unicorn/test
Steven Van Acker 7144e756e5 fail hard on any error + verify that all scripts use bash -ex to fail
early on any error + anticipate that some tools can't be installed by
now, but we still want the test to return success to satisfy travis-ci
2017-02-16 22:40:17 +01:00

30 lines
859 B
Bash
Executable file

#!/bin/bash -ex
set -e -o pipefail
source ctf-tools-venv-activate
python <<EOF
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
# 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))
r_ecx = mu.reg_read(UC_X86_REG_ECX)
r_edx = mu.reg_read(UC_X86_REG_EDX)
assert r_ecx == 0x1235
assert r_edx == 0x788f
EOF