Interface IERoutineContext
- All Superinterfaces:
IOptimizerTarget
Routine (local) IR context. Every method being decompiled is having an associated IR context. The
routine context is also a factory for local IR objects, such as IR statements.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
buildCfg
(List<IEStatement> statements) Build an IR-CFG using the provided list of statements, and set the resulting CFG as the current CFG for this converted routine.buildCfg
(List<IEStatement> statements, boolean subroutineCallNotBreaking, boolean assignToContext) Build an IR-CFG from a list of statements.Initialize a state to emulate this routine.convertIntermediateOffset
(int offset) Conversion FROM IR offset TO native address.convertNativeAddress
(long address) Conversion FROM native address to IR offset.copyFinder
(StorageEntry entry, Collection<Integer> filters, Long irOffset) copyPairOfVariables
(IEVar lo, IEVar hi) Create a copy variable for a pair of variable.copyTruncatedVariable
(IEVar var, int lowPartBitsize) Create a truncated copy of a variable.copyVariable
(IEVar var) Create the copy of a variable.createAssign
(IEGeneric dst, IEGeneric src) createAssignIf
(IEAssign assignTpl, IEGeneric predicate) createBranchAssign
(IEGeneric dst, IEGeneric src, boolean subroutineCall) createBuiltinMethodCall
(String name, IEGeneric retexp, IEGeneric... argexps) Create aCall
to a built-in method reference.createCall
(IEGeneric callsite, IEGeneric retloc, List<IEGeneric> returns, List<IEGeneric> params, int stackPointerDelta, List<IEGeneric> spoiledExpressions, IWildcardPrototype prototype) createCall
(IEGeneric callsite, List<IEVar> targetCandidates, IWildcardPrototype prototype, List<IWildcardType> varArgTypes, boolean failsafePrototype) createCompose
(IEGeneric... elts) Create a composition.createCompose
(Collection<IEGeneric> elts) Create a composition.createCond
(IEGeneric p, IEGeneric a, IEGeneric b) createConversionOperation
(OperationType convOperator, IEGeneric src, int dstSize) Create a conversion operation: an integer truncation, integer extension (zero or signed), float truncation or extension, float-to-int and int-to-float conversion.createGroupElt
(IEGroup collection, IEGeneric index) createImm
(byte[] v, int bitsize) createImm
(double v) createImm
(float v) createImm
(long v, int bitsize) createImm
(BigInteger v, int bitsize) createJump
(int branchAddress) createJump
(int branchAddress, IEGeneric condition) createJumpFar
(IEGeneric jumpSite) createJumpFar
(IEGeneric jumpSite, IEGeneric condition) createNop
(IEStatement template) createOperation
(FunctionOptype functionOptype, IEGeneric... opnds) createOperation
(OperationType optype, IEGeneric op1) createOperation
(OperationType optype, IEGeneric op1, IEGeneric op2) createResizeOperation
(IEGeneric opnd, int bitsize, boolean signed) Create a resize operation operation: truncation, zero-extension, or sign-extension.createReturn
(IEGeneric value) createReturn
(List<IEGeneric> values) createStackReference
(long stkVarOffset) Retrieve or create a stack reference, ie a pointer to stack-memory variable.createStackReference
(long stkVarOffset, IWildcardType type) Retrieve or create a stack reference, ie a pointer to stack-memory variable.createSwitch
(IEGeneric controlExpression, int defaultAddress) createSymbolForField
(INativeFieldItem variable) createSymbolForGlobalVariable
(INativeDataItem variable) createSymbolForRoutine
(INativeMethodItem routine) createUntranslatedInstruction
(long nativeAddress, String nativeMnemonic, IEGeneric... irOperands) Create or retrieve a special routine-scope variable.createVirtualVar
(String name, int bitsize) Create or retrieve a virtual routine-scope variable.getCfg()
IEConverter<?>
getCopiesOfVariable
(int id) Get the set of all variables that are copies or partial copies of the provided input id.getCopiesUsingVariable
(int id) Get the set of all variables making use of the provided variable.Retrieve a piece of transient data.Convenience method to retrieve a reference to the decompiler that owns this context.getDuplicatesForRegister
(int regId) Retrieve the list of duplicates (mirror, secondary dups) associated to a register.getInputVariableForRegister
(IDFA<IEStatement> dfa, long nativeRegId) getInputVariableForRegister
(IDFA<IEStatement> dfa, IEVar reg) getIntermediateOffsetsMappingToNativeAddress
(long address) Retrieve the list of memory variables used by this context: stack variables and global variables.getNotes()
getOutputVariableForRegister
(IDFA<IEStatement> dfa, long exitAddress, int nativeRegId) getOutputVariableForRegister
(IDFA<IEStatement> dfa, long exitAddress, IEVar reg) Convenience method.int
Convenience method.Convenience method.getRegisterMirror
(IEVar reg) Retrieve or create the mirror - that is, the first full copy, in the [IEVar.IDL_MIRROR
,IEVar.IDL_MIRROR_END
[ range - of the provided register.Retrieve the IR expressions holding the routine's parameters.getRoutineVariablesInRange
(int idStart, int idEnd) getSourceForVariable
(int id) Retrieve the manager for local IEVars representing physical stack variables (in the general sense, ie memory slots).Convenience method.int
Convenience method.getStackReference
(long stkVarOffset) Retrieve a stack reference, i.e.getStackVariable
(int offset) Retrieve the stack variable at the provided offset.Retrieve the list of memory stack variables used by this context.getStackVariables
(int offsetStart, int offsetEnd) Retrieve all defined stack variables whose (starting) offset are included in the provided range.Retrieve the raw list of converted IR-statements.getUnderlyingRegisterId
(int varid) Retrieve the id of the underlying IEVar-register used to hold this variable.getVariableById
(int id) Retrieve a variable (routine-scope or global-scope) by id.getVariableByName
(String name) Retrieve a routine-scope variable by name.void
Invalidate all data flow analysis for the IR-CFG managed by this context.boolean
void
void
logUnsafeOpt
(String format, Object... args) boolean
removeNote
(String note) removeStackReference
(long stkVarOffset) Remove a stack reference.retrieveVariableForRegister
(IEGeneric reg, Collection<Integer> filters, boolean createIfNotFound) void
setCfg
(CFG<IEStatement> cfg) void
Store a piece of transient data.void
setPrototype
(IWildcardPrototype prototype) Convenience method.void
setRoutine
(INativeMethodItem routine) void
setStatements
(List<IEStatement> statements) Set the converted list of raw IR-statements.void
setStatements
(List<IEStatement> statements, boolean verifyStatements, boolean replaceLeftAssignSlices, boolean buildCfg) Set the converted list of raw IR-statements.void
setTypeForSame
(IEGeneric exp, IWildcardType type) boolean
Methods inherited from interface com.pnfsoftware.jeb.core.units.code.asm.decompiler.opt.IOptimizerTarget
getTargetName
-
Method Details
-
isAllowUnsafeAnalysis
boolean isAllowUnsafeAnalysis() -
getRoutine
INativeMethodItem getRoutine() -
setRoutine
-
getPrototype
IWildcardPrototype getPrototype()Convenience method.- Returns:
-
setPrototype
Convenience method.- Parameters:
prototype
-
-
getGlobalContext
IEGlobalContext getGlobalContext() -
getConverter
IEConverter<?> getConverter() -
getDecompiler
INativeDecompilerContext getDecompiler()Convenience method to retrieve a reference to the decompiler that owns this context. That is, the decompiler that owns the IR converter that originally created this IR context).- Returns:
- a reference to a decompiler (likely, a
INativeDecompilerUnit
), or null
-
getNativeContext
INativeContext getNativeContext() -
getWildcardTypeManager
IWildcardTypeManager getWildcardTypeManager() -
getStackManager
IEStackManager getStackManager()Retrieve the manager for local IEVars representing physical stack variables (in the general sense, ie memory slots).- Returns:
-
getProgramCounter
IEVar getProgramCounter()Convenience method.- Returns:
-
getProgramCounterId
int getProgramCounterId()Convenience method.- Returns:
-
getStackPointer
IEVar getStackPointer()Convenience method.- Returns:
-
getStackPointerId
int getStackPointerId()Convenience method.- Returns:
-
setStatements
Set the converted list of raw IR-statements. A list of statements can only be assigned once, else this method will throwIllegalStateException
(however, this method may be called with the current list).- Parameters:
statements
- a list of statements coming out of a converter
-
setStatements
void setStatements(List<IEStatement> statements, boolean verifyStatements, boolean replaceLeftAssignSlices, boolean buildCfg) Set the converted list of raw IR-statements.- Parameters:
statements
- a list of statements coming out of a converterverifyStatements
- optionalreplaceLeftAssignSlices
- optionalbuildCfg
- optional
-
buildCfg
Build an IR-CFG using the provided list of statements, and set the resulting CFG as the current CFG for this converted routine. The current conversion lists will be used.- Parameters:
statements
- input list ofIEStatement
s- Returns:
- the newly created CFG
-
buildCfg
CFG<IEStatement> buildCfg(List<IEStatement> statements, boolean subroutineCallNotBreaking, boolean assignToContext) Build an IR-CFG from a list of statements. The first statement is the input statement. Note that the resulting CFG may not contain all provided IR statements; only reachable IR statements are present. The resulting CFG is gap-less.- Parameters:
statements
- list of statementssubroutineCallNotBreaking
- if true,IECall
-like statements do not necessarily break a basic block (to be used solely in latest pipeline stages)- Returns:
- a CFG; note that
getCfg()
is not updated; to update the CFG reference stored in this context, usesetCfg()
-
invalidateDataFlowAnalysis
void invalidateDataFlowAnalysis()Invalidate all data flow analysis for the IR-CFG managed by this context. Convenience method. -
convertNativeAddress
Conversion FROM native address to IR offset. The IR offset is an int, but returned as a long to conveniently manipulate it with IInstruction.- Parameters:
address
- physical address- Returns:
- IR offset or null on error
-
convertIntermediateOffset
Conversion FROM IR offset TO native address.- Parameters:
offset
- IR offset- Returns:
- physical address or null on error
-
getIntermediateOffsetsMappingToNativeAddress
-
getIntermediateOffsetsMappingToNativeAddresses
-
getStatements
List<IEStatement> getStatements()Retrieve the raw list of converted IR-statements. Beware: this list gets stale very quickly, as the decompiler deals with and optimizes an IR-CFG (initially built from this list), instead.- Returns:
- the initial IR-statements raw list
-
getCfg
CFG<IEStatement> getCfg() -
setCfg
-
buildEmptyState
EState buildEmptyState()Initialize a state to emulate this routine. The variables map is uninitialized.- Returns:
-
createAssign
-
createBranchAssign
-
createAssignIf
-
createSwitch
-
createJump
-
createJump
-
createJumpFar
-
createJumpFar
-
createNop
IENop createNop() -
createNop
-
createReturn
IEReturn createReturn() -
createReturn
-
createReturn
-
createCall
-
createCall
IECall createCall(IEGeneric callsite, List<IEVar> targetCandidates, IWildcardPrototype prototype, List<IWildcardType> varArgTypes, boolean failsafePrototype) -
createUntranslatedInstruction
IEUntranslatedInstruction createUntranslatedInstruction(long nativeAddress, String nativeMnemonic, IEGeneric... irOperands) -
createMem
-
createMem
-
createOperation
-
createOperation
-
createOperation
-
createResizeOperation
Create a resize operation operation: truncation, zero-extension, or sign-extension.- Parameters:
opnd
- the source to be extended (dstSize > srcSize) or truncated (dstSize < srcSize)bitsize
- the destination size; should be different than the source'ssigned
- for extensions, else N/A- Returns:
- the operation IRE
-
createConversionOperation
Create a conversion operation: an integer truncation, integer extension (zero or signed), float truncation or extension, float-to-int and int-to-float conversion.- Parameters:
convOperator
- one of for whichOperationType.isConversion()
returns true (eg,OperationType.CAST
,OperationType.CAST_S
,OperationType.FP2FP
,OperationType.FP2INT
,OperationType.INT2FP
)src
- operand to be extended, truncated, or converteddstSize
- resulting bitsize- Returns:
- the operation IRE
-
createImm
-
createImm
-
createImm
-
createImm
-
createImm
-
createImm
-
createCompose
Create a composition.- Parameters:
elts
- at least two elements, from lowest-significant to highest-significant- Returns:
-
createCompose
Create a composition.- Parameters:
elts
- at least two elements, from lowest-significant to highest-significant- Returns:
-
createCond
-
createGroupElt
-
createVar
Create or retrieve a special routine-scope variable. The variable id is in the [SPECIAL
,SPECIAL_END
] range.Clients should avoid using this method. Non-stack routine-scope variables created by third-party code should generally be in the VIRTUAL range. See the
createVirtualVar(String, int)
method.- Parameters:
name
-bitsize
-- Returns:
-
createVirtualVar
Create or retrieve a virtual routine-scope variable. The variable id is in the [VIRTUAL
,VIRTUAL_END
] range.- Parameters:
name
-bitsize
-- Returns:
-
getStackReference
Retrieve a stack reference, i.e. a pointer to stack-memory variable.- Parameters:
stkVarOffset
- stack offset- Returns:
- a local symbol var, null if none
-
removeStackReference
Remove a stack reference.- Parameters:
stkVarOffset
-- Returns:
-
createStackReference
Retrieve or create a stack reference, ie a pointer to stack-memory variable.- Parameters:
stkVarOffset
- stack offsettype
- optional type- Returns:
-
createStackReference
Retrieve or create a stack reference, ie a pointer to stack-memory variable.- Parameters:
stkVarOffset
- stack offset- Returns:
-
getVariableByName
Retrieve a routine-scope variable by name.- Parameters:
name
- var name- Returns:
- the variable or null
-
getVariableById
Retrieve a variable (routine-scope or global-scope) by id.- Parameters:
id
- var id- Returns:
- the variable or null
-
getRoutineVariablesInRange
- Parameters:
idStart
-idEnd
-- Returns:
-
getStackVariables
Collection<IEVar> getStackVariables()Retrieve the list of memory stack variables used by this context.- Returns:
-
getStackVariable
Retrieve the stack variable at the provided offset.- Parameters:
offset
-- Returns:
-
getStackVariables
Retrieve all defined stack variables whose (starting) offset are included in the provided range. Note that the last variable may span outside the range.- Parameters:
offsetStart
-offsetEnd
- must be greater than the start value- Returns:
-
getMemoryVariables
Collection<IEVar> getMemoryVariables()Retrieve the list of memory variables used by this context: stack variables and global variables.- Returns:
-
createSymbolForRoutine
-
createSymbolForField
-
createSymbolForGlobalVariable
-
usesCopyVars
boolean usesCopyVars()- Returns:
-
getDuplicatesForRegister
Retrieve the list of duplicates (mirror, secondary dups) associated to a register.- Parameters:
regId
- id of a register-EVar- Returns:
- a list (possibly empty), or null if the id was not a legal register-EVar id
-
getUnderlyingRegisterId
Retrieve the id of the underlying IEVar-register used to hold this variable.- Parameters:
varid
- a variable id, which may or not be a register var- Returns:
- an id, null if the input variable does not originate from a register, or if it does not fit on a single physical register (which means that if the input varid is for a copy of a pair of registers, this method will return null)
-
getRegisterMirror
Retrieve or create the mirror - that is, the first full copy, in the [IEVar.IDL_MIRROR
,IEVar.IDL_MIRROR_END
[ range - of the provided register.Note: A register
IEVar
is global and non-typeable. A mirrorIEVar
is local and typeable. -
copyVariable
Create the copy of a variable.Not all variables can be copied. Currently, copies are limited to registers variables.
- Parameters:
var
- anIEVar
-register- Returns:
- null on error, else, the copied variable
-
copyTruncatedVariable
Create a truncated copy of a variable.Not all variables can be copied. Currently, copies are limited to registers variables.
- Parameters:
var
- anIEVar
-registerlowPartBitsize
-- Returns:
- null on error, else, a tuple containing the copy variables: low part (truncated LSB), and high part (remainder MSB)
-
copyPairOfVariables
Create a copy variable for a pair of variable.Not all variables can be copied. Currently, copies are limited to registers variables.
-
copyFinder
-
getSourceForVariable
- Parameters:
id
- a copy-var id- Returns:
- the source or null (only copy-var have sources)
-
getCopiesOfVariable
Get the set of all variables that are copies or partial copies of the provided input id. The input id may be of a copy variable itself, in which case, this method is equivalent as retrieving the copies of its source.The copies returned is a list of vars entirely contained in the input var.
- Parameters:
id
- input id- Returns:
- a set of id, including self if it was a copy
-
getCopiesUsingVariable
Get the set of all variables making use of the provided variable.The copies returned is a list of vars whose overlap with the input var is non-null.
- Parameters:
id
- input id- Returns:
- a set of id, including self if it was a copy
-
retrieveVariableForRegister
IEGeneric retrieveVariableForRegister(IEGeneric reg, Collection<Integer> filters, boolean createIfNotFound) -
getInputVariableForRegister
- Parameters:
dfa
-nativeRegId
- the id of a native register (per the processor's register bank definition; do not confuse this withIEVar
-register id)- Returns:
-
getInputVariableForRegister
- Parameters:
dfa
-reg
-- Returns:
-
getOutputVariableForRegister
- Parameters:
dfa
-exitAddress
-nativeRegId
- the id of a native register (per the processor's register bank definition; do not confuse this withIEVar
-register id)- Returns:
-
getOutputVariableForRegister
- Parameters:
dfa
-exitAddress
-reg
-- Returns:
-
getRoutineInputVariables
Retrieve the IR expressions holding the routine's parameters. May be used only after a decompilation has fully completed.- Returns:
-
setTypeForSame
-
acquireNativeItem
- Parameters:
t
-
-
log
-
logUnsafeOpt
-
setData
Store a piece of transient data.- Parameters:
key
-value
-
-
getData
Retrieve a piece of transient data.- Parameters:
key
-- Returns:
-
addNote
- Parameters:
note
-- Returns:
-
removeNote
- Parameters:
note
-- Returns:
-
getNotes
- Returns:
-
createBuiltinMethodCall
Create aCall
to a built-in method reference.- Parameters:
name
- built-in method name, supported values:strcpy
,memcpy
,memset
retexp
- the optional return valueargexps
- the list of IR arguments- Returns:
- a call IR expression, null on error
-