From 9e64cba6ecfd0cf434a0633d18a7474d725ec9ad Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Wed, 30 Sep 2015 14:46:55 +0800 Subject: [PATCH] Rename some hook related enums: - UC_ERR_READ_INVALID -> UC_ERR_READ_UNMAPPED - UC_ERR_WRITE_INVALID -> UC_ERR_WRITE_UNMAPPED - UC_ERR_FETCH_INVALID -> UC_ERR_FETCH_UNMAPPED - UC_MEM_READ_INVALID -> UC_MEM_READ_UNMAPPED - UC_MEM_WRITE_INVALID -> UC_MEM_WRITE_UNMAPPED - UC_MEM_FETCH_INVALID -> UC_MEM_FETCH_UNMAPPED - UC_HOOK_MEM_READ_INVALID -> UC_HOOK_MEM_READ_UNMAPPED - UC_HOOK_MEM_WRITE_INVALID -> UC_HOOK_MEM_WRITE_UNMAPPED - UC_HOOK_MEM_FETCH_INVALID -> UC_HOOK_MEM_FETCH_UNMAPPED - UC_HOOK_MEM_INVALID -> UC_HOOK_MEM_UNMAPPED This also renames some newly added macros to use _INVALID postfix: - UC_HOOK_MEM_READ_ERR -> UC_HOOK_MEM_READ_INVALID - UC_HOOK_MEM_WRITE_ERR -> UC_HOOK_MEM_WRITE_INVALID - UC_HOOK_MEM_FETCH_ERR -> UC_HOOK_MEM_FETCH_INVALID - UC_HOOK_MEM_ERR -> UC_HOOK_MEM_INVALID Fixed all the bindings Java, Go & Python. --- bindings/go/unicorn/hook.go | 2 +- bindings/go/unicorn/unicorn_const.go | 39 +++++++++++----------- bindings/java/samples/Sample_x86.java | 2 +- bindings/java/unicorn/Unicorn.java | 14 ++++---- bindings/java/unicorn/UnicornConst.java | 39 +++++++++++----------- bindings/java/unicorn/UnicornErrors.java | 7 ++-- bindings/java/unicorn_Unicorn.c | 8 ++--- bindings/python/sample_x86.py | 4 +-- bindings/python/unicorn/unicorn.py | 4 +-- bindings/python/unicorn/unicorn_const.py | 39 +++++++++++----------- include/unicorn/unicorn.h | 31 +++++++++--------- qemu/cpu-exec.c | 2 +- qemu/cputlb.c | 7 ++-- qemu/softmmu_template.h | 32 +++++++++--------- samples/mem_apis.c | 10 +++--- samples/sample_x86.c | 4 +-- tests/regress/arm_bxeq_hang.py | 3 +- tests/regress/jmp_ebx_hang.py | 4 +-- tests/regress/mem_unmap.c | 2 +- tests/regress/mips_except.py | 4 +-- tests/regress/reg_write_sign_extension.py | 2 +- tests/regress/ro_mem_test.c | 2 +- tests/regress/sparc_reg.py | 2 +- tests/unit/test_x86.c | 6 ++-- uc.c | 40 +++++++++++------------ 25 files changed, 151 insertions(+), 158 deletions(-) diff --git a/bindings/go/unicorn/hook.go b/bindings/go/unicorn/hook.go index c286f08f..3176df9f 100644 --- a/bindings/go/unicorn/hook.go +++ b/bindings/go/unicorn/hook.go @@ -90,7 +90,7 @@ func (u *uc) HookAdd(htype int, cb interface{}, extra ...uint64) (Hook, error) { } default: // special case for mask - if htype&(HOOK_MEM_READ_INVALID|HOOK_MEM_WRITE_INVALID|HOOK_MEM_FETCH_INVALID| + if htype&(HOOK_MEM_READ_UNMAPPED|HOOK_MEM_WRITE_UNMAPPED|HOOK_MEM_FETCH_UNMAPPED| HOOK_MEM_READ_PROT|HOOK_MEM_WRITE_PROT|HOOK_MEM_FETCH_PROT) != 0 { rangeMode = true callback = C.hookMemInvalid_cgo diff --git a/bindings/go/unicorn/unicorn_const.go b/bindings/go/unicorn/unicorn_const.go index 8bd35349..5afeec46 100644 --- a/bindings/go/unicorn/unicorn_const.go +++ b/bindings/go/unicorn/unicorn_const.go @@ -39,26 +39,25 @@ const ( ERR_HANDLE = 3 ERR_MODE = 4 ERR_VERSION = 5 - ERR_READ_INVALID = 6 - ERR_WRITE_INVALID = 7 - ERR_FETCH_INVALID = 8 - ERR_CODE_INVALID = 9 - ERR_HOOK = 10 - ERR_INSN_INVALID = 11 - ERR_MAP = 12 - ERR_WRITE_PROT = 13 - ERR_READ_PROT = 14 - ERR_FETCH_PROT = 15 - ERR_ARG = 16 - ERR_READ_UNALIGNED = 17 - ERR_WRITE_UNALIGNED = 18 - ERR_FETCH_UNALIGNED = 19 + ERR_READ_UNMAPPED = 6 + ERR_WRITE_UNMAPPED = 7 + ERR_FETCH_UNMAPPED = 8 + ERR_HOOK = 9 + ERR_INSN_INVALID = 10 + ERR_MAP = 11 + ERR_WRITE_PROT = 12 + ERR_READ_PROT = 13 + ERR_FETCH_PROT = 14 + ERR_ARG = 15 + ERR_READ_UNALIGNED = 16 + ERR_WRITE_UNALIGNED = 17 + ERR_FETCH_UNALIGNED = 18 MEM_READ = 16 MEM_WRITE = 17 MEM_FETCH = 18 - MEM_READ_INVALID = 19 - MEM_WRITE_INVALID = 20 - MEM_FETCH_INVALID = 21 + MEM_READ_UNMAPPED = 19 + MEM_WRITE_UNMAPPED = 20 + MEM_FETCH_UNMAPPED = 21 MEM_WRITE_PROT = 22 MEM_READ_PROT = 23 MEM_FETCH_PROT = 24 @@ -66,9 +65,9 @@ const ( HOOK_INSN = 2 HOOK_CODE = 4 HOOK_BLOCK = 8 - HOOK_MEM_READ_INVALID = 16 - HOOK_MEM_WRITE_INVALID = 32 - HOOK_MEM_FETCH_INVALID = 64 + HOOK_MEM_READ_UNMAPPED = 16 + HOOK_MEM_WRITE_UNMAPPED = 32 + HOOK_MEM_FETCH_UNMAPPED = 64 HOOK_MEM_READ_PROT = 128 HOOK_MEM_WRITE_PROT = 256 HOOK_MEM_FETCH_PROT = 512 diff --git a/bindings/java/samples/Sample_x86.java b/bindings/java/samples/Sample_x86.java index edda0e97..91ca2698 100644 --- a/bindings/java/samples/Sample_x86.java +++ b/bindings/java/samples/Sample_x86.java @@ -419,7 +419,7 @@ public class Sample_x86 { u.hook_add(new MyCodeHook(), 1, 0, null); // intercept invalid memory events - u.hook_add(new MyWriteInvalidHook(), Unicorn.UC_HOOK_MEM_WRITE_INVALID, null); + u.hook_add(new MyWriteInvalidHook(), Unicorn.UC_HOOK_MEM_WRITE_UNMAPPED, null); // emulate machine code in infinite time try { diff --git a/bindings/java/unicorn/Unicorn.java b/bindings/java/unicorn/Unicorn.java index 9abfeb60..5a28c267 100644 --- a/bindings/java/unicorn/Unicorn.java +++ b/bindings/java/unicorn/Unicorn.java @@ -72,9 +72,9 @@ public class Unicorn implements UnicornConst, ArmConst, Arm64Const, M68kConst, S //required to load native method implementations static { System.loadLibrary("unicorn_java"); //loads unicorn.dll or libunicorn.so - eventMemMap.put(UC_HOOK_MEM_READ_INVALID, UC_MEM_READ_INVALID); - eventMemMap.put(UC_HOOK_MEM_WRITE_INVALID, UC_MEM_WRITE_INVALID); - eventMemMap.put(UC_HOOK_MEM_FETCH_INVALID, UC_MEM_FETCH_INVALID); + eventMemMap.put(UC_HOOK_MEM_READ_UNMAPPED, UC_MEM_READ_UNMAPPED); + eventMemMap.put(UC_HOOK_MEM_WRITE_UNMAPPED, UC_MEM_WRITE_UNMAPPED); + eventMemMap.put(UC_HOOK_MEM_FETCH_UNMAPPED, UC_MEM_FETCH_UNMAPPED); eventMemMap.put(UC_HOOK_MEM_READ_PROT, UC_MEM_READ_PROT); eventMemMap.put(UC_HOOK_MEM_WRITE_PROT, UC_MEM_WRITE_PROT); eventMemMap.put(UC_HOOK_MEM_FETCH_PROT, UC_MEM_FETCH_PROT); @@ -140,10 +140,10 @@ public class Unicorn implements UnicornConst, ArmConst, Arm64Const, M68kConst, S } /** - * Invoke all UC_HOOK_MEM_XXX_INVALID andor UC_HOOK_MEM_XXX_PROT callbacks registered + * Invoke all UC_HOOK_MEM_XXX_UNMAPPED andor UC_HOOK_MEM_XXX_PROT callbacks registered * for a specific Unicorn. * This function gets invoked from the native C callback registered for - * for UC_HOOK_MEM_XXX_INVALID or UC_HOOK_MEM_XXX_PROT + * for UC_HOOK_MEM_XXX_UNMAPPED or UC_HOOK_MEM_XXX_PROT * * @param eng A Unicorn uc_engine* eng returned by uc_open * @param type The type of event that is taking place @@ -535,12 +535,12 @@ public class Unicorn implements UnicornConst, ArmConst, Arm64Const, M68kConst, S } /** - * Hook registration for UC_HOOK_MEM_XXX_INVALID and UC_HOOK_MEM_XXX_PROT hooks. + * Hook registration for UC_HOOK_MEM_XXX_UNMAPPED and UC_HOOK_MEM_XXX_PROT hooks. * The registered callback function will be invoked whenever a read or write is * attempted from an invalid or protected memory address. * * @param callback Implementation of a EventMemHook interface - * @param type Type of memory event being hooked such as UC_HOOK_MEM_READ_INVALID or UC_HOOK_MEM_WRITE_PROT + * @param type Type of memory event being hooked such as UC_HOOK_MEM_READ_UNMAPPED or UC_HOOK_MEM_WRITE_PROT * @param user_data User data to be passed to the callback function each time the event is triggered */ public void hook_add(EventMemHook callback, int type, Object user_data) throws UnicornException { diff --git a/bindings/java/unicorn/UnicornConst.java b/bindings/java/unicorn/UnicornConst.java index 615a6906..7cff4e63 100644 --- a/bindings/java/unicorn/UnicornConst.java +++ b/bindings/java/unicorn/UnicornConst.java @@ -41,26 +41,25 @@ public interface UnicornConst { public static final int UC_ERR_HANDLE = 3; public static final int UC_ERR_MODE = 4; public static final int UC_ERR_VERSION = 5; - public static final int UC_ERR_READ_INVALID = 6; - public static final int UC_ERR_WRITE_INVALID = 7; - public static final int UC_ERR_FETCH_INVALID = 8; - public static final int UC_ERR_CODE_INVALID = 9; - public static final int UC_ERR_HOOK = 10; - public static final int UC_ERR_INSN_INVALID = 11; - public static final int UC_ERR_MAP = 12; - public static final int UC_ERR_WRITE_PROT = 13; - public static final int UC_ERR_READ_PROT = 14; - public static final int UC_ERR_FETCH_PROT = 15; - public static final int UC_ERR_ARG = 16; - public static final int UC_ERR_READ_UNALIGNED = 17; - public static final int UC_ERR_WRITE_UNALIGNED = 18; - public static final int UC_ERR_FETCH_UNALIGNED = 19; + public static final int UC_ERR_READ_UNMAPPED = 6; + public static final int UC_ERR_WRITE_UNMAPPED = 7; + public static final int UC_ERR_FETCH_UNMAPPED = 8; + public static final int UC_ERR_HOOK = 9; + public static final int UC_ERR_INSN_INVALID = 10; + public static final int UC_ERR_MAP = 11; + public static final int UC_ERR_WRITE_PROT = 12; + public static final int UC_ERR_READ_PROT = 13; + public static final int UC_ERR_FETCH_PROT = 14; + public static final int UC_ERR_ARG = 15; + public static final int UC_ERR_READ_UNALIGNED = 16; + public static final int UC_ERR_WRITE_UNALIGNED = 17; + public static final int UC_ERR_FETCH_UNALIGNED = 18; public static final int UC_MEM_READ = 16; public static final int UC_MEM_WRITE = 17; public static final int UC_MEM_FETCH = 18; - public static final int UC_MEM_READ_INVALID = 19; - public static final int UC_MEM_WRITE_INVALID = 20; - public static final int UC_MEM_FETCH_INVALID = 21; + public static final int UC_MEM_READ_UNMAPPED = 19; + public static final int UC_MEM_WRITE_UNMAPPED = 20; + public static final int UC_MEM_FETCH_UNMAPPED = 21; public static final int UC_MEM_WRITE_PROT = 22; public static final int UC_MEM_READ_PROT = 23; public static final int UC_MEM_FETCH_PROT = 24; @@ -68,9 +67,9 @@ public interface UnicornConst { public static final int UC_HOOK_INSN = 2; public static final int UC_HOOK_CODE = 4; public static final int UC_HOOK_BLOCK = 8; - public static final int UC_HOOK_MEM_READ_INVALID = 16; - public static final int UC_HOOK_MEM_WRITE_INVALID = 32; - public static final int UC_HOOK_MEM_FETCH_INVALID = 64; + public static final int UC_HOOK_MEM_READ_UNMAPPED = 16; + public static final int UC_HOOK_MEM_WRITE_UNMAPPED = 32; + public static final int UC_HOOK_MEM_FETCH_UNMAPPED = 64; public static final int UC_HOOK_MEM_READ_PROT = 128; public static final int UC_HOOK_MEM_WRITE_PROT = 256; public static final int UC_HOOK_MEM_FETCH_PROT = 512; diff --git a/bindings/java/unicorn/UnicornErrors.java b/bindings/java/unicorn/UnicornErrors.java index 3d74aa3d..d3f376f5 100644 --- a/bindings/java/unicorn/UnicornErrors.java +++ b/bindings/java/unicorn/UnicornErrors.java @@ -31,9 +31,8 @@ public interface UnicornErrors { public static final int UC_ERR_VERSION = 6; // Unsupported version (bindings) public static final int UC_ERR_MEM_READ = 7; // Quit emulation due to invalid memory READ: uc_emu_start() public static final int UC_ERR_MEM_WRITE = 8; // Quit emulation due to invalid memory WRITE: uc_emu_start() - public static final int UC_ERR_CODE_INVALID = 9; // Quit emulation due to invalid code address: uc_emu_start() - public static final int UC_ERR_HOOK = 10; // Invalid hook type: uc_hook_add() - public static final int UC_ERR_INSN_INVALID = 11; // Quit emulation due to invalid instruction: uc_emu_start() - public static final int UC_ERR_MAP = 12; // Invalid memory mapping: uc_mem_map() + public static final int UC_ERR_HOOK = 9; // Invalid hook type: uc_hook_add() + public static final int UC_ERR_INSN_INVALID = 10; // Quit emulation due to invalid instruction: uc_emu_start() + public static final int UC_ERR_MAP = 11; // Invalid memory mapping: uc_mem_map() } diff --git a/bindings/java/unicorn_Unicorn.c b/bindings/java/unicorn_Unicorn.c index 470c6340..a14bd9e4 100644 --- a/bindings/java/unicorn_Unicorn.c +++ b/bindings/java/unicorn_Unicorn.c @@ -160,7 +160,7 @@ static void cb_hookmem(uc_engine *eng, uc_mem_type type, (*cachedJVM)->DetachCurrentThread(cachedJVM); } -// Callback function for handling memory events (for UC_HOOK_MEM_INVALID) +// Callback function for handling memory events (for UC_HOOK_MEM_UNMAPPED) // @type: this memory is being READ, or WRITE // @address: address where the code is being executed // @size: size of data being read or written @@ -389,9 +389,9 @@ JNIEXPORT jlong JNICALL Java_unicorn_Unicorn_registerHook__JI } err = uc_hook_add((uc_engine*)eng, &hh, (uc_hook_type)type, cb_hookintr, env); break; - case UC_HOOK_MEM_FETCH_INVALID: // Hook for all invalid memory access events - case UC_HOOK_MEM_READ_INVALID: // Hook for all invalid memory access events - case UC_HOOK_MEM_WRITE_INVALID: // Hook for all invalid memory access events + case UC_HOOK_MEM_FETCH_UNMAPPED: // Hook for all invalid memory access events + case UC_HOOK_MEM_READ_UNMAPPED: // Hook for all invalid memory access events + case UC_HOOK_MEM_WRITE_UNMAPPED: // Hook for all invalid memory access events case UC_HOOK_MEM_FETCH_PROT: // Hook for all invalid memory access events case UC_HOOK_MEM_READ_PROT: // Hook for all invalid memory access events case UC_HOOK_MEM_WRITE_PROT: // Hook for all invalid memory access events diff --git a/bindings/python/sample_x86.py b/bindings/python/sample_x86.py index 151ed73c..f4a98b22 100755 --- a/bindings/python/sample_x86.py +++ b/bindings/python/sample_x86.py @@ -33,7 +33,7 @@ def hook_code(uc, address, size, user_data): # callback for tracing invalid memory access (READ or WRITE) def hook_mem_invalid(uc, access, address, size, value, user_data): - if access == UC_MEM_WRITE_INVALID: + if access == UC_MEM_WRITE_UNMAPPED: print(">>> Missing memory is being WRITE at 0x%x, data size = %u, data value = 0x%x" \ %(address, size, value)) # map this memory in with 2MB in size @@ -231,7 +231,7 @@ def test_i386_invalid_mem_write(): #mu.hook_add(UC_HOOK_CODE, hook_code) # intercept invalid memory events - mu.hook_add(UC_HOOK_MEM_READ_INVALID | UC_HOOK_MEM_WRITE_INVALID, hook_mem_invalid) + mu.hook_add(UC_HOOK_MEM_READ_UNMAPPED | UC_HOOK_MEM_WRITE_UNMAPPED, hook_mem_invalid) try: # emulate machine code in infinite time diff --git a/bindings/python/unicorn/unicorn.py b/bindings/python/unicorn/unicorn.py index dd67306a..d8fc62b0 100644 --- a/bindings/python/unicorn/unicorn.py +++ b/bindings/python/unicorn/unicorn.py @@ -272,8 +272,8 @@ class Uc(object): cb = ctypes.cast(UC_HOOK_CODE_CB(self._hookcode_cb), UC_HOOK_CODE_CB) status = _uc.uc_hook_add(self._uch, ctypes.byref(_h2), htype, cb, \ ctypes.cast(self._callback_count, ctypes.c_void_p), begin, end) - elif htype & UC_HOOK_MEM_READ_INVALID or htype & UC_HOOK_MEM_WRITE_INVALID or \ - htype & UC_HOOK_MEM_FETCH_INVALID or htype & UC_HOOK_MEM_READ_PROT or \ + elif htype & UC_HOOK_MEM_READ_UNMAPPED or htype & UC_HOOK_MEM_WRITE_UNMAPPED or \ + htype & UC_HOOK_MEM_FETCH_UNMAPPED or htype & UC_HOOK_MEM_READ_PROT or \ htype & UC_HOOK_MEM_WRITE_PROT or htype & UC_HOOK_MEM_FETCH_PROT: cb = ctypes.cast(UC_HOOK_MEM_INVALID_CB(self._hook_mem_invalid_cb), UC_HOOK_MEM_INVALID_CB) status = _uc.uc_hook_add(self._uch, ctypes.byref(_h2), htype, \ diff --git a/bindings/python/unicorn/unicorn_const.py b/bindings/python/unicorn/unicorn_const.py index 467cdd29..a401c83a 100644 --- a/bindings/python/unicorn/unicorn_const.py +++ b/bindings/python/unicorn/unicorn_const.py @@ -37,26 +37,25 @@ UC_ERR_ARCH = 2 UC_ERR_HANDLE = 3 UC_ERR_MODE = 4 UC_ERR_VERSION = 5 -UC_ERR_READ_INVALID = 6 -UC_ERR_WRITE_INVALID = 7 -UC_ERR_FETCH_INVALID = 8 -UC_ERR_CODE_INVALID = 9 -UC_ERR_HOOK = 10 -UC_ERR_INSN_INVALID = 11 -UC_ERR_MAP = 12 -UC_ERR_WRITE_PROT = 13 -UC_ERR_READ_PROT = 14 -UC_ERR_FETCH_PROT = 15 -UC_ERR_ARG = 16 -UC_ERR_READ_UNALIGNED = 17 -UC_ERR_WRITE_UNALIGNED = 18 -UC_ERR_FETCH_UNALIGNED = 19 +UC_ERR_READ_UNMAPPED = 6 +UC_ERR_WRITE_UNMAPPED = 7 +UC_ERR_FETCH_UNMAPPED = 8 +UC_ERR_HOOK = 9 +UC_ERR_INSN_INVALID = 10 +UC_ERR_MAP = 11 +UC_ERR_WRITE_PROT = 12 +UC_ERR_READ_PROT = 13 +UC_ERR_FETCH_PROT = 14 +UC_ERR_ARG = 15 +UC_ERR_READ_UNALIGNED = 16 +UC_ERR_WRITE_UNALIGNED = 17 +UC_ERR_FETCH_UNALIGNED = 18 UC_MEM_READ = 16 UC_MEM_WRITE = 17 UC_MEM_FETCH = 18 -UC_MEM_READ_INVALID = 19 -UC_MEM_WRITE_INVALID = 20 -UC_MEM_FETCH_INVALID = 21 +UC_MEM_READ_UNMAPPED = 19 +UC_MEM_WRITE_UNMAPPED = 20 +UC_MEM_FETCH_UNMAPPED = 21 UC_MEM_WRITE_PROT = 22 UC_MEM_READ_PROT = 23 UC_MEM_FETCH_PROT = 24 @@ -64,9 +63,9 @@ UC_HOOK_INTR = 1 UC_HOOK_INSN = 2 UC_HOOK_CODE = 4 UC_HOOK_BLOCK = 8 -UC_HOOK_MEM_READ_INVALID = 16 -UC_HOOK_MEM_WRITE_INVALID = 32 -UC_HOOK_MEM_FETCH_INVALID = 64 +UC_HOOK_MEM_READ_UNMAPPED = 16 +UC_HOOK_MEM_WRITE_UNMAPPED = 32 +UC_HOOK_MEM_FETCH_UNMAPPED = 64 UC_HOOK_MEM_READ_PROT = 128 UC_HOOK_MEM_WRITE_PROT = 256 UC_HOOK_MEM_FETCH_PROT = 512 diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index e70ca737..bc4edd40 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -111,10 +111,9 @@ typedef enum uc_err { UC_ERR_HANDLE, // Invalid handle UC_ERR_MODE, // Invalid/unsupported mode: uc_open() UC_ERR_VERSION, // Unsupported version (bindings) - UC_ERR_READ_INVALID, // Quit emulation due to invalid memory READ: uc_emu_start() - UC_ERR_WRITE_INVALID, // Quit emulation due to invalid memory WRITE: uc_emu_start() - UC_ERR_FETCH_INVALID, // Quit emulation due to invalid memory FETCH: uc_emu_start() - UC_ERR_CODE_INVALID, // Quit emulation due to invalid code address: uc_emu_start() + UC_ERR_READ_UNMAPPED, // Quit emulation due to READ on unmapped memory: uc_emu_start() + UC_ERR_WRITE_UNMAPPED, // Quit emulation due to WRITE on unmapped memory: uc_emu_start() + UC_ERR_FETCH_UNMAPPED, // Quit emulation due to FETCH on unmapped memory: uc_emu_start() UC_ERR_HOOK, // Invalid hook type: uc_hook_add() UC_ERR_INSN_INVALID, // Quit emulation due to invalid instruction: uc_emu_start() UC_ERR_MAP, // Invalid memory mapping: uc_mem_map() @@ -156,9 +155,9 @@ typedef enum uc_mem_type { UC_MEM_READ = 16, // Memory is read from UC_MEM_WRITE, // Memory is written to UC_MEM_FETCH, // Memory is fetched - UC_MEM_READ_INVALID, // Unmapped memory is read from - UC_MEM_WRITE_INVALID, // Unmapped memory is written to - UC_MEM_FETCH_INVALID, // Unmapped memory is fetched + UC_MEM_READ_UNMAPPED, // Unmapped memory is read from + UC_MEM_WRITE_UNMAPPED, // Unmapped memory is written to + UC_MEM_FETCH_UNMAPPED, // Unmapped memory is fetched UC_MEM_WRITE_PROT, // Write to write protected, but mapped, memory UC_MEM_READ_PROT, // Read from read protected, but mapped, memory UC_MEM_FETCH_PROT, // Fetch from non-executable, but mapped, memory @@ -170,9 +169,9 @@ typedef enum uc_hook_type { UC_HOOK_INSN = 1 << 1, // Hook a particular instruction UC_HOOK_CODE = 1 << 2, // Hook a range of code UC_HOOK_BLOCK = 1 << 3, // Hook basic blocks - UC_HOOK_MEM_READ_INVALID = 1 << 4, // Hook for invalid memory read events - UC_HOOK_MEM_WRITE_INVALID = 1 << 5, // Hook for invalid memory write events - UC_HOOK_MEM_FETCH_INVALID = 1 << 6, // Hook for invalid memory fetch for execution events + UC_HOOK_MEM_READ_UNMAPPED = 1 << 4, // Hook for memory read on unmapped memory + UC_HOOK_MEM_WRITE_UNMAPPED = 1 << 5, // Hook for invalid memory write events + UC_HOOK_MEM_FETCH_UNMAPPED = 1 << 6, // Hook for invalid memory fetch for execution events UC_HOOK_MEM_READ_PROT = 1 << 7, // Hook for memory read on read-protected memory UC_HOOK_MEM_WRITE_PROT = 1 << 8, // Hook for memory write on write-protected memory UC_HOOK_MEM_FETCH_PROT = 1 << 9, // Hook for memory fetch on non-executable memory @@ -182,17 +181,17 @@ typedef enum uc_hook_type { } uc_hook_type; // hook type for all events of unmapped memory access -#define UC_HOOK_MEM_INVALID (UC_HOOK_MEM_READ_INVALID + UC_HOOK_MEM_WRITE_INVALID + UC_HOOK_MEM_FETCH_INVALID) +#define UC_HOOK_MEM_UNMAPPED (UC_HOOK_MEM_READ_UNMAPPED + UC_HOOK_MEM_WRITE_UNMAPPED + UC_HOOK_MEM_FETCH_UNMAPPED) // hook type for all events of illegal protected memory access #define UC_HOOK_MEM_PROT (UC_HOOK_MEM_READ_PROT + UC_HOOK_MEM_WRITE_PROT + UC_HOOK_MEM_FETCH_PROT) // hook type for all events of illegal read memory access -#define UC_HOOK_MEM_READ_ERR (UC_HOOK_MEM_READ_PROT + UC_HOOK_MEM_READ_INVALID) +#define UC_HOOK_MEM_READ_INVALID (UC_HOOK_MEM_READ_PROT + UC_HOOK_MEM_READ_UNMAPPED) // hook type for all events of illegal write memory access -#define UC_HOOK_MEM_WRITE_ERR (UC_HOOK_MEM_WRITE_PROT + UC_HOOK_MEM_WRITE_INVALID) +#define UC_HOOK_MEM_WRITE_INVALID (UC_HOOK_MEM_WRITE_PROT + UC_HOOK_MEM_WRITE_UNMAPPED) // hook type for all events of illegal fetch memory access -#define UC_HOOK_MEM_FETCH_ERR (UC_HOOK_MEM_FETCH_PROT + UC_HOOK_MEM_FETCH_INVALID) +#define UC_HOOK_MEM_FETCH_INVALID (UC_HOOK_MEM_FETCH_PROT + UC_HOOK_MEM_FETCH_UNMAPPED) // hook type for all events of illegal memory access -#define UC_HOOK_MEM_ERR (UC_HOOK_MEM_INVALID + UC_HOOK_MEM_PROT) +#define UC_HOOK_MEM_INVALID (UC_HOOK_MEM_UNMAPPED + UC_HOOK_MEM_PROT) // Callback function for hooking memory (UC_MEM_READ, UC_MEM_WRITE & UC_MEM_FETCH) // @type: this memory is being READ, or WRITE @@ -203,7 +202,7 @@ typedef enum uc_hook_type { typedef void (*uc_cb_hookmem_t)(uc_engine *uc, uc_mem_type type, uint64_t address, int size, int64_t value, void *user_data); -// Callback function for handling invalid memory access events (UC_MEM_*_INVALID and +// Callback function for handling invalid memory access events (UC_MEM_*_UNMAPPED and // UC_MEM_*PROT events) // @type: this memory is being READ, or WRITE // @address: address where the code is being executed diff --git a/qemu/cpu-exec.c b/qemu/cpu-exec.c index 33069e35..b74e8e87 100644 --- a/qemu/cpu-exec.c +++ b/qemu/cpu-exec.c @@ -200,7 +200,7 @@ int cpu_exec(struct uc_struct *uc, CPUArchState *env) // qq have_tb_lock = true; tb = tb_find_fast(env); // qq if (!tb) { // invalid TB due to invalid code? - uc->invalid_error = UC_ERR_CODE_INVALID; + uc->invalid_error = UC_ERR_FETCH_UNMAPPED; ret = EXCP_HLT; break; } diff --git a/qemu/cputlb.c b/qemu/cputlb.c index 7439b78b..468219ae 100644 --- a/qemu/cputlb.c +++ b/qemu/cputlb.c @@ -302,7 +302,6 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr) cpu_ldub_code(env1, addr); //check for NX related error from softmmu if (env1->invalid_error == UC_ERR_FETCH_PROT) { - env1->invalid_error = UC_ERR_CODE_INVALID; return -1; } } @@ -317,14 +316,14 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr) //cpu_abort(cpu, "Trying to execute code outside RAM or ROM at 0x" // TARGET_FMT_lx "\n", addr); // qq env1->invalid_addr = addr; - env1->invalid_error = UC_ERR_CODE_INVALID; - return -1; // qq FIXME + env1->invalid_error = UC_ERR_FETCH_UNMAPPED; + return -1; } } p = (void *)((uintptr_t)addr + env1->tlb_table[mmu_idx][page_index].addend); if (!qemu_ram_addr_from_host_nofail(cpu->uc, p, &ram_addr)) { env1->invalid_addr = addr; - env1->invalid_error = UC_ERR_FETCH_INVALID; // FIXME UC_ERR_FETCH_UNMAPPED + env1->invalid_error = UC_ERR_FETCH_UNMAPPED; return -1; } else return ram_addr; diff --git a/qemu/softmmu_template.h b/qemu/softmmu_template.h index 9730c840..2818bde0 100644 --- a/qemu/softmmu_template.h +++ b/qemu/softmmu_template.h @@ -185,14 +185,14 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx, // memory can be unmapped while reading or fetching if (mr == NULL) { #if defined(SOFTMMU_CODE_ACCESS) - error_code = UC_ERR_FETCH_INVALID; + error_code = UC_ERR_FETCH_UNMAPPED; if (uc->hook_mem_fetch_idx != 0 && ((uc_cb_eventmem_t)uc->hook_callbacks[uc->hook_mem_fetch_idx].callback)( - uc, UC_MEM_FETCH_INVALID, addr, DATA_SIZE, 0, + uc, UC_MEM_FETCH_UNMAPPED, addr, DATA_SIZE, 0, uc->hook_callbacks[uc->hook_mem_fetch_idx].user_data)) { #else - error_code = UC_ERR_READ_INVALID; + error_code = UC_ERR_READ_UNMAPPED; if (uc->hook_mem_read_idx != 0 && ((uc_cb_eventmem_t)uc->hook_callbacks[uc->hook_mem_read_idx].callback)( - uc, UC_MEM_READ_INVALID, addr, DATA_SIZE, 0, + uc, UC_MEM_READ_UNMAPPED, addr, DATA_SIZE, 0, uc->hook_callbacks[uc->hook_mem_read_idx].user_data)) { #endif env->invalid_error = UC_ERR_OK; @@ -284,7 +284,7 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx, ioaddr = env->iotlb[mmu_idx][index]; if (ioaddr == 0) { env->invalid_addr = addr; - env->invalid_error = UC_ERR_READ_INVALID; + env->invalid_error = UC_ERR_READ_UNMAPPED; // printf("Invalid memory read at " TARGET_FMT_lx "\n", addr); cpu_exit(env->uc->current_cpu); return 0; @@ -376,14 +376,14 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx, // memory can be unmapped while reading or fetching if (mr == NULL) { #if defined(SOFTMMU_CODE_ACCESS) - error_code = UC_ERR_FETCH_INVALID; + error_code = UC_ERR_FETCH_UNMAPPED; if (uc->hook_mem_fetch_idx != 0 && ((uc_cb_eventmem_t)uc->hook_callbacks[uc->hook_mem_fetch_idx].callback)( - uc, UC_MEM_FETCH_INVALID, addr, DATA_SIZE, 0, + uc, UC_MEM_FETCH_UNMAPPED, addr, DATA_SIZE, 0, uc->hook_callbacks[uc->hook_mem_fetch_idx].user_data)) { #else - error_code = UC_ERR_READ_INVALID; + error_code = UC_ERR_READ_UNMAPPED; if (uc->hook_mem_read_idx != 0 && ((uc_cb_eventmem_t)uc->hook_callbacks[uc->hook_mem_read_idx].callback)( - uc, UC_MEM_READ_INVALID, addr, DATA_SIZE, 0, + uc, UC_MEM_READ_UNMAPPED, addr, DATA_SIZE, 0, uc->hook_callbacks[uc->hook_mem_read_idx].user_data)) { #endif env->invalid_error = UC_ERR_OK; @@ -475,7 +475,7 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx, if (ioaddr == 0) { env->invalid_addr = addr; - env->invalid_error = UC_ERR_READ_INVALID; + env->invalid_error = UC_ERR_READ_UNMAPPED; // printf("Invalid memory read at " TARGET_FMT_lx "\n", addr); cpu_exit(env->uc->current_cpu); return 0; @@ -612,11 +612,11 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, // Unicorn: callback on invalid memory if (uc->hook_mem_write_idx && mr == NULL) { if (!((uc_cb_eventmem_t)uc->hook_callbacks[uc->hook_mem_write_idx].callback)( - uc, UC_MEM_WRITE_INVALID, addr, DATA_SIZE, (int64_t)val, + uc, UC_MEM_WRITE_UNMAPPED, addr, DATA_SIZE, (int64_t)val, uc->hook_callbacks[uc->hook_mem_write_idx].user_data)) { // save error & quit env->invalid_addr = addr; - env->invalid_error = UC_ERR_WRITE_INVALID; + env->invalid_error = UC_ERR_WRITE_UNMAPPED; // printf("***** Invalid memory write at " TARGET_FMT_lx "\n", addr); cpu_exit(uc->current_cpu); return; @@ -673,7 +673,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, ioaddr = env->iotlb[mmu_idx][index]; if (ioaddr == 0) { env->invalid_addr = addr; - env->invalid_error = UC_ERR_WRITE_INVALID; + env->invalid_error = UC_ERR_WRITE_UNMAPPED; // printf("***** Invalid memory write at " TARGET_FMT_lx "\n", addr); cpu_exit(env->uc->current_cpu); return; @@ -759,11 +759,11 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, // Unicorn: callback on invalid memory if (uc->hook_mem_write_idx && mr == NULL) { if (!((uc_cb_eventmem_t)uc->hook_callbacks[uc->hook_mem_write_idx].callback)( - uc, UC_MEM_WRITE_INVALID, addr, DATA_SIZE, (int64_t)val, + uc, UC_MEM_WRITE_UNMAPPED, addr, DATA_SIZE, (int64_t)val, uc->hook_callbacks[uc->hook_mem_write_idx].user_data)) { // save error & quit env->invalid_addr = addr; - env->invalid_error = UC_ERR_WRITE_INVALID; + env->invalid_error = UC_ERR_WRITE_UNMAPPED; // printf("***** Invalid memory write at " TARGET_FMT_lx "\n", addr); cpu_exit(uc->current_cpu); return; @@ -820,7 +820,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, ioaddr = env->iotlb[mmu_idx][index]; if (ioaddr == 0) { env->invalid_addr = addr; - env->invalid_error = UC_ERR_WRITE_INVALID; + env->invalid_error = UC_ERR_WRITE_UNMAPPED; // printf("***** Invalid memory write at " TARGET_FMT_lx "\n", addr); cpu_exit(env->uc->current_cpu); return; diff --git a/samples/mem_apis.c b/samples/mem_apis.c index 28f2b60c..db0240d8 100644 --- a/samples/mem_apis.c +++ b/samples/mem_apis.c @@ -79,10 +79,10 @@ static bool hook_mem_invalid(uc_engine *uc, uc_mem_type type, default: printf("not ok - UC_HOOK_MEM_INVALID type: %d at 0x%" PRIx64 "\n", type, addr); return false; - case UC_MEM_READ_INVALID: + case UC_MEM_READ_UNMAPPED: printf("not ok - Read from invalid memory at 0x%"PRIx64 ", data size = %u\n", addr, size); return false; - case UC_MEM_WRITE_INVALID: + case UC_MEM_WRITE_UNMAPPED: printf("not ok - Write to invalid memory at 0x%"PRIx64 ", data size = %u, data value = 0x%"PRIx64 "\n", addr, size, value); return false; case UC_MEM_FETCH_PROT: @@ -147,7 +147,7 @@ static void do_nx_demo(bool cause_fault) // intercept code and invalid memory events if (uc_hook_add(uc, &trace2, UC_HOOK_CODE, hook_code, NULL, (uint64_t)1, (uint64_t)0) != UC_ERR_OK || - uc_hook_add(uc, &trace1, UC_HOOK_MEM_ERR, + uc_hook_add(uc, &trace1, UC_HOOK_MEM_INVALID, hook_mem_invalid, NULL) != UC_ERR_OK) { printf("not ok - Failed to install hooks\n"); return; @@ -228,7 +228,7 @@ static void do_perms_demo(bool change_perms) // intercept code and invalid memory events if (uc_hook_add(uc, &trace2, UC_HOOK_CODE, hook_code, NULL, (uint64_t)1, (uint64_t)0) != UC_ERR_OK || uc_hook_add(uc, &trace1, - UC_HOOK_MEM_READ_INVALID | UC_HOOK_MEM_WRITE_INVALID | UC_HOOK_MEM_FETCH_INVALID | UC_HOOK_MEM_FETCH_PROT | UC_HOOK_MEM_WRITE_PROT | UC_HOOK_MEM_READ_PROT, + UC_HOOK_MEM_INVALID, hook_mem_invalid, NULL) != UC_ERR_OK) { printf("not ok - Failed to install hooks\n"); return; @@ -306,7 +306,7 @@ static void do_unmap_demo(bool do_unmap) // intercept code and invalid memory events if (uc_hook_add(uc, &trace2, UC_HOOK_CODE, hook_code, NULL, (uint64_t)1, (uint64_t)0) != UC_ERR_OK || uc_hook_add(uc, &trace1, - UC_HOOK_MEM_READ_INVALID | UC_HOOK_MEM_WRITE_INVALID | UC_HOOK_MEM_FETCH_INVALID | UC_HOOK_MEM_FETCH_PROT | UC_HOOK_MEM_WRITE_PROT | UC_HOOK_MEM_READ_PROT, + UC_HOOK_MEM_INVALID, hook_mem_invalid, NULL) != UC_ERR_OK) { printf("not ok - Failed to install hooks\n"); return; diff --git a/samples/sample_x86.c b/samples/sample_x86.c index f2a28916..49118e42 100644 --- a/samples/sample_x86.c +++ b/samples/sample_x86.c @@ -73,7 +73,7 @@ static bool hook_mem_invalid(uc_engine *uc, uc_mem_type type, default: // return false to indicate we want to stop emulation return false; - case UC_MEM_WRITE_INVALID: + case UC_MEM_WRITE_UNMAPPED: printf(">>> Missing memory is being WRITE at 0x%"PRIx64 ", data size = %u, data value = 0x%"PRIx64 "\n", address, size, value); // map this memory in with 2MB in size @@ -421,7 +421,7 @@ static void test_i386_invalid_mem_write(void) uc_hook_add(uc, &trace2, UC_HOOK_CODE, hook_code, NULL, (uint64_t)1, (uint64_t)0); // intercept invalid memory events - uc_hook_add(uc, &trace3, UC_HOOK_MEM_READ_INVALID | UC_HOOK_MEM_WRITE_INVALID, hook_mem_invalid, NULL); + uc_hook_add(uc, &trace3, UC_HOOK_MEM_READ_UNMAPPED | UC_HOOK_MEM_WRITE_UNMAPPED, hook_mem_invalid, NULL); // emulate machine code in infinite time err = uc_emu_start(uc, ADDRESS, ADDRESS + sizeof(X86_CODE32_MEM_WRITE) - 1, 0, 0); diff --git a/tests/regress/arm_bxeq_hang.py b/tests/regress/arm_bxeq_hang.py index 12f4a2ae..5040d725 100755 --- a/tests/regress/arm_bxeq_hang.py +++ b/tests/regress/arm_bxeq_hang.py @@ -10,8 +10,9 @@ class BxHang(regress.RegressTest): def runTest(self): uc = Uc(UC_ARCH_ARM, UC_MODE_ARM) uc.mem_map(0x1000, 0x1000) - uc.mem_write(0x1000, '1eff2f010000a0e1'.decode('hex')) + uc.mem_write(0x1000, '1eff2f010000a0e1'.decode('hex')) # bxeq lr; mov r0, r0 uc.count = 0 + def hook_block(uc, addr, *args): print 'enter block 0x%04x' % addr uc.count += 1 diff --git a/tests/regress/jmp_ebx_hang.py b/tests/regress/jmp_ebx_hang.py index 602c594f..221765d9 100755 --- a/tests/regress/jmp_ebx_hang.py +++ b/tests/regress/jmp_ebx_hang.py @@ -22,7 +22,7 @@ class JumEbxHang(regress.RegressTest): with self.assertRaises(UcError) as m: mu.emu_start(CODE_ADDR, CODE_ADDR + 2, count=1) - self.assertEqual(m.exception.errno, unicorn.UC_ERR_CODE_INVALID) + self.assertEqual(m.exception.errno, unicorn.UC_ERR_FETCH_UNMAPPED) print(">>> jmp ebx (ebx = 0xaa96a47f)"); mu = unicorn.Uc(unicorn.UC_ARCH_X86, unicorn.UC_MODE_32) @@ -33,7 +33,7 @@ class JumEbxHang(regress.RegressTest): with self.assertRaises(UcError) as m: mu.emu_start(CODE_ADDR, CODE_ADDR + 2, count=1) - self.assertEqual(m.exception.errno, unicorn.UC_ERR_CODE_INVALID) + self.assertEqual(m.exception.errno, unicorn.UC_ERR_FETCH_UNMAPPED) if __name__ == '__main__': regress.main() diff --git a/tests/regress/mem_unmap.c b/tests/regress/mem_unmap.c index 06223bfa..98e209f0 100644 --- a/tests/regress/mem_unmap.c +++ b/tests/regress/mem_unmap.c @@ -224,7 +224,7 @@ int main(int argc, char **argv, char **envp) } // intercept invalid memory events - if (uc_hook_add(uc, &trace1, UC_HOOK_MEM_WRITE_INVALID, hook_mem_invalid, NULL) != UC_ERR_OK) { + if (uc_hook_add(uc, &trace1, UC_HOOK_MEM_WRITE_UNMAPPED, hook_mem_invalid, NULL) != UC_ERR_OK) { printf("not ok %d - Failed to install memory invalid handler\n", log_num++); return 7; } else { diff --git a/tests/regress/mips_except.py b/tests/regress/mips_except.py index 23969e9e..b400efe6 100755 --- a/tests/regress/mips_except.py +++ b/tests/regress/mips_except.py @@ -28,13 +28,13 @@ class MipsExcept(regress.RegressTest): uc.reg_write(UC_MIPS_REG_SP, 0xFFFFFFF0) uc.emu_start(CODE, CODE + len(asm), 200) - self.assertEqual(UC_ERR_READ_INVALID, m.exception.errno) + self.assertEqual(UC_ERR_READ_UNMAPPED, m.exception.errno) with self.assertRaises(UcError) as m: uc.reg_write(UC_MIPS_REG_SP, 0x80000000) uc.emu_start(CODE, CODE + len(asm), 100) - self.assertEqual(UC_ERR_READ_INVALID, m.exception.errno) + self.assertEqual(UC_ERR_READ_UNMAPPED, m.exception.errno) if __name__ == '__main__': regress.main() diff --git a/tests/regress/reg_write_sign_extension.py b/tests/regress/reg_write_sign_extension.py index 34d65506..b7d3be55 100755 --- a/tests/regress/reg_write_sign_extension.py +++ b/tests/regress/reg_write_sign_extension.py @@ -24,7 +24,7 @@ class RegWriteSignExt(regress.RegressTest): # jmp ebx mu.mem_write(0x10000000, b'\xff\xe3') - mu.hook_add(unicorn.UC_HOOK_MEM_FETCH_INVALID | unicorn.UC_HOOK_MEM_FETCH_PROT, hook_mem_invalid) + mu.hook_add(unicorn.UC_HOOK_MEM_FETCH_UNMAPPED | unicorn.UC_HOOK_MEM_FETCH_PROT, hook_mem_invalid) mu.emu_start(0x10000000, 0x10000000 + 2, count=1) if __name__ == '__main__': diff --git a/tests/regress/ro_mem_test.c b/tests/regress/ro_mem_test.c index 1e612033..7b430497 100644 --- a/tests/regress/ro_mem_test.c +++ b/tests/regress/ro_mem_test.c @@ -142,7 +142,7 @@ int main(int argc, char **argv, char **envp) //uc_hook_add(uc, &trace2, UC_HOOK_CODE, hook_code, NULL, (uint64_t)0x400000, (uint64_t)0x400fff); // intercept invalid memory events - uc_hook_add(uc, &trace1, UC_HOOK_MEM_WRITE_INVALID | UC_HOOK_MEM_WRITE_PROT, hook_mem_invalid, NULL); + uc_hook_add(uc, &trace1, UC_HOOK_MEM_WRITE_UNMAPPED | UC_HOOK_MEM_WRITE_PROT, hook_mem_invalid, NULL); // emulate machine code in infinite time printf("BEGIN execution - 1\n"); diff --git a/tests/regress/sparc_reg.py b/tests/regress/sparc_reg.py index 326d00e4..03832de9 100755 --- a/tests/regress/sparc_reg.py +++ b/tests/regress/sparc_reg.py @@ -164,7 +164,7 @@ def print_registers(mu): print_registers(uc) -assert uc.reg_read(UC_SPARC_REG_PC) == 128 # make sure we executed all instructions +assert uc.reg_read(UC_SPARC_REG_PC) == 132 # make sure we executed all instructions assert uc.reg_read(UC_SPARC_REG_SP) == 101 assert uc.reg_read(UC_SPARC_REG_FP) == 201 diff --git a/tests/unit/test_x86.c b/tests/unit/test_x86.c index e1d6856c..04441123 100644 --- a/tests/unit/test_x86.c +++ b/tests/unit/test_x86.c @@ -408,7 +408,7 @@ static void test_i386_invalid_mem_read(void **state) // emulate machine code in infinite time err = uc_emu_start(uc, address, address+sizeof(code), 0, 0); - uc_assert_err(UC_ERR_READ_INVALID, err); + uc_assert_err(UC_ERR_READ_UNMAPPED, err); uc_assert_success(uc_close(uc)); } @@ -438,7 +438,7 @@ static void test_i386_invalid_mem_write(void **state) // emulate machine code in infinite time err = uc_emu_start(uc, address, address+sizeof(code), 0, 0); - uc_assert_err(UC_ERR_WRITE_INVALID, err); + uc_assert_err(UC_ERR_WRITE_UNMAPPED, err); uc_assert_success(uc_close(uc)); @@ -469,7 +469,7 @@ static void test_i386_jump_invalid(void **state) // emulate machine code in infinite time err = uc_emu_start(uc, address, address+sizeof(code), 0, 0); - uc_assert_err(UC_ERR_CODE_INVALID, err); + uc_assert_err(UC_ERR_FETCH_UNMAPPED, err); uc_assert_success(uc_close(uc)); diff --git a/uc.c b/uc.c index d5219542..b87d1a63 100644 --- a/uc.c +++ b/uc.c @@ -69,14 +69,12 @@ const char *uc_strerror(uc_err code) return "Invalid mode (UC_ERR_MODE)"; case UC_ERR_VERSION: return "Different API version between core & binding (UC_ERR_VERSION)"; - case UC_ERR_READ_INVALID: - return "Invalid memory read (UC_ERR_READ_INVALID)"; - case UC_ERR_WRITE_INVALID: - return "Invalid memory write (UC_ERR_WRITE_INVALID)"; - case UC_ERR_FETCH_INVALID: - return "Invalid memory fetch (UC_ERR_FETCH_INVALID)"; - case UC_ERR_CODE_INVALID: - return "Invalid code address (UC_ERR_CODE_INVALID)"; + case UC_ERR_READ_UNMAPPED: + return "Invalid memory read (UC_ERR_READ_UNMAPPED)"; + case UC_ERR_WRITE_UNMAPPED: + return "Invalid memory write (UC_ERR_WRITE_UNMAPPED)"; + case UC_ERR_FETCH_UNMAPPED: + return "Invalid memory fetch (UC_ERR_FETCH_UNMAPPED)"; case UC_ERR_HOOK: return "Invalid hook type (UC_ERR_HOOK)"; case UC_ERR_INSN_INVALID: @@ -343,7 +341,7 @@ uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, size_t size) uint8_t *bytes = _bytes; if (!check_mem_area(uc, address, size)) - return UC_ERR_READ_INVALID; + return UC_ERR_READ_UNMAPPED; size_t count = 0, len; @@ -364,7 +362,7 @@ uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, size_t size) if (count == size) return UC_ERR_OK; else - return UC_ERR_READ_INVALID; + return UC_ERR_READ_UNMAPPED; } UNICORN_EXPORT @@ -373,7 +371,7 @@ uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *_bytes, size_t const uint8_t *bytes = _bytes; if (!check_mem_area(uc, address, size)) - return UC_ERR_WRITE_INVALID; + return UC_ERR_WRITE_UNMAPPED; size_t count = 0, len; @@ -404,7 +402,7 @@ uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *_bytes, size_t if (count == size) return UC_ERR_OK; else - return UC_ERR_WRITE_INVALID; + return UC_ERR_WRITE_UNMAPPED; } #define TIMEOUT_STEP 2 // microseconds @@ -842,15 +840,15 @@ static uc_err _hook_mem_invalid(struct uc_struct* uc, int type, uc_cb_eventmem_t uc->hook_callbacks[i].callback = callback; uc->hook_callbacks[i].user_data = user_data; *evh = i; - if (type & UC_HOOK_MEM_READ_INVALID) + if (type & UC_HOOK_MEM_READ_UNMAPPED) uc->hook_mem_read_idx = i; if (type & UC_HOOK_MEM_READ_PROT) uc->hook_mem_read_prot_idx = i; - if (type & UC_HOOK_MEM_WRITE_INVALID) + if (type & UC_HOOK_MEM_WRITE_UNMAPPED) uc->hook_mem_write_idx = i; if (type & UC_HOOK_MEM_WRITE_PROT) uc->hook_mem_write_prot_idx = i; - if (type & UC_HOOK_MEM_FETCH_INVALID) + if (type & UC_HOOK_MEM_FETCH_UNMAPPED) uc->hook_mem_fetch_idx = i; if (type & UC_HOOK_MEM_FETCH_PROT) uc->hook_mem_fetch_prot_idx = i; @@ -940,14 +938,14 @@ uc_err uc_hook_add(uc_engine *uc, uc_hook *hh, int type, void *callback, void *u va_start(valist, user_data); - if (type & UC_HOOK_MEM_READ_INVALID) - ret = _hook_mem_invalid(uc, UC_HOOK_MEM_READ_INVALID, callback, user_data, hh); + if (type & UC_HOOK_MEM_READ_UNMAPPED) + ret = _hook_mem_invalid(uc, UC_HOOK_MEM_READ_UNMAPPED, callback, user_data, hh); - if (type & UC_HOOK_MEM_WRITE_INVALID) - ret = _hook_mem_invalid(uc, UC_HOOK_MEM_WRITE_INVALID, callback, user_data, hh); + if (type & UC_HOOK_MEM_WRITE_UNMAPPED) + ret = _hook_mem_invalid(uc, UC_HOOK_MEM_WRITE_UNMAPPED, callback, user_data, hh); - if (type & UC_HOOK_MEM_FETCH_INVALID) - ret = _hook_mem_invalid(uc, UC_HOOK_MEM_FETCH_INVALID, callback, user_data, hh); + if (type & UC_HOOK_MEM_FETCH_UNMAPPED) + ret = _hook_mem_invalid(uc, UC_HOOK_MEM_FETCH_UNMAPPED, callback, user_data, hh); if (type & UC_HOOK_MEM_READ_PROT) ret = _hook_mem_invalid(uc, UC_HOOK_MEM_READ_PROT, callback, user_data, hh);