Restore some of the less problematic old APIs for backwards compatibility.
This commit is contained in:
@@ -35,10 +35,10 @@ CLASSPATH=./
|
||||
.SUFFIXES: .java .class
|
||||
|
||||
tests/%.class: tests/%.java
|
||||
$(JC) -classpath .:unicorn.jar:testdep/junit-4.13.2.jar $(JFLAGS) $<
|
||||
$(JC) -Xlint:deprecation -classpath .:unicorn.jar:testdep/junit-4.13.2.jar $(JFLAGS) $<
|
||||
|
||||
%.class: %.java
|
||||
$(JC) -classpath .:unicorn.jar $(JFLAGS) $<
|
||||
$(JC) -Xlint:deprecation -classpath .:unicorn.jar $(JFLAGS) $<
|
||||
|
||||
OBJS=unicorn_Unicorn.o
|
||||
|
||||
@@ -48,7 +48,7 @@ JARFILE=unicorn.jar
|
||||
$(CC) -c $(CFLAGS) $(INCS) $< -o $@
|
||||
|
||||
unicorn_Unicorn.h: unicorn/Unicorn.java
|
||||
javac -h . $<
|
||||
$(JC) -h . $<
|
||||
|
||||
unicorn_Unicorn.o: unicorn_Unicorn.c unicorn_Unicorn.h
|
||||
$(CC) -O2 -Wall -Wextra -Wno-unused-parameter -c $(CFLAGS) $(INCS) $< -o $@
|
||||
@@ -73,17 +73,17 @@ install: lib jar
|
||||
cp $(JARFILE) /usr/share/java
|
||||
|
||||
uninstall:
|
||||
rm /usr/lib/libunicorn_java$(LIB_EXT)
|
||||
rm /usr/share/java/$(JARFILE)
|
||||
rm -f /usr/lib/libunicorn_java$(LIB_EXT)
|
||||
rm -f /usr/share/java/$(JARFILE)
|
||||
|
||||
gen_const:
|
||||
cd .. && python3 const_generator.py java
|
||||
|
||||
clean:
|
||||
rm unicorn/*.class
|
||||
rm samples/*.class
|
||||
rm *.so
|
||||
rm *.dylib
|
||||
rm *.dll
|
||||
rm -f unicorn/*.class
|
||||
rm -f samples/*.class
|
||||
rm -f *.so
|
||||
rm -f *.dylib
|
||||
rm -f *.dll
|
||||
|
||||
.PHONY: all lib samples jar install uninstall gen_const clean
|
||||
|
||||
@@ -472,6 +472,19 @@ public class Unicorn
|
||||
return result;
|
||||
}
|
||||
|
||||
/** @deprecated Use {@link #mem_read(long, int)} instead. */
|
||||
@Deprecated
|
||||
public byte[] mem_read(long address, long size) throws UnicornException {
|
||||
if (size < 0) {
|
||||
throw new NegativeArraySizeException("size cannot be negative");
|
||||
} else if (size > Integer.MAX_VALUE) {
|
||||
throw new IllegalArgumentException("size must fit in an int");
|
||||
}
|
||||
byte[] result = new byte[(int) size];
|
||||
_mem_read(nativePtr, address, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to memory.
|
||||
*
|
||||
@@ -656,8 +669,10 @@ public class Unicorn
|
||||
* whenever a CPU interrupt occurs.
|
||||
*
|
||||
* @param callback Implementation of a {@link InterruptHook} interface
|
||||
* @param user_data User data to be passed to the callback function each time
|
||||
* the event is triggered
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(InterruptHook callback, Object user_data)
|
||||
throws UnicornException {
|
||||
@@ -675,8 +690,10 @@ public class Unicorn
|
||||
* {@code UC_X86_INS_IN} or {@code UC_ARM64_INS_MRS}
|
||||
* @param begin Start address of hooking range
|
||||
* @param end End address of hooking range
|
||||
* @param user_data User data to be passed to the callback function each time
|
||||
* the event is triggered
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(InstructionHook callback, int insn, long begin,
|
||||
long end,
|
||||
@@ -686,6 +703,68 @@ public class Unicorn
|
||||
user_data, begin, end, insn));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@code UC_HOOK_INSN} hook for all program addresses.
|
||||
* The exact interface called will depend on the instruction being hooked.
|
||||
*
|
||||
* @param callback Implementation of an {@link InstructionHook}
|
||||
* sub-interface
|
||||
* @param insn {@code UC_<ARCH>_INS_<INSN>} constant, e.g.
|
||||
* {@code UC_X86_INS_IN} or {@code UC_ARM64_INS_MRS}
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(InstructionHook callback, int insn, Object user_data)
|
||||
throws UnicornException {
|
||||
return hook_add(callback, insn, 1, 0, user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a hook for the X86 IN instruction.
|
||||
* The registered callback will be called whenever an IN instruction
|
||||
* is executed.
|
||||
*
|
||||
* @param callback Object implementing the {@link InHook} interface
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(InHook callback, Object user_data)
|
||||
throws UnicornException {
|
||||
return hook_add(callback, UC_X86_INS_IN, user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a hook for the X86 OUT instruction.
|
||||
* The registered callback will be called whenever an OUT instruction
|
||||
* is executed.
|
||||
*
|
||||
* @param callback Object implementing the {@link InHook} interface
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(OutHook callback, Object user_data)
|
||||
throws UnicornException {
|
||||
return hook_add(callback, UC_X86_INS_OUT, user_data);
|
||||
}
|
||||
|
||||
/** @deprecated Use {@code hook_add(callback, UC_X86_INS_SYSCALL, begin,
|
||||
* end, user_data)} or {@code hook_add(callback,
|
||||
* UC_X86_INS_SYSENTER, begin, end, user_data)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public long hook_add(SyscallHook callback, Object user_data)
|
||||
throws UnicornException {
|
||||
// Old implementation only registered SYSCALL, not SYSENTER.
|
||||
// Since this is deprecated anyway, we retain the old behaviour.
|
||||
return hook_add(callback, UC_X86_INS_SYSCALL, user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@code UC_HOOK_CODE} hook. The hook function will be
|
||||
* invoked when an instruction is executed from the address range
|
||||
@@ -695,8 +774,10 @@ public class Unicorn
|
||||
* @param callback Implementation of a {@link CodeHook} interface
|
||||
* @param begin Start address of hooking range
|
||||
* @param end End address of hooking range
|
||||
* @param user_data User data to be passed to the callback function each time
|
||||
* the event is triggered
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(CodeHook callback, long begin, long end,
|
||||
Object user_data)
|
||||
@@ -707,16 +788,18 @@ public class Unicorn
|
||||
|
||||
/**
|
||||
* Register a {@code UC_HOOK_BLOCK} hook. The hook function will be
|
||||
* invoked when a basic block is entered and the address of the basic block
|
||||
* (BB) falls in the range begin <= BB <= end. For the special case in which
|
||||
* begin > end, the callback will be invoked whenver any basic block is
|
||||
* entered.
|
||||
* invoked when a basic block is entered and the address of the basic
|
||||
* block (BB) falls in the range begin <= BB <= end. For the special case
|
||||
* in which begin > end, the callback will be invoked whenver any basic
|
||||
* block is entered.
|
||||
*
|
||||
* @param callback Implementation of a {@link BlockHook} interface
|
||||
* @param begin Start address of hooking range
|
||||
* @param end End address of hooking range
|
||||
* @param user_data User data to be passed to the callback function each time
|
||||
* the event is triggered
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(BlockHook callback, long begin, long end,
|
||||
Object user_data)
|
||||
@@ -728,18 +811,21 @@ public class Unicorn
|
||||
/**
|
||||
* Register a {@code UC_HOOK_MEM_VALID} hook
|
||||
* ({@code UC_HOOK_MEM_[READ,WRITE,FETCH]} and/or
|
||||
* {@code UC_HOOK_MEM_READ_AFTER}. The registered callback function will be
|
||||
* invoked whenever a corresponding memory operation is performed within the
|
||||
* address range begin <= addr <= end. For the special case in which
|
||||
* begin > end, the callback will be invoked for ALL memory operations.
|
||||
* {@code UC_HOOK_MEM_READ_AFTER}. The registered callback function will
|
||||
* be invoked whenever a corresponding memory operation is performed
|
||||
* within the address range begin <= addr <= end. For the special case in
|
||||
* which begin > end, the callback will be invoked for ALL memory
|
||||
* operations.
|
||||
*
|
||||
* @param callback Implementation of a {@link MemHook} interface
|
||||
* @param type Bitwise OR of {@code UC_HOOK_MEM_*} constants for valid
|
||||
* memory events
|
||||
* @param type Bitwise OR of {@code UC_HOOK_MEM_*} constants for
|
||||
* valid memory events
|
||||
* @param begin Start address of memory range
|
||||
* @param end End address of memory range
|
||||
* @param user_data User data to be passed to the callback function each time
|
||||
* the event is triggered
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(MemHook callback, int type, long begin, long end,
|
||||
Object user_data)
|
||||
@@ -761,8 +847,10 @@ public class Unicorn
|
||||
* invalid memory events.
|
||||
* @param begin Start address of memory range
|
||||
* @param end End address of memory range
|
||||
* @param user_data User data to be passed to the callback function each time
|
||||
* the event is triggered
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(EventMemHook callback, int type, long begin, long end,
|
||||
Object user_data)
|
||||
@@ -771,14 +859,34 @@ public class Unicorn
|
||||
_hook_add(nativePtr, type, callback, user_data, begin, end));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@code UC_HOOK_MEM_*_UNMAPPED} and/or
|
||||
* {@code UC_HOOK_MEM_*_PROT} hook for all memory addresses.
|
||||
*
|
||||
* @param callback Implementation of a {@link EventMemHook} interface
|
||||
* @param type Bitwise OR of {@code UC_HOOK_MEM_*} constants for
|
||||
* invalid memory events.
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(EventMemHook callback, int type, Object user_data)
|
||||
throws UnicornException {
|
||||
return registerHook(
|
||||
_hook_add(nativePtr, type, callback, user_data, 1, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@code UC_HOOK_INSN_INVALID} hook. The hook function will be
|
||||
* invoked whenever an invalid instruction is encountered.
|
||||
*
|
||||
* @param callback Implementation of a {@link InvalidInstructionHook}
|
||||
* interface
|
||||
* @param user_data User data to be passed to the callback function each time
|
||||
* the event is triggered
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(InvalidInstructionHook callback,
|
||||
Object user_data) {
|
||||
@@ -787,16 +895,19 @@ public class Unicorn
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@code UC_HOOK_EDGE_GENERATED} hook. The hook function will be
|
||||
* invoked whenever a jump is made to a new (untranslated) basic block with
|
||||
* a start address in the range of begin <= pc <= end. For the special case
|
||||
* in which begin > end, the callback will be invoked for ALL new edges.
|
||||
* Register a {@code UC_HOOK_EDGE_GENERATED} hook. The hook function will
|
||||
* be invoked whenever a jump is made to a new (untranslated) basic block
|
||||
* with a start address in the range of begin <= pc <= end. For the
|
||||
* special case in which begin > end, the callback will be invoked for ALL
|
||||
* new edges.
|
||||
*
|
||||
* @param callback Implementation of a {@link EdgeGeneratedHook} interface
|
||||
* @param begin Start address
|
||||
* @param end End address
|
||||
* @param user_data User data to be passed to the callback function each time
|
||||
* the event is triggered
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(EdgeGeneratedHook callback, long begin, long end,
|
||||
Object user_data)
|
||||
@@ -813,11 +924,14 @@ public class Unicorn
|
||||
* @param callback Implementation of a {@link TcgOpcodeHook} interface
|
||||
* @param begin Start address
|
||||
* @param end End address
|
||||
* @param opcode Opcode to hook. One of the {@code UC_TCG_OP_*} constants.
|
||||
* @param opcode Opcode to hook. One of the {@code UC_TCG_OP_*}
|
||||
* constants.
|
||||
* @param flags Flags to filter opcode matches. A bitwise-OR of
|
||||
* {@code UC_TCG_OP_FLAG_*} constants.
|
||||
* @param user_data User data to be passed to the callback function each time
|
||||
* the event is triggered
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(TcgOpcodeHook callback, long begin, long end,
|
||||
int opcode, int flags,
|
||||
@@ -836,8 +950,10 @@ public class Unicorn
|
||||
* @param callback Implementation of a {@link TlbFillHook} interface
|
||||
* @param begin Start address
|
||||
* @param end End address
|
||||
* @param user_data User data to be passed to the callback function each time
|
||||
* the event is triggered
|
||||
* @param user_data User data to be passed to the callback function each
|
||||
* time the event is triggered
|
||||
* @return A value that can be passed to {@link #hook_del} to unregister
|
||||
* this hook
|
||||
*/
|
||||
public long hook_add(TlbFillHook callback, long begin, long end,
|
||||
Object user_data) throws UnicornException {
|
||||
@@ -863,11 +979,13 @@ public class Unicorn
|
||||
*
|
||||
* @param address Starting memory address of the MMIO area
|
||||
* @param size Size of the MMIO area
|
||||
* @param read_cb Implementation of {@link MmioReadHandler} to handle read
|
||||
* operations, or {@code null} for non-readable memory
|
||||
* @param read_cb Implementation of {@link MmioReadHandler} to handle
|
||||
* read operations, or {@code null} for non-readable
|
||||
* memory
|
||||
* @param user_data_read User data to be passed to the read callback
|
||||
* @param write_cb Implementation of {@link MmioWriteHandler} to handle
|
||||
* write operations, or {@code null} for non-writable memory
|
||||
* write operations, or {@code null} for non-writable
|
||||
* memory
|
||||
* @param user_data_write User data to be passed to the write callback
|
||||
* @throws UnicornException
|
||||
*/
|
||||
@@ -1146,5 +1264,4 @@ public class Unicorn
|
||||
|
||||
private static native void _ctl_tlb_mode(long uc, int mode)
|
||||
throws UnicornException;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user