Class GenericCodeFormatter<InsnType extends IInstruction>

java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.render.GenericCodeFormatter<InsnType>

@Ser public class GenericCodeFormatter<InsnType extends IInstruction> extends Object
A base formatter used by the INativeCodeUnit. Plugins implementing a processor may override some public and protected methods to customize their disassembly.
  • Field Details

    • MNEMONIC_RIGHT_PADDING_LENGTH_DEFAULT

      public static final int MNEMONIC_RIGHT_PADDING_LENGTH_DEFAULT
      See Also:
  • Constructor Details

    • GenericCodeFormatter

      public GenericCodeFormatter()
    • GenericCodeFormatter

      public GenericCodeFormatter(IVirtualMemory mem)
      FOR TESTING ONLY
  • Method Details

    • setCodeUnit

      public void setCodeUnit(INativeCodeUnit<InsnType> pbcu)
    • getCodeUnit

      public INativeCodeUnit<InsnType> getCodeUnit()
    • getMemory

      public IVirtualMemory getMemory()
    • getEndianness

      public Endianness getEndianness()
    • getRawDataDeclarator

      public String getRawDataDeclarator(int bitsize)
      The default implementation returns "dX". Can be overridden.
      Returns:
    • getDataSeparator

      public String getDataSeparator()
      The default implementation returns the comma string. Can be overridden.
      Returns:
    • getArrayElementPerLine

      public int getArrayElementPerLine()
      The default implementation returns 10. Can be overridden.
      Returns:
      a number >= 1
    • formatDataDeclarator

      public void formatDataDeclarator(int size, CodeDocumentPart out)
    • getProcedureDefinitionStart

      public String getProcedureDefinitionStart()
      Returns:
    • getProcedureDefinitionEnd

      public String getProcedureDefinitionEnd()
      Returns:
    • getLabelPrefix

      public String getLabelPrefix()
      Get the assembly label prefix. Can be overridden.
      Returns:
    • getLabelSuffix

      public String getLabelSuffix()
      Can be overridden.
      Returns:
    • getOperandSeparator

      public String getOperandSeparator()
      Can be overridden.
      Returns:
    • getMemoryAccessSizeInfo

      public String getMemoryAccessSizeInfo(InsnType insn, IInstructionOperandSized opnd)
      Can be overridden.
      Parameters:
      insn -
      opnd -
      Returns:
    • getMemoryAccessPrefix

      public String getMemoryAccessPrefix()
      The default implementation returns the opening square bracket. Can be overridden.
      Returns:
    • getMemoryAccessSuffix

      public String getMemoryAccessSuffix()
      The default implementation returns the closing square bracket. Can be overridden.
      Returns:
    • getMemoryAccessSegmentInfo

      public String getMemoryAccessSegmentInfo(InsnType insn, IInstructionOperand opnd)
      The default implementation returns the empty string. Can be overridden.
      Parameters:
      insn -
      opnd -
      Returns:
    • getInlineCommentString

      public String getInlineCommentString()
      The default implementation returns a semi-column string. Can be overridden.
      Returns:
    • getMultiLineCommentBegin

      public String getMultiLineCommentBegin()
      The default implementation returns "slash-*". Can be overridden.
      Returns:
    • getMultiLineCommentEnd

      public String getMultiLineCommentEnd()
      The default implementation returns "*-slash". Can be overridden.
      Returns:
    • getRegisterName

      public String getRegisterName(long registerIdentifier)
      The default implementation returns "rX". Should be overridden.
      Parameters:
      registerIdentifier -
      Returns:
      a register name, never null (on error, the implementation should return a default safe string)
    • generateHeader

      public String generateHeader()
      Generate the disassembly header. The default implementation returns the boilerplate line "Code Disassembly".
      Returns:
    • generateExtraSegmentHeader

      public String generateExtraSegmentHeader(ISegmentInformation segment)
    • generateExtraSectionHeader

      public String generateExtraSectionHeader(ISegmentInformation segment)
    • generateExtraMethodComment

      public String generateExtraMethodComment(long address)
      Generate an optional string that will be prepended to a function header comment. The default implementation returns null.
      Parameters:
      address - function address
      Returns:
    • generateExtraComment

      public CharSequence generateExtraComment(long insnAddress, InsnType instruction)
      Generate an optional string that will be displayed at the line instruction. The default implementation returns null.
      Parameters:
      insnAddress - address
      instruction - instruction. Can be null if no instruction is defined at this address.
      Returns:
    • formatInstruction

      public void formatInstruction(long address, InsnType insn, CodeDocumentPart out)
      Displays only pure assembly code: Mnemonic and Operands, without address and bytecode.
      Parameters:
      address -
      insn -
      out -
    • formatPrefix

      protected int formatPrefix(long address, InsnType insn, CodeDocumentPart out)
    • formatMnemonic

      protected void formatMnemonic(long address, InsnType insn, boolean prependPrefix, CodeDocumentPart out)
    • generateMnemonic

      protected String generateMnemonic(long address, InsnType insn)
    • setMnemonicRightPaddingLength

      public final void setMnemonicRightPaddingLength(int length)
    • getMnemonicRightPaddingLength

      public final int getMnemonicRightPaddingLength()
    • formatOperands

      protected void formatOperands(long address, InsnType insn, CodeDocumentPart out)
    • formatOperand

      public void formatOperand(long address, InsnType insn, IInstructionOperand opnd, int opndIndexGlobal, int opndDepth, CodeDocumentPart out)
      Generic operand formatter. Can be overridden, although not recommended. If the processor uses custom instructions, that is, instructions that are neither IInstructionOperandGeneric or IInstructionOperandCMA, the processor should override this method.
      Parameters:
      address -
      insn -
      opnd -
      opndIndexGlobal -
      opndDepth -
      out -
    • addPrefix

      protected final void addPrefix(InsnType insn, IInstructionOperandGeneric opnd, CodeDocumentPart out)
    • addSuffix

      protected final void addSuffix(InsnType insn, IInstructionOperandGeneric opnd, CodeDocumentPart out)
    • formatImm

      public final void formatImm(long address, IInstructionOperandSized opnd, long value, int opndIndexGlobal, CodeDocumentPart out)
    • formatAddress

      public final void formatAddress(long address, CodeDocumentPart out)
    • formatRelativeAddress

      public final void formatRelativeAddress(IInstructionOperandGeneric opnd, long address, CodeDocumentPart out)
    • formatAddress

      public void formatAddress(long address, IInstructionOperandGeneric opnd, CodeDocumentPart out)
      Format an address regarding getDefaultAddressFormatter()
      Parameters:
      address - address to represent
      opnd - optional; IFF address is a relative address
      out -
    • formatRegister

      protected void formatRegister(long regValue, CodeDocumentPart out)
    • getDefaultNumberFormatter

      public NumberFormatter getDefaultNumberFormatter()
    • getNumberFormatter

      public NumberFormatter getNumberFormatter(INativeDataItem item)
    • getNumberFormatter

      public NumberFormatter getNumberFormatter(IInstructionOperand opnd, boolean createIfNone)
    • getDefaultAddressFormatter

      public AddressFormatter getDefaultAddressFormatter()
    • getBestClassIdForAddress

      public ItemClassIdentifiers getBestClassIdForAddress(long address)
    • createItemIdForMnemonic

      public final long createItemIdForMnemonic(InsnType insn)
    • createItemIdForAddress

      public final long createItemIdForAddress(long address)
    • createItemIdForImmediate

      public final long createItemIdForImmediate(long insnAddress, int opndIndexGlobal)
    • createItemIdForDefaultRegister

      public long createItemIdForDefaultRegister(long regCode)
      Default method to retrieve item id of a register. By default, Bitsize and bitstart are ignored.
      Parameters:
      regCode - Code Register, see RegisterUtil for details
      Returns:
      createItemIdForRegister with filtered register based on pure id.
    • createItemIdForRegister

      public final long createItemIdForRegister(long regCode)
    • setDoNotAttemptImmediateToAddressResolution

      public void setDoNotAttemptImmediateToAddressResolution(boolean doNotResolveImmAsAddr)
    • isDoNotAttemptImmediateToAddressResolution

      public boolean isDoNotAttemptImmediateToAddressResolution()