public class UnicornBackend extends AbstractBackend implements Backend
AbstractBackend.BreakPointImpl| 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
Backend.context_save(long) and Backend.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.
|
long |
getMemAllocatedSize()
Returns the total virtual memory size allocated via
Backend.mem_map(long, long, int). |
long |
getMemResidentSize()
Returns the actual physical memory resident in RAM.
|
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.
|
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.
|
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.
|
boolean |
removeBreakPoint(long address)
Removes a previously added breakpoint.
|
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).
|
checkVectorRegId, decodeSWI, enableVFP, getCpuFeatures, getPageSize, onInitialize, registerEmuCountHook, removeJitCodeCache, switchUserModeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCpuFeatures, getPageSize, isHypervisor, onInitialize, registerEmuCountHook, removeJitCodeCachepublic void switchUserMode()
BackendswitchUserMode in interface Backendpublic void enableVFP()
Backendpublic byte[] reg_read_vector(int regId)
throws BackendException
Backendreg_read_vector in interface BackendregId - vector register ID (e.g., UC_ARM64_REG_Q0..Q31 or UC_ARM_REG_D0..D15)BackendException - if the register read failspublic void reg_write_vector(int regId,
byte[] vector)
throws BackendException
Backendreg_write_vector in interface BackendregId - vector register IDvector - 16-byte array containing the value to writeBackendException - if the register write failspublic Number reg_read(int regId) throws BackendException
Backendreg_read in interface BackendregId - register ID, typically from unicorn.ArmConst or unicorn.Arm64ConstNumber (Integer for 32-bit, Long for 64-bit)BackendException - if the register read failspublic void reg_write(int regId,
Number value)
throws BackendException
Backendreg_write in interface BackendregId - register IDvalue - the value to write (truncated to 32-bit for AArch32)BackendException - if the register write failspublic byte[] mem_read(long address,
long size)
throws BackendException
Backendmem_read in interface Backendaddress - starting guest virtual addresssize - number of bytes to readBackendException - if the address is unmapped or read failspublic void mem_write(long address,
byte[] bytes)
throws BackendException
Backendmem_write in interface Backendaddress - starting guest virtual addressbytes - data to writeBackendException - if the address is unmapped or write failspublic void mem_map(long address,
long size,
int perms)
throws BackendException
Backendmmap(MAP_ANONYMOUS).mem_map in interface Backendaddress - 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 failspublic void mem_protect(long address,
long size,
int perms)
throws BackendException
Backendmem_protect in interface Backendaddress - page-aligned starting guest virtual addresssize - page-aligned size in bytesperms - new permissions bitmaskBackendException - if the region is not mapped or operation failspublic void mem_unmap(long address,
long size)
throws BackendException
Backendmem_unmap in interface Backendaddress - page-aligned starting guest virtual addresssize - page-aligned size in bytesBackendException - if the region is not mapped or unmapping failspublic BreakPoint addBreakPoint(long address, BreakPointCallback callback, boolean thumb)
BackendaddBreakPoint in interface Backendaddress - 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 breakpointpublic boolean removeBreakPoint(long address)
BackendremoveBreakPoint in interface Backendaddress - guest virtual address of the breakpoint to removetrue if the breakpoint was found and removedpublic void setSingleStep(int singleStep)
BackendsetSingleStep in interface BackendsingleStep - number of instructions to execute before breaking; 0 to disablepublic void setFastDebug(boolean fastDebug)
BackendsetFastDebug in interface BackendfastDebug - true to enable fast debug modepublic void hook_add_new(CodeHook callback, long begin, long end, Object user_data) throws BackendException
Backendhook_add_new in interface Backendcallback - 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 failspublic void debugger_add(DebugHook callback, long begin, long end, Object user_data) throws BackendException
Backenddebugger_add in interface Backendcallback - 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 failspublic void hook_add_new(ReadHook callback, long begin, long end, Object user_data) throws BackendException
Backendhook_add_new in interface Backendcallback - 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 failspublic void hook_add_new(WriteHook callback, long begin, long end, Object user_data) throws BackendException
Backendhook_add_new in interface Backendcallback - 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 failspublic void hook_add_new(EventMemHook callback, int type, Object user_data) throws BackendException
Backendhook_add_new in interface Backendcallback - 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 failspublic void hook_add_new(InterruptHook callback, Object user_data) throws BackendException
Backendhook_add_new in interface Backendcallback - the interrupt hook callbackuser_data - arbitrary user data passed to the callbackBackendException - if hook registration failspublic void hook_add_new(BlockHook callback, long begin, long end, Object user_data) throws BackendException
Backendhook_add_new in interface Backendcallback - 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 failspublic final void emu_start(long begin,
long until,
long timeout,
long count)
throws BackendException
Backendemu_start in interface Backendbegin - 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 failspublic void emu_stop()
throws BackendException
Backendemu_stop in interface BackendBackendException - if the operation failspublic void destroy()
throws BackendException
Backenddestroy in interface BackendBackendException - if cleanup failspublic void context_restore(long context)
Backendcontext_restore in interface Backendcontext - handle returned by Backend.context_alloc()Backend.context_save(long)public void context_save(long context)
Backendcontext_save in interface Backendcontext - handle returned by Backend.context_alloc()Backend.context_restore(long)public long context_alloc()
BackendBackend.context_save(long) and Backend.context_restore(long).context_alloc in interface BackendBackend.context_free(long)public void context_free(long context)
Backendcontext_free in interface Backendcontext - handle returned by Backend.context_alloc()public long getMemAllocatedSize()
BackendBackend.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().
getMemAllocatedSize in interface BackendgetMemAllocatedSize in class AbstractBackendpublic long getMemResidentSize()
Backend
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 Backend.getMemAllocatedSize().
getMemResidentSize in interface BackendgetMemResidentSize in class AbstractBackendCopyright © 2026. All rights reserved.