Class AbstractConverter<InsnType extends IInstruction>

java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.decompiler.AbstractConverter<InsnType>
Type Parameters:
InsnType - native instruction type handled by this converter
All Implemented Interfaces:
IEConverter<InsnType>

@Ser public abstract class AbstractConverter<InsnType extends IInstruction> extends Object implements IEConverter<InsnType>
Skeleton class for code converters. A converter is implemented as part of a decompiler plugin. It provides routines to translate low-level machine code to a gendec intermediate representation.
  • Field Details

    • gCtx

      protected IEGlobalContext gCtx
      Global IR context.
    • nctx

      protected INativeContext nctx
      Native code context.
    • proc

      protected IProcessor<InsnType extends IInstruction> proc
      Processor used by this converter.
    • regNormalBitsize

      protected int regNormalBitsize
      Standard register size, in bits.
    • doNotGenerateNops

      protected boolean doNotGenerateNops
      True to suppress generated NOP statements.
    • methodConversionCountFailure

      protected int methodConversionCountFailure
      Number of routine conversions that failed.
    • methodConversionCountSuccess

      protected int methodConversionCountSuccess
      Number of routine conversions that completed successfully.
    • ctx

      protected IERoutineContext 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

      protected Set<Long> parameterRegistersForAllCC
      Parameter registers for all calling conventions, using native register ids.
    • spoiledRegistersForAllCC

      protected Set<Long> spoiledRegistersForAllCC
      Spoiled registers for all calling conventions, using native register ids.
  • Constructor Details

    • AbstractConverter

      protected AbstractConverter(IProcessor<InsnType> proc)
      Create a converter for a processor.
      Parameters:
      proc - processor
    • AbstractConverter

      protected AbstractConverter(IProcessor<InsnType> proc, int registerBitsize)
      Create a converter for a processor and register bitsize.
      Parameters:
      proc - processor
      registerBitsize - general-purpose register bitsize
    • AbstractConverter

      protected AbstractConverter(IProcessor<InsnType> proc, int registerBitsize, int addressBitsize)
      Create a converter for a processor, register bitsize, and address bitsize.
      Parameters:
      proc - processor
      registerBitsize - general-purpose register bitsize
      addressBitsize - address bitsize
    • AbstractConverter

      protected AbstractConverter(INativeContext nctx)
      Create a converter for a native context.
      Parameters:
      nctx - native context
  • Method Details

    • initialize

      public void initialize()
      Description copied from interface: IEConverter
      This 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:
      initialize in interface IEConverter<InsnType extends IInstruction>
    • setNativeContext

      public void setNativeContext(INativeContext nctx)
      Set the native context used by this converter.
      Parameters:
      nctx - native context
    • getNativeContext

      public INativeContext getNativeContext()
      Description copied from interface: IEConverter
      Retrieve the native code context that this converter should use.
      Specified by:
      getNativeContext in interface IEConverter<InsnType extends IInstruction>
      Returns:
      never null
    • getGlobalContext

      public IEGlobalContext getGlobalContext()
      Description copied from interface: IEConverter
      Retrieve the global program context. There is a single global context per decompiler, common to all routine contexts.
      Specified by:
      getGlobalContext in interface IEConverter<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

      public void setDecompiler(INativeDecompilerContext decompiler)
      Reserved.
      Parameters:
      decompiler - owning decompiler context
    • getDecompiler

      public INativeDecompilerContext getDecompiler()
      Description copied from interface: IEConverter
      Retrieve a reference to the decompiler managing this converter.
      Specified by:
      getDecompiler in interface IEConverter<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 synthetic IEJump as 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 context
      irlist - 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:
      getAddressBitsize in interface IEConverter<InsnType extends IInstruction>
      Returns:
      the native address size, in bits
    • getRegisterBitsize

      public int getRegisterBitsize()
      The default implementation returns the address bitsize.
      Specified by:
      getRegisterBitsize in interface IEConverter<InsnType extends IInstruction>
      Returns:
      the general-purpose register size, in bits
    • getStackSlotSize

      public int getStackSlotSize()
      Description copied from interface: IEConverter
      Get the size of a standard slot on the stack, in bytes.
      Specified by:
      getStackSlotSize in interface IEConverter<InsnType extends IInstruction>
      Returns:
      the stack slot size, in bytes
    • getWildcardTypeManagerDefaultResolutionGroup

      public IWildcardType.Group getWildcardTypeManagerDefaultResolutionGroup()
      The default implementation returns IWildcardType.Group.INTEGER.
      Specified by:
      getWildcardTypeManagerDefaultResolutionGroup in interface IEConverter<InsnType extends IInstruction>
      Returns:
      the default wildcard type resolution group
    • getRegister

      public final IEGeneric getRegister(String name)
      Description copied from interface: IEConverter
      Retrieve an IEVar-register by its name, without conversion location information.
      Specified by:
      getRegister in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      name - register name
      Returns:
      the register expression, or null if no such register exists
    • getRegister

      public IEGeneric getRegister(String name, ELocation loc)
      The default implementation forwards to IEGlobalContext.getVariableByName(String).
      Specified by:
      getRegister in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      name - register name
      loc - optional IR statement location at which the conversion is taking place
      Returns:
      the register expression, or null if no such register exists
    • getRegisterVariableFromNativeRegisterId

      public final IEGeneric getRegisterVariableFromNativeRegisterId(long nativeRegId)
      Description copied from interface: IEConverter
      Specified by:
      getRegisterVariableFromNativeRegisterId in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      nativeRegId - native register id or number
      Returns:
      a global IEVar-register
    • getRegisterVariableFromNativeRegisterId

      public IEGeneric 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. It throws if the resolution fails.
      Specified by:
      getRegisterVariableFromNativeRegisterId in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      nativeRegId - a native register id, used by the IProcessor that this converter is relying on; the id may be a full id, that is, one supported by IInstructionOperandRegisterBased.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

      public long getNativeRegisterIdFromRegisterVariable(IEVar regVar, boolean shortForm)
      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:
      getNativeRegisterIdFromRegisterVariable in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      regVar - a global IEVar-register
      shortForm - if true the value provided does not contain the converter-specific information present in the long form (used in particular by IInstructionOperandRegisterBased.getRegisterName(long)), otherwise it is the long form
      Returns:
      a native register id
    • getNativeRegisterIdFromRegisterVariable

      public final long getNativeRegisterIdFromRegisterVariable(IEVar regVar)
      Description copied from interface: IEConverter
      Specified by:
      getNativeRegisterIdFromRegisterVariable in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      regVar - a global IEVar-register
      Returns:
      a native register id
    • getSlicedRegisterName

      public String getSlicedRegisterName(String registerName, int bitstart, int bitend)
      Description copied from interface: IEConverter
      Get 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:
      getSlicedRegisterName in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      registerName - full name of a physical register
      bitstart - slice start bit
      bitend - slice end bit
      Returns:
      null if the slice does not have a particular name
    • setCurrentContext

      public void setCurrentContext(IERoutineContext ctx)
      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 by convert before converting the blocks. The default implementation simply calls insertOptionalEntryPointTrampoline(IERoutineContext, List).
      Parameters:
      routine - native routine being converted
      ctx - routine conversion context
      irlist - current list of converted IR statements
    • postRoutineConversion

      protected void postRoutineConversion(INativeMethodItem routine, IERoutineContext ctx)
      Executed by convert after converting the blocks. The default implementation does nothing.
      Parameters:
      routine - native routine being converted
      ctx - routine conversion context
    • convert

      public IERoutineContext convert(INativeMethodItem routine)
      Convert the blocks of the native routine's CFG after the other. The blocks' edges are not considered.

      The default implementation works as follows:

      It is recommended to use the default implementation.
      Specified by:
      convert in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      routine - the routine to be converted; must have a data definition
      Returns:
      the converted IR routine context
    • preBlockConversion

      protected BasicBlock<InsnType> preBlockConversion(CFG<InsnType> cfg, BasicBlock<InsnType> b, List<IEStatement> interlist)
      This method is called before convertBlock(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 CFG
      b - block about to be converted
      interlist - destination list for converted IR statements
      Returns:
      the provided input block or a new block
    • convertBlock

      protected void convertBlock(BasicBlock<InsnType> b, List<IEStatement> interlist)
      Convert a basic block. This method may be overridden. The lower-level addresses are set on IEStatement if they are not present.
      Parameters:
      b - block to be converted
      interlist - output list of converted IR statements
    • convertInstruction

      public void convertInstruction(ConverterInstructionEntry<InsnType> e)
      This method is called by convertBlock(BasicBlock, List). If this method is not overridden, the methods convertInstructionFirstChance(ConverterInstructionEntry, String, boolean) and convertInstructionLastChance(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 convert
      mn - instruction mnemonic
      allowRecurse - true if recursive conversion is allowed
      Returns:
      true if the instruction was converted
    • convertInstructionLastChance

      protected boolean convertInstructionLastChance(ConverterInstructionEntry<InsnType> e)
      Attempt a last-chance instruction conversion.
      Parameters:
      e - instruction entry to convert
      Returns:
      true if the instruction was converted
    • convertOperand

      protected IEGeneric convertOperand(long insnAddress, InsnType insn, int opndIndex)
      This method is called by the AbstractConverter<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 address
      insn - native instruction
      opndIndex - operand index
      Returns:
      converted operand expression
    • attemptConversionByExtension

      protected boolean attemptConversionByExtension(ConverterInstructionEntry<InsnType> e)
      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 convert
      target - 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 after convertBlock(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 converted
      b - the native basic block that was just converted
      interlist - 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 converted
      cnt - the number of IR statements that correspond to the conversion of the provided native block
    • convertBlockForTest

      public final List<IEStatement> convertBlockForTest(BasicBlock<InsnType> b)
      Reserved for testing.
      Parameters:
      b - native basic block to convert
      Returns:
      converted IR statements
    • createStackMemoryAccess

      public IEMem createStackMemoryAccess(IEGeneric address, int bitsize)
      The default implementation assumes a segment-less memory model. (The EMem segment component is set to null.)
      Specified by:
      createStackMemoryAccess in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      address - stack memory address expression
      bitsize - access size, in bits
      Returns:
      a stack memory access expression
    • sanitizeNativeAddress

      public long sanitizeNativeAddress(long address)
      The default implementation truncates the provided value to accomodate getAddressBitsize().
      Specified by:
      sanitizeNativeAddress in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      address - a native address
      Returns:
      the normalized native address
    • isSegmentEMemReferencingPrimaryMemory

      public Boolean isSegmentEMemReferencingPrimaryMemory(IEMem e)
      The default implementation returns true: by default, all EMem are assumed to reference bytes in the primary VM.
      Specified by:
      isSegmentEMemReferencingPrimaryMemory in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      e - memory expression to examine
      Returns:
      3-state result: true/false, null= cannot determine
    • getPrototypeHandler

      public IEPrototypeHandler getPrototypeHandler(IERoutineContext ctx)
      Description copied from interface: IEConverter
      Create an instance of a prototype handler.
      Specified by:
      getPrototypeHandler in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      ctx - routine context
      Returns:
      a prototype handler
    • canCreateCalls

      public boolean canCreateCalls()
      The default implementation returns true.
      Specified by:
      canCreateCalls in interface IEConverter<InsnType extends IInstruction>
      Returns:
      true if the pipeline may create additional calls
    • convertReturnLocation

      public IEGeneric convertReturnLocation(IERoutineContext ctx, IWildcardPrototype prototype)
      Description copied from interface: IEConverter
      Given 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:
      convertReturnLocation in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      ctx - routine context
      prototype - 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: IEConverter
      Given a prototype, determine the list of IR expressions representing the output expressions. Spoiled register expressions can also be returned.

      Used by IECall.

      Specified by:
      convertReturnExpressions in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      ctx - routine context
      prototype - call prototype
      targetRoutine - optional target routine
      varArgTypes - optional variable argument types
      outSpoiled - 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: IEConverter
      Given a prototype, determine the list of IR expressions representing the input expressions (would also contain implicitly read registers).

      Used by IECall.

      Specified by:
      convertParameterExpressions in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      ctx - routine context
      prototype - mandatory prototype
      targetRoutine - optional
      varArgTypes - optional
      Returns:
      a list of non-copy IEVars holding storage of input expressions
    • getInputVariableByIndex

      public IEVar getInputVariableByIndex(IERoutineContext ctx, int i)
      The default implementation returns null.
      Specified by:
      getInputVariableByIndex in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      ctx - routine context
      i - input variable index
      Returns:
      the input variable, or null if unavailable
    • getOutputVariableByIndex

      public IEVar getOutputVariableByIndex(IERoutineContext ctx, int i)
      The default implementation returns null.
      Specified by:
      getOutputVariableByIndex in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      ctx - routine context
      i - output variable index
      Returns:
      the output variable, or null if unavailable
    • determineStackPointerDeltaAfterIRCall

      public Integer determineStackPointerDeltaAfterIRCall(IWildcardPrototype prototype, List<IWildcardType> varArgTypes)
      Description copied from interface: IEConverter
      Determine the stack pointer delta (in bytes) after the IECall executed 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 over IECall.

      Used by IECall.

      Specified by:
      determineStackPointerDeltaAfterIRCall in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      prototype - call prototype
      varArgTypes - optional variable argument types
      Returns:
      null on error
    • determineStackBytesUsedByCall

      public Integer determineStackBytesUsedByCall(IWildcardPrototype prototype, List<IWildcardType> varArgTypes)
      Description copied from interface: IEConverter
      Determine 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:
      determineStackBytesUsedByCall in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      prototype - call prototype
      varArgTypes - optional variable argument types
      Returns:
      the number of stack bytes used by the call, or null on error
    • determineStackPointerDeltaFromSimulation

      public Integer determineStackPointerDeltaFromSimulation(SimulationPointInformation simuinfo)
      The default implementation returns null.
      Specified by:
      determineStackPointerDeltaFromSimulation in interface IEConverter<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

      public IEBranchDetails getDefaultBranchToRoutineSideEffects(INativeMethodItem optionalRoutine)
      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:
      getDefaultBranchToRoutineSideEffects in interface IEConverter<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

      public IWildcardPrototype buildFailsafePrototype(IERoutineContext ctx, IEStatement stm)
      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:
      buildFailsafePrototype in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      ctx - routine for which a failsafe prototype is to be generated
      stm - optional statement calling into the routine
      Returns:
      a prototype object, should never be null
    • insertReturns

      public int insertReturns(IERoutineContext ctx)
      Description copied from interface: IEConverter
      This method introduces IEReturn statements 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:
      insertReturns in interface IEConverter<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: IEConverter
      Normalize a branching expression.
      Specified by:
      normalizeBranchingExpression in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      dfa - a DFA object
      b - 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 DFA
      b - BasicBlock containing the PC assign instruction (last one of the block)
      PCRightVal - right Value of the PC assign instruction
      expectedReturnAddress - expected return expression (should be an IEVar) per the selected calling convention
      Returns:
      true if right value is equivalent to a return instruction
    • defaultPCConversion

      public int defaultPCConversion(IERoutineContext ctx)
      Description copied from interface: IEConverter
      Convert PC-assignment to IEJumpFar statements. 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:
      defaultPCConversion in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      ctx - routine context
      Returns:
      the number of PC-conversions performed
    • resolveCustomCalls

      public boolean resolveCustomCalls(IERoutineContext ctx)
      Description copied from interface: IEConverter
      Implementations should be aggressive and fast: calls to this method should always be enclosed in a try-catch.

      TODO: MOVE to the CBDU

      Specified by:
      resolveCustomCalls in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      ctx - routine context
      Returns:
      true if custom call resolution changed the routine
    • initializeStateRegisters

      public final void initializeStateRegisters(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 (see isPossibleParameterRegisterForProcessorCallingConventions(long)). After this is done, customInitStateRegisters(EState, Long) is invoked.
      Specified by:
      initializeStateRegisters in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      state - input state to be initialized
      optionalNativeProgramCounter - optional current native PC
    • customInitStateRegisters

      public void customInitStateRegisters(EState state, Long optionalNativeProgramCounter)
      The default implementation does nothing.
      Specified by:
      customInitStateRegisters in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      state - input state to customize
      optionalNativeProgramCounter - 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

      public int getStateProcessorMode(EState state)
      Description copied from interface: IEConverter
      Retrieve the current processor mode relative to the provided EState. Refer to IProcessor.getMode() for the semantics of mode.
      Specified by:
      getStateProcessorMode in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      state - optional IR state
      Returns:
      the processor mode (most often 8, 16, 32 or 64)
    • getReturnAddressRegister

      public IEVar getReturnAddressRegister()
      The default implementation considers that there is no specific Return Address Register. Override if one exists.
      Specified by:
      getReturnAddressRegister in interface IEConverter<InsnType extends IInstruction>
      Returns:
      can return null value if Processor does not use Return Address Register
    • getGPRegister

      public IEVar getGPRegister(int index)
      Description copied from interface: IEConverter
      Retrieve the IR variable object that represents the General Purpose register.
      Specified by:
      getGPRegister in interface IEConverter<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

      public IEVar getFPRegister(int index)
      Description copied from interface: IEConverter
      Retrieve the IR variable object that represents the Floating-point register.
      Specified by:
      getFPRegister in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      index - register index
      Returns:
      the floating-point register variable, or null if unavailable
    • getTempRegister

      public IEVar getTempRegister(int index)
      Description copied from interface: IEConverter
      Retrieve a temporary register variable.
      Specified by:
      getTempRegister in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      index - temporary register index
      Returns:
      the temporary register variable, or null if unavailable
    • formatStatistics

      public String formatStatistics()
      The default implementation formats basic details about the number of converted methods.
      Specified by:
      formatStatistics in interface IEConverter<InsnType extends IInstruction>
      Returns:
      formatted converter statistics
    • generateASTForUntranslatedIR

      public ICStatement generateASTForUntranslatedIR(IEUntranslatedInstruction insn, IERoutineContext ectx, ICMethod cctx)
      The default implementation returns null.
      Specified by:
      generateASTForUntranslatedIR in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      insn - untranslated IR instruction
      ectx - IR routine context
      cctx - 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:
      evaluateUntranslatedIR in interface IEConverter<InsnType extends IInstruction>
      Parameters:
      insn - untranslated IR instruction
      ectx - IR routine context
      state - current evaluation state
      Returns:
      the evaluated immediate value, or null if no value can be produced
    • autoConvert

      public final boolean autoConvert(ConverterInstructionEntry<InsnType> e, ACS acs)
      Apply an auto-conversion semantic description to an instruction entry.
      Parameters:
      e - instruction entry to convert
      acs - auto-conversion semantic description
      Returns:
      true if conversion succeeded