Class GenericCodeFormatter<InsnType extends IInstruction>
java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.render.GenericCodeFormatter<InsnType>
- Type Parameters:
InsnType- instruction type formatted by this formatter
A base formatter used by the
INativeCodeUnit. Plugins implementing a processor may
override some public and protected methods to customize their disassembly.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault right padding length for instruction mnemonics. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a generic code formatter.Create a formatter bound to a virtual memory. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidaddPrefix(InsnType insn, IInstructionOperandGeneric opnd, CodeDocumentPart out) Add an operand prefix.protected final voidaddSuffix(InsnType insn, IInstructionOperandGeneric opnd, CodeDocumentPart out) Add an operand suffix.final longcreateItemIdForAddress(long address) Create an item identifier for an address.longcreateItemIdForDefaultRegister(long regCode) Default method to retrieve item id of a register.final longcreateItemIdForImmediate(long insnAddress, int opndIndexGlobal) Create an item identifier for an immediate.final longCreate an item identifier for a mnemonic.final longcreateItemIdForRegister(long regCode) Create an item identifier for a register.final voidformatAddress(long address, CodeDocumentPart out) Format an address.voidformatAddress(long address, IInstructionOperandGeneric opnd, CodeDocumentPart out) Format an address regardinggetDefaultAddressFormatter()voidformatDataDeclarator(int size, CodeDocumentPart out) Format a data declarator.final voidformatImm(long address, IInstructionOperandSized opnd, long value, int opndIndexGlobal, CodeDocumentPart out) Format an immediate operand value.voidformatInstruction(long address, InsnType insn, CodeDocumentPart out) Displays only pure assembly code: Mnemonic and Operands, without address and bytecode.protected voidformatMnemonic(long address, InsnType insn, boolean prependPrefix, CodeDocumentPart out) Format an instruction mnemonic.voidformatOperand(long address, InsnType insn, IInstructionOperand opnd, int opndIndexGlobal, int opndDepth, CodeDocumentPart out) Generic operand formatter.protected voidformatOperands(long address, InsnType insn, CodeDocumentPart out) Format instruction operands.protected intformatPrefix(long address, InsnType insn, CodeDocumentPart out) Format an instruction prefix.protected voidformatRegister(long regValue, CodeDocumentPart out) Format a register.final voidformatRelativeAddress(IInstructionOperandGeneric opnd, long address, CodeDocumentPart out) Format a relative address.generateExtraComment(long insnAddress, InsnType instruction) Generate an optional string that will be displayed at the line instruction.generateExtraMethodComment(long address) Generate an optional string that will be prepended to a function header comment.Generate an optional extra section header.Generate an optional extra segment header.Generate the disassembly header.protected StringgenerateMnemonic(long address, InsnType insn) Generate an instruction mnemonic.intThe default implementation returns 10.getBestClassIdForAddress(long address) Get the best item class identifier for an address.protected booleangetCachedBooleanProperty(String propname) Convenience method to retrieve and cache (for 5 second) a code unit's property.protected intgetCachedIntegerProperty(String propname) Convenience method to retrieve and cache (for 5 second) a code unit's property.protected StringgetCachedStringProperty(String propname) Convenience method to retrieve and cache (for 5 second) a code unit's property.Retrieve the code unit formatted by this object.protected intGet the number of operands to format.The default implementation returns the comma string.Get the default address formatter.Get the default number formatter.Retrieve the formatter endianness.The default implementation returns a semi-column string.Get the assembly label prefix.Can be overridden.Retrieve the virtual memory being formatted.The default implementation returns the opening square bracket.getMemoryAccessSegmentInfo(InsnType insn, IInstructionOperand opnd) The default implementation returns the empty string.getMemoryAccessSizeInfo(InsnType insn, IInstructionOperandSized opnd) Can be overridden.The default implementation returns the closing square bracket.final intGet the mnemonic right padding length.The default implementation returns "slash-*".The default implementation returns "*-slash".Get a number formatter for a data item.getNumberFormatter(IInstructionOperand opnd, boolean createIfNone) Get a number formatter for an operand.Can be overridden.Get the procedure definition end marker.Get the procedure definition start marker.getRawDataDeclarator(int bitsize) The default implementation returns "dX".getRegisterName(long registerIdentifier) The default implementation returns "rX".booleanDetermine whether immediate-to-address resolution is disabled.voidsetCodeUnit(INativeCodeUnit<InsnType> pbcu) Set the code unit formatted by this object.voidsetDoNotAttemptImmediateToAddressResolution(boolean doNotResolveImmAsAddr) Set whether immediate-to-address resolution is disabled.final voidsetMnemonicRightPaddingLength(int length) Set the mnemonic right padding length.
-
Field Details
-
MNEMONIC_RIGHT_PADDING_LENGTH_DEFAULT
public static final int MNEMONIC_RIGHT_PADDING_LENGTH_DEFAULTDefault right padding length for instruction mnemonics.- See Also:
-
-
Constructor Details
-
GenericCodeFormatter
public GenericCodeFormatter()Create a generic code formatter. -
GenericCodeFormatter
Create a formatter bound to a virtual memory.For testing only.
- Parameters:
mem- virtual memory
-
-
Method Details
-
setCodeUnit
Set the code unit formatted by this object.- Parameters:
pbcu- native code unit
-
getCodeUnit
Retrieve the code unit formatted by this object.- Returns:
- native code unit
-
getMemory
Retrieve the virtual memory being formatted.- Returns:
- virtual memory
-
getEndianness
Retrieve the formatter endianness.- Returns:
- endianness
-
getRawDataDeclarator
The default implementation returns "dX". Can be overridden.- Parameters:
bitsize- raw data size in bits- Returns:
- raw data declarator
-
getDataSeparator
The default implementation returns the comma string. Can be overridden.- Returns:
- data separator
-
getArrayElementPerLine
public int getArrayElementPerLine()The default implementation returns 10. Can be overridden.- Returns:
- a number >= 1
-
formatDataDeclarator
Format a data declarator.- Parameters:
size- data size in bytesout- output document part
-
getProcedureDefinitionStart
Get the procedure definition start marker.- Returns:
- procedure start marker
-
getProcedureDefinitionEnd
Get the procedure definition end marker.- Returns:
- procedure end marker
-
getLabelPrefix
Get the assembly label prefix. Can be overridden.- Returns:
- label prefix
-
getLabelSuffix
Can be overridden.- Returns:
- label suffix
-
getOperandSeparator
Can be overridden.- Returns:
- operand separator
-
getMemoryAccessSizeInfo
Can be overridden.- Parameters:
insn- instructionopnd- operand- Returns:
- memory access size text
-
getMemoryAccessPrefix
The default implementation returns the opening square bracket. Can be overridden.- Returns:
- memory access prefix
-
getMemoryAccessSuffix
The default implementation returns the closing square bracket. Can be overridden.- Returns:
- memory access suffix
-
getMemoryAccessSegmentInfo
The default implementation returns the empty string. Can be overridden.- Parameters:
insn- instructionopnd- operand- Returns:
- memory access segment text
-
getInlineCommentString
The default implementation returns a semi-column string. Can be overridden.- Returns:
- inline comment marker
-
getMultiLineCommentBegin
The default implementation returns "slash-*". Can be overridden.- Returns:
- multiline comment opening marker
-
getMultiLineCommentEnd
The default implementation returns "*-slash". Can be overridden.- Returns:
- multiline comment closing marker
-
getRegisterName
The default implementation returns "rX". Should be overridden.- Parameters:
registerIdentifier- register identifier- Returns:
- a register name, never null (on error, the implementation should return a default safe string)
-
generateHeader
Generate the disassembly header. The default implementation returns the boilerplate line "Code Disassembly".- Returns:
- disassembly header
-
generateExtraSegmentHeader
Generate an optional extra segment header.- Parameters:
segment- segment information- Returns:
- extra segment header, or null
-
generateExtraSectionHeader
Generate an optional extra section header.- Parameters:
segment- section information- Returns:
- extra section header, or null
-
generateExtraMethodComment
Generate an optional string that will be prepended to a function header comment. The default implementation returns null.- Parameters:
address- function address- Returns:
- extra method comment, or null
-
generateExtraComment
Generate an optional string that will be displayed at the line instruction. The default implementation returns null.- Parameters:
insnAddress- instruction addressinstruction- instruction. Can be null if no instruction is defined at this address.- Returns:
- extra comment, or null
-
formatInstruction
Displays only pure assembly code: Mnemonic and Operands, without address and bytecode.- Parameters:
address- instruction addressinsn- instructionout- output document part
-
formatPrefix
Format an instruction prefix.- Parameters:
address- instruction addressinsn- instructionout- output document part- Returns:
- number of formatted characters
-
formatMnemonic
protected void formatMnemonic(long address, InsnType insn, boolean prependPrefix, CodeDocumentPart out) Format an instruction mnemonic.- Parameters:
address- instruction addressinsn- instructionprependPrefix- if true, prepend the instruction prefixout- output document part
-
generateMnemonic
Generate an instruction mnemonic.- Parameters:
address- instruction addressinsn- instruction- Returns:
- mnemonic
-
setMnemonicRightPaddingLength
public final void setMnemonicRightPaddingLength(int length) Set the mnemonic right padding length.- Parameters:
length- padding length
-
getMnemonicRightPaddingLength
public final int getMnemonicRightPaddingLength()Get the mnemonic right padding length.- Returns:
- padding length
-
getCountOfFormattedOperands
Get the number of operands to format.- Parameters:
insn- instruction- Returns:
- operand count
-
formatOperands
Format instruction operands.- Parameters:
address- instruction addressinsn- instructionout- output document part
-
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 neitherIInstructionOperandGenericorIInstructionOperandCMA, the processor should override this method.- Parameters:
address- instruction addressinsn- instructionopnd- operandopndIndexGlobal- global operand indexopndDepth- operand nesting depthout- output document part
-
addPrefix
protected final void addPrefix(InsnType insn, IInstructionOperandGeneric opnd, CodeDocumentPart out) Add an operand prefix.- Parameters:
insn- instructionopnd- operandout- output document part
-
addSuffix
protected final void addSuffix(InsnType insn, IInstructionOperandGeneric opnd, CodeDocumentPart out) Add an operand suffix.- Parameters:
insn- instructionopnd- operandout- output document part
-
formatImm
public final void formatImm(long address, IInstructionOperandSized opnd, long value, int opndIndexGlobal, CodeDocumentPart out) Format an immediate operand value.- Parameters:
address- instruction addressopnd- operandvalue- immediate valueopndIndexGlobal- global operand indexout- output document part
-
formatAddress
Format an address.- Parameters:
address- address to formatout- output document part
-
formatRelativeAddress
public final void formatRelativeAddress(IInstructionOperandGeneric opnd, long address, CodeDocumentPart out) Format a relative address.- Parameters:
opnd- operandaddress- address to formatout- output document part
-
formatAddress
Format an address regardinggetDefaultAddressFormatter()- Parameters:
address- address to representopnd- optional; IFF address is a relative addressout- output document part
-
formatRegister
Format a register.- Parameters:
regValue- register valueout- output document part
-
getDefaultNumberFormatter
Get the default number formatter.- Returns:
- default number formatter
-
getNumberFormatter
Get a number formatter for a data item.- Parameters:
item- data item- Returns:
- number formatter
-
getNumberFormatter
Get a number formatter for an operand.- Parameters:
opnd- operandcreateIfNone- if true, create a formatter if none exists- Returns:
- number formatter, or null
-
getDefaultAddressFormatter
Get the default address formatter.- Returns:
- default address formatter
-
getBestClassIdForAddress
Get the best item class identifier for an address.- Parameters:
address- address- Returns:
- item class identifier
-
createItemIdForMnemonic
Create an item identifier for a mnemonic.- Parameters:
insn- instruction- Returns:
- item identifier
-
createItemIdForAddress
public final long createItemIdForAddress(long address) Create an item identifier for an address.- Parameters:
address- address- Returns:
- item identifier
-
createItemIdForImmediate
public final long createItemIdForImmediate(long insnAddress, int opndIndexGlobal) Create an item identifier for an immediate.- Parameters:
insnAddress- instruction addressopndIndexGlobal- global operand index- Returns:
- item identifier
-
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, seeRegisterUtilfor details- Returns:
- createItemIdForRegister with filtered register based on pure id.
-
createItemIdForRegister
public final long createItemIdForRegister(long regCode) Create an item identifier for a register.- Parameters:
regCode- register code- Returns:
- item identifier
-
setDoNotAttemptImmediateToAddressResolution
public void setDoNotAttemptImmediateToAddressResolution(boolean doNotResolveImmAsAddr) Set whether immediate-to-address resolution is disabled.- Parameters:
doNotResolveImmAsAddr- true to disable immediate-to-address resolution
-
isDoNotAttemptImmediateToAddressResolution
public boolean isDoNotAttemptImmediateToAddressResolution()Determine whether immediate-to-address resolution is disabled.- Returns:
- true if immediate-to-address resolution is disabled
-
getCachedBooleanProperty
Convenience method to retrieve and cache (for 5 second) a code unit's property.- Parameters:
propname- code unit's property name- Returns:
- the property value (on failure: false)
-
getCachedIntegerProperty
Convenience method to retrieve and cache (for 5 second) a code unit's property.- Parameters:
propname- code unit's property name- Returns:
- the property value (on failure: 0)
-
getCachedStringProperty
Convenience method to retrieve and cache (for 5 second) a code unit's property.- Parameters:
propname- code unit's property name- Returns:
- the property value (on failure: the empty string)
-