From 7c0520f75455956ad030bd527194be0dafddb0a1 Mon Sep 17 00:00:00 2001 From: nonempty <1168808+secretnonempty@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:28:51 -0800 Subject: [PATCH 01/10] Remove the size limit for memory read and write Eliminate the maximum size restriction for uc_mem_read and uc_mem_write. This change is required to support applications, such as LLVM CFI, that map or unmap memory blocks with sizes equal to or greater than INT_MAX. --- .../Binding/BindingFactory.fs | 0 .../Binding/IBinding.fs | 0 .../Binding/MockBinding.fs | 0 .../Binding/NativeBinding.fs | 26 ++-- .../Const/Arm.fs | 0 .../Const/Arm64.fs | 0 .../Const/Common.fs | 0 .../Const/M68k.fs | 0 .../Const/Mips.fs | 0 .../Const/Ppc.fs | 0 .../Const/Riscv.fs | 0 .../Const/S390x.fs | 0 .../Const/Sparc.fs | 0 .../Const/TriCore.fs | 0 .../Const/X86.fs | 0 .../ConvertUtility.fs | 0 .../InternalHooks.fs | 0 .../Unicorn.fs | 0 .../UnicornEngine.fsproj} | 0 .../UnicornEngineException.fs | 0 bindings/go/unicorn/unicorn.go | 12 +- bindings/java/unicorn_Unicorn.c | 12 +- bindings/pascal/unicorn/Unicorn_dyn.pas | 12 +- bindings/python/unicorn/unicorn.py | 50 +++---- bindings/ruby/unicorn_gem/ext/unicorn.c | 30 ++-- bindings/rust/src/ffi.rs | 14 +- bindings/rust/src/lib.rs | 28 ++-- bindings/vb6/main.cpp | 68 ++++----- bindings/vb6/uc_def.bas | 42 +++--- include/uc_priv.h | 28 +++- include/unicorn/unicorn.h | 14 +- qemu/unicorn_common.h | 4 +- tests/rust-tests/main.rs | 12 +- tests/unit/test_mem.c | 75 ++++++++++ uc.c | 138 +++++++----------- 35 files changed, 317 insertions(+), 248 deletions(-) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Binding/BindingFactory.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Binding/IBinding.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Binding/MockBinding.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Binding/NativeBinding.fs (94%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/Arm.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/Arm64.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/Common.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/M68k.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/Mips.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/Ppc.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/Riscv.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/S390x.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/Sparc.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/TriCore.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Const/X86.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/ConvertUtility.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/InternalHooks.fs (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/Unicorn.fs (100%) rename bindings/dotnet/{UnicornManaged/UnicornManaged.fsproj => UnicornEngine/UnicornEngine.fsproj} (100%) rename bindings/dotnet/{UnicornManaged => UnicornEngine}/UnicornEngineException.fs (100%) diff --git a/bindings/dotnet/UnicornManaged/Binding/BindingFactory.fs b/bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Binding/BindingFactory.fs rename to bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs diff --git a/bindings/dotnet/UnicornManaged/Binding/IBinding.fs b/bindings/dotnet/UnicornEngine/Binding/IBinding.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Binding/IBinding.fs rename to bindings/dotnet/UnicornEngine/Binding/IBinding.fs diff --git a/bindings/dotnet/UnicornManaged/Binding/MockBinding.fs b/bindings/dotnet/UnicornEngine/Binding/MockBinding.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Binding/MockBinding.fs rename to bindings/dotnet/UnicornEngine/Binding/MockBinding.fs diff --git a/bindings/dotnet/UnicornManaged/Binding/NativeBinding.fs b/bindings/dotnet/UnicornEngine/Binding/NativeBinding.fs similarity index 94% rename from bindings/dotnet/UnicornManaged/Binding/NativeBinding.fs rename to bindings/dotnet/UnicornEngine/Binding/NativeBinding.fs index 6be7b2f36e..a88743a23c 100644 --- a/bindings/dotnet/UnicornManaged/Binding/NativeBinding.fs +++ b/bindings/dotnet/UnicornEngine/Binding/NativeBinding.fs @@ -1,4 +1,4 @@ -namespace UnicornManaged.Binding +namespace UnicornEngine.Binding open System open System.Runtime.InteropServices @@ -6,34 +6,34 @@ open System.Runtime.InteropServices module NativeBinding = [] - module private Imported = + module private Imported = [] extern Int32 uc_version(UIntPtr major, UIntPtr minor) [] - extern Int32 uc_open(UInt32 arch, UInt32 mode, UIntPtr[] engine) + extern Int32 uc_open(UInt32 arch, UInt32 mode, UIntPtr[] engine) [] - extern Int32 uc_close(UIntPtr eng) + extern Int32 uc_close(UIntPtr eng) [] - extern Int32 uc_mem_map(UIntPtr eng, UInt64 address, UIntPtr size, UInt32 perm) + extern Int32 uc_mem_map(UIntPtr eng, UInt64 address, UInt64 size, UInt32 perm) [] - extern Int32 uc_mem_map_ptr(UIntPtr eng, UInt64 address, UIntPtr size, UInt32 perm, UIntPtr ptr) + extern Int32 uc_mem_map_ptr(UIntPtr eng, UInt64 address, UInt64 size, UInt32 perm, UIntPtr ptr) [] - extern Int32 uc_mem_unmap(UIntPtr eng, UInt64 address, UIntPtr size) + extern Int32 uc_mem_unmap(UIntPtr eng, UInt64 address, UInt64 size) [] - extern Int32 uc_mem_protect(UIntPtr eng, UInt64 address, UIntPtr size, UInt32 perms) - + extern Int32 uc_mem_protect(UIntPtr eng, UInt64 address, UInt64 size, UInt32 perms) + [] - extern Int32 uc_mem_write(UIntPtr eng, UInt64 address, Byte[] value, UIntPtr size) + extern Int32 uc_mem_write(UIntPtr eng, UInt64 address, Byte[] value, UInt64 size) [] - extern Int32 uc_mem_read(UIntPtr eng, UInt64 address, Byte[] value, UIntPtr size) + extern Int32 uc_mem_read(UIntPtr eng, UInt64 address, Byte[] value, UInt64 size) [] extern Int32 uc_reg_write(UIntPtr eng, Int32 regId, Byte[] value) @@ -67,7 +67,7 @@ module NativeBinding = [] extern Int32 uc_hook_add_arg0_arg1(UIntPtr eng, UIntPtr hh, Int32 callbackType, UIntPtr callback, IntPtr userData, UInt64 hookbegin, UInt64 hookend, UInt64 arg0, UInt64 arg1) - + let instance = {new IBinding with member thi.Version(major, minor) = uc_version(major, minor) @@ -90,4 +90,4 @@ module NativeBinding = member thi.HookAddNoarg(eng, hh, callbackType, callback, userData, hookBegin, hookEnd) = uc_hook_add_noarg(eng, hh, callbackType, callback, userData, hookBegin, hookEnd) member thi.HookAddArg0(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0) = uc_hook_add_arg0(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0) member thi.HookAddArg0Arg1(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0, arg1) = uc_hook_add_arg0_arg1(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0, arg1) - } \ No newline at end of file + } diff --git a/bindings/dotnet/UnicornManaged/Const/Arm.fs b/bindings/dotnet/UnicornEngine/Const/Arm.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/Arm.fs rename to bindings/dotnet/UnicornEngine/Const/Arm.fs diff --git a/bindings/dotnet/UnicornManaged/Const/Arm64.fs b/bindings/dotnet/UnicornEngine/Const/Arm64.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/Arm64.fs rename to bindings/dotnet/UnicornEngine/Const/Arm64.fs diff --git a/bindings/dotnet/UnicornManaged/Const/Common.fs b/bindings/dotnet/UnicornEngine/Const/Common.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/Common.fs rename to bindings/dotnet/UnicornEngine/Const/Common.fs diff --git a/bindings/dotnet/UnicornManaged/Const/M68k.fs b/bindings/dotnet/UnicornEngine/Const/M68k.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/M68k.fs rename to bindings/dotnet/UnicornEngine/Const/M68k.fs diff --git a/bindings/dotnet/UnicornManaged/Const/Mips.fs b/bindings/dotnet/UnicornEngine/Const/Mips.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/Mips.fs rename to bindings/dotnet/UnicornEngine/Const/Mips.fs diff --git a/bindings/dotnet/UnicornManaged/Const/Ppc.fs b/bindings/dotnet/UnicornEngine/Const/Ppc.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/Ppc.fs rename to bindings/dotnet/UnicornEngine/Const/Ppc.fs diff --git a/bindings/dotnet/UnicornManaged/Const/Riscv.fs b/bindings/dotnet/UnicornEngine/Const/Riscv.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/Riscv.fs rename to bindings/dotnet/UnicornEngine/Const/Riscv.fs diff --git a/bindings/dotnet/UnicornManaged/Const/S390x.fs b/bindings/dotnet/UnicornEngine/Const/S390x.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/S390x.fs rename to bindings/dotnet/UnicornEngine/Const/S390x.fs diff --git a/bindings/dotnet/UnicornManaged/Const/Sparc.fs b/bindings/dotnet/UnicornEngine/Const/Sparc.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/Sparc.fs rename to bindings/dotnet/UnicornEngine/Const/Sparc.fs diff --git a/bindings/dotnet/UnicornManaged/Const/TriCore.fs b/bindings/dotnet/UnicornEngine/Const/TriCore.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/TriCore.fs rename to bindings/dotnet/UnicornEngine/Const/TriCore.fs diff --git a/bindings/dotnet/UnicornManaged/Const/X86.fs b/bindings/dotnet/UnicornEngine/Const/X86.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Const/X86.fs rename to bindings/dotnet/UnicornEngine/Const/X86.fs diff --git a/bindings/dotnet/UnicornManaged/ConvertUtility.fs b/bindings/dotnet/UnicornEngine/ConvertUtility.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/ConvertUtility.fs rename to bindings/dotnet/UnicornEngine/ConvertUtility.fs diff --git a/bindings/dotnet/UnicornManaged/InternalHooks.fs b/bindings/dotnet/UnicornEngine/InternalHooks.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/InternalHooks.fs rename to bindings/dotnet/UnicornEngine/InternalHooks.fs diff --git a/bindings/dotnet/UnicornManaged/Unicorn.fs b/bindings/dotnet/UnicornEngine/Unicorn.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/Unicorn.fs rename to bindings/dotnet/UnicornEngine/Unicorn.fs diff --git a/bindings/dotnet/UnicornManaged/UnicornManaged.fsproj b/bindings/dotnet/UnicornEngine/UnicornEngine.fsproj similarity index 100% rename from bindings/dotnet/UnicornManaged/UnicornManaged.fsproj rename to bindings/dotnet/UnicornEngine/UnicornEngine.fsproj diff --git a/bindings/dotnet/UnicornManaged/UnicornEngineException.fs b/bindings/dotnet/UnicornEngine/UnicornEngineException.fs similarity index 100% rename from bindings/dotnet/UnicornManaged/UnicornEngineException.fs rename to bindings/dotnet/UnicornEngine/UnicornEngineException.fs diff --git a/bindings/go/unicorn/unicorn.go b/bindings/go/unicorn/unicorn.go index 50b221adaa..2e3aad1155 100644 --- a/bindings/go/unicorn/unicorn.go +++ b/bindings/go/unicorn/unicorn.go @@ -190,14 +190,14 @@ func (u *uc) MemWrite(addr uint64, data []byte) error { if len(data) == 0 { return nil } - return errReturn(C.uc_mem_write(u.handle, C.uint64_t(addr), unsafe.Pointer(&data[0]), C.size_t(len(data)))) + return errReturn(C.uc_mem_write(u.handle, C.uint64_t(addr), unsafe.Pointer(&data[0]), C.uint64_t(len(data)))) } func (u *uc) MemReadInto(dst []byte, addr uint64) error { if len(dst) == 0 { return nil } - return errReturn(C.uc_mem_read(u.handle, C.uint64_t(addr), unsafe.Pointer(&dst[0]), C.size_t(len(dst)))) + return errReturn(C.uc_mem_read(u.handle, C.uint64_t(addr), unsafe.Pointer(&dst[0]), C.uint64_t(len(dst)))) } func (u *uc) MemRead(addr, size uint64) ([]byte, error) { @@ -206,7 +206,7 @@ func (u *uc) MemRead(addr, size uint64) ([]byte, error) { } func (u *uc) MemMapProt(addr, size uint64, prot int) error { - return errReturn(C.uc_mem_map(u.handle, C.uint64_t(addr), C.size_t(size), C.uint32_t(prot))) + return errReturn(C.uc_mem_map(u.handle, C.uint64_t(addr), C.uint64_t(size), C.uint32_t(prot))) } func (u *uc) MemMap(addr, size uint64) error { @@ -214,15 +214,15 @@ func (u *uc) MemMap(addr, size uint64) error { } func (u *uc) MemMapPtr(addr, size uint64, prot int, ptr unsafe.Pointer) error { - return errReturn(C.uc_mem_map_ptr(u.handle, C.uint64_t(addr), C.size_t(size), C.uint32_t(prot), ptr)) + return errReturn(C.uc_mem_map_ptr(u.handle, C.uint64_t(addr), C.uint64_t(size), C.uint32_t(prot), ptr)) } func (u *uc) MemProtect(addr, size uint64, prot int) error { - return errReturn(C.uc_mem_protect(u.handle, C.uint64_t(addr), C.size_t(size), C.uint32_t(prot))) + return errReturn(C.uc_mem_protect(u.handle, C.uint64_t(addr), C.uint64_t(size), C.uint32_t(prot))) } func (u *uc) MemUnmap(addr, size uint64) error { - return errReturn(C.uc_mem_unmap(u.handle, C.uint64_t(addr), C.size_t(size))) + return errReturn(C.uc_mem_unmap(u.handle, C.uint64_t(addr), C.uint64_t(size))) } func (u *uc) Query(queryType int) (uint64, error) { diff --git a/bindings/java/unicorn_Unicorn.c b/bindings/java/unicorn_Unicorn.c index fb7f220f27..10a02826a7 100644 --- a/bindings/java/unicorn_Unicorn.c +++ b/bindings/java/unicorn_Unicorn.c @@ -447,7 +447,7 @@ JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1write uc_engine *eng = getEngine(env, self); jbyte *array = (*env)->GetByteArrayElements(env, bytes, NULL); jsize size = (*env)->GetArrayLength(env, bytes); - uc_err err = uc_mem_write(eng, (uint64_t)address, array, (size_t)size); + uc_err err = uc_mem_write(eng, (uint64_t)address, array, (uint64_t)size); if (err != UC_ERR_OK) { throwException(env, err); @@ -467,7 +467,7 @@ JNIEXPORT jbyteArray JNICALL Java_unicorn_Unicorn_mem_1read jbyteArray bytes = (*env)->NewByteArray(env, (jsize)size); jbyte *array = (*env)->GetByteArrayElements(env, bytes, NULL); - uc_err err = uc_mem_read(eng, (uint64_t)address, array, (size_t)size); + uc_err err = uc_mem_read(eng, (uint64_t)address, array, (uint64_t)size); if (err != UC_ERR_OK) { throwException(env, err); } @@ -634,7 +634,7 @@ JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1map (JNIEnv *env, jobject self, jlong address, jlong size, jint perms) { uc_engine *eng = getEngine(env, self); - uc_err err = uc_mem_map(eng, (uint64_t)address, (size_t)size, (uint32_t)perms); + uc_err err = uc_mem_map(eng, (uint64_t)address, (uint64_t)size, (uint32_t)perms); if (err != UC_ERR_OK) { throwException(env, err); } @@ -649,7 +649,7 @@ JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1map_1ptr (JNIEnv *env, jobject self, jlong address, jlong size, jint perms, jbyteArray block) { uc_engine *eng = getEngine(env, self); jbyte *array = (*env)->GetByteArrayElements(env, block, NULL); - uc_err err = uc_mem_map_ptr(eng, (uint64_t)address, (size_t)size, (uint32_t)perms, (void*)array); + uc_err err = uc_mem_map_ptr(eng, (uint64_t)address, (uint64_t)size, (uint32_t)perms, (void*)array); if (err != UC_ERR_OK) { throwException(env, err); } @@ -667,7 +667,7 @@ JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1unmap (JNIEnv *env, jobject self, jlong address, jlong size) { uc_engine *eng = getEngine(env, self); - uc_err err = uc_mem_unmap(eng, (uint64_t)address, (size_t)size); + uc_err err = uc_mem_unmap(eng, (uint64_t)address, (uint64_t)size); if (err != UC_ERR_OK) { throwException(env, err); } @@ -685,7 +685,7 @@ JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1protect (JNIEnv *env, jobject self, jlong address, jlong size, jint perms) { uc_engine *eng = getEngine(env, self); - uc_err err = uc_mem_protect(eng, (uint64_t)address, (size_t)size, (uint32_t)perms); + uc_err err = uc_mem_protect(eng, (uint64_t)address, (uint64_t)size, (uint32_t)perms); if (err != UC_ERR_OK) { throwException(env, err); } diff --git a/bindings/pascal/unicorn/Unicorn_dyn.pas b/bindings/pascal/unicorn/Unicorn_dyn.pas index 427813cf75..96f296587c 100755 --- a/bindings/pascal/unicorn/Unicorn_dyn.pas +++ b/bindings/pascal/unicorn/Unicorn_dyn.pas @@ -291,7 +291,7 @@ uc_mem_region = record for detailed error). *) uc_mem_write_ : function (uc : uc_engine; address : UInt64; const bytes : Pointer; - size : Cardinal) : uc_err; cdecl; + size : UInt64) : uc_err; cdecl; (* Read a range of bytes in memory. @@ -307,7 +307,7 @@ uc_mem_region = record for detailed error). *) uc_mem_read_ : function (uc : uc_engine; address : UInt64; bytes : Pointer; - size : Cardinal) : uc_err; cdecl; + size : UInt64) : uc_err; cdecl; (* Emulate machine code in a specific duration of time. @@ -400,7 +400,7 @@ function (uc : uc_engine; var hh : uc_hook; _type : integer; @return UC_ERR_OK on success, or other value on failure (refer to uc_err enum for detailed error). *) - uc_mem_map : function (uc : uc_engine; address : UInt64; size : Cardinal; perms : UInt32) : uc_err; cdecl; + uc_mem_map : function (uc : uc_engine; address : UInt64; size : UInt64; perms : UInt32) : uc_err; cdecl; (* @@ -422,7 +422,7 @@ function (uc : uc_engine; var hh : uc_hook; _type : integer; @return UC_ERR_OK on success, or other value on failure (refer to uc_err enum for detailed error). *) - uc_mem_map_ptr : function(uc : uc_engine; address : UInt64; size : Cardinal; perms : UInt32; ptr : Pointer) : uc_err; cdecl; + uc_mem_map_ptr : function(uc : uc_engine; address : UInt64; size : UInt64; perms : UInt32; ptr : Pointer) : uc_err; cdecl; (* @@ -438,7 +438,7 @@ function (uc : uc_engine; var hh : uc_hook; _type : integer; @return UC_ERR_OK on success, or other value on failure (refer to uc_err enum \ for detailed error). *) - uc_mem_unmap : function (uc : uc_engine; address : UInt64; size : Cardinal) : uc_err; cdecl ; + uc_mem_unmap : function (uc : uc_engine; address : UInt64; size : UInt64) : uc_err; cdecl ; (* Set memory permissions for emulation memory. @@ -456,7 +456,7 @@ function (uc : uc_engine; var hh : uc_hook; _type : integer; @return UC_ERR_OK on success, or other value on failure (refer to uc_err enum \ for detailed error). *) - uc_mem_protect : function (uc : uc_engine; address : UInt64; size : Cardinal; perms : UInt32) : uc_err; cdecl ; + uc_mem_protect : function (uc : uc_engine; address : UInt64; size : UInt64; perms : UInt32) : uc_err; cdecl ; (* Retrieve all memory regions mapped by uc_mem_map() and uc_mem_map_ptr() diff --git a/bindings/python/unicorn/unicorn.py b/bindings/python/unicorn/unicorn.py index 2e6a938f43..d5ca00ec28 100644 --- a/bindings/python/unicorn/unicorn.py +++ b/bindings/python/unicorn/unicorn.py @@ -103,7 +103,7 @@ def _load_lib(path, lib_name): for _path in _path_list: if _path is None: continue - + _uc = _load_lib(_path, "libunicorn.so") if _uc is not None: # In this case, show a warning for users @@ -153,16 +153,16 @@ class uc_tb(ctypes.Structure): _setup_prototype(_uc, "uc_errno", ucerr, uc_engine) _setup_prototype(_uc, "uc_reg_read", ucerr, uc_engine, ctypes.c_int, ctypes.c_void_p) _setup_prototype(_uc, "uc_reg_write", ucerr, uc_engine, ctypes.c_int, ctypes.c_void_p) -_setup_prototype(_uc, "uc_mem_read", ucerr, uc_engine, ctypes.c_uint64, ctypes.POINTER(ctypes.c_char), ctypes.c_size_t) -_setup_prototype(_uc, "uc_mem_write", ucerr, uc_engine, ctypes.c_uint64, ctypes.POINTER(ctypes.c_char), ctypes.c_size_t) +_setup_prototype(_uc, "uc_mem_read", ucerr, uc_engine, ctypes.c_uint64, ctypes.POINTER(ctypes.c_char), ctypes.c_uint64) +_setup_prototype(_uc, "uc_mem_write", ucerr, uc_engine, ctypes.c_uint64, ctypes.POINTER(ctypes.c_char), ctypes.c_uint64) _setup_prototype(_uc, "uc_emu_start", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_uint64, ctypes.c_uint64, ctypes.c_size_t) _setup_prototype(_uc, "uc_emu_stop", ucerr, uc_engine) _setup_prototype(_uc, "uc_hook_del", ucerr, uc_engine, uc_hook_h) -_setup_prototype(_uc, "uc_mmio_map", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_size_t, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p) -_setup_prototype(_uc, "uc_mem_map", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_size_t, ctypes.c_uint32) -_setup_prototype(_uc, "uc_mem_map_ptr", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_size_t, ctypes.c_uint32, ctypes.c_void_p) -_setup_prototype(_uc, "uc_mem_unmap", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_size_t) -_setup_prototype(_uc, "uc_mem_protect", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_size_t, ctypes.c_uint32) +_setup_prototype(_uc, "uc_mmio_map", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_uint64, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p) +_setup_prototype(_uc, "uc_mem_map", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_uint64, ctypes.c_uint32) +_setup_prototype(_uc, "uc_mem_map_ptr", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_uint64, ctypes.c_uint32, ctypes.c_void_p) +_setup_prototype(_uc, "uc_mem_unmap", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_uint64) +_setup_prototype(_uc, "uc_mem_protect", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_uint64, ctypes.c_uint32) _setup_prototype(_uc, "uc_query", ucerr, uc_engine, ctypes.c_uint32, ctypes.POINTER(ctypes.c_size_t)) _setup_prototype(_uc, "uc_context_alloc", ucerr, uc_engine, ctypes.POINTER(uc_context)) _setup_prototype(_uc, "uc_free", ucerr, ctypes.c_void_p) @@ -593,7 +593,7 @@ def _mmio_map_write_cb(self, handle, offset, size, value, user_data): (cb, data) = self._callbacks[user_data] cb(self, offset, size, value, data) - def mmio_map(self, address: int, size: int, + def mmio_map(self, address: int, size: int, read_cb: UC_MMIO_READ_TYPE, user_data_read: Any, write_cb: UC_MMIO_WRITE_TYPE, user_data_write: Any): internal_read_cb = ctypes.cast(UC_MMIO_READ_CB(self._mmio_map_read_cb), UC_MMIO_READ_CB) @@ -609,7 +609,7 @@ def mmio_map(self, address: int, size: int, status = _uc.uc_mmio_map(self._uch, address, size, internal_read_cb, read_count, internal_write_cb, write_count) if status != uc.UC_ERR_OK: raise UcError(status) - + # https://docs.python.org/3/library/ctypes.html#callback-functions self._ctype_cbs.append(internal_read_cb) self._ctype_cbs.append(internal_write_cb) @@ -731,12 +731,12 @@ def __ctl(self, ctl, nr, rw): def __ctl_r(self, ctl, nr): return self.__ctl(ctl, nr, uc.UC_CTL_IO_READ) - + def __ctl_w(self, ctl, nr): return self.__ctl(ctl, nr, uc.UC_CTL_IO_WRITE) - + def __ctl_rw(self, ctl, nr): - return self.__ctl(ctl, nr, uc.UC_CTL_IO_READ_WRITE) + return self.__ctl(ctl, nr, uc.UC_CTL_IO_READ_WRITE) def __ctl_r_1_arg(self, ctl, ctp): arg = ctp() @@ -746,7 +746,7 @@ def __ctl_r_1_arg(self, ctl, ctp): def __ctl_w_1_arg(self, ctl, val, ctp): arg = ctp(val) self.ctl(self.__ctl_w(ctl, 1), arg) - + def __ctl_w_2_arg(self, ctl, val1, val2, ctp1, ctp2): arg1 = ctp1(val1) arg2 = ctp2(val2) @@ -763,7 +763,7 @@ def ctl_get_mode(self): def ctl_get_page_size(self): return self.__ctl_r_1_arg(uc.UC_CTL_UC_PAGE_SIZE, ctypes.c_uint32) - + def ctl_set_page_size(self, val: int): self.__ctl_w_1_arg(uc.UC_CTL_UC_PAGE_SIZE, val, ctypes.c_uint32) @@ -772,10 +772,10 @@ def ctl_get_arch(self): def ctl_get_timeout(self): return self.__ctl_r_1_arg(uc.UC_CTL_UC_TIMEOUT, ctypes.c_uint64) - + def ctl_exits_enabled(self, val: bool): self.__ctl_w_1_arg(uc.UC_CTL_UC_USE_EXITS, val, ctypes.c_int) - + def ctl_get_exits_cnt(self): return self.__ctl_r_1_arg(uc.UC_CTL_UC_EXITS_CNT, ctypes.c_size_t) @@ -793,7 +793,7 @@ def ctl_set_exits(self, exits: List[int]): def ctl_get_cpu_model(self): return self.__ctl_r_1_arg(uc.UC_CTL_CPU_MODEL, ctypes.c_int) - + def ctl_set_cpu_model(self, val: int): self.__ctl_w_1_arg(uc.UC_CTL_CPU_MODEL, val, ctypes.c_int) @@ -802,7 +802,7 @@ def ctl_remove_cache(self, addr: int, end: int): def ctl_request_cache(self, addr: int): return self.__ctl_rw_1_1_arg(uc.UC_CTL_TB_REQUEST_CACHE, addr, ctypes.c_uint64, uc_tb) - + def ctl_flush_tb(self): self.ctl(self.__ctl_w(uc.UC_CTL_TB_FLUSH, 0)) @@ -963,7 +963,7 @@ def size(self): @property def arch(self): return self._arch - + @property def mode(self): return self._mode @@ -1012,11 +1012,11 @@ def __del__(self): UC_HOOK_TCG_OPCODE_TYPE = Callable[[Uc, int, int, int, Any], None] UC_HOOK_CALLBACK_TYPE = Union[ - UC_HOOK_CODE_TYPE, - UC_HOOK_INSN_INVALID_TYPE, - UC_HOOK_MEM_INVALID_TYPE, - UC_HOOK_MEM_ACCESS_TYPE, - UC_HOOK_INSN_IN_TYPE, + UC_HOOK_CODE_TYPE, + UC_HOOK_INSN_INVALID_TYPE, + UC_HOOK_MEM_INVALID_TYPE, + UC_HOOK_MEM_ACCESS_TYPE, + UC_HOOK_INSN_IN_TYPE, UC_HOOK_INSN_OUT_TYPE, UC_HOOK_INSN_SYSCALL_TYPE, UC_HOOK_INSN_SYS_TYPE, diff --git a/bindings/ruby/unicorn_gem/ext/unicorn.c b/bindings/ruby/unicorn_gem/ext/unicorn.c index bb7363f8d1..20472e6833 100644 --- a/bindings/ruby/unicorn_gem/ext/unicorn.c +++ b/bindings/ruby/unicorn_gem/ext/unicorn.c @@ -37,7 +37,7 @@ void Init_unicorn_engine() { UcError = rb_define_class_under(UnicornModule, "UcError", rb_eStandardError); SavedContext = rb_define_class_under(UnicornModule, "SavedContext", rb_cObject); Hook = rb_define_class_under(UnicornModule, "Hook", rb_cObject); - + UcClass = rb_define_class_under(UnicornModule, "Uc", rb_cObject); rb_define_method(UcClass, "initialize", m_uc_initialize, 2); rb_define_method(UcClass, "emu_start", m_uc_emu_start, -1); @@ -68,7 +68,7 @@ VALUE m_uc_initialize(VALUE self, VALUE arch, VALUE mode) { VALUE uc = Data_Wrap_Struct(UcClass, 0, uc_close, _uc); rb_iv_set(self, "@uch", uc); rb_iv_set(self, "@hooks", rb_ary_new()); - + return self; } @@ -201,7 +201,7 @@ VALUE m_uc_reg_write(VALUE self, VALUE reg_id, VALUE reg_value){ int64_t tmp; uc_engine *_uc; Data_Get_Struct(rb_iv_get(self,"@uch"), uc_engine, _uc); - + uc_arch arch; uc_query(_uc, UC_QUERY_ARCH, &arch); @@ -263,7 +263,7 @@ VALUE m_uc_reg_write(VALUE self, VALUE reg_id, VALUE reg_value){ return Qnil; } } - + tmp = NUM2ULL(reg_value); err = uc_reg_write(_uc, NUM2INT(reg_id), &tmp); if (err != UC_ERR_OK) { @@ -273,17 +273,17 @@ VALUE m_uc_reg_write(VALUE self, VALUE reg_id, VALUE reg_value){ } VALUE m_uc_mem_read(VALUE self, VALUE address, VALUE size){ - size_t isize = NUM2UINT(size); - uint8_t bytes[isize]; + size_t _size = NUM2ULL(size); + uint8_t bytes[_size]; uc_err err; uc_engine *_uc; Data_Get_Struct(rb_iv_get(self,"@uch"), uc_engine, _uc); - err = uc_mem_read(_uc, NUM2ULL(address), &bytes, isize); + err = uc_mem_read(_uc, NUM2ULL(address), &bytes, _size); if (err != UC_ERR_OK) { rb_raise(UcError, "%s", uc_strerror(err)); } - return rb_str_new(bytes, isize); + return rb_str_new(bytes, _size); } VALUE m_uc_mem_write(VALUE self, VALUE address, VALUE bytes){ @@ -308,7 +308,7 @@ VALUE m_uc_mem_map(int argc, VALUE* argv, VALUE self){ if (NIL_P(perms)) perms = INT2NUM(UC_PROT_ALL); - err = uc_mem_map(_uc, NUM2ULL(address), NUM2UINT(size), NUM2UINT(perms)); + err = uc_mem_map(_uc, NUM2ULL(address), NUM2ULL(size), NUM2UINT(perms)); if (err != UC_ERR_OK) { rb_raise(UcError, "%s", uc_strerror(err)); } @@ -319,7 +319,7 @@ VALUE m_uc_mem_unmap(VALUE self, VALUE address, VALUE size){ uc_err err; uc_engine *_uc; Data_Get_Struct(rb_iv_get(self, "@uch"), uc_engine, _uc); - err = uc_mem_unmap(_uc, NUM2ULL(address), NUM2UINT(size)); + err = uc_mem_unmap(_uc, NUM2ULL(address), NUM2ULL(size)); if (err != UC_ERR_OK) { rb_raise(UcError, "%s", uc_strerror(err)); } @@ -330,7 +330,7 @@ VALUE m_uc_mem_protect(VALUE self, VALUE address, VALUE size, VALUE perms){ uc_err err; uc_engine *_uc; Data_Get_Struct(rb_iv_get(self,"@uch"), uc_engine, _uc); - err = uc_mem_protect(_uc, NUM2ULL(address), NUM2UINT(size), NUM2UINT(perms)); + err = uc_mem_protect(_uc, NUM2ULL(address), NUM2ULL(size), NUM2UINT(perms)); if (err != UC_ERR_OK) { rb_raise(UcError, "%s", uc_strerror(err)); } @@ -370,7 +370,7 @@ static bool cb_hook_mem_invalid(uc_engine *uc, uint32_t access, uint64_t address cb = hook->cb; ud = hook->ud; rUc = hook->rUc; - + return RTEST(rb_funcall(cb, rb_intern("call"), 6, rUc, UINT2NUM(access), ULL2NUM(address), UINT2NUM(size), LL2NUM(value), ud)); } @@ -438,7 +438,7 @@ VALUE m_uc_hook_add(int argc, VALUE* argv, VALUE self){ VALUE arg1; uc_engine *_uc; Data_Get_Struct(rb_iv_get(self, "@uch"), uc_engine, _uc); - + rb_scan_args(argc, argv, "24",&hook_type, &callback, &user_data, &begin, &end, &arg1); if (NIL_P(begin)) begin = ULL2NUM(1); @@ -463,7 +463,7 @@ VALUE m_uc_hook_add(int argc, VALUE* argv, VALUE self){ r_hook = Data_Wrap_Struct(Hook, mark_hook, free, hook); hooks_list = rb_iv_get(self, "@hooks"); rb_ary_push(hooks_list, r_hook); - + uint32_t htype = NUM2UINT(hook_type); if(htype == UC_HOOK_INSN){ switch(NUM2INT(arg1)){ @@ -516,7 +516,7 @@ VALUE m_uc_hook_del(VALUE self, VALUE hook){ struct hook *h; Data_Get_Struct(hook, struct hook, h); err = uc_hook_del(_uc, h->trace); - + rb_ary_delete(rb_iv_get(self, "@hooks"), hook); if (err != UC_ERR_OK) { diff --git a/bindings/rust/src/ffi.rs b/bindings/rust/src/ffi.rs index a4624a02c4..6e6e841c74 100644 --- a/bindings/rust/src/ffi.rs +++ b/bindings/rust/src/ffi.rs @@ -25,36 +25,36 @@ extern "C" { engine: uc_handle, address: u64, bytes: *const u8, - size: libc::size_t, + size: u64, ) -> uc_error; pub fn uc_mem_read( engine: uc_handle, address: u64, bytes: *mut u8, - size: libc::size_t, + size: u64, ) -> uc_error; - pub fn uc_mem_map(engine: uc_handle, address: u64, size: libc::size_t, perms: u32) -> uc_error; + pub fn uc_mem_map(engine: uc_handle, address: u64, size: u64, perms: u32) -> uc_error; pub fn uc_mem_map_ptr( engine: uc_handle, address: u64, - size: libc::size_t, + size: u64, perms: u32, ptr: *mut c_void, ) -> uc_error; pub fn uc_mmio_map( engine: uc_handle, address: u64, - size: libc::size_t, + size: u64, read_cb: *mut c_void, user_data_read: *mut c_void, write_cb: *mut c_void, user_data_write: *mut c_void, ) -> uc_error; - pub fn uc_mem_unmap(engine: uc_handle, address: u64, size: libc::size_t) -> uc_error; + pub fn uc_mem_unmap(engine: uc_handle, address: u64, size: u64) -> uc_error; pub fn uc_mem_protect( engine: uc_handle, address: u64, - size: libc::size_t, + size: u64, perms: u32, ) -> uc_error; pub fn uc_mem_regions( diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs index 7959e2d5de..32a57bd507 100644 --- a/bindings/rust/src/lib.rs +++ b/bindings/rust/src/lib.rs @@ -90,7 +90,7 @@ impl<'a> MmioCallbackScope<'a> { !self.regions.is_empty() } - fn unmap(&mut self, begin: u64, size: usize) { + fn unmap(&mut self, begin: u64, size: u64) { let end: u64 = begin + size as u64; self.regions = self .regions @@ -276,7 +276,7 @@ impl<'a, D> Unicorn<'a, D> { /// Read a range of bytes from memory at the specified address. pub fn mem_read(&self, address: u64, buf: &mut [u8]) -> Result<(), uc_error> { let err = - unsafe { ffi::uc_mem_read(self.get_handle(), address, buf.as_mut_ptr(), buf.len()) }; + unsafe { ffi::uc_mem_read(self.get_handle(), address, buf.as_mut_ptr(), buf.len().try_into().unwrap()) }; if err == uc_error::OK { Ok(()) } else { @@ -285,8 +285,8 @@ impl<'a, D> Unicorn<'a, D> { } /// Return a range of bytes from memory at the specified address as vector. - pub fn mem_read_as_vec(&self, address: u64, size: usize) -> Result, uc_error> { - let mut buf = vec![0; size]; + pub fn mem_read_as_vec(&self, address: u64, size: u64) -> Result, uc_error> { + let mut buf = vec![0; size.try_into().unwrap()]; let err = unsafe { ffi::uc_mem_read(self.get_handle(), address, buf.as_mut_ptr(), size) }; if err == uc_error::OK { Ok(buf) @@ -297,7 +297,7 @@ impl<'a, D> Unicorn<'a, D> { pub fn mem_write(&mut self, address: u64, bytes: &[u8]) -> Result<(), uc_error> { let err = - unsafe { ffi::uc_mem_write(self.get_handle(), address, bytes.as_ptr(), bytes.len()) }; + unsafe { ffi::uc_mem_write(self.get_handle(), address, bytes.as_ptr(), bytes.len().try_into().unwrap()) }; if err == uc_error::OK { Ok(()) } else { @@ -321,7 +321,7 @@ impl<'a, D> Unicorn<'a, D> { pub unsafe fn mem_map_ptr( &mut self, address: u64, - size: usize, + size: u64, perms: Permission, ptr: *mut c_void, ) -> Result<(), uc_error> { @@ -340,7 +340,7 @@ impl<'a, D> Unicorn<'a, D> { pub fn mem_map( &mut self, address: u64, - size: libc::size_t, + size: u64, perms: Permission, ) -> Result<(), uc_error> { let err = unsafe { ffi::uc_mem_map(self.get_handle(), address, size, perms.bits()) }; @@ -358,7 +358,7 @@ impl<'a, D> Unicorn<'a, D> { pub fn mmio_map( &mut self, address: u64, - size: libc::size_t, + size: u64, read_callback: Option, write_callback: Option, ) -> Result<(), uc_error> @@ -405,7 +405,7 @@ impl<'a, D> Unicorn<'a, D> { let rd = read_data.map(|c| c as Box); let wd = write_data.map(|c| c as Box); self.inner_mut().mmio_callbacks.push(MmioCallbackScope { - regions: vec![(address, size)], + regions: vec![(address, size.try_into().unwrap())], read_callback: rd, write_callback: wd, }); @@ -423,7 +423,7 @@ impl<'a, D> Unicorn<'a, D> { pub fn mmio_map_ro( &mut self, address: u64, - size: libc::size_t, + size: u64, callback: F, ) -> Result<(), uc_error> where @@ -444,7 +444,7 @@ impl<'a, D> Unicorn<'a, D> { pub fn mmio_map_wo( &mut self, address: u64, - size: libc::size_t, + size: u64, callback: F, ) -> Result<(), uc_error> where @@ -462,7 +462,7 @@ impl<'a, D> Unicorn<'a, D> { /// /// `address` must be aligned to 4kb or this will return `Error::ARG`. /// `size` must be a multiple of 4kb or this will return `Error::ARG`. - pub fn mem_unmap(&mut self, address: u64, size: libc::size_t) -> Result<(), uc_error> { + pub fn mem_unmap(&mut self, address: u64, size: u64) -> Result<(), uc_error> { let err = unsafe { ffi::uc_mem_unmap(self.get_handle(), address, size) }; self.mmio_unmap(address, size); @@ -474,7 +474,7 @@ impl<'a, D> Unicorn<'a, D> { } } - fn mmio_unmap(&mut self, address: u64, size: libc::size_t) { + fn mmio_unmap(&mut self, address: u64, size: u64) { for scope in self.inner_mut().mmio_callbacks.iter_mut() { scope.unmap(address, size); } @@ -490,7 +490,7 @@ impl<'a, D> Unicorn<'a, D> { pub fn mem_protect( &mut self, address: u64, - size: libc::size_t, + size: u64, perms: Permission, ) -> Result<(), uc_error> { let err = unsafe { ffi::uc_mem_protect(self.get_handle(), address, size, perms.bits()) }; diff --git a/bindings/vb6/main.cpp b/bindings/vb6/main.cpp index 140d44981a..4a73c9f3f4 100644 --- a/bindings/vb6/main.cpp +++ b/bindings/vb6/main.cpp @@ -1,8 +1,8 @@ -/* +/* stdcall unicorn engine shim layer for use with VB6 or C# - code ripped from unicorn_dynload.c - + code ripped from unicorn_dynload.c + Contributed by: FireEye FLARE team Author: David Zimmer , License: Apache 2.0 @@ -31,9 +31,9 @@ //you can find examples here: https://github.com/dzzie/VS_LIBEMU/tree/master/libemu/include //if you want to include disassembler support: -// 1) install libdasm in your compilers include directory +// 1) install libdasm in your compilers include directory // 2) add libdasm.h/.c to the project (drag and drop into VS project explorer), -// 3) remove the comment from the define below. +// 3) remove the comment from the define below. //The vb code detects the changes at runtime. //#define INCLUDE_DISASM @@ -49,21 +49,21 @@ enum hookCatagory{hc_code = 0, hc_block = 1, hc_inst = 2, hc_int = 3, hc_mem = 4, hc_memInvalid = 5}; -//tracing UC_HOOK_CODE & UC_HOOK_BLOCK -typedef void (__stdcall *vb_cb_hookcode_t) (uc_engine *uc, uint64_t address, uint32_t size, void *user_data); +//tracing UC_HOOK_CODE & UC_HOOK_BLOCK +typedef void (__stdcall *vb_cb_hookcode_t) (uc_engine *uc, uint64_t address, uint32_t size, void *user_data); vb_cb_hookcode_t vbHookcode = 0; vb_cb_hookcode_t vbHookBlock = 0; -//hooking memory UC_MEM_READ/WRITE/FETCH +//hooking memory UC_MEM_READ/WRITE/FETCH typedef void (__stdcall *vb_cb_hookmem_t) (uc_engine *uc, uc_mem_type type, uint64_t address, int size,int64_t value, void *user_data); vb_cb_hookmem_t vbHookMem = 0; -//invalid memory access UC_MEM_*_UNMAPPED and UC_MEM_*PROT events -typedef bool (__stdcall *vb_cb_eventmem_t) (uc_engine *uc, uc_mem_type type, uint64_t address, int size, int64_t value, void *user_data); +//invalid memory access UC_MEM_*_UNMAPPED and UC_MEM_*PROT events +typedef bool (__stdcall *vb_cb_eventmem_t) (uc_engine *uc, uc_mem_type type, uint64_t address, int size, int64_t value, void *user_data); vb_cb_eventmem_t vbInvalidMem = 0; -//tracing interrupts for uc_hook_intr() -typedef void (__stdcall *vb_cb_hookintr_t) (uc_engine *uc, uint32_t intno, void *user_data); +//tracing interrupts for uc_hook_intr() +typedef void (__stdcall *vb_cb_hookintr_t) (uc_engine *uc, uint32_t intno, void *user_data); vb_cb_hookintr_t vbHookInt = 0; /* @@ -172,7 +172,7 @@ unsigned int __stdcall ucs_dynload(char *path){ return uc_dyn_load(path, 0); #else*/ return 1; - //#endif + //#endif } unsigned int __stdcall ucs_version(unsigned int *major, unsigned int *minor){ @@ -230,12 +230,12 @@ uc_err __stdcall ucs_reg_read_batch(uc_engine *uc, int *regs, void **vals, int c return uc_reg_read_batch(uc, regs, vals, count); } -uc_err __stdcall ucs_mem_write(uc_engine *uc, uint64_t address, const void *bytes, size_t size){ +uc_err __stdcall ucs_mem_write(uc_engine *uc, uint64_t address, const void *bytes, uint64_t size){ #pragma EXPORT return uc_mem_write(uc, address, bytes, size); } -uc_err __stdcall ucs_mem_read(uc_engine *uc, uint64_t address, void *bytes, size_t size){ +uc_err __stdcall ucs_mem_read(uc_engine *uc, uint64_t address, void *bytes, uint64_t size){ #pragma EXPORT return uc_mem_read(uc, address, bytes, size); } @@ -255,24 +255,24 @@ uc_err __stdcall ucs_hook_del(uc_engine *uc, uc_hook hh){ return uc_hook_del(uc, hh); } -uc_err __stdcall ucs_mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t perms){ +uc_err __stdcall ucs_mem_map(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms){ #pragma EXPORT return uc_mem_map(uc, address, size, perms); } //requires link against v1.0 -uc_err __stdcall ucs_mem_map_ptr(uc_engine *uc, uint64_t address, size_t size, uint32_t perms, void *ptr){ +uc_err __stdcall ucs_mem_map_ptr(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms, void *ptr){ #pragma EXPORT return uc_mem_map_ptr(uc, address, size, perms, ptr); } -uc_err __stdcall ucs_mem_unmap(uc_engine *uc, uint64_t address, size_t size){ +uc_err __stdcall ucs_mem_unmap(uc_engine *uc, uint64_t address, uint64_t size){ #pragma EXPORT return uc_mem_unmap(uc, address, size); } -uc_err __stdcall ucs_mem_protect(uc_engine *uc, uint64_t address, size_t size, uint32_t perms){ +uc_err __stdcall ucs_mem_protect(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms){ #pragma EXPORT return uc_mem_protect(uc, address, size, perms); } @@ -304,15 +304,15 @@ uc_err __stdcall ucs_context_restore(uc_engine *uc, uc_context *context){ /* char* asprintf(char* format, ...){ - + char *ret = 0; - + if(!format) return 0; - va_list args; - va_start(args,format); - int size = _vscprintf(format, args); - + va_list args; + va_start(args,format); + int size = _vscprintf(format, args); + if(size > 0){ size++; //for null ret = (char*)malloc(size+2); @@ -338,18 +338,18 @@ int __stdcall disasm_addr(uc_engine *uc, uint32_t va, char *str, int bufLen){ readLen--; if(readLen == 0) return -2; } - + instr_len = get_instruction(&inst, data, MODE_32); if( instr_len == 0 ) return -3; get_instruction_string(&inst, FORMAT_INTEL, va, str, bufLen); - /* + /* if(inst.type == INSTRUCTION_TYPE_JMP || inst.type == INSTRUCTION_TYPE_JMPC){ if(inst.op1.type == OPERAND_TYPE_IMMEDIATE){ if(strlen(str) + 6 < bufLen){ if(getJmpTarget(str) < va){ - strcat(str," ^^"); + strcat(str," ^^"); }else{ strcat(str," vv"); } @@ -363,18 +363,18 @@ int __stdcall disasm_addr(uc_engine *uc, uint32_t va, char *str, int bufLen){ //maps and write in one shot, auto handles alignment.. -uc_err __stdcall mem_write_block(uc_engine *uc, uint64_t address, void* data, uint32_t size, uint32_t perm){ +uc_err __stdcall mem_write_block(uc_engine *uc, uint64_t address, void* data, uint64_t size, uint32_t perm){ #pragma EXPORT uc_err x; uint64_t base = address; - uint32_t sz = size; + uint64_t sz = size; while(base % 0x1000 !=0){ base--; if(base==0) break; } - + sz += address-base; //if data starts mid block, we need to alloc more than just size.. while(sz % 0x1000 !=0){ sz++; @@ -402,7 +402,7 @@ uc_err __stdcall get_memMap(uc_engine *uc, _CollectionPtr *pColl){ char tmp[200]; //max 46 chars used uc_err err = uc_mem_regions(uc, ®ions, &count); - + if (err != UC_ERR_OK) return err; for (uint32_t i = 0; i < count; i++) { @@ -411,7 +411,7 @@ uc_err __stdcall get_memMap(uc_engine *uc, _CollectionPtr *pColl){ } //free(regions); //https://github.com/unicorn-engine/unicorn/pull/373#issuecomment-271187118 - + uc_free((void*)regions); return err; @@ -456,4 +456,4 @@ unsigned int __stdcall ULong(unsigned int v1, unsigned int v2, int operation){ return -1; -} \ No newline at end of file +} diff --git a/bindings/vb6/uc_def.bas b/bindings/vb6/uc_def.bas index 43193a8a15..497fc4b25e 100644 --- a/bindings/vb6/uc_def.bas +++ b/bindings/vb6/uc_def.bas @@ -2077,8 +2077,8 @@ Public Declare Function ucs_reg_read Lib "ucvbshim.dll" (ByVal hEngine As Long, ' for detailed error). '*/ 'UNICORN_EXPORT -'uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *bytes, size_t size); -Public Declare Function ucs_mem_write Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByRef b As Byte, ByVal size As Long) As uc_err +'uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *bytes, uint64_t size); +Public Declare Function ucs_mem_write Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByRef b As Byte, ByVal size As Currency) As uc_err @@ -2096,8 +2096,8 @@ Public Declare Function ucs_mem_write Lib "ucvbshim.dll" (ByVal hEngine As Long, ' for detailed error). '*/ 'UNICORN_EXPORT -'uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *bytes, size_t size); -Public Declare Function ucs_mem_read Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByRef b As Byte, ByVal size As Long) As uc_err +'uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *bytes, uint64_t size); +Public Declare Function ucs_mem_read Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByRef b As Byte, ByVal size As Currency) As uc_err @@ -2202,8 +2202,8 @@ Public Declare Function ucs_hook_del Lib "ucvbshim.dll" (ByVal hEngine As Long, ' for detailed error). '*/ 'UNICORN_EXPORT -'uc_err uc_mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t perms); -Public Declare Function ucs_mem_map Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByVal size As Long, ByVal perms As uc_prot) As uc_err +'uc_err uc_mem_map(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms); +Public Declare Function ucs_mem_map Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByVal size As Currency, ByVal perms As uc_prot) As uc_err @@ -2227,8 +2227,8 @@ Public Declare Function ucs_mem_map Lib "ucvbshim.dll" (ByVal hEngine As Long, B ' for detailed error). '*/ 'UNICORN_EXPORT -'uc_err uc_mem_map_ptr(uc_engine *uc, uint64_t address, size_t size, uint32_t perms, void *ptr); -Public Declare Function ucs_mem_map_ptr Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByVal size As Long, ByVal perms As uc_prot, ByVal ptr As Long) As uc_err +'uc_err uc_mem_map_ptr(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms, void *ptr); +Public Declare Function ucs_mem_map_ptr Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByVal size As Currency, ByVal perms As uc_prot, ByVal ptr As Long) As uc_err @@ -2246,8 +2246,8 @@ Public Declare Function ucs_mem_map_ptr Lib "ucvbshim.dll" (ByVal hEngine As Lon ' for detailed error). '*/ 'UNICORN_EXPORT -'uc_err uc_mem_unmap(uc_engine *uc, uint64_t address, size_t size); -Public Declare Function ucs_mem_unmap Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByVal size As Long) As uc_err +'uc_err uc_mem_unmap(uc_engine *uc, uint64_t address, uint64_t size); +Public Declare Function ucs_mem_unmap Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByVal size As Currency) As uc_err '/* @@ -2267,8 +2267,8 @@ Public Declare Function ucs_mem_unmap Lib "ucvbshim.dll" (ByVal hEngine As Long, ' for detailed error). '*/ 'UNICORN_EXPORT -'uc_err uc_mem_protect(uc_engine *uc, uint64_t address, size_t size, uint32_t perms); -Public Declare Function ucs_mem_protect Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByVal size As Long, ByVal perm As uc_prot) As uc_err +'uc_err uc_mem_protect(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms); +Public Declare Function ucs_mem_protect Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByVal size As Currency, ByVal perm As uc_prot) As uc_err @@ -2367,8 +2367,8 @@ Public Declare Function disasm_addr Lib "ucvbshim.dll" (ByVal hEngine As Long, B 'simplified access to map and write data to emu memory -'uc_err __stdcall mem_write_block(uc_engine *uc, uint64_t address, void* data, uint32_t size, uint32_t perm){ -Public Declare Function mem_write_block Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByRef data As Byte, ByVal size As Long, ByVal perm As Long) As uc_err +'uc_err __stdcall mem_write_block(uc_engine *uc, uint64_t address, void* data, uint64_t size, uint32_t perm){ +Public Declare Function mem_write_block Lib "ucvbshim.dll" (ByVal hEngine As Long, ByVal addr As Currency, ByRef data As Byte, ByVal size As Currency, ByVal perm As Long) As uc_err Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long @@ -2393,9 +2393,9 @@ Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString 'End Function Function err2str(e As uc_err) As String - + err2str = "Unknown error code: " & e - + If e = uc_err_ok Then err2str = "No error: everything was fine" If e = UC_ERR_NOMEM Then err2str = "Out-Of-Memory error: uc_open(), uc_emulate()" If e = UC_ERR_ARCH Then err2str = "Unsupported architecture: uc_open()" @@ -2418,13 +2418,13 @@ Function err2str(e As uc_err) As String If e = UC_ERR_HOOK_EXIST Then err2str = "hook for this event already existed" If e = UC_ERR_RESOURCE Then err2str = "Insufficient resource: uc_emu_start()" If e = UC_ERR_EXCEPTION Then err2str = "Unhandled CPU exception" - + End Function Function memType2str(t As uc_mem_type) - + memType2str = "Unknown memType: " & t - + If t = UC_MEM_READ Then memType2str = "Memory is read from" If t = uc_mem_write Then memType2str = "Memory is written to" If t = UC_MEM_FETCH Then memType2str = "Memory is fetched" @@ -2435,10 +2435,10 @@ Function memType2str(t As uc_mem_type) If t = UC_MEM_READ_PROT Then memType2str = "Read from read protected, but mapped, memory" If t = UC_MEM_FETCH_PROT Then memType2str = "Fetch from non-executable, but mapped, memory" If t = UC_MEM_READ_AFTER Then memType2str = "Memory is read from (successful access)" - + End Function - + diff --git a/include/uc_priv.h b/include/uc_priv.h index 030fadce60..7a4345a589 100644 --- a/include/uc_priv.h +++ b/include/uc_priv.h @@ -80,10 +80,10 @@ typedef struct { typedef void (*reg_reset_t)(struct uc_struct *uc); typedef bool (*uc_write_mem_t)(AddressSpace *as, hwaddr addr, - const uint8_t *buf, int len); + const uint8_t *buf, hwaddr len); typedef bool (*uc_read_mem_t)(AddressSpace *as, hwaddr addr, uint8_t *buf, - int len); + hwaddr len); typedef void (*uc_args_void_t)(void *); @@ -409,7 +409,7 @@ struct uc_context { }; // check if this address is mapped in (via uc_mem_map()) -MemoryRegion *memory_mapping(struct uc_struct *uc, uint64_t address); +MemoryRegion *find_memory_region(struct uc_struct *uc, uint64_t address); // We have to support 32bit system so we can't hold uint64_t on void* static inline void uc_add_exit(uc_engine *uc, uint64_t addr) @@ -486,6 +486,28 @@ static inline void hooked_regions_check(uc_engine *uc, uint64_t start, length); } +/* + break translation loop: + This is done in two cases: + 1. the user wants to stop the emulation. + 2. the user has set it IP. This requires to restart the internal + CPU emulation and rebuild some translation blocks +*/ +static inline uc_err break_translation_loop(uc_engine *uc) +{ + if (uc->emulation_done) { + return UC_ERR_OK; + } + + // TODO: make this atomic somehow? + if (uc->cpu) { + // exit the current TB + cpu_exit(uc->cpu); + } + + return UC_ERR_OK; +} + #ifdef UNICORN_TRACER #define UC_TRACE_START(loc) trace_start(get_tracer(), loc) #define UC_TRACE_END(loc, fmt, ...) \ diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index 4b169d761f..0429cf256c 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -794,7 +794,7 @@ uc_err uc_reg_read_batch(uc_engine *uc, int *regs, void **vals, int count); */ UNICORN_EXPORT uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *bytes, - size_t size); + uint64_t size); /* Read a range of bytes in memory. @@ -810,7 +810,7 @@ uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *bytes, for detailed error). */ UNICORN_EXPORT -uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *bytes, size_t size); +uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *bytes, uint64_t size); /* Emulate machine code in a specific duration of time. @@ -917,7 +917,7 @@ typedef enum uc_prot { for detailed error). */ UNICORN_EXPORT -uc_err uc_mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t perms); +uc_err uc_mem_map(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms); /* Map existing host memory in for emulation. @@ -942,7 +942,7 @@ uc_err uc_mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t perms); for detailed error). */ UNICORN_EXPORT -uc_err uc_mem_map_ptr(uc_engine *uc, uint64_t address, size_t size, +uc_err uc_mem_map_ptr(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms, void *ptr); /* @@ -965,7 +965,7 @@ uc_err uc_mem_map_ptr(uc_engine *uc, uint64_t address, size_t size, for detailed error). */ UNICORN_EXPORT -uc_err uc_mmio_map(uc_engine *uc, uint64_t address, size_t size, +uc_err uc_mmio_map(uc_engine *uc, uint64_t address, uint64_t size, uc_cb_mmio_read_t read_cb, void *user_data_read, uc_cb_mmio_write_t write_cb, void *user_data_write); @@ -985,7 +985,7 @@ uc_err uc_mmio_map(uc_engine *uc, uint64_t address, size_t size, for detailed error). */ UNICORN_EXPORT -uc_err uc_mem_unmap(uc_engine *uc, uint64_t address, size_t size); +uc_err uc_mem_unmap(uc_engine *uc, uint64_t address, uint64_t size); /* Set memory permissions for emulation memory. @@ -1006,7 +1006,7 @@ uc_err uc_mem_unmap(uc_engine *uc, uint64_t address, size_t size); for detailed error). */ UNICORN_EXPORT -uc_err uc_mem_protect(uc_engine *uc, uint64_t address, size_t size, +uc_err uc_mem_protect(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms); /* diff --git a/qemu/unicorn_common.h b/qemu/unicorn_common.h index 3e06ccac61..a85c6d45c2 100644 --- a/qemu/unicorn_common.h +++ b/qemu/unicorn_common.h @@ -14,13 +14,13 @@ void tcg_exec_init(struct uc_struct *uc, unsigned long tb_size); // return true on success, false on failure static inline bool cpu_physical_mem_read(AddressSpace *as, hwaddr addr, - uint8_t *buf, int len) + uint8_t *buf, hwaddr len) { return cpu_physical_memory_rw(as, addr, (void *)buf, len, 0); } static inline bool cpu_physical_mem_write(AddressSpace *as, hwaddr addr, - const uint8_t *buf, int len) + const uint8_t *buf, hwaddr len) { return cpu_physical_memory_rw(as, addr, (void *)buf, len, 1); } diff --git a/tests/rust-tests/main.rs b/tests/rust-tests/main.rs index b64b6aa617..970bd922b1 100644 --- a/tests/rust-tests/main.rs +++ b/tests/rust-tests/main.rs @@ -153,7 +153,7 @@ fn emulate_x86() { assert_eq!(emu.mem_map(0x1000, 0x4000, Permission::ALL), Ok(())); assert_eq!(emu.mem_write(0x1000, &x86_code32), Ok(())); assert_eq!( - emu.mem_read_as_vec(0x1000, x86_code32.len()), + emu.mem_read_as_vec(0x1000, x86_code32.len().try_into().unwrap()), Ok(x86_code32.clone()) ); @@ -550,7 +550,7 @@ fn emulate_arm() { assert_eq!(emu.mem_map(0x1000, 0x4000, Permission::ALL), Ok(())); assert_eq!(emu.mem_write(0x1000, &arm_code32), Ok(())); assert_eq!( - emu.mem_read_as_vec(0x1000, arm_code32.len()), + emu.mem_read_as_vec(0x1000, arm_code32.len().try_into().unwrap()), Ok(arm_code32.clone()) ); @@ -581,7 +581,7 @@ fn emulate_mips() { assert_eq!(emu.mem_map(0x1000, 0x4000, Permission::ALL), Ok(())); assert_eq!(emu.mem_write(0x1000, &mips_code32), Ok(())); assert_eq!( - emu.mem_read_as_vec(0x1000, mips_code32.len()), + emu.mem_read_as_vec(0x1000, mips_code32.len().try_into().unwrap()), Ok(mips_code32.clone()) ); assert_eq!(emu.reg_write(RegisterMIPS::AT, 0), Ok(())); @@ -606,7 +606,7 @@ fn emulate_ppc() { assert_eq!(emu.mem_map(0x1000, 0x4000, Permission::ALL), Ok(())); assert_eq!(emu.mem_write(0x1000, &ppc_code32), Ok(())); assert_eq!( - emu.mem_read_as_vec(0x1000, ppc_code32.len()), + emu.mem_read_as_vec(0x1000, ppc_code32.len().try_into().unwrap()), Ok(ppc_code32.clone()) ); assert_eq!(emu.reg_write(RegisterPPC::R3, 42), Ok(())); @@ -652,7 +652,7 @@ fn mem_map_ptr() { ); assert_eq!(emu.mem_write(0x1000, &x86_code32), Ok(())); assert_eq!( - emu.mem_read_as_vec(0x1000, x86_code32.len()), + emu.mem_read_as_vec(0x1000, x86_code32.len().try_into().unwrap()), Ok(x86_code32.clone()) ); @@ -688,7 +688,7 @@ fn mem_map_ptr() { ); assert_eq!(emu.mem_write(0x1000, &x86_code32), Ok(())); assert_eq!( - emu.mem_read_as_vec(0x1000, x86_code32.len()), + emu.mem_read_as_vec(0x1000, x86_code32.len().try_into().unwrap()), Ok(x86_code32.clone()) ); diff --git a/tests/unit/test_mem.c b/tests/unit/test_mem.c index 4e2f176a39..813f60f81c 100644 --- a/tests/unit/test_mem.c +++ b/tests/unit/test_mem.c @@ -275,6 +275,79 @@ static void test_mem_protect_mmio(void) OK(uc_close(uc)); } +static void __inline parts_increment(size_t idx, char parts[3]) +{ + if (idx && idx % 3 == 0) { + if (++parts[2] > '9') { + parts[2] = '0'; + if (++parts[1] > 'z') { + parts[1] = 'a'; + if (++parts[0] > 'Z') + parts[0] = 'A'; + } + } + } +} + +// Create a pattern string. It works the same as +// https://github.com/rapid7/metasploit-framework/blob/master/tools/exploit/pattern_create.rb +static void pattern_create(char *buf, size_t len) +{ + char parts[] = {'A', 'a', '0'}; + size_t i; + + for (i = 0; i < len; i++) { + buf[i] = parts[i % 3]; + parts_increment(i, parts); + } +} + +static bool pattern_verify(const char *buf, size_t len) +{ + char parts[] = {'A', 'a', '0'}; + size_t i; + + for (i = 0; i < len; i++) { + if (buf[i] != parts[i % 3]) + return false; + parts_increment(i, parts); + } + + return true; +} + +// Test for reading and writing memory block that are bigger than INT_MAX. +static void test_mem_read_and_write_large_memory_block(void) +{ + uc_engine *uc; + uint64_t mem_addr = 0x1000000; + uint64_t mem_size = 0x9f000000; + char *pmem = NULL; + + if (sizeof(void *) < 8) { + // Don't perform the test on a 32-bit platforms since we may not have + // enough memory space. + return; + } + + OK(uc_open(UC_ARCH_ARM64, UC_MODE_ARM, &uc)); + OK(uc_mem_map(uc, mem_addr, mem_size, UC_PROT_ALL)); + + pmem = malloc(mem_size); + if (TEST_CHECK(pmem != NULL)) { + pattern_create(pmem, mem_size); + + OK(uc_mem_write(uc, mem_addr, pmem, mem_size)); + memset(pmem, 'a', mem_size); + OK(uc_mem_read(uc, mem_addr, pmem, mem_size)); + TEST_CHECK(pattern_verify(pmem, mem_size)); + free(pmem); + } + + OK(uc_mem_unmap(uc, mem_addr, mem_size)); + OK(uc_close(uc)); +} + TEST_LIST = {{"test_map_correct", test_map_correct}, {"test_map_wrapping", test_map_wrapping}, {"test_mem_protect", test_mem_protect}, @@ -286,4 +359,6 @@ TEST_LIST = {{"test_map_correct", test_map_correct}, {"test_map_big_memory", test_map_big_memory}, {"test_mem_protect_remove_exec", test_mem_protect_remove_exec}, {"test_mem_protect_mmio", test_mem_protect_mmio}, + {"test_mem_read_and_write_large_memory_block", + test_mem_read_and_write_large_memory_block}, {NULL, NULL}}; diff --git a/uc.c b/uc.c index 667f40ca4f..8b12fbfb10 100644 --- a/uc.c +++ b/uc.c @@ -547,14 +547,14 @@ uc_err uc_reg_write(uc_engine *uc, int regid, const void *value) // check if a memory area is mapped // this is complicated because an area can overlap adjacent blocks -static bool check_mem_area(uc_engine *uc, uint64_t address, size_t size) +static bool check_mem_area(uc_engine *uc, uint64_t address, uint64_t size) { - size_t count = 0, len; + uint64_t count = 0, len; while (count < size) { - MemoryRegion *mr = memory_mapping(uc, address); + MemoryRegion *mr = find_memory_region(uc, address); if (mr) { - len = (size_t)MIN(size - count, mr->end - address); + len = (uint64_t)MIN(size - count, mr->end - address); count += len; address += len; } else { // this address is not mapped in yet @@ -566,17 +566,13 @@ static bool check_mem_area(uc_engine *uc, uint64_t address, size_t size) } UNICORN_EXPORT -uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, size_t size) +uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, uint64_t size) { - size_t count = 0, len; + uint64_t count = 0, len; uint8_t *bytes = _bytes; UC_INIT(uc); - // qemu cpu_physical_memory_rw() size is an int - if (size > INT_MAX) - return UC_ERR_ARG; - if (uc->mem_redirect) { address = uc->mem_redirect(address); } @@ -587,9 +583,9 @@ uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, size_t size) // memory area can overlap adjacent memory blocks while (count < size) { - MemoryRegion *mr = memory_mapping(uc, address); + MemoryRegion *mr = find_memory_region(uc, address); if (mr) { - len = (size_t)MIN(size - count, mr->end - address); + len = (uint64_t)MIN(size - count, mr->end - address); if (uc->read_mem(&uc->address_space_memory, address, bytes, len) == false) { break; @@ -611,17 +607,13 @@ uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, size_t size) UNICORN_EXPORT uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *_bytes, - size_t size) + uint64_t size) { - size_t count = 0, len; + uint64_t count = 0, len; const uint8_t *bytes = _bytes; UC_INIT(uc); - // qemu cpu_physical_memory_rw() size is an int - if (size > INT_MAX) - return UC_ERR_ARG; - if (uc->mem_redirect) { address = uc->mem_redirect(address); } @@ -632,7 +624,7 @@ uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *_bytes, // memory area can overlap adjacent memory blocks while (count < size) { - MemoryRegion *mr = memory_mapping(uc, address); + MemoryRegion *mr = find_memory_region(uc, address); if (mr) { uint32_t operms = mr->perms; if (!(operms & UC_PROT_WRITE)) { // write protected @@ -641,7 +633,7 @@ uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *_bytes, uc->readonly_mem(mr, false); } - len = (size_t)MIN(size - count, mr->end - address); + len = (uint64_t)MIN(size - count, mr->end - address); if (uc->write_mem(&uc->address_space_memory, address, bytes, len) == false) { break; @@ -907,19 +899,8 @@ UNICORN_EXPORT uc_err uc_emu_stop(uc_engine *uc) { UC_INIT(uc); - - if (uc->emulation_done) { - return UC_ERR_OK; - } - uc->stop_request = true; - // TODO: make this atomic somehow? - if (uc->cpu) { - // exit the current TB - cpu_exit(uc->cpu); - } - - return UC_ERR_OK; + return break_translation_loop(uc); } // return target index where a memory region at the address exists, or could be @@ -956,7 +937,7 @@ static int bsearch_mapped_blocks(const uc_engine *uc, uint64_t address) } // find if a memory range overlaps with existing mapped regions -static bool memory_overlap(struct uc_struct *uc, uint64_t begin, size_t size) +static bool memory_overlap(struct uc_struct *uc, uint64_t begin, uint64_t size) { unsigned int i; uint64_t end = begin + size - 1; @@ -976,8 +957,7 @@ static bool memory_overlap(struct uc_struct *uc, uint64_t begin, size_t size) } // common setup/error checking shared between uc_mem_map and uc_mem_map_ptr -static uc_err mem_map(uc_engine *uc, uint64_t address, size_t size, - uint32_t perms, MemoryRegion *block) +static uc_err mem_map(uc_engine *uc, MemoryRegion *block) { MemoryRegion **regions; int pos; @@ -1008,7 +988,7 @@ static uc_err mem_map(uc_engine *uc, uint64_t address, size_t size, return UC_ERR_OK; } -static uc_err mem_map_check(uc_engine *uc, uint64_t address, size_t size, +static uc_err mem_map_check(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms) { if (size == 0) { @@ -1045,7 +1025,7 @@ static uc_err mem_map_check(uc_engine *uc, uint64_t address, size_t size, } UNICORN_EXPORT -uc_err uc_mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t perms) +uc_err uc_mem_map(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms) { uc_err res; @@ -1060,12 +1040,11 @@ uc_err uc_mem_map(uc_engine *uc, uint64_t address, size_t size, uint32_t perms) return res; } - return mem_map(uc, address, size, perms, - uc->memory_map(uc, address, size, perms)); + return mem_map(uc, uc->memory_map(uc, address, size, perms)); } UNICORN_EXPORT -uc_err uc_mem_map_ptr(uc_engine *uc, uint64_t address, size_t size, +uc_err uc_mem_map_ptr(uc_engine *uc, uint64_t address, uint64_t size, uint32_t perms, void *ptr) { uc_err res; @@ -1085,12 +1064,11 @@ uc_err uc_mem_map_ptr(uc_engine *uc, uint64_t address, size_t size, return res; } - return mem_map(uc, address, size, UC_PROT_ALL, - uc->memory_map_ptr(uc, address, size, perms, ptr)); + return mem_map(uc, uc->memory_map_ptr(uc, address, size, perms, ptr)); } UNICORN_EXPORT -uc_err uc_mmio_map(uc_engine *uc, uint64_t address, size_t size, +uc_err uc_mmio_map(uc_engine *uc, uint64_t address, uint64_t size, uc_cb_mmio_read_t read_cb, void *user_data_read, uc_cb_mmio_write_t write_cb, void *user_data_write) { @@ -1108,19 +1086,18 @@ uc_err uc_mmio_map(uc_engine *uc, uint64_t address, size_t size, // The callbacks do not need to be checked for NULL here, as their presence // (or lack thereof) will determine the permissions used. - return mem_map(uc, address, size, UC_PROT_NONE, - uc->memory_map_io(uc, address, size, read_cb, write_cb, - user_data_read, user_data_write)); + return mem_map(uc, uc->memory_map_io(uc, address, size, read_cb, write_cb, + user_data_read, user_data_write)); } // Create a backup copy of the indicated MemoryRegion. // Generally used in prepartion for splitting a MemoryRegion. static uint8_t *copy_region(struct uc_struct *uc, MemoryRegion *mr) { - uint8_t *block = (uint8_t *)g_malloc0((size_t)int128_get64(mr->size)); + uint8_t *block = (uint8_t *)g_malloc0((uint64_t)int128_get64(mr->size)); if (block != NULL) { uc_err err = - uc_mem_read(uc, mr->addr, block, (size_t)int128_get64(mr->size)); + uc_mem_read(uc, mr->addr, block, (uint64_t)int128_get64(mr->size)); if (err != UC_ERR_OK) { free(block); block = NULL; @@ -1136,10 +1113,10 @@ static uint8_t *copy_region(struct uc_struct *uc, MemoryRegion *mr) Note this function may be called recursively. */ static bool split_mmio_region(struct uc_struct *uc, MemoryRegion *mr, - uint64_t address, size_t size, bool do_delete) + uint64_t address, uint64_t size, bool do_delete) { uint64_t begin, end, chunk_end; - size_t l_size, r_size, m_size; + uint64_t l_size, r_size, m_size; mmio_cbs backup; chunk_end = address + size; @@ -1166,7 +1143,7 @@ static bool split_mmio_region(struct uc_struct *uc, MemoryRegion *mr, */ // unmap this region first, then do split it later - if (uc_mem_unmap(uc, mr->addr, (size_t)int128_get64(mr->size)) != + if (uc_mem_unmap(uc, mr->addr, (uint64_t)int128_get64(mr->size)) != UC_ERR_OK) { return false; } @@ -1180,9 +1157,9 @@ static bool split_mmio_region(struct uc_struct *uc, MemoryRegion *mr, } // compute sub region sizes - l_size = (size_t)(address - begin); - r_size = (size_t)(end - chunk_end); - m_size = (size_t)(chunk_end - address); + l_size = (uint64_t)(address - begin); + r_size = (uint64_t)(end - chunk_end); + m_size = (uint64_t)(chunk_end - address); if (l_size > 0) { if (uc_mmio_map(uc, begin, l_size, backup.read, backup.user_data_read, @@ -1225,12 +1202,12 @@ static bool split_mmio_region(struct uc_struct *uc, MemoryRegion *mr, // TODO: investigate whether qemu region manipulation functions already offered // this capability static bool split_region(struct uc_struct *uc, MemoryRegion *mr, - uint64_t address, size_t size, bool do_delete) + uint64_t address, uint64_t size, bool do_delete) { uint8_t *backup; uint32_t perms; uint64_t begin, end, chunk_end; - size_t l_size, m_size, r_size; + uint64_t l_size, m_size, r_size; RAMBlock *block = NULL; bool prealloc = false; @@ -1254,14 +1231,7 @@ static bool split_region(struct uc_struct *uc, MemoryRegion *mr, // Find the correct and large enough (which contains our target mr) // to create the content backup. - QLIST_FOREACH(block, &uc->ram_list.blocks, next) - { - // block->offset is the offset within ram_addr_t, not GPA - if (block->mr->addr <= mr->addr && - block->used_length + block->mr->addr >= mr->end) { - break; - } - } + block = mr->ram_block; if (block == NULL) { return false; @@ -1287,7 +1257,7 @@ static bool split_region(struct uc_struct *uc, MemoryRegion *mr, end = mr->end; // unmap this region first, then do split it later - if (uc_mem_unmap(uc, mr->addr, (size_t)int128_get64(mr->size)) != + if (uc_mem_unmap(uc, mr->addr, (uint64_t)int128_get64(mr->size)) != UC_ERR_OK) { goto error; } @@ -1308,9 +1278,9 @@ static bool split_region(struct uc_struct *uc, MemoryRegion *mr, } // compute sub region sizes - l_size = (size_t)(address - begin); - r_size = (size_t)(end - chunk_end); - m_size = (size_t)(chunk_end - address); + l_size = (uint64_t)(address - begin); + r_size = (uint64_t)(end - chunk_end); + m_size = (uint64_t)(chunk_end - address); // If there are error in any of the below operations, things are too far // gone at that point to recover. Could try to remap orignal region, but @@ -1378,13 +1348,13 @@ static bool split_region(struct uc_struct *uc, MemoryRegion *mr, } UNICORN_EXPORT -uc_err uc_mem_protect(struct uc_struct *uc, uint64_t address, size_t size, +uc_err uc_mem_protect(struct uc_struct *uc, uint64_t address, uint64_t size, uint32_t perms) { MemoryRegion *mr; uint64_t addr = address; uint64_t pc; - size_t count, len; + uint64_t count, len; bool remove_exec = false; UC_INIT(uc); @@ -1423,14 +1393,14 @@ uc_err uc_mem_protect(struct uc_struct *uc, uint64_t address, size_t size, addr = address; count = 0; while (count < size) { - mr = memory_mapping(uc, addr); - len = (size_t)MIN(size - count, mr->end - addr); + mr = find_memory_region(uc, addr); + len = (uint64_t)MIN(size - count, mr->end - addr); if (mr->ram) { if (!split_region(uc, mr, addr, len, false)) { return UC_ERR_NOMEM; } - mr = memory_mapping(uc, addr); + mr = find_memory_region(uc, addr); // will this remove EXEC permission? if (((mr->perms & UC_PROT_EXEC) != 0) && ((perms & UC_PROT_EXEC) == 0)) { @@ -1444,7 +1414,7 @@ uc_err uc_mem_protect(struct uc_struct *uc, uint64_t address, size_t size, return UC_ERR_NOMEM; } - mr = memory_mapping(uc, addr); + mr = find_memory_region(uc, addr); mr->perms = perms; } @@ -1466,11 +1436,11 @@ uc_err uc_mem_protect(struct uc_struct *uc, uint64_t address, size_t size, } UNICORN_EXPORT -uc_err uc_mem_unmap(struct uc_struct *uc, uint64_t address, size_t size) +uc_err uc_mem_unmap(struct uc_struct *uc, uint64_t address, uint64_t size) { MemoryRegion *mr; uint64_t addr; - size_t count, len; + uint64_t count, len; UC_INIT(uc); @@ -1503,8 +1473,8 @@ uc_err uc_mem_unmap(struct uc_struct *uc, uint64_t address, size_t size) addr = address; count = 0; while (count < size) { - mr = memory_mapping(uc, addr); - len = (size_t)MIN(size - count, mr->end - addr); + mr = find_memory_region(uc, addr); + len = (uint64_t)MIN(size - count, mr->end - addr); if (!mr->ram) { if (!split_mmio_region(uc, mr, addr, len, true)) { return UC_ERR_NOMEM; @@ -1517,7 +1487,7 @@ uc_err uc_mem_unmap(struct uc_struct *uc, uint64_t address, size_t size) // if we can retrieve the mapping, then no splitting took place // so unmap here - mr = memory_mapping(uc, addr); + mr = find_memory_region(uc, addr); if (mr != NULL) { uc->memory_unmap(uc, mr); } @@ -1529,7 +1499,7 @@ uc_err uc_mem_unmap(struct uc_struct *uc, uint64_t address, size_t size) } // find the memory region of this address -MemoryRegion *memory_mapping(struct uc_struct *uc, uint64_t address) +MemoryRegion *find_memory_region(struct uc_struct *uc, uint64_t address) { unsigned int i; @@ -1544,14 +1514,16 @@ MemoryRegion *memory_mapping(struct uc_struct *uc, uint64_t address) // try with the cache index first i = uc->mapped_block_cache_index; - if (i < uc->mapped_block_count && address >= uc->mapped_blocks[i]->addr && + if (i < uc->mapped_block_count && + address >= uc->mapped_blocks[i]->addr && address < uc->mapped_blocks[i]->end) { return uc->mapped_blocks[i]; } i = bsearch_mapped_blocks(uc, address); - if (i < uc->mapped_block_count && address >= uc->mapped_blocks[i]->addr && + if (i < uc->mapped_block_count && + address >= uc->mapped_blocks[i]->addr && address <= uc->mapped_blocks[i]->end - 1) return uc->mapped_blocks[i]; @@ -2431,4 +2403,4 @@ void trace_end(uc_tracer *tracer, trace_loc loc, const char *fmt, ...) fprintf(stderr, "%.6fus\n", (double)(end - tracer->starts[loc]) / (double)(1000)); } -#endif \ No newline at end of file +#endif From 4833375f369e80fa7ee2ab4762338f63d12387ad Mon Sep 17 00:00:00 2001 From: r0b0t <1168808+secretnonempty@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:33:51 -0700 Subject: [PATCH 02/10] Update BindingFactory.fs --- bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs b/bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs index 9e1e621417..083dbde753 100644 --- a/bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs +++ b/bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs @@ -8,4 +8,5 @@ module BindingFactory = _instance <- binding let getDefault() = - _instance \ No newline at end of file + _instance + From b7eb4baf6de478141a1da7d697f61756424b861b Mon Sep 17 00:00:00 2001 From: r0b0t <1168808+secretnonempty@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:38:04 -0700 Subject: [PATCH 03/10] Update UnicornEngine.fsproj --- bindings/dotnet/UnicornEngine/UnicornEngine.fsproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/dotnet/UnicornEngine/UnicornEngine.fsproj b/bindings/dotnet/UnicornEngine/UnicornEngine.fsproj index da65fec35c..2228259cae 100644 --- a/bindings/dotnet/UnicornEngine/UnicornEngine.fsproj +++ b/bindings/dotnet/UnicornEngine/UnicornEngine.fsproj @@ -46,4 +46,4 @@ - \ No newline at end of file + From 6e87abf51c4405caa23ec66537a9eef12eb86b4b Mon Sep 17 00:00:00 2001 From: r0b0t <1168808+secretnonempty@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:38:31 -0700 Subject: [PATCH 04/10] Update MockBinding.fs --- bindings/dotnet/UnicornEngine/Binding/MockBinding.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/dotnet/UnicornEngine/Binding/MockBinding.fs b/bindings/dotnet/UnicornEngine/Binding/MockBinding.fs index 1de1bf150e..b5c64efb62 100644 --- a/bindings/dotnet/UnicornEngine/Binding/MockBinding.fs +++ b/bindings/dotnet/UnicornEngine/Binding/MockBinding.fs @@ -48,4 +48,4 @@ module internal MockBinding = member thi.HookAddArg0(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0) = hook_add_arg0(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0) member thi.HookAddArg0Arg1(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0, arg1) = hook_add_arg0_arg1(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0, arg1) } - \ No newline at end of file + From 939e4c7afba135ae8d79d80ee05b9fd9160ef37b Mon Sep 17 00:00:00 2001 From: r0b0t <1168808+secretnonempty@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:40:32 -0700 Subject: [PATCH 05/10] Update Arm.fs From cc9466e3bd52eb57bebfeb0554a83e4bfbf9f0ab Mon Sep 17 00:00:00 2001 From: r0b0t <1168808+secretnonempty@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:40:59 -0700 Subject: [PATCH 06/10] Update Unicorn.fs --- bindings/dotnet/UnicornEngine/Unicorn.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/dotnet/UnicornEngine/Unicorn.fs b/bindings/dotnet/UnicornEngine/Unicorn.fs index 7c8b699f6c..28c2879588 100644 --- a/bindings/dotnet/UnicornEngine/Unicorn.fs +++ b/bindings/dotnet/UnicornEngine/Unicorn.fs @@ -353,4 +353,5 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) = interface IDisposable with member this.Dispose() = - this.Dispose() \ No newline at end of file + this.Dispose() + From 271755efc85ac4614d161c18c3355d820be3071a Mon Sep 17 00:00:00 2001 From: r0b0t <1168808+secretnonempty@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:44:00 -0700 Subject: [PATCH 07/10] Update Common.fs --- bindings/dotnet/UnicornEngine/Const/Common.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/dotnet/UnicornEngine/Const/Common.fs b/bindings/dotnet/UnicornEngine/Const/Common.fs index 73f9663cad..d0ed7b98dc 100644 --- a/bindings/dotnet/UnicornEngine/Const/Common.fs +++ b/bindings/dotnet/UnicornEngine/Const/Common.fs @@ -9,13 +9,13 @@ module Common = let UC_API_MAJOR = 2 let UC_API_MINOR = 0 - let UC_API_PATCH = 1 - let UC_API_EXTRA = 255 + let UC_API_PATCH = 2 + let UC_API_EXTRA = 1 let UC_VERSION_MAJOR = 2 let UC_VERSION_MINOR = 0 - let UC_VERSION_PATCH = 1 - let UC_VERSION_EXTRA = 255 + let UC_VERSION_PATCH = 2 + let UC_VERSION_EXTRA = 1 let UC_SECOND_SCALE = 1000000 let UC_MILISECOND_SCALE = 1000 let UC_ARCH_ARM = 1 From a6129967b6506293b1a86bcad8eb0513a5165e28 Mon Sep 17 00:00:00 2001 From: r0b0t <1168808+secretnonempty@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:46:36 -0700 Subject: [PATCH 08/10] Update uc.c --- bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs | 3 +-- bindings/dotnet/UnicornEngine/Binding/IBinding.fs | 3 ++- bindings/dotnet/UnicornEngine/Binding/MockBinding.fs | 4 ++-- bindings/dotnet/UnicornEngine/Const/Arm.fs | 1 + bindings/dotnet/UnicornEngine/Const/M68k.fs | 1 + bindings/dotnet/UnicornEngine/Const/Ppc.fs | 1 + bindings/dotnet/UnicornEngine/ConvertUtility.fs | 2 +- bindings/dotnet/UnicornEngine/InternalHooks.fs | 2 +- bindings/dotnet/UnicornEngine/Unicorn.fs | 3 +-- bindings/dotnet/UnicornEngine/UnicornEngine.fsproj | 2 +- bindings/dotnet/UnicornEngine/UnicornEngineException.fs | 3 ++- uc.c | 2 +- 12 files changed, 15 insertions(+), 12 deletions(-) diff --git a/bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs b/bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs index 083dbde753..30c7f82131 100644 --- a/bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs +++ b/bindings/dotnet/UnicornEngine/Binding/BindingFactory.fs @@ -1,4 +1,4 @@ -namespace UnicornEngine.Binding +namespace UnicornEngine.Binding module BindingFactory = @@ -9,4 +9,3 @@ module BindingFactory = let getDefault() = _instance - diff --git a/bindings/dotnet/UnicornEngine/Binding/IBinding.fs b/bindings/dotnet/UnicornEngine/Binding/IBinding.fs index 7d0d391340..b6c3edc09c 100644 --- a/bindings/dotnet/UnicornEngine/Binding/IBinding.fs +++ b/bindings/dotnet/UnicornEngine/Binding/IBinding.fs @@ -1,4 +1,4 @@ -namespace UnicornEngine.Binding +namespace UnicornEngine.Binding open System @@ -25,3 +25,4 @@ type IBinding = abstract HookAddArg0 : UIntPtr * UIntPtr * Int32 * UIntPtr * IntPtr * UInt64 * UInt64 * Int32 -> Int32 abstract HookAddArg0Arg1 : UIntPtr * UIntPtr * Int32 * UIntPtr * IntPtr * UInt64 * UInt64 * UInt64 * UInt64 -> Int32 end + diff --git a/bindings/dotnet/UnicornEngine/Binding/MockBinding.fs b/bindings/dotnet/UnicornEngine/Binding/MockBinding.fs index b5c64efb62..3eeefe89d7 100644 --- a/bindings/dotnet/UnicornEngine/Binding/MockBinding.fs +++ b/bindings/dotnet/UnicornEngine/Binding/MockBinding.fs @@ -1,4 +1,4 @@ -namespace UnicornEngine.Binding +namespace UnicornEngine.Binding open System @@ -48,4 +48,4 @@ module internal MockBinding = member thi.HookAddArg0(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0) = hook_add_arg0(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0) member thi.HookAddArg0Arg1(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0, arg1) = hook_add_arg0_arg1(eng, hh, callbackType, callback, userData, hookBegin, hookEnd, arg0, arg1) } - + diff --git a/bindings/dotnet/UnicornEngine/Const/Arm.fs b/bindings/dotnet/UnicornEngine/Const/Arm.fs index 90053c60c8..8a275261f0 100644 --- a/bindings/dotnet/UnicornEngine/Const/Arm.fs +++ b/bindings/dotnet/UnicornEngine/Const/Arm.fs @@ -197,3 +197,4 @@ module Arm = let UC_ARM_REG_SL = 76 let UC_ARM_REG_FP = 77 let UC_ARM_REG_IP = 78 + diff --git a/bindings/dotnet/UnicornEngine/Const/M68k.fs b/bindings/dotnet/UnicornEngine/Const/M68k.fs index ff5dbff564..768bc12b99 100644 --- a/bindings/dotnet/UnicornEngine/Const/M68k.fs +++ b/bindings/dotnet/UnicornEngine/Const/M68k.fs @@ -42,3 +42,4 @@ module M68k = let UC_M68K_REG_SR = 17 let UC_M68K_REG_PC = 18 let UC_M68K_REG_ENDING = 19 + diff --git a/bindings/dotnet/UnicornEngine/Const/Ppc.fs b/bindings/dotnet/UnicornEngine/Const/Ppc.fs index b35ad09c4a..54a18b3b01 100644 --- a/bindings/dotnet/UnicornEngine/Const/Ppc.fs +++ b/bindings/dotnet/UnicornEngine/Const/Ppc.fs @@ -409,3 +409,4 @@ module Ppc = let UC_PPC_REG_FPSCR = 78 let UC_PPC_REG_CR = 79 let UC_PPC_REG_ENDING = 80 + diff --git a/bindings/dotnet/UnicornEngine/ConvertUtility.fs b/bindings/dotnet/UnicornEngine/ConvertUtility.fs index e3937c1384..a453c86150 100644 --- a/bindings/dotnet/UnicornEngine/ConvertUtility.fs +++ b/bindings/dotnet/UnicornEngine/ConvertUtility.fs @@ -1,4 +1,4 @@ -namespace UnicornEngine +namespace UnicornEngine open System diff --git a/bindings/dotnet/UnicornEngine/InternalHooks.fs b/bindings/dotnet/UnicornEngine/InternalHooks.fs index 5d5d79d961..062de03cf1 100644 --- a/bindings/dotnet/UnicornEngine/InternalHooks.fs +++ b/bindings/dotnet/UnicornEngine/InternalHooks.fs @@ -1,4 +1,4 @@ -namespace UnicornEngine +namespace UnicornEngine open System open System.Runtime.InteropServices diff --git a/bindings/dotnet/UnicornEngine/Unicorn.fs b/bindings/dotnet/UnicornEngine/Unicorn.fs index 28c2879588..56a683b0b8 100644 --- a/bindings/dotnet/UnicornEngine/Unicorn.fs +++ b/bindings/dotnet/UnicornEngine/Unicorn.fs @@ -1,4 +1,4 @@ -namespace UnicornEngine +namespace UnicornEngine open System open System.Collections.Generic @@ -354,4 +354,3 @@ and Unicorn(arch: Int32, mode: Int32, binding: IBinding) = interface IDisposable with member this.Dispose() = this.Dispose() - diff --git a/bindings/dotnet/UnicornEngine/UnicornEngine.fsproj b/bindings/dotnet/UnicornEngine/UnicornEngine.fsproj index 2228259cae..8fd0d7909f 100644 --- a/bindings/dotnet/UnicornEngine/UnicornEngine.fsproj +++ b/bindings/dotnet/UnicornEngine/UnicornEngine.fsproj @@ -1,4 +1,4 @@ - + net6.0 UnicornEngine.Unicorn diff --git a/bindings/dotnet/UnicornEngine/UnicornEngineException.fs b/bindings/dotnet/UnicornEngine/UnicornEngineException.fs index 62244e4ea0..686229511c 100644 --- a/bindings/dotnet/UnicornEngine/UnicornEngineException.fs +++ b/bindings/dotnet/UnicornEngine/UnicornEngineException.fs @@ -1,4 +1,4 @@ -namespace UnicornEngine +namespace UnicornEngine open System @@ -6,3 +6,4 @@ type UnicornEngineException(errNo: Int32, msg: String) = inherit ApplicationException(msg) member this.ErrorNo = errNo + diff --git a/uc.c b/uc.c index 289fded222..8b12fbfb10 100644 --- a/uc.c +++ b/uc.c @@ -2403,4 +2403,4 @@ void trace_end(uc_tracer *tracer, trace_loc loc, const char *fmt, ...) fprintf(stderr, "%.6fus\n", (double)(end - tracer->starts[loc]) / (double)(1000)); } -#endif \ No newline at end of file +#endif From d3f6e9e1942a989a117327eaf38bab57b9de57e0 Mon Sep 17 00:00:00 2001 From: r0b0t <1168808+secretnonempty@users.noreply.github.com> Date: Mon, 13 Mar 2023 21:33:12 -0700 Subject: [PATCH 09/10] Update stale.yml --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 214472cf6a..04c46b3ef9 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -14,5 +14,5 @@ jobs: days-before-stale: 60 days-before-close: 15 exempt-all-milestones: true - exempt-issue-labels: 'pinned,help wanted,enhancement,bug' + exempt-issue-labels: 'pinned,help wanted' exempt-pr-labels: 'pinned' From 15d0434f35e693e3e272d5ae7632b0d68842e217 Mon Sep 17 00:00:00 2001 From: r0b0t <1168808+secretnonempty@users.noreply.github.com> Date: Mon, 13 Mar 2023 21:34:13 -0700 Subject: [PATCH 10/10] Update ChangeLog --- ChangeLog | 10 ---------- tests/unit/test_mem.c | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e7113d859..224883de77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,15 +1,5 @@ This file details the changelog of Unicorn Engine. -------------------------------- -[Version 2.0.1.post1]: Nov 22nd, 2022 - -This is a small release to complement the previous 2.0.1 release. - -Fix: - -- Fix the endianness detection in tests. -- Fix the version number in CMakeLists.txt. - ------------------------------- [Version 2.0.1]: Nov 1st, 2022 diff --git a/tests/unit/test_mem.c b/tests/unit/test_mem.c index 813f60f81c..2e963829f9 100644 --- a/tests/unit/test_mem.c +++ b/tests/unit/test_mem.c @@ -275,7 +275,7 @@ static void test_mem_protect_mmio(void) OK(uc_close(uc)); } -static void __inline parts_increment(size_t idx, char parts[3]) +static void parts_increment(size_t idx, char parts[3]) { if (idx && idx % 3 == 0) { if (++parts[2] > '9') {