Class AbstractConverter<InsnType extends IInstruction>
- Type Parameters:
InsnType- native instruction type handled by this converter
- All Implemented Interfaces:
IEConverter<InsnType>
gendec intermediate
representation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceMarks a converter method associated with a native mnemonic. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected IERoutineContextPer-routine data - works because convert() is not re-entrant (same found in X86ConvXxx helper classes).
Should be set before converting a routine, and reset to null after it's done.protected booleanTrue to suppress generated NOP statements.protected IEGlobalContextGlobal IR context.protected intNumber of routine conversions that failed.protected intNumber of routine conversions that completed successfully.protected INativeContextNative code context.Parameter registers for all calling conventions, using native register ids.protected IProcessor<InsnType> Processor used by this converter.protected intStandard register size, in bits.Spoiled registers for all calling conventions, using native register ids. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate a converter for a native context.protectedAbstractConverter(IProcessor<InsnType> proc) Create a converter for a processor.protectedAbstractConverter(IProcessor<InsnType> proc, int registerBitsize) Create a converter for a processor and register bitsize.protectedAbstractConverter(IProcessor<InsnType> proc, int registerBitsize, int addressBitsize) Create a converter for a processor, register bitsize, and address bitsize. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanattemptCallInliningByExtension(ConverterInstructionEntry<InsnType> e, long target) Attempt call inlining through registered extensions.protected booleanAttempt instruction conversion through registered extensions.final booleanautoConvert(ConverterInstructionEntry<InsnType> e, ACS acs) Apply an auto-conversion semantic description to an instruction entry.The default implementation provides a no-arg/no-return prototype: "void __defaultCC ()".booleanThe default implementation returns true.convert(INativeMethodItem routine) Convert the blocks of the native routine's CFG after the other.protected voidconvertBlock(BasicBlock<InsnType> b, List<IEStatement> interlist) Convert a basic block.final List<IEStatement> Reserved for testing.voidThis method is called byconvertBlock(BasicBlock, List).protected booleanconvertInstructionFirstChance(ConverterInstructionEntry<InsnType> e, String mn, boolean allowRecurse) Attempt a first-chance instruction conversion.protected booleanAttempt a last-chance instruction conversion.protected IEGenericconvertOperand(long insnAddress, InsnType insn, int opndIndex) This method is called by theAbstractConverter<InsnType extends IInstruction>.com.pnfsoftware.jeb.core.units.code.asm.decompiler.AbstractConverter.AutoConverter.convertParameterExpressions(IERoutineContext ctx, IWildcardPrototype prototype, INativeMethodItem targetRoutine, List<IWildcardType> varArgTypes) Given a prototype, determine the list of IR expressions representing the input expressions (would also contain implicitly read registers).convertReturnExpressions(IERoutineContext ctx, IWildcardPrototype prototype, INativeMethodItem targetRoutine, List<IWildcardType> varArgTypes, List<IEGeneric> outSpoiled) Given a prototype, determine the list of IR expressions representing the output expressions.convertReturnLocation(IERoutineContext ctx, IWildcardPrototype prototype) Given a prototype, determine the IR expression representing the return address location of a call to a method of said prototype.createStackMemoryAccess(IEGeneric address, int bitsize) The default implementation assumes a segment-less memory model.voidcustomInitStateRegisters(EState state, Long optionalNativeProgramCounter) The default implementation does nothing.intConvert PC-assignment toIEJumpFarstatements.determineStackBytesUsedByCall(IWildcardPrototype prototype, List<IWildcardType> varArgTypes) Determine the amount of bytes that were pushed on the stack before calling the routine with the provided prototype and optional additional slots.determineStackPointerDeltaAfterIRCall(IWildcardPrototype prototype, List<IWildcardType> varArgTypes) Determine the stack pointer delta (in bytes) after theIECallexecuted and returned.
Careful: "IR-Call" and the "native-call" may not have the same structure; it depends on how the conversion of "native-call" is implemented, and therefore is converter-dependent.The default implementation returns null.evaluateUntranslatedIR(IEUntranslatedInstruction insn, IERoutineContext ectx, EState state) The default implementation returns null.The default implementation formats basic details about the number of converted methods.generateASTForUntranslatedIR(IEUntranslatedInstruction insn, IERoutineContext ectx, ICMethod cctx) The default implementation returns null.intThe default implementation returns the size of the program counter.Retrieve a reference to the decompiler managing this converter.getDefaultBranchToRoutineSideEffects(INativeMethodItem optionalRoutine) The default implementation returns a basic branch detail object specifying nothing (no def, no use, no spoils, etc.).getFPRegister(int index) Retrieve the IR variable object that represents the Floating-point register.Retrieve the global program context.getGPRegister(int index) Retrieve the IR variable object that represents the General Purpose register.getInputVariableByIndex(IERoutineContext ctx, int i) The default implementation returns null.Retrieve the native code context that this converter should use.final longlonggetNativeRegisterIdFromRegisterVariable(IEVar regVar, boolean shortForm) The default implementation attempts to resolve the register variable by querying the associated processor's register bank layout.getOutputVariableByIndex(IERoutineContext ctx, int i) The default implementation returns null.Create an instance of a prototype handler.final IEGenericgetRegister(String name) Retrieve anIEVar-register by its name, without conversion location information.getRegister(String name, ELocation loc) The default implementation forwards toIEGlobalContext.getVariableByName(String).intThe default implementation returns the address bitsize.final IEGenericgetRegisterVariableFromNativeRegisterId(long nativeRegId) getRegisterVariableFromNativeRegisterId(long nativeRegId, ELocation loc) The default implementation attempts to resolve the native register id or number by querying the associated processor's register bank layout.The default implementation considers that there is no specific Return Address Register.getSlicedRegisterName(String registerName, int bitstart, int bitend) Get the name of the slice of a physical register.intGet the size of a standard slot on the stack, in bytes.intgetStateProcessorMode(EState state) Retrieve the current processor mode relative to the providedEState.getTempRegister(int index) Retrieve a temporary register variable.The default implementation returnsIWildcardType.Group.INTEGER.voidThis method is called by the owner decompiler after the principal components of the lower-level code unit have been initialized.final voidinitializeStateRegisters(EState state, Long optionalNativeProgramCounter) This method initializes and sets all physical registers declared by this converter to 0, except for the ones possibly used as arguments that are kept undefined (seeisPossibleParameterRegisterForProcessorCallingConventions(long)).protected final booleaninsertOptionalEntryPointTrampoline(IERoutineContext ctx, List<IEStatement> irlist) For native routines that have their entry point in-the-middle (i.e., not at their lowest address), insert a syntheticIEJumpas the first instruction of the converted method.intThis method introducesIEReturnstatements into the IR.booleanDetermine whether generated NOP statements are suppressed.protected final booleanisPCRightValueCompatibleReturnValue(IDFA<IEStatement> dfa, BasicBlock<IEStatement> b, IEGeneric PCRightVal, IEGeneric expectedReturnAddress) Can be overridden by implementors when complex return expression matching is needed.booleanisPossibleParameterRegisterForProcessorCallingConventions(long nativeRegId) Check if a native register id corresponds to a register that can possibly be used as a routine parameter on this processor.booleanisPossibleSpoiledRegistersForProcessorCallingConventions(long nativeRegId) Check if a native register id corresponds to a physical register that can possibly be spoiled by a routine call on this processor.The default implementation returns true: by default, all EMem are assumed to reference bytes in the primary VM.normalizeBranchingExpression(IDFA<IEStatement> dfa, BasicBlock<IEStatement> b, IEGeneric target, IEGeneric expectedTarget) Normalize a branching expression.protected voidpostBlockConversion(CFG<InsnType> cfg, BasicBlock<InsnType> b, List<IEStatement> interlist, int cnt) This method is called afterconvertBlock(BasicBlock, List)is called.protected voidpostRoutineConversion(INativeMethodItem routine, IERoutineContext ctx) Executed byconvertafter converting the blocks.protected BasicBlock<InsnType> preBlockConversion(CFG<InsnType> cfg, BasicBlock<InsnType> b, List<IEStatement> interlist) This method is called beforeconvertBlock(BasicBlock, List)is called.protected voidpreRoutineConversion(INativeMethodItem routine, IERoutineContext ctx, List<IEStatement> irlist) Executed byconvertbefore converting the blocks.booleanImplementations should be aggressive and fast: calls to this method should always be enclosed in a try-catch.longsanitizeNativeAddress(long address) The default implementation truncates the provided value to accomodategetAddressBitsize().voidSet the current routine conversion context used by helper converter classes.voidsetDecompiler(INativeDecompilerContext decompiler) Reserved.voidsetDoNotGenerateNops(boolean doNotGenerateNops) Set whether generated NOP statements should be suppressed.voidSet the native context used by this converter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.pnfsoftware.jeb.core.units.code.asm.decompiler.IEConverter
getProgramCounter, getStackPointer
-
Field Details
-
gCtx
Global IR context. -
nctx
Native code context. -
proc
Processor used by this converter. -
regNormalBitsize
protected int regNormalBitsizeStandard register size, in bits. -
doNotGenerateNops
protected boolean doNotGenerateNopsTrue to suppress generated NOP statements. -
methodConversionCountFailure
protected int methodConversionCountFailureNumber of routine conversions that failed. -
methodConversionCountSuccess
protected int methodConversionCountSuccessNumber of routine conversions that completed successfully. -
ctx
Per-routine data - works because convert() is not re-entrant (same found in X86ConvXxx helper classes).
Should be set before converting a routine, and reset to null after it's done. -
parameterRegistersForAllCC
Parameter registers for all calling conventions, using native register ids. -
spoiledRegistersForAllCC
Spoiled registers for all calling conventions, using native register ids.
-
-
Constructor Details
-
AbstractConverter
Create a converter for a processor.- Parameters:
proc- processor
-
AbstractConverter
Create a converter for a processor and register bitsize.- Parameters:
proc- processorregisterBitsize- general-purpose register bitsize
-
AbstractConverter
Create a converter for a processor, register bitsize, and address bitsize.- Parameters:
proc- processorregisterBitsize- general-purpose register bitsizeaddressBitsize- address bitsize
-
AbstractConverter
Create a converter for a native context.- Parameters:
nctx- native context
-
-
Method Details
-
initialize
public void initialize()Description copied from interface:IEConverterThis method is called by the owner decompiler after the principal components of the lower-level code unit have been initialized. Initialization requiring, e.g. access to the type manager, should be performed here instead of within the constructor.- Specified by:
initializein interfaceIEConverter<InsnType extends IInstruction>
-
setNativeContext
Set the native context used by this converter.- Parameters:
nctx- native context
-
getNativeContext
Description copied from interface:IEConverterRetrieve the native code context that this converter should use.- Specified by:
getNativeContextin interfaceIEConverter<InsnType extends IInstruction>- Returns:
- never null
-
getGlobalContext
Description copied from interface:IEConverterRetrieve the global program context. There is a single global context per decompiler, common to allroutine contexts.- Specified by:
getGlobalContextin interfaceIEConverter<InsnType extends IInstruction>- Returns:
- the global context
-
setDoNotGenerateNops
public void setDoNotGenerateNops(boolean doNotGenerateNops) Set whether generated NOP statements should be suppressed.- Parameters:
doNotGenerateNops- true to suppress generated NOP statements
-
isDoNotGenerateNops
public boolean isDoNotGenerateNops()Determine whether generated NOP statements are suppressed.- Returns:
- true if generated NOP statements are suppressed
-
setDecompiler
Reserved.- Parameters:
decompiler- owning decompiler context
-
getDecompiler
Description copied from interface:IEConverterRetrieve a reference to the decompiler managing this converter.- Specified by:
getDecompilerin interfaceIEConverter<InsnType extends IInstruction>- Returns:
- a reference to a decompiler (likely, a
INativeDecompilerUnit), or null
-
insertOptionalEntryPointTrampoline
protected final boolean insertOptionalEntryPointTrampoline(IERoutineContext ctx, List<IEStatement> irlist) For native routines that have their entry point in-the-middle (i.e., not at their lowest address), insert a syntheticIEJumpas the first instruction of the converted method.That ensures that native routines that have their entry-point in the middle of their code can be converted to IR routines with an entry-point always set to offset 0 (the beginning of the IR code). The reason is that this helps with graph manipulation passes that come later on, in the AST phases.
- Parameters:
ctx- translation contextirlist- the current list of converted IR statements, which should be empty when this method is called- Returns:
- true if a trampoline was inserted, false if it was not needed (and therefore, not inserted)
-
getAddressBitsize
public int getAddressBitsize()The default implementation returns the size of the program counter.- Specified by:
getAddressBitsizein interfaceIEConverter<InsnType extends IInstruction>- Returns:
- the native address size, in bits
-
getRegisterBitsize
public int getRegisterBitsize()The default implementation returns the address bitsize.- Specified by:
getRegisterBitsizein interfaceIEConverter<InsnType extends IInstruction>- Returns:
- the general-purpose register size, in bits
-
getStackSlotSize
public int getStackSlotSize()Description copied from interface:IEConverterGet the size of a standard slot on the stack, in bytes.- Specified by:
getStackSlotSizein interfaceIEConverter<InsnType extends IInstruction>- Returns:
- the stack slot size, in bytes
-
getWildcardTypeManagerDefaultResolutionGroup
The default implementation returnsIWildcardType.Group.INTEGER.- Specified by:
getWildcardTypeManagerDefaultResolutionGroupin interfaceIEConverter<InsnType extends IInstruction>- Returns:
- the default wildcard type resolution group
-
getRegister
Description copied from interface:IEConverterRetrieve anIEVar-register by its name, without conversion location information.- Specified by:
getRegisterin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
name- register name- Returns:
- the register expression, or null if no such register exists
-
getRegister
The default implementation forwards toIEGlobalContext.getVariableByName(String).- Specified by:
getRegisterin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
name- register nameloc- optional IR statement location at which the conversion is taking place- Returns:
- the register expression, or null if no such register exists
-
getRegisterVariableFromNativeRegisterId
Description copied from interface:IEConverterSeeIEConverter.getRegisterVariableFromNativeRegisterId(long, ELocation). No location provided- Specified by:
getRegisterVariableFromNativeRegisterIdin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
nativeRegId- native register id or number- Returns:
- a global
IEVar-register
-
getRegisterVariableFromNativeRegisterId
The default implementation attempts to resolve the native register id or number by querying the associated processor's register bank layout. It throws if the resolution fails.- Specified by:
getRegisterVariableFromNativeRegisterIdin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
nativeRegId- a native register id, used by theIProcessorthat this converter is relying on; the id may be a full id, that is, one supported byIInstructionOperandRegisterBased.getRegisterName(long), or a short-form of it (eg, the default X86 Processor module uses short-form 0 for the eAX register, that is the first GP register whose size matches the current processor mode).loc- optional IR statement location at which the conversion is taking place- Returns:
- a global
IEVar-register
-
getNativeRegisterIdFromRegisterVariable
The default implementation attempts to resolve the register variable by querying the associated processor's register bank layout. It throws if the resolution fails.- Specified by:
getNativeRegisterIdFromRegisterVariablein interfaceIEConverter<InsnType extends IInstruction>- Parameters:
regVar- a globalIEVar-registershortForm- if true the value provided does not contain the converter-specific information present in the long form (used in particular byIInstructionOperandRegisterBased.getRegisterName(long)), otherwise it is the long form- Returns:
- a native register id
-
getNativeRegisterIdFromRegisterVariable
Description copied from interface:IEConverter- Specified by:
getNativeRegisterIdFromRegisterVariablein interfaceIEConverter<InsnType extends IInstruction>- Parameters:
regVar- a globalIEVar-register- Returns:
- a native register id
-
getSlicedRegisterName
Description copied from interface:IEConverterGet the name of the slice of a physical register. The slice name may be an official name or a convenience name decided by the converter.- Specified by:
getSlicedRegisterNamein interfaceIEConverter<InsnType extends IInstruction>- Parameters:
registerName- full name of a physical registerbitstart- slice start bitbitend- slice end bit- Returns:
- null if the slice does not have a particular name
-
setCurrentContext
Set the current routine conversion context used by helper converter classes.- Parameters:
ctx- current routine context
-
preRoutineConversion
protected void preRoutineConversion(INativeMethodItem routine, IERoutineContext ctx, List<IEStatement> irlist) Executed byconvertbefore converting the blocks. The default implementation simply callsinsertOptionalEntryPointTrampoline(IERoutineContext, List).- Parameters:
routine- native routine being convertedctx- routine conversion contextirlist- current list of converted IR statements
-
postRoutineConversion
Executed byconvertafter converting the blocks. The default implementation does nothing.- Parameters:
routine- native routine being convertedctx- routine conversion context
-
convert
Convert the blocks of the native routine's CFG after the other. The blocks' edges are not considered.The default implementation works as follows:
- call
preRoutineConversion - for each block:
- call
preBlockConversion - call
convertBlock - call
postBlockConversion
- call
- call
postRoutineConversiononce
- Specified by:
convertin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
routine- the routine to be converted; must have adatadefinition- Returns:
- the converted IR routine context
- call
-
preBlockConversion
protected BasicBlock<InsnType> preBlockConversion(CFG<InsnType> cfg, BasicBlock<InsnType> b, List<IEStatement> interlist) This method is called beforeconvertBlock(BasicBlock, List)is called. It can be overridden. Sub-classes do not need to call the default implementation. The default implementation returns the provided input block.- Parameters:
cfg- the CFGb- block about to be convertedinterlist- destination list for converted IR statements- Returns:
- the provided input block or a new block
-
convertBlock
Convert a basic block. This method may be overridden. The lower-level addresses are set onIEStatementif they are not present.- Parameters:
b- block to be convertedinterlist- output list of converted IR statements
-
convertInstruction
This method is called byconvertBlock(BasicBlock, List). If this method is not overridden, the methodsconvertInstructionFirstChance(ConverterInstructionEntry, String, boolean)andconvertInstructionLastChance(ConverterInstructionEntry)must be implemented. If this method is overridden, the two aforementioned methods can be ignored.- Parameters:
e- instruction entry to convert
-
convertInstructionFirstChance
protected boolean convertInstructionFirstChance(ConverterInstructionEntry<InsnType> e, String mn, boolean allowRecurse) Attempt a first-chance instruction conversion.- Parameters:
e- instruction entry to convertmn- instruction mnemonicallowRecurse- true if recursive conversion is allowed- Returns:
- true if the instruction was converted
-
convertInstructionLastChance
Attempt a last-chance instruction conversion.- Parameters:
e- instruction entry to convert- Returns:
- true if the instruction was converted
-
convertOperand
This method is called by theAbstractConverter<InsnType extends IInstruction>.com.pnfsoftware.jeb.core.units.code.asm.decompiler.AbstractConverter.AutoConverter. If the auto-converter is used, it must be implemented.- Parameters:
insnAddress- native instruction addressinsn- native instructionopndIndex- operand index- Returns:
- converted operand expression
-
attemptConversionByExtension
Attempt instruction conversion through registered extensions.- Parameters:
e- instruction entry to convert- Returns:
- true if an extension converted the instruction
-
attemptCallInliningByExtension
protected boolean attemptCallInliningByExtension(ConverterInstructionEntry<InsnType> e, long target) Attempt call inlining through registered extensions.- Parameters:
e- instruction entry to converttarget- call target address- Returns:
- true if an extension inlined the call
-
postBlockConversion
protected void postBlockConversion(CFG<InsnType> cfg, BasicBlock<InsnType> b, List<IEStatement> interlist, int cnt) This method is called afterconvertBlock(BasicBlock, List)is called. The default implementation sanitizes fake calls, i.e. it switches call-to-sub-PC-assigns to regular PC-assigns if the underlying analyzer detected that what looked like a call-to-sub is not.- Parameters:
cfg- the native CFG of the method being convertedb- the native basic block that was just convertedinterlist- the current list of IR statements for the routine (not only for the provided block!); the last IR statements in that list are those of the routine that was just convertedcnt- the number of IR statements that correspond to the conversion of the provided native block
-
convertBlockForTest
Reserved for testing.- Parameters:
b- native basic block to convert- Returns:
- converted IR statements
-
createStackMemoryAccess
The default implementation assumes a segment-less memory model. (The EMem segment component is set to null.)- Specified by:
createStackMemoryAccessin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
address- stack memory address expressionbitsize- access size, in bits- Returns:
- a stack memory access expression
-
sanitizeNativeAddress
public long sanitizeNativeAddress(long address) The default implementation truncates the provided value to accomodategetAddressBitsize().- Specified by:
sanitizeNativeAddressin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
address- a native address- Returns:
- the normalized native address
-
isSegmentEMemReferencingPrimaryMemory
The default implementation returns true: by default, all EMem are assumed to reference bytes in the primary VM.- Specified by:
isSegmentEMemReferencingPrimaryMemoryin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
e- memory expression to examine- Returns:
- 3-state result: true/false, null= cannot determine
-
getPrototypeHandler
Description copied from interface:IEConverterCreate an instance of a prototype handler.- Specified by:
getPrototypeHandlerin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
ctx- routine context- Returns:
- a prototype handler
-
canCreateCalls
public boolean canCreateCalls()The default implementation returns true.- Specified by:
canCreateCallsin interfaceIEConverter<InsnType extends IInstruction>- Returns:
- true if the pipeline may create additional calls
-
convertReturnLocation
Description copied from interface:IEConverterGiven a prototype, determine the IR expression representing the return address location of a call to a method of said prototype.Used by
IECall.- Specified by:
convertReturnLocationin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
ctx- routine contextprototype- call prototype- Returns:
- the return address location expression, or null if unavailable
-
convertReturnExpressions
public List<IEGeneric> convertReturnExpressions(IERoutineContext ctx, IWildcardPrototype prototype, INativeMethodItem targetRoutine, List<IWildcardType> varArgTypes, List<IEGeneric> outSpoiled) Description copied from interface:IEConverterGiven a prototype, determine the list of IR expressions representing the output expressions. Spoiled register expressions can also be returned.Used by
IECall.- Specified by:
convertReturnExpressionsin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
ctx- routine contextprototype- call prototypetargetRoutine- optional target routinevarArgTypes- optional variable argument typesoutSpoiled- optional sink for spoiled register expressions- Returns:
- a list of non-copy IEVars holding storage of output expressions
-
convertParameterExpressions
public List<IEGeneric> convertParameterExpressions(IERoutineContext ctx, IWildcardPrototype prototype, INativeMethodItem targetRoutine, List<IWildcardType> varArgTypes) Description copied from interface:IEConverterGiven a prototype, determine the list of IR expressions representing the input expressions (would also contain implicitly read registers).Used by
IECall.- Specified by:
convertParameterExpressionsin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
ctx- routine contextprototype- mandatory prototypetargetRoutine- optionalvarArgTypes- optional- Returns:
- a list of non-copy IEVars holding storage of input expressions
-
getInputVariableByIndex
The default implementation returns null.- Specified by:
getInputVariableByIndexin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
ctx- routine contexti- input variable index- Returns:
- the input variable, or null if unavailable
-
getOutputVariableByIndex
The default implementation returns null.- Specified by:
getOutputVariableByIndexin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
ctx- routine contexti- output variable index- Returns:
- the output variable, or null if unavailable
-
determineStackPointerDeltaAfterIRCall
public Integer determineStackPointerDeltaAfterIRCall(IWildcardPrototype prototype, List<IWildcardType> varArgTypes) Description copied from interface:IEConverterDetermine the stack pointer delta (in bytes) after theIECallexecuted and returned.
Careful: "IR-Call" and the "native-call" may not have the same structure; it depends on how the conversion of "native-call" is implemented, and therefore is converter-dependent. The SP delta returned by this method is the one after an execution overIECall.Used by
IECall.- Specified by:
determineStackPointerDeltaAfterIRCallin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
prototype- call prototypevarArgTypes- optional variable argument types- Returns:
- null on error
-
determineStackBytesUsedByCall
public Integer determineStackBytesUsedByCall(IWildcardPrototype prototype, List<IWildcardType> varArgTypes) Description copied from interface:IEConverterDetermine the amount of bytes that were pushed on the stack before calling the routine with the provided prototype and optional additional slots. That should include all routine parameters pushed on the stack as well as the return address bytes as well, if it is located on the stack (per the provided calling convention).Used by
IECall.- Specified by:
determineStackBytesUsedByCallin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
prototype- call prototypevarArgTypes- optional variable argument types- Returns:
- the number of stack bytes used by the call, or null on error
-
determineStackPointerDeltaFromSimulation
The default implementation returns null.- Specified by:
determineStackPointerDeltaFromSimulationin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
simuinfo- state of IR execution; PC is assumed to be on the target routine entry-point- Returns:
- null on error, otherwise, the SP delta after the routine has executed and returned to the caller
-
getDefaultBranchToRoutineSideEffects
The default implementation returns a basic branch detail object specifying nothing (no def, no use, no spoils, etc.).Converters should override this method.
- Specified by:
getDefaultBranchToRoutineSideEffectsin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
optionalRoutine- the optional target routine; if provided, the implementation may use that information to provide more accurate results- Returns:
- a branch details object (never null)
-
buildFailsafePrototype
The default implementation provides a no-arg/no-return prototype: "void __defaultCC ()".Custom implementations may return something more suitable to a given architecture
- Specified by:
buildFailsafePrototypein interfaceIEConverter<InsnType extends IInstruction>- Parameters:
ctx- routine for which a failsafe prototype is to be generatedstm- optional statement calling into the routine- Returns:
- a prototype object, should never be null
-
insertReturns
Description copied from interface:IEConverterThis method introducesIEReturnstatements into the IR. Must be performed only after prototype discovery is completed.Data chains: not used, may be invalidated; in the latter case, this method is responsible for recalculating them.
- Specified by:
insertReturnsin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
ctx- the routine context- Returns:
- the number of insertions performed
-
normalizeBranchingExpression
public IEGeneric normalizeBranchingExpression(IDFA<IEStatement> dfa, BasicBlock<IEStatement> b, IEGeneric target, IEGeneric expectedTarget) Description copied from interface:IEConverterNormalize a branching expression.- Specified by:
normalizeBranchingExpressionin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
dfa- a DFA objectb- basic block whose last instruction is a branching statement (e.g. EAssign to PC, ECall, EJumpFar, etc.)target- the callsite of the branching statement targeted by the basic block `b`expectedTarget- optional- Returns:
- the normalized branching expression
-
isPCRightValueCompatibleReturnValue
protected final boolean isPCRightValueCompatibleReturnValue(IDFA<IEStatement> dfa, BasicBlock<IEStatement> b, IEGeneric PCRightVal, IEGeneric expectedReturnAddress) Can be overridden by implementors when complex return expression matching is needed.- Parameters:
dfa- current DFAb-BasicBlockcontaining the PC assign instruction (last one of the block)PCRightVal- right Value of the PC assign instructionexpectedReturnAddress- expected return expression (should be an IEVar) per the selected calling convention- Returns:
- true if right value is equivalent to a return instruction
-
defaultPCConversion
Description copied from interface:IEConverterConvert PC-assignment toIEJumpFarstatements. This method is a fail-safe converter for PC-assignments, and should be called as late as possible in the IR conversion phases. After executing this method, the CFG should no longer contain PC-assignments.- Specified by:
defaultPCConversionin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
ctx- routine context- Returns:
- the number of PC-conversions performed
-
resolveCustomCalls
Description copied from interface:IEConverterImplementations should be aggressive and fast: calls to this method should always be enclosed in a try-catch.TODO: MOVE to the CBDU
- Specified by:
resolveCustomCallsin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
ctx- routine context- Returns:
- true if custom call resolution changed the routine
-
initializeStateRegisters
This method initializes and sets all physical registers declared by this converter to 0, except for the ones possibly used as arguments that are kept undefined (seeisPossibleParameterRegisterForProcessorCallingConventions(long)). After this is done,customInitStateRegisters(EState, Long)is invoked.- Specified by:
initializeStateRegistersin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
state- input state to be initializedoptionalNativeProgramCounter- optional current native PC
-
customInitStateRegisters
The default implementation does nothing.- Specified by:
customInitStateRegistersin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
state- input state to customizeoptionalNativeProgramCounter- optional current native PC
-
isPossibleParameterRegisterForProcessorCallingConventions
public boolean isPossibleParameterRegisterForProcessorCallingConventions(long nativeRegId) Check if a native register id corresponds to a register that can possibly be used as a routine parameter on this processor.To do so, the given id is compared against all input registers for all known calling conventions for the current processor. In particular, this method does not rely on the routine prototype and calling convention being defined, and can therefore be used early on during decompilation.
- Parameters:
nativeRegId- native register id- Returns:
- true if the provided register id corresponds to a register that can be used as a parameter, false otherwise
-
isPossibleSpoiledRegistersForProcessorCallingConventions
public boolean isPossibleSpoiledRegistersForProcessorCallingConventions(long nativeRegId) Check if a native register id corresponds to a physical register that can possibly be spoiled by a routine call on this processor.To do so, the given id is compared against all spoiled registers for all known calling conventions for the current processor. In particular, this method does not rely on the routine prototype and calling convention being defined, and can therefore be used early on during decompilation.
- Parameters:
nativeRegId- native register id- Returns:
- true if the provided a native register id is a register that can be spoiled by a routine call, false otherwise
-
getStateProcessorMode
Description copied from interface:IEConverterRetrieve the current processor mode relative to the providedEState. Refer toIProcessor.getMode()for the semantics of mode.- Specified by:
getStateProcessorModein interfaceIEConverter<InsnType extends IInstruction>- Parameters:
state- optional IR state- Returns:
- the processor mode (most often 8, 16, 32 or 64)
-
getReturnAddressRegister
The default implementation considers that there is no specific Return Address Register. Override if one exists.- Specified by:
getReturnAddressRegisterin interfaceIEConverter<InsnType extends IInstruction>- Returns:
- can return null value if Processor does not use Return Address Register
-
getGPRegister
Description copied from interface:IEConverterRetrieve the IR variable object that represents the General Purpose register.- Specified by:
getGPRegisterin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
index- register index (eg 0 for x86 eax, ARM R0, Arm64 X0...)- Returns:
- the general-purpose register variable, or null if unavailable
-
getFPRegister
Description copied from interface:IEConverterRetrieve the IR variable object that represents the Floating-point register.- Specified by:
getFPRegisterin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
index- register index- Returns:
- the floating-point register variable, or null if unavailable
-
getTempRegister
Description copied from interface:IEConverterRetrieve a temporary register variable.- Specified by:
getTempRegisterin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
index- temporary register index- Returns:
- the temporary register variable, or null if unavailable
-
formatStatistics
The default implementation formats basic details about the number of converted methods.- Specified by:
formatStatisticsin interfaceIEConverter<InsnType extends IInstruction>- Returns:
- formatted converter statistics
-
generateASTForUntranslatedIR
public ICStatement generateASTForUntranslatedIR(IEUntranslatedInstruction insn, IERoutineContext ectx, ICMethod cctx) The default implementation returns null.- Specified by:
generateASTForUntranslatedIRin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
insn- untranslated IR instructionectx- IR routine contextcctx- C method context- Returns:
- the generated C statement, or null to use the default generator
-
evaluateUntranslatedIR
public IEImm evaluateUntranslatedIR(IEUntranslatedInstruction insn, IERoutineContext ectx, EState state) The default implementation returns null.- Specified by:
evaluateUntranslatedIRin interfaceIEConverter<InsnType extends IInstruction>- Parameters:
insn- untranslated IR instructionectx- IR routine contextstate- current evaluation state- Returns:
- the evaluated immediate value, or null if no value can be produced
-
autoConvert
Apply an auto-conversion semantic description to an instruction entry.- Parameters:
e- instruction entry to convertacs- auto-conversion semantic description- Returns:
- true if conversion succeeded
-