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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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, \
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user