public interface Backend
| Modifier and Type | Method and Description |
|---|---|
BreakPoint |
addBreakPoint(long address,
BreakPointCallback callback,
boolean thumb)
Adds a software breakpoint at the given address.
|
long |
context_alloc()
Allocates a new CPU context snapshot that can be used with
context_save(long) and context_restore(long). |
void |
context_free(long context)
Frees a previously allocated CPU context snapshot.
|
void |
context_restore(long context)
Restores the CPU context from a previously saved snapshot.
|
void |
context_save(long context)
Saves the current CPU context (registers and internal metadata) into the given snapshot.
|
void |
debugger_add(DebugHook callback,
long begin,
long end,
Object user_data)
Registers a debugger hook that handles breakpoints and single-step events
within the given address range.
|
void |
destroy()
Releases all resources associated with this backend, including the underlying
engine, mapped memory, and registered hooks.
|
void |
emu_start(long begin,
long until,
long timeout,
long count)
Starts emulation of machine code.
|
void |
emu_stop()
Stops the current emulation.
|
void |
enableVFP()
Enables the VFP (Vector Floating-Point) and Advanced SIMD (NEON) coprocessor.
|
Map<String,Integer> |
getCpuFeatures()
Returns the CPU feature flags supported by the backend.
|
long |
getMemAllocatedSize()
Returns the total virtual memory size allocated via
mem_map(long, long, int). |
long |
getMemResidentSize()
Returns the actual physical memory resident in RAM.
|
int |
getPageSize()
Returns the memory page size used by this backend.
|
void |
hook_add_new(BlockHook callback,
long begin,
long end,
Object user_data)
Registers a hook that is called at the beginning of each basic block
within the given address range.
|
void |
hook_add_new(CodeHook callback,
long begin,
long end,
Object user_data)
Registers a hook that is called for every instruction executed within the given address range.
|
void |
hook_add_new(EventMemHook callback,
int type,
Object user_data)
Registers a hook for invalid memory access events (unmapped or protection violations).
|
void |
hook_add_new(InterruptHook callback,
Object user_data)
Registers a hook for CPU interrupt/exception events (SVC, HVC, etc.).
|
void |
hook_add_new(ReadHook callback,
long begin,
long end,
Object user_data)
Registers a hook for memory read events within the given address range.
|
void |
hook_add_new(WriteHook callback,
long begin,
long end,
Object user_data)
Registers a hook for memory write events within the given address range.
|
default boolean |
isHypervisor()
Returns whether this backend runs on Apple's Hypervisor.framework.
|
void |
mem_map(long address,
long size,
int perms)
Maps a region of emulated memory.
|
void |
mem_protect(long address,
long size,
int perms)
Changes the access permissions of an existing memory mapping.
|
byte[] |
mem_read(long address,
long size)
Reads a range of bytes from emulated memory.
|
void |
mem_unmap(long address,
long size)
Unmaps a previously mapped memory region and releases the associated host memory.
|
void |
mem_write(long address,
byte[] bytes)
Writes a byte array into emulated memory.
|
void |
onInitialize()
Called after the backend is constructed to perform any additional initialization,
such as mapping exception vector tables (hypervisor) or setting up initial CPU state.
|
byte[] |
reg_read_vector(int regId)
Reads a 128-bit SIMD/FP vector register.
|
Number |
reg_read(int regId)
Reads the value of a CPU register.
|
void |
reg_write_vector(int regId,
byte[] vector)
Writes a 128-bit SIMD/FP vector register.
|
void |
reg_write(int regId,
Number value)
Writes a value to a CPU register.
|
void |
registerEmuCountHook(long emu_count)
Registers a hook that stops emulation after the specified number of instructions
have been executed.
|
boolean |
removeBreakPoint(long address)
Removes a previously added breakpoint.
|
void |
removeJitCodeCache(long begin,
long end)
Invalidates the JIT code cache for the specified address range.
|
void |
setFastDebug(boolean fastDebug)
Toggles fast debug mode.
|
void |
setSingleStep(int singleStep)
Configures single-step execution.
|
void |
switchUserMode()
Switches the CPU to user mode (EL0/USR).
|
void onInitialize()
void switchUserMode()
void enableVFP()
Number reg_read(int regId) throws BackendException
regId - register ID, typically from unicorn.ArmConst or unicorn.Arm64ConstNumber (Integer for 32-bit, Long for 64-bit)BackendException - if the register read failsbyte[] reg_read_vector(int regId)
throws BackendException
regId - vector register ID (e.g., UC_ARM64_REG_Q0..Q31 or UC_ARM_REG_D0..D15)BackendException - if the register read failsvoid reg_write_vector(int regId,
byte[] vector)
throws BackendException
regId - vector register IDvector - 16-byte array containing the value to writeBackendException - if the register write failsvoid reg_write(int regId,
Number value)
throws BackendException
regId - register IDvalue - the value to write (truncated to 32-bit for AArch32)BackendException - if the register write failsbyte[] mem_read(long address,
long size)
throws BackendException
address - starting guest virtual addresssize - number of bytes to readBackendException - if the address is unmapped or read failsvoid mem_write(long address,
byte[] bytes)
throws BackendException
address - starting guest virtual addressbytes - data to writeBackendException - if the address is unmapped or write failsvoid mem_map(long address,
long size,
int perms)
throws BackendException
mmap(MAP_ANONYMOUS).address - page-aligned starting guest virtual addresssize - page-aligned size in bytesperms - permissions bitmask (combination of UC_PROT_READ, UC_PROT_WRITE, UC_PROT_EXEC)BackendException - if alignment is invalid or mapping failsvoid mem_protect(long address,
long size,
int perms)
throws BackendException
address - page-aligned starting guest virtual addresssize - page-aligned size in bytesperms - new permissions bitmaskBackendException - if the region is not mapped or operation failsvoid mem_unmap(long address,
long size)
throws BackendException
address - page-aligned starting guest virtual addresssize - page-aligned size in bytesBackendException - if the region is not mapped or unmapping failsBreakPoint addBreakPoint(long address, BreakPointCallback callback, boolean thumb)
address - guest virtual address to break oncallback - optional callback invoked when the breakpoint is hit, may be nullthumb - true if the breakpoint targets a Thumb instruction (AArch32 only)BreakPoint handle that can be used to query or modify the breakpointboolean removeBreakPoint(long address)
address - guest virtual address of the breakpoint to removetrue if the breakpoint was found and removedvoid setSingleStep(int singleStep)
singleStep - number of instructions to execute before breaking; 0 to disablevoid setFastDebug(boolean fastDebug)
fastDebug - true to enable fast debug modevoid removeJitCodeCache(long begin,
long end)
throws BackendException
begin - start address of the range (inclusive)end - end address of the range (exclusive)BackendException - if the operation failsvoid hook_add_new(CodeHook callback, long begin, long end, Object user_data) throws BackendException
callback - the code hook callbackbegin - start address of the hook range (inclusive)end - end address of the hook range (inclusive)user_data - arbitrary user data passed to the callbackBackendException - if hook registration failsvoid debugger_add(DebugHook callback, long begin, long end, Object user_data) throws BackendException
callback - the debug hook callbackbegin - start address of the hook range (inclusive)end - end address of the hook range (inclusive)user_data - arbitrary user data passed to the callbackBackendException - if hook registration failsvoid hook_add_new(ReadHook callback, long begin, long end, Object user_data) throws BackendException
callback - the read hook callbackbegin - start address of the hook range (inclusive)end - end address of the hook range (inclusive)user_data - arbitrary user data passed to the callbackBackendException - if hook registration failsvoid hook_add_new(WriteHook callback, long begin, long end, Object user_data) throws BackendException
callback - the write hook callbackbegin - start address of the hook range (inclusive)end - end address of the hook range (inclusive)user_data - arbitrary user data passed to the callbackBackendException - if hook registration failsvoid hook_add_new(EventMemHook callback, int type, Object user_data) throws BackendException
callback - the event memory hook callbacktype - bitmask of event types (e.g., UC_HOOK_MEM_READ_UNMAPPED, UC_HOOK_MEM_WRITE_UNMAPPED)user_data - arbitrary user data passed to the callbackBackendException - if hook registration failsvoid hook_add_new(InterruptHook callback, Object user_data) throws BackendException
callback - the interrupt hook callbackuser_data - arbitrary user data passed to the callbackBackendException - if hook registration failsvoid hook_add_new(BlockHook callback, long begin, long end, Object user_data) throws BackendException
callback - the block hook callbackbegin - start address of the hook range (inclusive)end - end address of the hook range (inclusive)user_data - arbitrary user data passed to the callbackBackendException - if hook registration failsvoid emu_start(long begin,
long until,
long timeout,
long count)
throws BackendException
begin - guest virtual address where emulation startsuntil - guest virtual address where emulation stops (the instruction at this address is NOT executed)timeout - maximum duration in microseconds; 0 for no limitcount - maximum number of instructions to emulate; 0 for no limitBackendException - if emulation failsvoid emu_stop()
throws BackendException
BackendException - if the operation failsvoid destroy()
throws BackendException
BackendException - if cleanup failsvoid context_restore(long context)
context - handle returned by context_alloc()context_save(long)void context_save(long context)
context - handle returned by context_alloc()context_restore(long)long context_alloc()
context_save(long) and context_restore(long).context_free(long)void context_free(long context)
context - handle returned by context_alloc()int getPageSize()
void registerEmuCountHook(long emu_count)
emu_count - maximum number of instructions before the hook fires; must be > 0Map<String,Integer> getCpuFeatures()
arm64_features hw.optional.floatingpoint hw.optional.AdvSIMD hw.optional.arm.AdvSIMD hw.optional.arm.FEAT_AES hw.optional.arm.FEAT_PMULL hw.optional.arm.FEAT_SHA1 hw.optional.arm.FEAT_SHA256 hw.optional.armv8_crc32 hw.optional.arm.FEAT_LSE hw.optional.arm.FEAT_FP16 hw.optional.arm.AdvSIMD_HPFPCvt hw.optional.arm.FEAT_RDM hw.optional.arm.FEAT_JSCVT hw.optional.arm.FEAT_FCMA hw.optional.arm.FEAT_LRCPC hw.optional.arm.FEAT_DPB hw.optional.arm.FEAT_SHA3 hw.optional.arm.FEAT_DotProd hw.optional.arm.FEAT_SHA512 hw.optional.arm.FEAT_FHM hw.optional.arm.FEAT_DIT hw.optional.arm.FEAT_LSE2 hw.optional.arm.FEAT_FlagM hw.optional.arm.FEAT_SSBS hw.optional.arm.FEAT_SB hw.optional.arm.FEAT_FlagM2 hw.optional.arm.FEAT_FRINTTS hw.optional.arm.FEAT_I8MM hw.optional.arm.FEAT_BF16 hw.optional.arm.FEAT_BTI
long getMemAllocatedSize()
mem_map(long, long, int).
This is the sum of all mapped pages tracked by the backend's native memory hash table.
For unicorn2, this is computed from uc_mem_regions().
long getMemResidentSize()
On macOS/Linux, this uses mincore() to check which pages are actually
backed by physical memory, since mmap(MAP_ANONYMOUS) allocates lazily.
Only pages that have been read from or written to will be counted.
On Windows (dynarmic) and unicorn2 (QEMU-based), host memory pointers are not
accessible, so this returns the same value as getMemAllocatedSize().
default boolean isHypervisor()
true if this is a hypervisor backendCopyright © 2026. All rights reserved.