diff --git a/.appveyor.yml b/.appveyor.yml index 03d5d411..6a699bb0 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,21 +1,23 @@ # Appveyor configuration file for CI build of Unicorn Engine on Windows (under Cygwin) environment: + CYG_MIRROR: http://cygwin.mirror.constant.com 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_SETUP: setup-x86_64.exe - CYG_MIRROR: http://cygwin.mirror.constant.com 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 - CYG_ROOT: C:\cygwin - CYG_SETUP: setup-x86.exe - CYG_MIRROR: http://cygwin.mirror.constant.com 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 -# - 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: @@ -30,12 +32,13 @@ init: # Install needed build dependencies install: - - ps: 'if ($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 MSYS_ROOT (%MSYS_BASH% -lc "pacman -S --noconfirm mingw-w64-x86_64-glib2") + - 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,ruby,mingw64-i686-gcc-core,mingw64-x86_64-gcc-core --upgrade-also) + - if defined MSYSTEM (%BASH% -lc "pacman -Sy --noconfirm mingw-w64-x86_64-glib2 mingw-w64-i686-glib2 cmake") 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 MSYS_ROOT (%MSYS_BASH% -lc "MSYS=winsymlinks, cd $(cygpath ${APPVEYOR_BUILD_FOLDER}); x86_64-w64-mingw32-gcc --version; ./install-cmocka-linux.sh; make") + - if defined BASH (%BASH% -lc "cd $(cygpath ${APPVEYOR_BUILD_FOLDER}); ./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' # Allows RDP #on_finish: @@ -43,4 +46,5 @@ build_script: # 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") diff --git a/.travis.yml b/.travis.yml index 75139721..543cbb42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" == "linux" ]]; then ./install-cmocka-linux.sh; fi script: - - make && make test -# TODO make bindings enabled -# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then make clean && ./make.sh ios; fi + - make && make -C bindings/go && make -C bindings/go test && make test compiler: - clang - gcc @@ -23,8 +21,6 @@ matrix: - os: osx compiler: gcc env: MACOS_UNIVERSAL=yes -# - os: osx -# compiler: x86_64-w64-mingw32-gcc addons: apt: packages: diff --git a/Makefile b/Makefile index 2f828d35..e9c04294 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,7 @@ include pkgconfig.mk # package version LIBNAME = unicorn 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)\ - $(wildcard qemu/hw/core/*.o) $(wildcard qemu/qapi/*.o) $(wildcard qemu/qobject/*.o) +GENOBJ = $(shell find qemu/$(1) -name "*.o" 2>/dev/null) ifneq (,$(findstring x86,$(UNICORN_ARCHS))) UC_TARGET_OBJ += $(call GENOBJ,x86_64-softmmu) @@ -196,6 +195,8 @@ else PKGCFGDIR ?= $(LIBDATADIR)/pkgconfig endif +$(LIBNAME)_LDFLAGS += $(GLIB) -lm + .PHONY: all all: unicorn $(MAKE) -C samples @@ -210,15 +211,16 @@ qemu/config-host.h-timestamp: compile_lib: config qemu/config-host.h-timestamp $(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) - $(CC) $(CFLAGS) -shared $(GENOBJ) uc.o list.o -o $(LIBRARY) $(GLIB) -lm $($(LIBNAME)_LDFLAGS) - ln -sf $(LIBRARY) $(LIBRARY_SYMLINK) +$(LIBRARY): compile_lib uc.o list.o + $(CC) $(CFLAGS) -shared $(UC_TARGET_OBJ) uc.o list.o -o $(LIBRARY) $($(LIBNAME)_LDFLAGS) + -ln -sf $(LIBRARY) $(LIBRARY_SYMLINK) -$(ARCHIVE): $(UC_TARGET_OBJ) uc.o list.o - $(AR) q $(ARCHIVE) $^ +$(ARCHIVE): compile_lib uc.o list.o + $(AR) q $(ARCHIVE) $(UC_TARGET_OBJ) uc.o list.o $(RANLIB) $(ARCHIVE) @@ -228,6 +230,7 @@ $(PKGCFGF): .PHONY: test test: all $(MAKE) -C tests/unit test + $(MAKE) -C tests/regress test $(MAKE) -C bindings test install: compile_lib $(PKGCFGF) diff --git a/bindings/Makefile b/bindings/Makefile index 7ded2e10..ed958f75 100644 --- a/bindings/Makefile +++ b/bindings/Makefile @@ -1,19 +1,17 @@ # Unicorn Engine # By Nguyen Anh Quynh & Dang Hoang Vu, 2015 -TMP_DIR = /tmp/unicorn_sample +DIFF = diff -DIFF = diff -u -w - -SAMPLE_ARM = $(TMP_DIR)/sample_arm -SAMPLE_ARM64 = $(TMP_DIR)/sample_arm64 -SAMPLE_MIPS = $(TMP_DIR)/sample_mips -SAMPLE_M68K = $(TMP_DIR)/sample_m68k -SAMPLE_SPARC = $(TMP_DIR)/sample_sparc -SAMPLE_X86 = $(TMP_DIR)/sample_x86 +SAMPLE_SOURCE = $(wildcard ../samples/*.c) +SAMPLE = $(SAMPLE_SOURCE:../samples/%.c=%) +SAMPLE := $(SAMPLE:mem_apis=) +SAMPLE := $(SAMPLE:sample_batch_reg=) +SAMPLE := $(SAMPLE:sample_x86_32_gdt_and_seg_regs=) +SAMPLE := $(SAMPLE:shellcode=) 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: $(MAKE) -C python gen_const @@ -26,39 +24,22 @@ install: build $(MAKE) -C python install $(MAKE) -C java install -test: expected python sample_diff +test: $(SAMPLE:%=%.py.test) -expected: +c: $(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: $(MAKE) -C python - $(ENV_VARS) python python/sample_arm.py > $(SAMPLE_ARM)_o - $(ENV_VARS) python python/sample_arm64.py > $(SAMPLE_ARM64)_o - $(ENV_VARS) python python/sample_mips.py > $(SAMPLE_MIPS)_o - $(ENV_VARS) python python/sample_sparc.py > $(SAMPLE_SPARC)_o - $(ENV_VARS) python python/sample_m68k.py > $(SAMPLE_M68K)_o - $(ENV_VARS) python python/sample_x86.py > $(SAMPLE_X86)_o +%.c.txt: c + $(ENV_VARS) ../samples/$(@:%.c.txt=%) > $@ +%.py.txt: python + $(ENV_VARS) python python/$(@:%.txt=%) > $@ -sample_diff: - $(DIFF) $(SAMPLE_ARM)_e $(SAMPLE_ARM)_o - $(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 +%.py.test: %.c.txt %.py.txt + $(DIFF) $(@:%.py.test=%.c.txt) $(@:%.py.test=%.py.txt) clean: - rm -rf $(TMP_DIR) +# rm -rf *.txt $(MAKE) -C python clean $(MAKE) -C java clean diff --git a/bindings/go/Makefile b/bindings/go/Makefile index 17e450c2..fe898ae1 100644 --- a/bindings/go/Makefile +++ b/bindings/go/Makefile @@ -1,14 +1,12 @@ # Go binding for Unicorn engine. Ryan Hileman -.PHONY: gen_const test +.PHONY: all gen_const test -all: - $(MAKE) gen_const +all: gen_const cd unicorn && go build - $(MAKE) test gen_const: cd .. && python const_generator.py go -test: - cd unicorn && go test +test: all + cd unicorn && LD_LIBRARY_PATH=../../../ DYLD_LIBRARY_PATH=../../../ go test diff --git a/bindings/go/unicorn/unicorn.go b/bindings/go/unicorn/unicorn.go index 58e28939..6ac3ecce 100644 --- a/bindings/go/unicorn/unicorn.go +++ b/bindings/go/unicorn/unicorn.go @@ -7,8 +7,8 @@ import ( ) /* -#cgo CFLAGS: -O3 -#cgo LDFLAGS: -lunicorn +#cgo CFLAGS: -O3 -Wall -Werror -I../../../include +#cgo LDFLAGS: -L../../../ -lunicorn -lglib-2.0 #include #include "uc.h" */ diff --git a/bindings/python/sample_x86.py b/bindings/python/sample_x86.py index 981a6d5e..a6a54615 100755 --- a/bindings/python/sample_x86.py +++ b/bindings/python/sample_x86.py @@ -442,38 +442,25 @@ def test_i386_context_save(): # write machine code to be emulated to memory mu.mem_write(address, code) - print(">>> set eax to 1") + # set eax to 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) - 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() - print(">>> execute 'inc eax'") + print(">>> Running emulation for the second time") 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") - assert mu.reg_read(UC_X86_REG_EAX) == 3 - - print(">>> restore the CPU context") + print(">>> CPU context restored. Below is the CPU context") mu.context_restore(saved_context) - - 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 + print(">>> EAX = 0x%x" %(mu.reg_read(UC_X86_REG_EAX))) except UcError as e: print("ERROR: %s" % e) @@ -644,6 +631,8 @@ if __name__ == '__main__': print("=" * 35) test_i386_inout() print("=" * 35) + test_i386_context_save() + print("=" * 35) test_i386_jump() print("=" * 35) test_i386_loop() diff --git a/bindings/python/shellcode.py b/bindings/python/shellcode.py index 898ada7b..ed65effa 100755 --- a/bindings/python/shellcode.py +++ b/bindings/python/shellcode.py @@ -21,7 +21,7 @@ def hook_code(uc, address, size, user_data): print(">>> Tracing instruction at 0x%x, instruction size = 0x%x" %(address, size)) # read this instruction code from memory tmp = uc.mem_read(address, size) - print(">>> Instruction code at [0x%x] =" %(address), end="") + print("*** EIP = %x *** :" %(address), end="") for i in tmp: print(" %02x" %i, end="") print("") diff --git a/bindings/python/unicorn/unicorn.py b/bindings/python/unicorn/unicorn.py index 1bad25fa..45056726 100644 --- a/bindings/python/unicorn/unicorn.py +++ b/bindings/python/unicorn/unicorn.py @@ -17,12 +17,11 @@ _python2 = sys.version_info[0] < 3 if _python2: range = xrange -if sys.platform == 'darwin': - _lib = "libunicorn.dylib" -elif sys.platform in ('win32', 'cygwin'): - _lib = "unicorn.dll" -else: - _lib = "libunicorn.so" +_lib = { 'darwin': 'libunicorn.dylib', + 'win32': 'unicorn.dll', + 'cygwin': 'cygunicorn.dll', + 'linux': 'libunicorn.so', + 'linux2': 'libunicorn.so' } # Windows DLL in dependency order _all_windows_dlls = ( @@ -45,7 +44,7 @@ def _load_lib(path): if sys.platform in ('win32', 'cygwin'): _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) except OSError: return None diff --git a/bindings/ruby/Makefile b/bindings/ruby/Makefile index 6e801fc6..6fa1faf3 100644 --- a/bindings/ruby/Makefile +++ b/bindings/ruby/Makefile @@ -2,8 +2,8 @@ .PHONY: gen_const -install: - $(MAKE) gen_const +# Use bundle install && rake to install gem and test +install: gen_const cd unicorn_gem && rake build cd unicorn_gem && gem install --local pkg/unicorn-0.9.0.gem diff --git a/install-cmocka-linux.sh b/install-cmocka-linux.sh index feb9bd36..86b5df11 100755 --- a/install-cmocka-linux.sh +++ b/install-cmocka-linux.sh @@ -1,8 +1,12 @@ -#!/bin/sh +#!/bin/bash set -ex mkdir cmocka 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 +fi #cmocka does not include headers in build cp -R /tmp/cmocka-1.1.0/include/ . diff --git a/samples/sample_x86.c b/samples/sample_x86.c index 4c5da3e3..12af8372 100644 --- a/samples/sample_x86.c +++ b/samples/sample_x86.c @@ -996,13 +996,15 @@ int main(int argc, char **argv, char **envp) printf("Error dynamically loading shared library.\n"); printf("Please check that unicorn.dll/unicorn.so is available as well as\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; } #endif - if (argc == 2) { - if (!strcmp(argv[1], "-32")) { + if (argc == 2) { + if (!strcmp(argv[1], "-16")) { + test_x86_16(); + } + else if (!strcmp(argv[1], "-32")) { test_i386(); test_i386_map_ptr(); test_i386_inout(); @@ -1013,19 +1015,29 @@ int main(int argc, char **argv, char **envp) test_i386_invalid_mem_write(); test_i386_jump_invalid(); } - - if (!strcmp(argv[1], "-64")) { + else if (!strcmp(argv[1], "-64")) { test_x86_64(); test_x86_64_syscall(); } - - if (!strcmp(argv[1], "-16")) { - test_x86_16(); + else if (!strcmp(argv[1], "-h")) { + printf("Syntax: %s <-16|-32|-64>\n", argv[0]); } - } 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 #ifdef DYNLOAD uc_dyn_free(); diff --git a/samples/shellcode.c b/samples/shellcode.c index 8ad0c69b..ee706a6e 100644 --- a/samples/shellcode.c +++ b/samples/shellcode.c @@ -168,12 +168,15 @@ int main(int argc, char **argv, char **envp) } #endif - if (argc == 2) { + if (argc == 2) { if (!strcmp(argv[1], "-32")) { test_i386(); } + else if (!strcmp(argv[1], "-h")) { + printf("Syntax: %s <-32|-64>\n", argv[0]); + } } else { - printf("Syntax: %s <-32|-64>\n", argv[0]); + test_i386(); } // dynamically free shared library diff --git a/tests/regress/Makefile b/tests/regress/Makefile index 532f6da0..f9ff4a8b 100644 --- a/tests/regress/Makefile +++ b/tests/regress/Makefile @@ -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))) -LDFLAGS += ../../unicorn.lib $(shell pkg-config --libs glib-2.0) -lpthread -lm -else -LDFLAGS += ../../libunicorn.a $(shell pkg-config --libs glib-2.0) -lpthread -lm -endif +TESTS_SOURCE = $(wildcard *.c) +TESTS = $(TESTS_SOURCE:%.c=%) -TESTS = map_crash map_write -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 +.PHONY: all clean test -TESTS += memleak_x86 -TESTS += memleak_arm -TESTS += memleak_arm64 -TESTS += memleak_mips -TESTS += memleak_m68k -TESTS += memleak_sparc +test: $(TESTS) all: $(TESTS) clean: rm -f $(TESTS) - -%: %.c - $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ - -.PHONY: all clean diff --git a/tests/regress/block_test.c b/tests/regress/block_test.c index 71d1021f..979d989f 100644 --- a/tests/regress/block_test.c +++ b/tests/regress/block_test.c @@ -63,7 +63,7 @@ int main() { } 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); if (err != UC_ERR_OK) { diff --git a/tests/regress/eflags_nosync.c b/tests/regress/eflags_nosync.c index 3510b499..433dcfbc 100644 --- a/tests/regress/eflags_nosync.c +++ b/tests/regress/eflags_nosync.c @@ -11,7 +11,7 @@ #define PAGE_4K (1 << 12) #define TARGET_PAGE_MASK ~(PAGE_4K - 1) #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; @@ -69,7 +69,6 @@ static void VM_exec() { uc_engine *uc; uc_err err; - uint32_t tmp; 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 tr_eax, tr_ebx, tr_ecx, tr_edx, tr_ebp, tr_esp, tr_esi, tr_edi, tr_eip, t_eflags; diff --git a/tests/regress/emu_stop_in_hook_overrun.c b/tests/regress/emu_stop_in_hook_overrun.c index 9b962a25..2336fc4b 100644 --- a/tests/regress/emu_stop_in_hook_overrun.c +++ b/tests/regress/emu_stop_in_hook_overrun.c @@ -60,7 +60,6 @@ int main(int argc, char **argv, char **envp) { uc_engine *uc; uc_err err; - int ret; uc_hook hhc; uint32_t val; diff --git a/tests/regress/mem_64_c.c b/tests/regress/mem_64_c.c index e09a90da..b760fd08 100644 --- a/tests/regress/mem_64_c.c +++ b/tests/regress/mem_64_c.c @@ -1,4 +1,5 @@ #include +#include #include uint64_t starts[] = {0x10000000, 0x110004000ll}; @@ -24,10 +25,10 @@ int main(int argc, char **argv, char **envp) { err = uc_mem_regions(uc, ®ions, &count); if (err == UC_ERR_OK) { 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]) { 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); } } diff --git a/tests/regress/mem_double_unmap.c b/tests/regress/mem_double_unmap.c index 3373a5cc..e7203ab8 100644 --- a/tests/regress/mem_double_unmap.c +++ b/tests/regress/mem_double_unmap.c @@ -11,7 +11,6 @@ int main(int argc, char **argv, char **envp) { uc_engine *uc; - uc_hook trace1, trace2; uc_err err; // Initialize emulator in X86-32bit mode diff --git a/tests/regress/mem_fuzz.c b/tests/regress/mem_fuzz.c index bbf37eec..c62d74c0 100644 --- a/tests/regress/mem_fuzz.c +++ b/tests/regress/mem_fuzz.c @@ -84,7 +84,6 @@ void perform_fuzz_step(uc_engine *uc){ int main(int argc, char **argv, char **envp) { uc_engine *uc; - uc_hook trace1, trace2; uc_err err; if(argc<2){ printf("usage: mem_fuzz $seed\n"); diff --git a/tests/regress/mem_map_large.c b/tests/regress/mem_map_large.c index 33f754a4..f0f4cdbf 100644 --- a/tests/regress/mem_map_large.c +++ b/tests/regress/mem_map_large.c @@ -8,7 +8,7 @@ int main() { printf("uc_open() failed: %s\n", uc_strerror(err)); } 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)); return -1; } diff --git a/tests/regress/nr_mem_test.c b/tests/regress/nr_mem_test.c index b6ab8d8e..40ffa39f 100644 --- a/tests/regress/nr_mem_test.c +++ b/tests/regress/nr_mem_test.c @@ -55,7 +55,7 @@ static bool hook_mem_invalid(uc_engine *uc, uc_mem_type type, int main(int argc, char **argv, char **envp) { uc_engine *uc; - uc_hook trace1, trace2; + uc_hook trace1; uc_err err; uint32_t eax, ebx; diff --git a/tests/regress/ro_mem_test.c b/tests/regress/ro_mem_test.c index 845859b1..b5b26393 100644 --- a/tests/regress/ro_mem_test.c +++ b/tests/regress/ro_mem_test.c @@ -46,7 +46,7 @@ bottom: */ // 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; 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); } +*/ // callback for tracing memory access (READ or WRITE) 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) { uc_engine *uc; - uc_hook trace1, trace2; + uc_hook trace1; uc_err err; uint8_t bytes[8]; uint32_t esp; - int result; int map_stack = 0; if (argc == 2 && strcmp(argv[1], "--map-stack") == 0) { diff --git a/tests/regress/sigill2.c b/tests/regress/sigill2.c index 1e5b7284..8e6ad560 100644 --- a/tests/regress/sigill2.c +++ b/tests/regress/sigill2.c @@ -9,7 +9,6 @@ int main() { int size; - uint8_t *buf; uc_engine *uc; uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc);