public class

GenericCodeFormatter

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

Class Overview

A base formatter used by the INativeCodeUnit. Plugins implementing a processor may override some public and protected methods to customize their disassembly.

Summary

Constants
int MNEMONIC_RIGHT_PADDING_LENGTH_DEFAULT
Public Constructors
GenericCodeFormatter()
GenericCodeFormatter(IVirtualMemory mem)
FOR TESTING ONLY
Public Methods
final long createItemIdForAddress(long address)
long createItemIdForDefaultRegister(long regCode)
Default method to retrieve item id of a register.
final long createItemIdForImmediate(long insnAddress, int opndIndexGlobal)
final long createItemIdForMnemonic(InsnType insn)
final long createItemIdForRegister(long regCode)
final void formatAddress(long address, CodeDocumentPart out)
void formatAddress(long address, IInstructionOperandGeneric opnd, CodeDocumentPart out)
Format an address regarding getDefaultAddressFormatter()
void formatDataDeclarator(int size, CodeDocumentPart out)
final void formatImm(long address, IInstructionOperandSized opnd, long value, int opndIndexGlobal, CodeDocumentPart out)
void formatInstruction(long address, InsnType insn, CodeDocumentPart out)
Displays only pure assembly code: Mnemonic and Operands, without address and bytecode.
void formatOperand(long address, InsnType insn, IInstructionOperand opnd, int opndIndexGlobal, int opndDepth, CodeDocumentPart out)
Generic operand formatter.
final void formatRelativeAddress(IInstructionOperandGeneric opnd, long address, CodeDocumentPart out)
CharSequence generateExtraComment(long insnAddress, InsnType instruction)
Generate an optional string that will be displayed at the line instruction.
String generateExtraMethodComment(long address)
Generate an optional string that will be prepended to a function header comment.
String generateExtraSectionHeader(ISegmentInformation segment)
String generateExtraSegmentHeader(ISegmentInformation segment)
String generateHeader()
Generate the disassembly header.
int getArrayElementPerLine()
The default implementation returns 10.
ItemClassIdentifiers getBestClassIdForAddress(long address)
INativeCodeUnit<InsnType> getCodeUnit()
String getDataSeparator()
The default implementation returns the comma string.
AddressFormatter getDefaultAddressFormatter()
NumberFormatter getDefaultNumberFormatter()
Endianness getEndianness()
String getInlineCommentString()
The default implementation returns a semi-column string.
String getLabelPrefix()
Get the assembly label prefix.
String getLabelSuffix()
Can be overridden.
IVirtualMemory getMemory()
String getMemoryAccessPrefix()
The default implementation returns the opening square bracket.
String getMemoryAccessSegmentInfo(InsnType insn, IInstructionOperand opnd)
The default implementation returns the empty string.
String getMemoryAccessSizeInfo(InsnType insn, IInstructionOperandSized opnd)
Can be overridden.
String getMemoryAccessSuffix()
The default implementation returns the closing square bracket.
final int getMnemonicRightPaddingLength()
String getMultiLineCommentBegin()
The default implementation returns "slash-*".
String getMultiLineCommentEnd()
The default implementation returns "*-slash".
NumberFormatter getNumberFormatter(INativeDataItem item)
NumberFormatter getNumberFormatter(IInstructionOperand opnd, boolean createIfNone)
String getOperandSeparator()
Can be overridden.
String getProcedureDefinitionEnd()
String getProcedureDefinitionStart()
String getRawDataDeclarator(int bitsize)
The default implementation returns "dX".
String getRegisterName(long registerIdentifier)
The default implementation returns "rX".
boolean isDoNotAttemptImmediateToAddressResolution()
void setCodeUnit(INativeCodeUnit<InsnType> pbcu)
void setDoNotAttemptImmediateToAddressResolution(boolean doNotResolveImmAsAddr)
final void setMnemonicRightPaddingLength(int length)
Protected Methods
final void addPrefix(InsnType insn, IInstructionOperandGeneric opnd, CodeDocumentPart out)
final void addSuffix(InsnType insn, IInstructionOperandGeneric opnd, CodeDocumentPart out)
void formatMnemonic(long address, InsnType insn, boolean prependPrefix, CodeDocumentPart out)
void formatOperands(long address, InsnType insn, CodeDocumentPart out)
int formatPrefix(long address, InsnType insn, CodeDocumentPart out)
void formatRegister(long regValue, CodeDocumentPart out)
String generateMnemonic(long address, InsnType insn)
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int MNEMONIC_RIGHT_PADDING_LENGTH_DEFAULT

Constant Value: 10 (0x0000000a)

Public Constructors

public GenericCodeFormatter ()

public GenericCodeFormatter (IVirtualMemory mem)

FOR TESTING ONLY

Public Methods

public final long createItemIdForAddress (long address)

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.

public final long createItemIdForImmediate (long insnAddress, int opndIndexGlobal)

public final long createItemIdForMnemonic (InsnType insn)

public final long createItemIdForRegister (long regCode)

public final void formatAddress (long address, CodeDocumentPart out)

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

public void formatDataDeclarator (int size, CodeDocumentPart out)

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

public void formatInstruction (long address, InsnType insn, CodeDocumentPart out)

Displays only pure assembly code: Mnemonic and Operands, without address and bytecode.

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.

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

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.

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

public String generateExtraSectionHeader (ISegmentInformation segment)

public String generateExtraSegmentHeader (ISegmentInformation segment)

public String generateHeader ()

Generate the disassembly header. The default implementation returns the boilerplate line "Code Disassembly".

public int getArrayElementPerLine ()

The default implementation returns 10. Can be overridden.

Returns
  • a number >= 1

public ItemClassIdentifiers getBestClassIdForAddress (long address)

public INativeCodeUnit<InsnType> getCodeUnit ()

public String getDataSeparator ()

The default implementation returns the comma string. Can be overridden.

public AddressFormatter getDefaultAddressFormatter ()

public NumberFormatter getDefaultNumberFormatter ()

public Endianness getEndianness ()

public String getInlineCommentString ()

The default implementation returns a semi-column string. Can be overridden.

public String getLabelPrefix ()

Get the assembly label prefix. Can be overridden.

public String getLabelSuffix ()

Can be overridden.

public IVirtualMemory getMemory ()

public String getMemoryAccessPrefix ()

The default implementation returns the opening square bracket. Can be overridden.

public String getMemoryAccessSegmentInfo (InsnType insn, IInstructionOperand opnd)

The default implementation returns the empty string. Can be overridden.

public String getMemoryAccessSizeInfo (InsnType insn, IInstructionOperandSized opnd)

Can be overridden.

public String getMemoryAccessSuffix ()

The default implementation returns the closing square bracket. Can be overridden.

public final int getMnemonicRightPaddingLength ()

public String getMultiLineCommentBegin ()

The default implementation returns "slash-*". Can be overridden.

public String getMultiLineCommentEnd ()

The default implementation returns "*-slash". Can be overridden.

public NumberFormatter getNumberFormatter (INativeDataItem item)

public NumberFormatter getNumberFormatter (IInstructionOperand opnd, boolean createIfNone)

public String getOperandSeparator ()

Can be overridden.

public String getProcedureDefinitionEnd ()

public String getProcedureDefinitionStart ()

public String getRawDataDeclarator (int bitsize)

The default implementation returns "dX". Can be overridden.

public String getRegisterName (long registerIdentifier)

The default implementation returns "rX". Should be overridden.

Returns
  • a register name, never null (on error, the implementation should return a default safe string)

public boolean isDoNotAttemptImmediateToAddressResolution ()

public void setCodeUnit (INativeCodeUnit<InsnType> pbcu)

public void setDoNotAttemptImmediateToAddressResolution (boolean doNotResolveImmAsAddr)

public final void setMnemonicRightPaddingLength (int length)

Protected Methods

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

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

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

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

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

protected void formatRegister (long regValue, CodeDocumentPart out)

protected String generateMnemonic (long address, InsnType insn)