Class EEmulator
java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.decompiler.ir.emulator.EEmulator
IR emulator, a controller for an
IR state. Also referred to as a "processor
emulator", because this object is used to control the emulation of processor instructions
converted to intermediate code.
How to use:
- pass an existing EState to a constructor or use
createStandard(IEGlobalContext) to create a state and an emulator
- use the settters to customize the emulator.
- setup() it
- run() it
Three modes of execution:
1- IR routine emulation
2- IR routine-supported stub emulation
3- Global routine emulation (disregarding routines), a generalized variant of 2, suitable for
full program emulation
4- Global stub emulation
The full mode supports multi-threading and multi-processing (thread groups).
default memory addresses (can be changed): baseAddressForExterns 0x7A00_0000 defaultStackBase 0x7E00_0000 defaultReturnAddr 0x1122_3340
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanstatic final booleanstatic final longstatic final longstatic final intstatic final booleanstatic final booleanstatic final longstatic final longstatic booleanstatic boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArgument(byte[] val, INativeType t) voidaddArgument(long val, INativeType t) voidaddArgument(IEImm val) voidbooleancommitMemoryChanges(boolean commitModifiedPagesOnly) intcondCreate(long addr, int attr) booleancondDestroy(int idx) booleancondSignal(int idx, boolean broadcast) intcondWait(int idx, int mutexIdx, long maxIterNumber) longcreatePseudoRoutine(INativeMethodItem routine) longcreatePseudoRoutine(String name) static EEmulatorCreate an emulator as well as a standardemulation statethat will be controlled by the emulator.static EEmulatorcreateStandard(IEGlobalContext gctx, int maxIterationCount) Create an emulator as well as a standardemulation statethat will be controlled by the emulator.final longvoidenableMultiThreading(Object initialProcessClientTag, Object initialThreadClientTag) To be called beforesetup().longfindRegisteredRoutine(String name) findRegisteredRoutineByAddress(long addr) intlonglongA convenience method to retrieve memory changes performed during emulation.longintgetRegisterValue(String regname) longintgetState()longgetTruncatedRegisterValue(String regname) hooksEvaluateAt(long addr, IInstruction hintNativeStm) hooksEvaluateExternal(String routineName, INativeMethodItem routine) booleanhooksEvaluateSyscall(long addr, IInstruction insn) booleanbooleanvoidvoidvoidmonitorHLSpecial(int code, Object... params) intmutexCreate(long addr, int attr) booleanmutexDestroy(int idx) intmutexGetOwnerTidx(int idx) intmutexLock(int idx, boolean tryLocking) booleanmutexUnlock(int idx) intprocessCreate(int pid, Long startAddress, Map<String, IEImm> regmap) Fork a process and optionally start a new main thread in the forked process.intbooleanprocessDestroy(int pidx) booleanret-addr on stack: pop and return
ret-addr in register: TBIbooleanprocessStoredReturnAddress(StorageEntry entry, int stkSlotAdj) ret-addr on stack: pop and return
ret-addr in register: TBIbooleanprocessTerminate(int pidx) Mark the thread group and all the threads of the group: they will no longer be scheduled for execution.readPointer(long addr) Convenience method.readStorage(StorageEntry entry) voidregisterHooks(IEEmulatorHooks hooks) voidregisterHooks(IEEmulatorHooks hooks, boolean insertFirst) longregisterRoutine(long addr, INativeMethodItem routine) longregisterRoutine(long addr, INativeMethodItem routine, boolean overwrite) longregisterRoutine(long addr, String name) longregisterRoutine(long addr, String name, boolean overwrite) static IPrototypeItemretrievePrototype(INativeDecompilerContext decomp, INativeMethodItem routine) Convenience method used to verify whether or not an emulator object would be able to retrieve a target method prototype.voidrun()voidsetArguments(Collection<IEImm> vals) voidsetExternsRange(long base, long end) Must be called beforesetup().voidsetGlobalRoutineEmulation(long routineAddress, IPrototypeItem routinePrototype) voidvoidsetGlobalStubEmulation(long pcStart, Long pcStop) voidvoidsetPCAddress(long nativeAddress) voidsetPerformFreshDecompilations(boolean performFreshDecompilations) voidsetPreferredStackBase(long address) Must be called beforesetup().voidvoidsetRecordMemoryWrites(boolean recordMemoryWrites) voidsetRegisterValue(String regname, IEImm val) voidsetResetUnknownRegisters(boolean enabled) Must be called beforesetup().voidsetReturnAddress(long retAddr) voidsetSPAddress(long nativeAddress) booleanvoidsetStubExecution(IERoutineContext ctx, int irStart, int irStop) voidsetStubExecution(INativeMethodItem routine, long pcStart, long pcStop) voidsetTargetRoutine(INativeMethodItem routine) voidsetTaskSupervisor(EEmulator.ITaskSupervisor taskListener) voidsetup()booleanswapHooks(IEEmulatorHooks currentHooks, IEEmulatorHooks replHooks) voidteardown()Clean-up temporary constructs built duringsetup().intthreadCreate(Object threadClientTag, long routineAddress, long pseudoReturnAddress, Map<String, IEImm> regmap) intbooleanthreadDestroy(int idx) booleanthreadFreeze(int idx, boolean frozen) threadGetAssociatedVM(int idx) booleanthreadIsTerminated(int idx) intthreadJoin(int waitingToJoinOnThreadIdx, long addrRetValStorage) threadReadRegister(int idx, String registerName) voidthreadSleep(long waitcnt) booleanthreadTerminate(int idx, IEImm retVal) threadWriteRegister(int idx, String registerName, IEImm value) voidvoidunregisterHooks(IEEmulatorHooks hooks) longupdateSPAddress(int delta) Update the stack pointer register.booleanwritePointer(long addr, long ptr) booleanwriteStorage(StorageEntry entry, IEImm val)
-
Field Details
-
debugLogEnabled
public static boolean debugLogEnabled -
extraVerboseLogInsn
public static boolean extraVerboseLogInsn -
extraVerboseLogIR
public static boolean extraVerboseLogIR -
defaultMaxIterCount
public static final int defaultMaxIterCount- See Also:
-
defaultAllowOpt
public static final boolean defaultAllowOpt- See Also:
-
defaultStackBase
public static final long defaultStackBase- See Also:
-
defaultResetUnknownRegisters
public static final boolean defaultResetUnknownRegisters- See Also:
-
defaultReturnAddr
public static final long defaultReturnAddr- See Also:
-
defaultRecordMemoryWrites
public static final boolean defaultRecordMemoryWrites- See Also:
-
defaultExternsBase
public static final long defaultExternsBase- See Also:
-
defaultExternsEnd
public static final long defaultExternsEnd- See Also:
-
-
Constructor Details
-
EEmulator
-
-
Method Details
-
log
-
log
-
createStandard
Create an emulator as well as a standardemulation statethat will be controlled by the emulator. Set the standard maximum iteration count to 10000.- Parameters:
gctx-- Returns:
-
createStandard
Create an emulator as well as a standardemulation statethat will be controlled by the emulator.- Parameters:
gctx-maxIterationCount-- Returns:
-
getGlobalContext
-
getRegisterSize
public int getRegisterSize() -
getAddressSize
public int getAddressSize() -
getStackSlotSize
public int getStackSlotSize() -
setRecordMemoryWrites
public void setRecordMemoryWrites(boolean recordMemoryWrites) -
setResetUnknownRegisters
public void setResetUnknownRegisters(boolean enabled) Must be called beforesetup().- Parameters:
enabled-
-
setPreferredStackBase
public void setPreferredStackBase(long address) Must be called beforesetup().- Parameters:
address-
-
setExternsRange
public void setExternsRange(long base, long end) Must be called beforesetup().- Parameters:
address-
-
setPerformFreshDecompilations
public void setPerformFreshDecompilations(boolean performFreshDecompilations) -
setStubExecution
-
setStubExecution
-
setTargetRoutine
-
setPreferredTargetPrototype
-
setGlobalRoutineEmulation
-
setGlobalRoutineEmulation
-
setGlobalStubEmulation
-
setReturnAddress
public void setReturnAddress(long retAddr) -
clearArgument
public void clearArgument() -
addArgument
-
addArgument
-
addArgument
-
setArguments
-
retrievePrototype
public static IPrototypeItem retrievePrototype(INativeDecompilerContext decomp, INativeMethodItem routine) Convenience method used to verify whether or not an emulator object would be able to retrieve a target method prototype.- Parameters:
decomp- decompiler unitroutine- candidate target routine- Returns:
- the retrieved prototype that would be used by an emulator for the provided target routine
-
setup
public void setup() -
setStack
-
teardown
public void teardown()Clean-up temporary constructs built duringsetup(). -
isPrimaryEmulator
public boolean isPrimaryEmulator() -
getState
-
getMemory
-
getMemoryChanges
A convenience method to retrieve memory changes performed during emulation.- Returns:
- a changes object
- Throws:
UnsupportedOperationException- if the emulator's memory is not a shim
-
getSPAddress
public long getSPAddress() -
setSPAddress
public void setSPAddress(long nativeAddress) -
updateSPAddress
public long updateSPAddress(int delta) Update the stack pointer register.- Parameters:
delta-- Returns:
- the updated SP value
-
getPCAddress
public long getPCAddress() -
setPCAddress
public void setPCAddress(long nativeAddress) -
getMaxIterationCount
public long getMaxIterationCount() -
getIterationCount
public long getIterationCount() -
run
- Throws:
EvaluationException
-
setLastEvaluationResult
-
getLastEvaluationResult
-
findRegisteredRoutine
-
findRegisteredRoutineByAddress
-
createPseudoRoutine
-
createPseudoRoutine
-
registerRoutine
-
registerRoutine
-
registerRoutine
-
registerRoutine
-
currentRequestId
public final long currentRequestId() -
hooksEvaluateAt
- Parameters:
addr-hintNativeStm-- Returns:
-
hooksEvaluateExternal
- Parameters:
routineName- mandatoryroutine- optional- Returns:
-
hooksEvaluateUntranslated
-
hooksEvaluateSyscall
-
monitorHLSpecial
-
readStorage
-
writeStorage
-
processStoredReturnAddress
ret-addr on stack: pop and return
ret-addr in register: TBI -
processStoredReturnAddress
ret-addr on stack: pop and return
ret-addr in register: TBI -
readPointer
Convenience method.- Parameters:
addr-- Returns:
-
writePointer
public boolean writePointer(long addr, long ptr) -
getMemoryWrites
-
getReturnValue
-
getReturnAddress
-
getRegisterValue
-
setRegisterValue
-
getTruncatedRegisterValue
-
commitMemoryChanges
public boolean commitMemoryChanges(boolean commitModifiedPagesOnly) -
registerHooks
-
registerHooks
-
unregisterHooks
-
swapHooks
-
isMainProcess
public boolean isMainProcess() -
enableMultiThreading
To be called beforesetup().- Parameters:
initialProcessClientTag-initialThreadClientTag-
-
processCurrentIndex
public int processCurrentIndex() -
processCurrentTag
-
processCreate
Fork a process and optionally start a new main thread in the forked process.- Parameters:
pid- new process wanted pid (high-level pid, not used directly by this emulator; the emulator simply passes it along to its listener)startAddress- if non-null, a main thread will be createdregmap- registers to be set in the new main thread- Returns:
-
processTerminate
public boolean processTerminate(int pidx) Mark the thread group and all the threads of the group: they will no longer be scheduled for execution.- Parameters:
pidx-exitCode- exit status code- Returns:
-
processDestroy
public boolean processDestroy(int pidx) -
threadCurrentIndex
public int threadCurrentIndex() -
threadCurrentTag
-
threadCreate
-
threadTerminate
-
threadIsTerminated
public boolean threadIsTerminated(int idx) -
threadDestroy
public boolean threadDestroy(int idx) -
threadGetAssociatedVM
-
threadReadRegister
-
threadWriteRegister
-
threadFreeze
public boolean threadFreeze(int idx, boolean frozen) -
threadJoin
public int threadJoin(int waitingToJoinOnThreadIdx, long addrRetValStorage) - Parameters:
addrRetValStorage-waitingToJoinOnIdx-- Returns:
- negative: error occurred; 0=joining succeeded, current thread is now WAITING; 1=no need to join, the target thread has already completed
-
threadSleep
public void threadSleep(long waitcnt) - Parameters:
waitcnt- iteration count (if negative or zero, this call is treated as ayield)
-
threadYields
public void threadYields() -
mutexCreate
public int mutexCreate(long addr, int attr) -
mutexDestroy
public boolean mutexDestroy(int idx) -
mutexGetOwnerTidx
public int mutexGetOwnerTidx(int idx) -
mutexLock
public int mutexLock(int idx, boolean tryLocking) - Parameters:
idx- mutex indextryLocking- true to attempt locking (will return 2 if the mutex is already locked)- Returns:
- negative: error; 0= lock acquired; 1= lock in-use, thread was moved to WAITING state; 2= lock in-use, bailing
-
mutexUnlock
public boolean mutexUnlock(int idx) -
condCreate
public int condCreate(long addr, int attr) -
condDestroy
public boolean condDestroy(int idx) -
condSignal
public boolean condSignal(int idx, boolean broadcast) -
condWait
public int condWait(int idx, int mutexIdx, long maxIterNumber) - Parameters:
idx-mutexIdx-maxIterNumber-- Returns:
- negative: error occurred (e.g. the cond-var does not exist; the mutex was not acquired); 0=first call, mutex unlocked, thread is now WAITING; 1=second call, mutex re-locked; 2=second call, mutex re-locked, timeout ellapsed cond var was not signaled
-
setTaskSupervisor
-