Class AddressableInstruction<InsnType extends IInstruction>

java.lang.Object
com.pnfsoftware.jeb.core.units.code.AddressableInstruction<InsnType>
All Implemented Interfaces:
IInstruction, ILocatedInstruction

@Ser public class AddressableInstruction<InsnType extends IInstruction> extends Object implements ILocatedInstruction
Decorator that makes address-less instructions addressable.
  • Constructor Details

    • AddressableInstruction

      public AddressableInstruction(long address, InsnType insn)
      Wrap an instruction and attach an address to it.
      Parameters:
      address - the address
      insn - the instruction
  • Method Details

    • getInstruction

      public InsnType getInstruction()
      Get the underlying instruction.
      Returns:
      the instruction
    • getOffset

      public long getOffset()
      Description copied from interface: ILocatedInstruction
      Get the instruction offset or address. The offset may be relative to a base, or absolute in the case of a memory address. The choice is up to the implementor.
      Specified by:
      getOffset in interface ILocatedInstruction
      Returns:
      the instruction offset/address
    • getProcessorMode

      public int getProcessorMode()
      Description copied from interface: IInstruction
      Get the mode the processor was in when it parsed and created this instruction. Refer to IProcessor MODE_xxx.
      Specified by:
      getProcessorMode in interface IInstruction
      Returns:
      the mode, 0 for none/default
    • getSize

      public int getSize()
      Description copied from interface: IInstruction
      Get the instruction size in bytes.
      Specified by:
      getSize in interface IInstruction
      Returns:
      the instruction size
    • getCode

      public byte[] getCode()
      Description copied from interface: IInstruction
      Get the binary code that makes up this instruction.
      Specified by:
      getCode in interface IInstruction
      Returns:
      an array of bytes, or null if the instruction is abstract
    • getPrefix

      public String getPrefix()
      Description copied from interface: IInstruction
      Get the instruction's optional prefix(es).
      Specified by:
      getPrefix in interface IInstruction
      Returns:
      the prefix (or prefix string list), null if none
    • getMnemonic

      public String getMnemonic()
      Description copied from interface: IInstruction
      The instruction mnemonic.
      Specified by:
      getMnemonic in interface IInstruction
      Returns:
    • getOperands

      public IInstructionOperand[] getOperands()
      Description copied from interface: IInstruction
      Get the list of operands for this instruction.
      Specified by:
      getOperands in interface IInstruction
      Returns:
      a list (possibly empty) of operands, or null if operands are not applicable to the instruction set
    • getBreakingFlow

      public IFlowInformation getBreakingFlow(long instructionAddress)
      Description copied from interface: IInstruction
      Determine if an instruction breaks the flow of execution.

      Examples: jump instructions, conditional jumps, return-to-caller instructions, etc. Sub-routine calls should not be regarded as flow-breakers by this method. Refer to getRoutineCall.

      Specified by:
      getBreakingFlow in interface IInstruction
      Parameters:
      instructionAddress - the address of the current instruction
      Returns:
      IFlowInformation.isBroken() is true if the instruction breaks the current flow of execution (sub-routine call instructions are excluded) , false otherwise; if true, IFlowInformation.getTargets() may be filled with potential addresses, and the first entry should be the fall-through instruction, if there is any
    • getBreakingFlow

      public IFlowInformation getBreakingFlow()
      Description copied from interface: ILocatedInstruction
      Determine if an instruction breaks the flow of execution. Examples: jump instructions, conditional jumps, return-to-caller instructions, etc. Sub-routine calls should not be regarded as flow-breakers by this method. Refer to getRoutineCall.
      Specified by:
      getBreakingFlow in interface ILocatedInstruction
      Returns:
      IFlowInformation.isBroken() is true if the instruction breaks the current flow of execution (sub-routine call instructions are excluded) , false otherwise; if true, IFlowInformation.getTargets() may be filled with potential addresses, and the first entry should be the fall-through instruction, if there is any
      See Also:
    • getRoutineCall

      public IFlowInformation getRoutineCall(long instructionAddress)
      Description copied from interface: IInstruction
      Determine if an instruction branches to (or calls into) a sub-routine.

      Under normal circumstances, those instructions save the return address (e.g., on a stack or in a register). Therefore, the fall-through address is implied and should not be returned by IFlowInformation.getTargets(). The list of targets should contain the branch address - or addresses, for example if the processor branching instruction allows branch selection.

      Specified by:
      getRoutineCall in interface IInstruction
      Parameters:
      instructionAddress - the address of the current instruction
      Returns:
      IFlowInformation.isBroken() is true if the instruction calls into a sub-routine, false otherwise; if true, IFlowInformation.getTargets() may be filled, else its contents is irrelevant
    • getRoutineCall

      public IFlowInformation getRoutineCall()
      Description copied from interface: ILocatedInstruction
      Determine if an instruction branches to (or calls into) a sub-routine.

      Under normal circumstances, those instructions save the return address (e.g., on a stack or in a register). Therefore, the fall-through address is implied and should not be returned by IFlowInformation.getTargets(). The list of targets should contain the branch address - or addresses, for example if the processor branching instruction allows branch selection.

      Specified by:
      getRoutineCall in interface ILocatedInstruction
      Returns:
      IFlowInformation.isBroken() is true if the instruction calls into a sub-routine, false otherwise; if true, IFlowInformation.getTargets() may be filled, else its contents is irrelevant
      See Also:
    • collectIndirectCallReferences

      public IFlowInformation collectIndirectCallReferences(long instructionAddress)
      Description copied from interface: IInstruction
      Collect the list of dereferenced addresses computed by a call-to-sub instruction. This method should not be confused with IInstruction.getRoutineCall(long).
      Specified by:
      collectIndirectCallReferences in interface IInstruction
      Parameters:
      instructionAddress - the address of the current instruction
      Returns:
      IFlowInformation.isBroken() is true if the instruction indirectly calls into a sub-routine, false otherwise (in particular for direct routine calls); if true, the IFlowInformation.getTargets() may be filled with the dereferenced addresses, else its contents is irrelevant
    • collectIndirectCallReferences

      public IFlowInformation collectIndirectCallReferences()
      Description copied from interface: ILocatedInstruction
      Collect the list of dereferenced addresses computed by a call-to-sub instruction. This method should not be confused with IInstruction.getRoutineCall(long).
      Specified by:
      collectIndirectCallReferences in interface ILocatedInstruction
      Returns:
      IFlowInformation.isBroken() is true if the instruction indirectly calls into a sub-routine, false otherwise (in particular for direct routine calls); if true, the IFlowInformation.getTargets() may be filled with the dereferenced addresses, else its contents is irrelevant
      See Also:
    • getPrimaryBranchAddress

      public long getPrimaryBranchAddress()
      Description copied from interface: ILocatedInstruction
      Convenience method used to retrieve the primary target of this branching instruction. If the instruction is not branching, or if the target cannot be determined, -1 is returned. If the instruction has multiple branches, only one is returned.
      Specified by:
      getPrimaryBranchAddress in interface ILocatedInstruction
      Returns:
      the target address, or -1 on error
    • getDefUse

      public void getDefUse(List<Integer> def, List<Integer> use, Object context)
      Description copied from interface: IInstruction
      Determine the variables defined and used by the instruction.
      Specified by:
      getDefUse in interface IInstruction
      Parameters:
      def - output, the list of variables defined by the instruction.
      use - output, the list of variables used by the instruction
      context - optional context (implementation specific)
    • getInstructionFlags

      public Collection<InstructionFlags> getInstructionFlags()
      Specified by:
      getInstructionFlags in interface IInstruction
      Returns:
      instruction flags, never null
    • canThrow

      public boolean canThrow()
      Description copied from interface: IInstruction
      Determine if the instruction can throw an exception.
      Specified by:
      canThrow in interface IInstruction
      Returns:
      true if the exception can raise
    • format

      public String format(Object context)
      Description copied from interface: IInstruction
      Format the instruction for printing
      Specified by:
      format in interface IInstruction
      Parameters:
      context - optional context, used to provide a better representation of the instruction (for instance, resolving strings or method names.) The implementor should do its best to return a decent result even if context is null.
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object