Update .travis.yml
Update eflags_nosync.c Update sigill2.c Update ro_mem_test.c Update ro_mem_test.c Update nr_mem_test.c Update mem_fuzz.c Update mem_double_unmap.c Update emu_stop_in_hook_overrun.c Update eflags_nosync.c remove unused Update Makefile Update Makefile Update Makefile Update Makefile Update Makefile Update Makefile Update Makefile Update mem_64_c.c Update mem_64_c.c Update Makefile Update Makefile Update Makefile Update Makefile Update Makefile Update Makefile Update .travis.yml try android ndk build Update unicorn.py Update unicorn.py Update Makefile Update unicorn.py Update unicorn.py remove an untrue comment if a dll/so/dylib gets loaded at runtime is dependent on many different factors, primarily the LD/DYLD paths. Those do not always include the current working directory Update Makefile Update .appveyor.yml Update .travis.yml Update Makefile Update .appveyor.yml Fix bad sample
This commit is contained in:
@ -1,21 +1,23 @@
|
|||||||
# Appveyor configuration file for CI build of Unicorn Engine on Windows (under Cygwin)
|
# Appveyor configuration file for CI build of Unicorn Engine on Windows (under Cygwin)
|
||||||
environment:
|
environment:
|
||||||
|
CYG_MIRROR: http://cygwin.mirror.constant.com
|
||||||
matrix:
|
matrix:
|
||||||
|
- MSYSTEM: MINGW64
|
||||||
|
BASH: C:\msys64\usr\bin\bash
|
||||||
|
CC: x86_64-w64-mingw32-gcc
|
||||||
|
- MSYSTEM: MINGW32
|
||||||
|
BASH: C:\msys64\usr\bin\bash
|
||||||
|
CC: i686-w64-mingw32-gcc
|
||||||
- CYG_ROOT: C:\cygwin64
|
- CYG_ROOT: C:\cygwin64
|
||||||
CYG_SETUP: setup-x86_64.exe
|
|
||||||
CYG_MIRROR: http://cygwin.mirror.constant.com
|
|
||||||
CYG_CACHE: C:\cygwin64\var\cache\setup
|
CYG_CACHE: C:\cygwin64\var\cache\setup
|
||||||
CYG_BASH: C:\cygwin64\bin\bash
|
CYG_SETUP: setup-x86_64.exe
|
||||||
|
BASH: C:\cygwin64\bin\bash
|
||||||
CC: gcc
|
CC: gcc
|
||||||
- CYG_ROOT: C:\cygwin
|
- CYG_ROOT: C:\cygwin
|
||||||
CYG_SETUP: setup-x86.exe
|
|
||||||
CYG_MIRROR: http://cygwin.mirror.constant.com
|
|
||||||
CYG_CACHE: C:\cygwin\var\cache\setup
|
CYG_CACHE: C:\cygwin\var\cache\setup
|
||||||
CYG_BASH: C:\cygwin\bin\bash
|
CYG_SETUP: setup-x86.exe
|
||||||
|
BASH: C:\cygwin\bin\bash
|
||||||
CC: gcc
|
CC: gcc
|
||||||
# - MSYS_ROOT: C:\msys64
|
|
||||||
# MSYS_BASH: C:\msys64\mingw64\bin\sh
|
|
||||||
# CC: x86_64-w64-mingw32-gcc
|
|
||||||
|
|
||||||
# Cache Cygwin files to speed up build
|
# Cache Cygwin files to speed up build
|
||||||
cache:
|
cache:
|
||||||
@ -30,12 +32,13 @@ init:
|
|||||||
|
|
||||||
# Install needed build dependencies
|
# Install needed build dependencies
|
||||||
install:
|
install:
|
||||||
- ps: 'if ($env:CYG_ROOT) { Start-FileDownload "http://cygwin.com/$env:CYG_SETUP" -FileName "$env:CYG_SETUP" }'
|
- ps: if (Test-Path Env:\CYG_ROOT) { Start-FileDownload "http://cygwin.com/$env:CYG_SETUP" -FileName "$env:CYG_SETUP" }
|
||||||
- if defined CYG_ROOT (%CYG_SETUP% --quiet-mode --no-shortcuts --only-site --root "%CYG_ROOT%" --site "%CYG_MIRROR%" --local-package-dir "%CYG_CACHE%" --packages make,gcc-core,clang,pkg-config,libpcre-devel,libglib2.0-devel,cmake,python-setuptools --upgrade-also)
|
- if defined CYG_ROOT (%CYG_SETUP% --quiet-mode --no-shortcuts --only-site --root "%CYG_ROOT%" --site "%CYG_MIRROR%" --local-package-dir "%CYG_CACHE%" --packages make,gcc-core,clang,pkg-config,libpcre-devel,libglib2.0-devel,cmake,python-setuptools,ruby,mingw64-i686-gcc-core,mingw64-x86_64-gcc-core --upgrade-also)
|
||||||
- if defined MSYS_ROOT (%MSYS_BASH% -lc "pacman -S --noconfirm mingw-w64-x86_64-glib2")
|
- if defined MSYSTEM (%BASH% -lc "pacman -Sy --noconfirm mingw-w64-x86_64-glib2 mingw-w64-i686-glib2 cmake")
|
||||||
build_script:
|
build_script:
|
||||||
- if defined CYG_ROOT (%CYG_BASH% -lc "export CYGWIN=winsymlinks:native; cd $APPVEYOR_BUILD_FOLDER; ./install-cmocka-linux.sh; make; export PATH=$PATH:../../:../../cmocka/src:../:../cmocka/src; make test")
|
- if defined BASH (%BASH% -lc "cd $(cygpath ${APPVEYOR_BUILD_FOLDER}); ./install-cmocka-linux.sh; make;")
|
||||||
- if defined MSYS_ROOT (%MSYS_BASH% -lc "MSYS=winsymlinks, cd $(cygpath ${APPVEYOR_BUILD_FOLDER}); x86_64-w64-mingw32-gcc --version; ./install-cmocka-linux.sh; make")
|
- if "%MSYSTEM%" == "MINGW64" (%BASH% -lc "cd $(cygpath ${APPVEYOR_BUILD_FOLDER}); make -C bindings/go")
|
||||||
|
# make test
|
||||||
#- 'cd %APPVEYOR_BUILD_FOLDER% && cd bindings\dotnet && msbuild UnicornDotNet.sln'
|
#- 'cd %APPVEYOR_BUILD_FOLDER% && cd bindings\dotnet && msbuild UnicornDotNet.sln'
|
||||||
# Allows RDP
|
# Allows RDP
|
||||||
#on_finish:
|
#on_finish:
|
||||||
@ -43,4 +46,5 @@ build_script:
|
|||||||
|
|
||||||
# Disable tests for now
|
# Disable tests for now
|
||||||
#
|
#
|
||||||
test: off
|
test_script:
|
||||||
|
- if defined CYG_ROOT (%BASH% -lc "export CYGWIN=winsymlinks:native; cd $APPVEYOR_BUILD_FOLDER; export PATH=$PATH:$APPVEYOR_BUILD_FOLDER:$APPVEYOR_BUILD_FOLDER/cmocka/src; make test")
|
||||||
|
@ -6,9 +6,7 @@ before_install:
|
|||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$MACOS_UNIVERSAL" == "yes" ]]; then brew install glib --universal cmocka; fi
|
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$MACOS_UNIVERSAL" == "yes" ]]; then brew install glib --universal cmocka; fi
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./install-cmocka-linux.sh; fi
|
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./install-cmocka-linux.sh; fi
|
||||||
script:
|
script:
|
||||||
- make && make test
|
- make && make -C bindings/go && make -C bindings/go test && make test
|
||||||
# TODO make bindings enabled
|
|
||||||
# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then make clean && ./make.sh ios; fi
|
|
||||||
compiler:
|
compiler:
|
||||||
- clang
|
- clang
|
||||||
- gcc
|
- gcc
|
||||||
@ -23,8 +21,6 @@ matrix:
|
|||||||
- os: osx
|
- os: osx
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
env: MACOS_UNIVERSAL=yes
|
env: MACOS_UNIVERSAL=yes
|
||||||
# - os: osx
|
|
||||||
# compiler: x86_64-w64-mingw32-gcc
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
|
19
Makefile
19
Makefile
@ -10,8 +10,7 @@ include pkgconfig.mk # package version
|
|||||||
LIBNAME = unicorn
|
LIBNAME = unicorn
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
|
|
||||||
GENOBJ = $(shell find qemu/$(1) -name "*.o" 2>/dev/null) $(wildcard qemu/util/*.o) $(wildcard qemu/*.o) $(wildcard qemu/qom/*.o)\
|
GENOBJ = $(shell find qemu/$(1) -name "*.o" 2>/dev/null)
|
||||||
$(wildcard qemu/hw/core/*.o) $(wildcard qemu/qapi/*.o) $(wildcard qemu/qobject/*.o)
|
|
||||||
|
|
||||||
ifneq (,$(findstring x86,$(UNICORN_ARCHS)))
|
ifneq (,$(findstring x86,$(UNICORN_ARCHS)))
|
||||||
UC_TARGET_OBJ += $(call GENOBJ,x86_64-softmmu)
|
UC_TARGET_OBJ += $(call GENOBJ,x86_64-softmmu)
|
||||||
@ -196,6 +195,8 @@ else
|
|||||||
PKGCFGDIR ?= $(LIBDATADIR)/pkgconfig
|
PKGCFGDIR ?= $(LIBDATADIR)/pkgconfig
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
$(LIBNAME)_LDFLAGS += $(GLIB) -lm
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: unicorn
|
all: unicorn
|
||||||
$(MAKE) -C samples
|
$(MAKE) -C samples
|
||||||
@ -210,15 +211,16 @@ qemu/config-host.h-timestamp:
|
|||||||
|
|
||||||
compile_lib: config qemu/config-host.h-timestamp
|
compile_lib: config qemu/config-host.h-timestamp
|
||||||
$(MAKE) -C qemu -j 4
|
$(MAKE) -C qemu -j 4
|
||||||
|
$(eval UC_TARGET_OBJ += $$(wildcard qemu/util/*.o) $$(wildcard qemu/*.o) $$(wildcard qemu/qom/*.o) $$(wildcard qemu/hw/core/*.o) $$(wildcard qemu/qapi/*.o) $$(wildcard qemu/qobject/*.o))
|
||||||
|
|
||||||
unicorn: compile_lib $(LIBRARY) $(ARCHIVE)
|
unicorn: $(LIBRARY) $(ARCHIVE)
|
||||||
|
|
||||||
$(LIBRARY): $(UC_TARGET_OBJ)
|
$(LIBRARY): compile_lib uc.o list.o
|
||||||
$(CC) $(CFLAGS) -shared $(GENOBJ) uc.o list.o -o $(LIBRARY) $(GLIB) -lm $($(LIBNAME)_LDFLAGS)
|
$(CC) $(CFLAGS) -shared $(UC_TARGET_OBJ) uc.o list.o -o $(LIBRARY) $($(LIBNAME)_LDFLAGS)
|
||||||
ln -sf $(LIBRARY) $(LIBRARY_SYMLINK)
|
-ln -sf $(LIBRARY) $(LIBRARY_SYMLINK)
|
||||||
|
|
||||||
$(ARCHIVE): $(UC_TARGET_OBJ) uc.o list.o
|
$(ARCHIVE): compile_lib uc.o list.o
|
||||||
$(AR) q $(ARCHIVE) $^
|
$(AR) q $(ARCHIVE) $(UC_TARGET_OBJ) uc.o list.o
|
||||||
$(RANLIB) $(ARCHIVE)
|
$(RANLIB) $(ARCHIVE)
|
||||||
|
|
||||||
|
|
||||||
@ -228,6 +230,7 @@ $(PKGCFGF):
|
|||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: all
|
test: all
|
||||||
$(MAKE) -C tests/unit test
|
$(MAKE) -C tests/unit test
|
||||||
|
$(MAKE) -C tests/regress test
|
||||||
$(MAKE) -C bindings test
|
$(MAKE) -C bindings test
|
||||||
|
|
||||||
install: compile_lib $(PKGCFGF)
|
install: compile_lib $(PKGCFGF)
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
# Unicorn Engine
|
# Unicorn Engine
|
||||||
# By Nguyen Anh Quynh & Dang Hoang Vu, 2015
|
# By Nguyen Anh Quynh & Dang Hoang Vu, 2015
|
||||||
TMP_DIR = /tmp/unicorn_sample
|
DIFF = diff
|
||||||
|
|
||||||
DIFF = diff -u -w
|
SAMPLE_SOURCE = $(wildcard ../samples/*.c)
|
||||||
|
SAMPLE = $(SAMPLE_SOURCE:../samples/%.c=%)
|
||||||
SAMPLE_ARM = $(TMP_DIR)/sample_arm
|
SAMPLE := $(SAMPLE:mem_apis=)
|
||||||
SAMPLE_ARM64 = $(TMP_DIR)/sample_arm64
|
SAMPLE := $(SAMPLE:sample_batch_reg=)
|
||||||
SAMPLE_MIPS = $(TMP_DIR)/sample_mips
|
SAMPLE := $(SAMPLE:sample_x86_32_gdt_and_seg_regs=)
|
||||||
SAMPLE_M68K = $(TMP_DIR)/sample_m68k
|
SAMPLE := $(SAMPLE:shellcode=)
|
||||||
SAMPLE_SPARC = $(TMP_DIR)/sample_sparc
|
|
||||||
SAMPLE_X86 = $(TMP_DIR)/sample_x86
|
|
||||||
|
|
||||||
ENV_VARS = LD_LIBRARY_PATH=../ DYLD_LIBRARY_PATH=../
|
ENV_VARS = LD_LIBRARY_PATH=../ DYLD_LIBRARY_PATH=../
|
||||||
|
|
||||||
.PHONY: build install expected python sample_diff clean check test
|
.PHONY: build install python c clean check test
|
||||||
|
|
||||||
build:
|
build:
|
||||||
$(MAKE) -C python gen_const
|
$(MAKE) -C python gen_const
|
||||||
@ -26,39 +24,22 @@ install: build
|
|||||||
$(MAKE) -C python install
|
$(MAKE) -C python install
|
||||||
$(MAKE) -C java install
|
$(MAKE) -C java install
|
||||||
|
|
||||||
test: expected python sample_diff
|
test: $(SAMPLE:%=%.py.test)
|
||||||
|
|
||||||
expected:
|
c:
|
||||||
$(MAKE) -C ../samples
|
$(MAKE) -C ../samples
|
||||||
mkdir -p $(TMP_DIR)
|
|
||||||
$(ENV_VARS) ../samples/sample_arm > $(SAMPLE_ARM)_e
|
|
||||||
$(ENV_VARS) ../samples/sample_arm64 > $(SAMPLE_ARM64)_e
|
|
||||||
$(ENV_VARS) ../samples/sample_mips > $(SAMPLE_MIPS)_e
|
|
||||||
$(ENV_VARS) ../samples/sample_sparc > $(SAMPLE_SPARC)_e
|
|
||||||
$(ENV_VARS) ../samples/sample_m68k > $(SAMPLE_M68K)_e
|
|
||||||
$(ENV_VARS) ../samples/sample_x86 -16 > $(SAMPLE_X86)_e
|
|
||||||
$(ENV_VARS) ../samples/sample_x86 -32 >> $(SAMPLE_X86)_e
|
|
||||||
$(ENV_VARS) ../samples/sample_x86 -64 >> $(SAMPLE_X86)_e
|
|
||||||
|
|
||||||
python:
|
python:
|
||||||
$(MAKE) -C python
|
$(MAKE) -C python
|
||||||
$(ENV_VARS) python python/sample_arm.py > $(SAMPLE_ARM)_o
|
%.c.txt: c
|
||||||
$(ENV_VARS) python python/sample_arm64.py > $(SAMPLE_ARM64)_o
|
$(ENV_VARS) ../samples/$(@:%.c.txt=%) > $@
|
||||||
$(ENV_VARS) python python/sample_mips.py > $(SAMPLE_MIPS)_o
|
%.py.txt: python
|
||||||
$(ENV_VARS) python python/sample_sparc.py > $(SAMPLE_SPARC)_o
|
$(ENV_VARS) python python/$(@:%.txt=%) > $@
|
||||||
$(ENV_VARS) python python/sample_m68k.py > $(SAMPLE_M68K)_o
|
|
||||||
$(ENV_VARS) python python/sample_x86.py > $(SAMPLE_X86)_o
|
|
||||||
|
|
||||||
sample_diff:
|
%.py.test: %.c.txt %.py.txt
|
||||||
$(DIFF) $(SAMPLE_ARM)_e $(SAMPLE_ARM)_o
|
$(DIFF) $(@:%.py.test=%.c.txt) $(@:%.py.test=%.py.txt)
|
||||||
$(DIFF) $(SAMPLE_ARM64)_e $(SAMPLE_ARM64)_o
|
|
||||||
$(DIFF) $(SAMPLE_MIPS)_e $(SAMPLE_MIPS)_o
|
|
||||||
$(DIFF) $(SAMPLE_SPARC)_e $(SAMPLE_SPARC)_o
|
|
||||||
$(DIFF) $(SAMPLE_M68K)_e $(SAMPLE_M68K)_o
|
|
||||||
$(DIFF) $(SAMPLE_X86)_e $(SAMPLE_X86)_o
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(TMP_DIR)
|
# rm -rf *.txt
|
||||||
$(MAKE) -C python clean
|
$(MAKE) -C python clean
|
||||||
$(MAKE) -C java clean
|
$(MAKE) -C java clean
|
||||||
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
# Go binding for Unicorn engine. Ryan Hileman <lunixbochs@gmail.com>
|
# Go binding for Unicorn engine. Ryan Hileman <lunixbochs@gmail.com>
|
||||||
|
|
||||||
.PHONY: gen_const test
|
.PHONY: all gen_const test
|
||||||
|
|
||||||
all:
|
all: gen_const
|
||||||
$(MAKE) gen_const
|
|
||||||
cd unicorn && go build
|
cd unicorn && go build
|
||||||
$(MAKE) test
|
|
||||||
|
|
||||||
gen_const:
|
gen_const:
|
||||||
cd .. && python const_generator.py go
|
cd .. && python const_generator.py go
|
||||||
|
|
||||||
test:
|
test: all
|
||||||
cd unicorn && go test
|
cd unicorn && LD_LIBRARY_PATH=../../../ DYLD_LIBRARY_PATH=../../../ go test
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo CFLAGS: -O3
|
#cgo CFLAGS: -O3 -Wall -Werror -I../../../include
|
||||||
#cgo LDFLAGS: -lunicorn
|
#cgo LDFLAGS: -L../../../ -lunicorn -lglib-2.0
|
||||||
#include <unicorn/unicorn.h>
|
#include <unicorn/unicorn.h>
|
||||||
#include "uc.h"
|
#include "uc.h"
|
||||||
*/
|
*/
|
||||||
|
@ -442,38 +442,25 @@ def test_i386_context_save():
|
|||||||
# write machine code to be emulated to memory
|
# write machine code to be emulated to memory
|
||||||
mu.mem_write(address, code)
|
mu.mem_write(address, code)
|
||||||
|
|
||||||
print(">>> set eax to 1")
|
# set eax to 1
|
||||||
mu.reg_write(UC_X86_REG_EAX, 1)
|
mu.reg_write(UC_X86_REG_EAX, 1)
|
||||||
|
|
||||||
print(">>> execute 'inc eax'")
|
print(">>> Running emulation for the first time")
|
||||||
mu.emu_start(address, address+1)
|
mu.emu_start(address, address+1)
|
||||||
|
|
||||||
print(">>> save the CPU context")
|
print(">>> Emulation done. Below is the CPU context")
|
||||||
|
print(">>> EAX = 0x%x" %(mu.reg_read(UC_X86_REG_EAX)))
|
||||||
|
print(">>> Saving CPU context")
|
||||||
saved_context = mu.context_save()
|
saved_context = mu.context_save()
|
||||||
|
|
||||||
print(">>> execute 'inc eax'")
|
print(">>> Running emulation for the second time")
|
||||||
mu.emu_start(address, address+1)
|
mu.emu_start(address, address+1)
|
||||||
|
print(">>> Emulation done. Below is the CPU context")
|
||||||
|
print(">>> EAX = 0x%x" %(mu.reg_read(UC_X86_REG_EAX)))
|
||||||
|
|
||||||
print(">>> assert eax == 3")
|
print(">>> CPU context restored. Below is the CPU context")
|
||||||
assert mu.reg_read(UC_X86_REG_EAX) == 3
|
|
||||||
|
|
||||||
print(">>> restore the CPU context")
|
|
||||||
mu.context_restore(saved_context)
|
mu.context_restore(saved_context)
|
||||||
|
print(">>> EAX = 0x%x" %(mu.reg_read(UC_X86_REG_EAX)))
|
||||||
print(">>> assert eax == 2")
|
|
||||||
assert mu.reg_read(UC_X86_REG_EAX) == 2
|
|
||||||
|
|
||||||
print(">>> execute 'inc eax'")
|
|
||||||
mu.emu_start(address, address+1)
|
|
||||||
|
|
||||||
print(">>> assert eax == 3")
|
|
||||||
assert mu.reg_read(UC_X86_REG_EAX) == 3
|
|
||||||
|
|
||||||
print(">>> restore the CPU context")
|
|
||||||
mu.context_restore(saved_context)
|
|
||||||
|
|
||||||
print(">>> assert eax == 2")
|
|
||||||
assert mu.reg_read(UC_X86_REG_EAX) == 2
|
|
||||||
|
|
||||||
except UcError as e:
|
except UcError as e:
|
||||||
print("ERROR: %s" % e)
|
print("ERROR: %s" % e)
|
||||||
@ -644,6 +631,8 @@ if __name__ == '__main__':
|
|||||||
print("=" * 35)
|
print("=" * 35)
|
||||||
test_i386_inout()
|
test_i386_inout()
|
||||||
print("=" * 35)
|
print("=" * 35)
|
||||||
|
test_i386_context_save()
|
||||||
|
print("=" * 35)
|
||||||
test_i386_jump()
|
test_i386_jump()
|
||||||
print("=" * 35)
|
print("=" * 35)
|
||||||
test_i386_loop()
|
test_i386_loop()
|
||||||
|
@ -21,7 +21,7 @@ def hook_code(uc, address, size, user_data):
|
|||||||
print(">>> Tracing instruction at 0x%x, instruction size = 0x%x" %(address, size))
|
print(">>> Tracing instruction at 0x%x, instruction size = 0x%x" %(address, size))
|
||||||
# read this instruction code from memory
|
# read this instruction code from memory
|
||||||
tmp = uc.mem_read(address, size)
|
tmp = uc.mem_read(address, size)
|
||||||
print(">>> Instruction code at [0x%x] =" %(address), end="")
|
print("*** EIP = %x *** :" %(address), end="")
|
||||||
for i in tmp:
|
for i in tmp:
|
||||||
print(" %02x" %i, end="")
|
print(" %02x" %i, end="")
|
||||||
print("")
|
print("")
|
||||||
|
@ -17,12 +17,11 @@ _python2 = sys.version_info[0] < 3
|
|||||||
if _python2:
|
if _python2:
|
||||||
range = xrange
|
range = xrange
|
||||||
|
|
||||||
if sys.platform == 'darwin':
|
_lib = { 'darwin': 'libunicorn.dylib',
|
||||||
_lib = "libunicorn.dylib"
|
'win32': 'unicorn.dll',
|
||||||
elif sys.platform in ('win32', 'cygwin'):
|
'cygwin': 'cygunicorn.dll',
|
||||||
_lib = "unicorn.dll"
|
'linux': 'libunicorn.so',
|
||||||
else:
|
'linux2': 'libunicorn.so' }
|
||||||
_lib = "libunicorn.so"
|
|
||||||
|
|
||||||
# Windows DLL in dependency order
|
# Windows DLL in dependency order
|
||||||
_all_windows_dlls = (
|
_all_windows_dlls = (
|
||||||
@ -45,7 +44,7 @@ def _load_lib(path):
|
|||||||
if sys.platform in ('win32', 'cygwin'):
|
if sys.platform in ('win32', 'cygwin'):
|
||||||
_load_win_support(path)
|
_load_win_support(path)
|
||||||
|
|
||||||
lib_file = os.path.join(path, _lib)
|
lib_file = os.path.join(path, _lib[sys.platform])
|
||||||
return ctypes.cdll.LoadLibrary(lib_file)
|
return ctypes.cdll.LoadLibrary(lib_file)
|
||||||
except OSError:
|
except OSError:
|
||||||
return None
|
return None
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
.PHONY: gen_const
|
.PHONY: gen_const
|
||||||
|
|
||||||
install:
|
# Use bundle install && rake to install gem and test
|
||||||
$(MAKE) gen_const
|
install: gen_const
|
||||||
cd unicorn_gem && rake build
|
cd unicorn_gem && rake build
|
||||||
cd unicorn_gem && gem install --local pkg/unicorn-0.9.0.gem
|
cd unicorn_gem && gem install --local pkg/unicorn-0.9.0.gem
|
||||||
|
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
set -ex
|
set -ex
|
||||||
mkdir cmocka
|
mkdir cmocka
|
||||||
wget https://cmocka.org/files/1.1/cmocka-1.1.0.tar.xz -O /tmp/cmocka-1.1.0.tar.xz
|
wget https://cmocka.org/files/1.1/cmocka-1.1.0.tar.xz -O /tmp/cmocka-1.1.0.tar.xz
|
||||||
tar -xf /tmp/cmocka-1.1.0.tar.xz -C /tmp
|
tar -xvf /tmp/cmocka-1.1.0.tar.xz -C /tmp
|
||||||
|
if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ] ; then
|
||||||
|
cd cmocka && which cmake && cmake -G "MinGW Makefiles" /tmp/cmocka-1.1.0 && make
|
||||||
|
else
|
||||||
cd cmocka && cmake /tmp/cmocka-1.1.0 && make
|
cd cmocka && cmake /tmp/cmocka-1.1.0 && make
|
||||||
|
fi
|
||||||
#cmocka does not include headers in build
|
#cmocka does not include headers in build
|
||||||
cp -R /tmp/cmocka-1.1.0/include/ .
|
cp -R /tmp/cmocka-1.1.0/include/ .
|
||||||
|
@ -996,13 +996,15 @@ int main(int argc, char **argv, char **envp)
|
|||||||
printf("Error dynamically loading shared library.\n");
|
printf("Error dynamically loading shared library.\n");
|
||||||
printf("Please check that unicorn.dll/unicorn.so is available as well as\n");
|
printf("Please check that unicorn.dll/unicorn.so is available as well as\n");
|
||||||
printf("any other dependent dll/so files.\n");
|
printf("any other dependent dll/so files.\n");
|
||||||
printf("The easiest way is to place them in the same directory as this app.\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
if (!strcmp(argv[1], "-32")) {
|
if (!strcmp(argv[1], "-16")) {
|
||||||
|
test_x86_16();
|
||||||
|
}
|
||||||
|
else if (!strcmp(argv[1], "-32")) {
|
||||||
test_i386();
|
test_i386();
|
||||||
test_i386_map_ptr();
|
test_i386_map_ptr();
|
||||||
test_i386_inout();
|
test_i386_inout();
|
||||||
@ -1013,19 +1015,29 @@ int main(int argc, char **argv, char **envp)
|
|||||||
test_i386_invalid_mem_write();
|
test_i386_invalid_mem_write();
|
||||||
test_i386_jump_invalid();
|
test_i386_jump_invalid();
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(argv[1], "-64")) {
|
||||||
if (!strcmp(argv[1], "-64")) {
|
|
||||||
test_x86_64();
|
test_x86_64();
|
||||||
test_x86_64_syscall();
|
test_x86_64_syscall();
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(argv[1], "-h")) {
|
||||||
if (!strcmp(argv[1], "-16")) {
|
printf("Syntax: %s <-16|-32|-64>\n", argv[0]);
|
||||||
test_x86_16();
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
printf("Syntax: %s <-16|-32|-64>\n", argv[0]);
|
else {
|
||||||
}
|
test_x86_16();
|
||||||
|
test_i386();
|
||||||
|
test_i386_map_ptr();
|
||||||
|
test_i386_inout();
|
||||||
|
test_i386_context_save();
|
||||||
|
test_i386_jump();
|
||||||
|
test_i386_loop();
|
||||||
|
test_i386_invalid_mem_read();
|
||||||
|
test_i386_invalid_mem_write();
|
||||||
|
test_i386_jump_invalid();
|
||||||
|
test_x86_64();
|
||||||
|
test_x86_64_syscall();
|
||||||
|
|
||||||
|
}
|
||||||
// dynamically free shared library
|
// dynamically free shared library
|
||||||
#ifdef DYNLOAD
|
#ifdef DYNLOAD
|
||||||
uc_dyn_free();
|
uc_dyn_free();
|
||||||
|
@ -168,12 +168,15 @@ int main(int argc, char **argv, char **envp)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
if (!strcmp(argv[1], "-32")) {
|
if (!strcmp(argv[1], "-32")) {
|
||||||
test_i386();
|
test_i386();
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(argv[1], "-h")) {
|
||||||
|
printf("Syntax: %s <-32|-64>\n", argv[0]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("Syntax: %s <-32|-64>\n", argv[0]);
|
test_i386();
|
||||||
}
|
}
|
||||||
|
|
||||||
// dynamically free shared library
|
// dynamically free shared library
|
||||||
|
@ -1,65 +1,16 @@
|
|||||||
|
CFLAGS += -Wall -Werror -I../../include
|
||||||
|
LDLIBS += -L../../ $(shell pkg-config --libs glib-2.0) -lpthread -lm -lunicorn
|
||||||
|
|
||||||
CFLAGS += -I../../include
|
EXECUTE_VARS = LD_LIBRARY_PATH=../../cmocka/src:../../ DYLD_LIBRARY_PATH=../../
|
||||||
|
|
||||||
ifeq (MING,$(findstring MING,$(shell uname -s)))
|
TESTS_SOURCE = $(wildcard *.c)
|
||||||
LDFLAGS += ../../unicorn.lib $(shell pkg-config --libs glib-2.0) -lpthread -lm
|
TESTS = $(TESTS_SOURCE:%.c=%)
|
||||||
else
|
|
||||||
LDFLAGS += ../../libunicorn.a $(shell pkg-config --libs glib-2.0) -lpthread -lm
|
|
||||||
endif
|
|
||||||
|
|
||||||
TESTS = map_crash map_write
|
.PHONY: all clean test
|
||||||
TESTS += sigill sigill2
|
|
||||||
TESTS += block_test
|
|
||||||
TESTS += ro_mem_test nr_mem_test
|
|
||||||
TESTS += timeout_segfault
|
|
||||||
TESTS += rep_movsb
|
|
||||||
TESTS += mem_unmap
|
|
||||||
TESTS += mem_double_unmap
|
|
||||||
TESTS += mem_protect
|
|
||||||
TESTS += mem_exec
|
|
||||||
TESTS += mips_kseg0_1
|
|
||||||
TESTS += eflags_nosync
|
|
||||||
TESTS += 00opcode_uc_crash
|
|
||||||
TESTS += eflags_noset
|
|
||||||
TESTS += mem_map_large
|
|
||||||
TESTS += invalid_read_in_cpu_tb_exec
|
|
||||||
TESTS += invalid_write_in_cpu_tb_exec_x86_64
|
|
||||||
TESTS += x86_16_segfault
|
|
||||||
TESTS += mips_invalid_read_of_size_4_when_tracing
|
|
||||||
TESTS += invalid_read_in_tb_flush_x86_64
|
|
||||||
TESTS += sparc_jump_to_zero
|
|
||||||
TESTS += mips_delay_slot_code_hook
|
|
||||||
TESTS += mem_nofree
|
|
||||||
TESTS += rw_hookstack
|
|
||||||
TESTS += threaded_emu_start
|
|
||||||
TESTS += emu_stop_in_hook_overrun
|
|
||||||
TESTS += mips_branch_likely_issue
|
|
||||||
TESTS += hook_extrainvoke
|
|
||||||
TESTS += sysenter_hook_x86
|
|
||||||
TESTS += emu_clear_errors
|
|
||||||
TESTS += mem_fuzz
|
|
||||||
TESTS += 001-bad_condition_code_0xe
|
|
||||||
TESTS += 002-qemu__fatal__unimplemented_control_register_write_0xffb___0x0
|
|
||||||
TESTS += 003-qemu__fatal__wdebug_not_implemented
|
|
||||||
TESTS += 004-segmentation_fault_1
|
|
||||||
TESTS += 005-qemu__fatal__illegal_instruction__0000___00000404
|
|
||||||
TESTS += 006-qemu__fatal__illegal_instruction__0421___00040026
|
|
||||||
TESTS += mem_64_c
|
|
||||||
TESTS += mem_map_0x100000000
|
|
||||||
|
|
||||||
TESTS += memleak_x86
|
test: $(TESTS)
|
||||||
TESTS += memleak_arm
|
|
||||||
TESTS += memleak_arm64
|
|
||||||
TESTS += memleak_mips
|
|
||||||
TESTS += memleak_m68k
|
|
||||||
TESTS += memleak_sparc
|
|
||||||
|
|
||||||
all: $(TESTS)
|
all: $(TESTS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(TESTS)
|
rm -f $(TESTS)
|
||||||
|
|
||||||
%: %.c
|
|
||||||
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
|
|
||||||
|
|
||||||
.PHONY: all clean
|
|
||||||
|
@ -63,7 +63,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
fprintf(stderr, "ok %d - uc_mem_write\n", count++);
|
fprintf(stderr, "ok %d - uc_mem_write\n", count++);
|
||||||
|
|
||||||
uc_hook h1, h2;
|
uc_hook h1;
|
||||||
|
|
||||||
err = uc_hook_add(uc, &h1, UC_HOOK_BLOCK, cb_hookblock, NULL, 1, 0);
|
err = uc_hook_add(uc, &h1, UC_HOOK_BLOCK, cb_hookblock, NULL, 1, 0);
|
||||||
if (err != UC_ERR_OK) {
|
if (err != UC_ERR_OK) {
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#define PAGE_4K (1 << 12)
|
#define PAGE_4K (1 << 12)
|
||||||
#define TARGET_PAGE_MASK ~(PAGE_4K - 1)
|
#define TARGET_PAGE_MASK ~(PAGE_4K - 1)
|
||||||
#define TARGET_PAGE_PREPARE(addr) (((addr) + PAGE_4K - 1) & TARGET_PAGE_MASK)
|
#define TARGET_PAGE_PREPARE(addr) (((addr) + PAGE_4K - 1) & TARGET_PAGE_MASK)
|
||||||
#define TARGET_PAGE_ALIGN(addr) (addr - (TARGET_PAGE_PREPARE(addr) - addr) & TARGET_PAGE_MASK)
|
#define TARGET_PAGE_ALIGN(addr) ((addr - (TARGET_PAGE_PREPARE(addr) - addr)) & TARGET_PAGE_MASK)
|
||||||
|
|
||||||
static uint64_t instructions = 0;
|
static uint64_t instructions = 0;
|
||||||
|
|
||||||
@ -69,7 +69,6 @@ static void VM_exec()
|
|||||||
{
|
{
|
||||||
uc_engine *uc;
|
uc_engine *uc;
|
||||||
uc_err err;
|
uc_err err;
|
||||||
uint32_t tmp;
|
|
||||||
uc_hook trace1, trace2;
|
uc_hook trace1, trace2;
|
||||||
unsigned int r_eax, r_ebx, r_ecx, r_edx, r_ebp, r_esp, r_esi, r_edi, r_eip, eflags;
|
unsigned int r_eax, r_ebx, r_ecx, r_edx, r_ebp, r_esp, r_esi, r_edi, r_eip, eflags;
|
||||||
unsigned int tr_eax, tr_ebx, tr_ecx, tr_edx, tr_ebp, tr_esp, tr_esi, tr_edi, tr_eip, t_eflags;
|
unsigned int tr_eax, tr_ebx, tr_ecx, tr_edx, tr_ebp, tr_esp, tr_esi, tr_edi, tr_eip, t_eflags;
|
||||||
|
@ -60,7 +60,6 @@ int main(int argc, char **argv, char **envp)
|
|||||||
{
|
{
|
||||||
uc_engine *uc;
|
uc_engine *uc;
|
||||||
uc_err err;
|
uc_err err;
|
||||||
int ret;
|
|
||||||
uc_hook hhc;
|
uc_hook hhc;
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <unicorn/unicorn.h>
|
#include <unicorn/unicorn.h>
|
||||||
|
|
||||||
uint64_t starts[] = {0x10000000, 0x110004000ll};
|
uint64_t starts[] = {0x10000000, 0x110004000ll};
|
||||||
@ -24,10 +25,10 @@ int main(int argc, char **argv, char **envp) {
|
|||||||
err = uc_mem_regions(uc, ®ions, &count);
|
err = uc_mem_regions(uc, ®ions, &count);
|
||||||
if (err == UC_ERR_OK) {
|
if (err == UC_ERR_OK) {
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
fprintf(stderr, "region %d: 0x%llx-0x%llx (%d)\n", i, regions[i].begin, regions[i].end - 1, regions[i].perms);
|
fprintf(stderr, "region %d: 0x%"PRIx64"-0x%"PRIx64" (%d)\n", i, regions[i].begin, regions[i].end - 1, regions[i].perms);
|
||||||
if (regions[i].begin != starts[i]) {
|
if (regions[i].begin != starts[i]) {
|
||||||
err_count++;
|
err_count++;
|
||||||
fprintf(stderr, " ERROR: region start does not match requested start address, expected 0x%llx, found 0x%llx\n",
|
fprintf(stderr, " ERROR: region start does not match requested start address, expected 0x%"PRIx64", found 0x%"PRIx64"\n",
|
||||||
starts[i], regions[i].begin);
|
starts[i], regions[i].begin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
int main(int argc, char **argv, char **envp)
|
int main(int argc, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
uc_engine *uc;
|
uc_engine *uc;
|
||||||
uc_hook trace1, trace2;
|
|
||||||
uc_err err;
|
uc_err err;
|
||||||
|
|
||||||
// Initialize emulator in X86-32bit mode
|
// Initialize emulator in X86-32bit mode
|
||||||
|
@ -84,7 +84,6 @@ void perform_fuzz_step(uc_engine *uc){
|
|||||||
int main(int argc, char **argv, char **envp)
|
int main(int argc, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
uc_engine *uc;
|
uc_engine *uc;
|
||||||
uc_hook trace1, trace2;
|
|
||||||
uc_err err;
|
uc_err err;
|
||||||
if(argc<2){
|
if(argc<2){
|
||||||
printf("usage: mem_fuzz $seed\n");
|
printf("usage: mem_fuzz $seed\n");
|
||||||
|
@ -8,7 +8,7 @@ int main() {
|
|||||||
printf("uc_open() failed: %s\n", uc_strerror(err));
|
printf("uc_open() failed: %s\n", uc_strerror(err));
|
||||||
}
|
}
|
||||||
printf("Trying large map.\n");
|
printf("Trying large map.\n");
|
||||||
if ((err = uc_mem_map(u, 0x60802000, 0x28bd211200004000, UC_PROT_ALL)) != UC_ERR_OK) {
|
if ((err = uc_mem_map(u, 0x60802000, (unsigned) 0x28bd211200004000, UC_PROT_ALL)) != UC_ERR_OK) {
|
||||||
printf("uc_mem_map() failed: %s\n", uc_strerror(err));
|
printf("uc_mem_map() failed: %s\n", uc_strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ static bool hook_mem_invalid(uc_engine *uc, uc_mem_type type,
|
|||||||
int main(int argc, char **argv, char **envp)
|
int main(int argc, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
uc_engine *uc;
|
uc_engine *uc;
|
||||||
uc_hook trace1, trace2;
|
uc_hook trace1;
|
||||||
uc_err err;
|
uc_err err;
|
||||||
uint32_t eax, ebx;
|
uint32_t eax, ebx;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ bottom:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// callback for tracing instruction
|
// callback for tracing instruction
|
||||||
static void hook_code(uc_engine *uc, uint64_t address, uint32_t size, void *user_data)
|
/*static void hook_code(uc_engine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||||
{
|
{
|
||||||
uint32_t esp;
|
uint32_t esp;
|
||||||
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
||||||
@ -55,6 +55,7 @@ static void hook_code(uc_engine *uc, uint64_t address, uint32_t size, void *user
|
|||||||
printf(">>> --- ESP is 0x%x\n", esp);
|
printf(">>> --- ESP is 0x%x\n", esp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// callback for tracing memory access (READ or WRITE)
|
// callback for tracing memory access (READ or WRITE)
|
||||||
static bool hook_mem_invalid(uc_engine *uc, uc_mem_type type,
|
static bool hook_mem_invalid(uc_engine *uc, uc_mem_type type,
|
||||||
@ -95,11 +96,10 @@ static bool hook_mem_invalid(uc_engine *uc, uc_mem_type type,
|
|||||||
int main(int argc, char **argv, char **envp)
|
int main(int argc, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
uc_engine *uc;
|
uc_engine *uc;
|
||||||
uc_hook trace1, trace2;
|
uc_hook trace1;
|
||||||
uc_err err;
|
uc_err err;
|
||||||
uint8_t bytes[8];
|
uint8_t bytes[8];
|
||||||
uint32_t esp;
|
uint32_t esp;
|
||||||
int result;
|
|
||||||
int map_stack = 0;
|
int map_stack = 0;
|
||||||
|
|
||||||
if (argc == 2 && strcmp(argv[1], "--map-stack") == 0) {
|
if (argc == 2 && strcmp(argv[1], "--map-stack") == 0) {
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
uint8_t *buf;
|
|
||||||
uc_engine *uc;
|
uc_engine *uc;
|
||||||
|
|
||||||
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc);
|
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc);
|
||||||
|
Reference in New Issue
Block a user