diff --git a/bindings/java/unicorn/EdgeGeneratedHook.java b/bindings/java/unicorn/EdgeGeneratedHook.java index 1564d752..9e2c5b3e 100644 --- a/bindings/java/unicorn/EdgeGeneratedHook.java +++ b/bindings/java/unicorn/EdgeGeneratedHook.java @@ -21,8 +21,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. package unicorn; -/** Callback for UC_HOOK_EDGE_GENERATED */ +/** Callback for {@code UC_HOOK_EDGE_GENERATED} */ public interface EdgeGeneratedHook extends Hook { + /** Called whenever a jump is made to a new (untranslated) basic block. + * + * @param u {@link Unicorn} instance firing this hook + * @param cur_tb newly translated block being entered + * @param prev_tb previous block being exited + * @param user user data provided when registering this hook + */ public void hook(Unicorn u, TranslationBlock cur_tb, TranslationBlock prev_tb, Object user); } diff --git a/bindings/java/unicorn/InvalidInstructionHook.java b/bindings/java/unicorn/InvalidInstructionHook.java index 1edb509a..8d54abce 100644 --- a/bindings/java/unicorn/InvalidInstructionHook.java +++ b/bindings/java/unicorn/InvalidInstructionHook.java @@ -21,7 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. package unicorn; -/* Callback for {@code UC_HOOK_INSN_INVALID} */ +/** Callback for {@code UC_HOOK_INSN_INVALID} */ public interface InvalidInstructionHook extends Hook { /** Called when an invalid instruction is encountered. * diff --git a/bindings/java/unicorn/Unicorn.java b/bindings/java/unicorn/Unicorn.java index d28f3999..884a9190 100644 --- a/bindings/java/unicorn/Unicorn.java +++ b/bindings/java/unicorn/Unicorn.java @@ -28,6 +28,7 @@ import java.nio.ByteOrder; import java.util.Arrays; import java.util.Hashtable; +/** Unicorn is a lightweight multi-platform, multi-architecture CPU emulator framework. */ public class Unicorn implements UnicornConst, Arm64Const, ArmConst, M68kConst, MipsConst, PpcConst, RiscvConst, S390xConst, SparcConst, TriCoreConst, X86Const { @@ -58,42 +59,46 @@ public class Unicorn } /** - * Read register value. See {@link Unicorn#reg_read(int)}. + * Read register value from saved context. * * @param regid Register ID that is to be retrieved. This function only supports * integer registers at most 64 bits long. * @return value of the register. + * @see Unicorn#reg_read(int) */ public long reg_read(int regid) throws UnicornException { return do_reg_read_long(nativePtr, 1, arch, regid); } /** - * Read register value. See {@link Unicorn#reg_read(int, Object)}. + * Read register value from saved context. * * @param regid Register ID that is to be retrieved. * @param opt Options for this register, or null if no options are required. * @return value of the register - Long, BigInteger, or structure. + * @see Unicorn#reg_read(int, Object) */ public Object reg_read(int regid, Object opt) throws UnicornException { return do_reg_read_obj(nativePtr, 1, arch, regid, opt); } /** - * Write to register. See {@link Unicorn#reg_write(int, long)}. + * Write to register in saved context. * * @param regid Register ID that is to be modified. * @param value Object containing the new register value. + * @see Unicorn#reg_write(int, long) */ public void reg_write(int regid, long value) throws UnicornException { do_reg_write_long(nativePtr, 1, arch, regid, value); } /** - * Write to register. See {@link Unicorn#reg_write(int, Object)}. + * Write to register in saved context. * * @param regid Register ID that is to be modified. * @param value Object containing the new register value. + * @see Unicorn#reg_write(int, Object) */ public void reg_write(int regid, Object value) throws UnicornException { do_reg_write_obj(nativePtr, 1, arch, regid, value); @@ -108,9 +113,9 @@ public class Unicorn /** * Create a new Unicorn object * - * @param arch Architecture type (UC_ARCH_*) - * @param mode Hardware mode. This is combined of UC_MODE_* - * @see unicorn.UnicornConst + * @param arch Architecture type. One of the {@code UC_ARCH_*} constants. + * @param mode Hardware mode. Bitwise combination of {@code UC_MODE_*} constants. + * @see UnicornConst * */ public Unicorn(int arch, int mode) throws UnicornException { @@ -121,10 +126,10 @@ public class Unicorn } /** - * Close the underlying uc_engine* eng associated with this Unicorn object - * + * Close the C {@code uc_engine} associated with this Unicorn object, + * freeing all associated resources. After calling this method, the + * API will no longer be usable. */ - public void close() throws UnicornException { if (nativePtr != 0) { _close(nativePtr); @@ -133,8 +138,7 @@ public class Unicorn } /** - * Perform native cleanup tasks associated with a Unicorn object - * + * Automatically close the {@code uc_engine} upon GC finalization. */ @Override protected void finalize() { @@ -144,10 +148,9 @@ public class Unicorn /** * Return combined API version & major and minor version numbers. * - * @return hexadecimal number as (major << 8 | minor), which encodes both major - * & minor versions. - * - * For example Unicorn version 1.2 would yield 0x0102 + * @return version number as {@code (major << 8 | minor)}, which encodes + * both major & minor versions. + * For example, Unicorn version 1.2 would yield 0x0102. */ public static int version() { return _version(); @@ -156,25 +159,26 @@ public class Unicorn /** * Determine if the given architecture is supported by this library. * - * @param arch Architecture type (UC_ARCH_*) - * @return true if this library supports the given arch. - * @see unicorn.UnicornConst + * @param arch Architecture type ({@code UC_ARCH_*} constant) + * @return {@code true} if this library supports the given arch. + * @see UnicornConst */ public static boolean arch_supported(int arch) { return _arch_supported(arch); } /** - * Emulate machine code in a specific duration of time. + * Emulate machine code for a specific length of time or number of + * instructions. * * @param begin Address where emulation starts - * @param until Address where emulation stops (i.e when this address is hit) - * @param timeout Duration to emulate the code (in microseconds). When this - * value is 0, we will emulate the code in infinite time, until - * the code is finished. - * @param count The number of instructions to be emulated. When this value is - * 0, we will emulate all the code available, until the code is - * finished. + * @param until Address where emulation stops (i.e. when this address is hit) + * @param timeout Duration to emulate the code for, in microseconds, or 0 to + * run indefinitely. + * @param count The maximum number of instructions to execute, or 0 to + * execute indefinitely. + * @throws UnicornException if an unhandled CPU exception or other error + * occurs during emulation. */ public void emu_start(long begin, long until, long timeout, long count) @@ -183,9 +187,11 @@ public class Unicorn } /** - * Stop emulation (which was started by emu_start() ). - * This is typically called from callback functions registered via tracing APIs. - * NOTE: for now, this will stop the execution only after the current block. + * Stop emulation (which was started by {@link #emu_start()}). + * + * This can be called from hook callbacks or from a separate thread. + * NOTE: for now, this will stop the execution only after the current + * basic block. */ public void emu_stop() throws UnicornException { _emu_stop(nativePtr); @@ -380,20 +386,21 @@ public class Unicorn } /** - * Read register value. This reads any register that would return a Long - * from {@link #reg_read(int, Object)}. + * Read register value of at most 64 bits in size. * * @param regid Register ID that is to be retrieved. This function only supports * integer registers at most 64 bits long. * @return value of the register. + * @see {@link #reg_read(int, Object)} to read larger registers or + * registers requiring configuration. */ public long reg_read(int regid) throws UnicornException { return do_reg_read_long(nativePtr, 0, arch, regid); } /** - * Read register value. The return type depends on regid as follows. - * opt should be null unless otherwise specified. + * Read register value. The return type depends on {@code regid} as + * follows. {@code opt} should be {@code null} unless otherwise specified. * * * @param regid Register ID that is to be retrieved. - * @param opt Options for this register, or null if no options are required. - * @return value of the register - Long, BigInteger, or structure. + * @param opt Options for this register, or {@code null} if no options + * are required. + * @return value of the register - {@link Long}, {@link BigInteger}, + * or other class. */ public Object reg_read(int regid, Object opt) throws UnicornException { return do_reg_read_obj(nativePtr, 0, arch, regid, opt); @@ -421,13 +430,15 @@ public class Unicorn * * @param regid Register ID that is to be modified. * @param value Object containing the new register value. + * @see {@link #reg_read(int, Object)} to write larger registers or + * registers requiring configuration. */ public void reg_write(int regid, long value) throws UnicornException { do_reg_write_long(nativePtr, 0, arch, regid, value); } /** - * Write to register. The type of {@code value} depends on regid: + * Write to register. The type of {@code value} depends on {@code regid}: *