Class GenericCodeFormatter<InsnType extends IInstruction>
java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.render.GenericCodeFormatter<InsnType>
A base formatter used by the
INativeCodeUnit
. Plugins implementing a processor may
override some public and protected methods to customize their disassembly.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFOR TESTING ONLY -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
addPrefix
(InsnType insn, IInstructionOperandGeneric opnd, CodeDocumentPart out) protected final void
addSuffix
(InsnType insn, IInstructionOperandGeneric opnd, CodeDocumentPart out) 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
final long
createItemIdForRegister
(long regCode) final void
formatAddress
(long address, CodeDocumentPart out) void
formatAddress
(long address, IInstructionOperandGeneric opnd, CodeDocumentPart out) Format an address regardinggetDefaultAddressFormatter()
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.protected void
formatMnemonic
(long address, InsnType insn, boolean prependPrefix, CodeDocumentPart out) void
formatOperand
(long address, InsnType insn, IInstructionOperand opnd, int opndIndexGlobal, int opndDepth, CodeDocumentPart out) Generic operand formatter.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) final void
formatRelativeAddress
(IInstructionOperandGeneric opnd, long address, CodeDocumentPart out) 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 the disassembly header.protected String
generateMnemonic
(long address, InsnType insn) int
The default implementation returns 10.getBestClassIdForAddress
(long address) The default implementation returns the comma string.The default implementation returns a semi-column string.Get the assembly label prefix.Can be overridden.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 int
The default implementation returns "slash-*".The default implementation returns "*-slash".getNumberFormatter
(IInstructionOperand opnd, boolean createIfNone) Can be overridden.getRawDataDeclarator
(int bitsize) The default implementation returns "dX".getRegisterName
(long registerIdentifier) The default implementation returns "rX".boolean
void
setCodeUnit
(INativeCodeUnit<InsnType> pbcu) void
setDoNotAttemptImmediateToAddressResolution
(boolean doNotResolveImmAsAddr) final void
setMnemonicRightPaddingLength
(int length)
-
Field Details
-
MNEMONIC_RIGHT_PADDING_LENGTH_DEFAULT
public static final int MNEMONIC_RIGHT_PADDING_LENGTH_DEFAULT- See Also:
-
-
Constructor Details
-
GenericCodeFormatter
public GenericCodeFormatter() -
GenericCodeFormatter
FOR TESTING ONLY
-
-
Method Details
-
setCodeUnit
-
getCodeUnit
-
getMemory
-
getEndianness
-
getRawDataDeclarator
The default implementation returns "dX". Can be overridden.- Returns:
-
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
-
getProcedureDefinitionStart
- Returns:
-
getProcedureDefinitionEnd
- Returns:
-
getLabelPrefix
Get the assembly label prefix. Can be overridden.- Returns:
-
getLabelSuffix
Can be overridden.- Returns:
-
getOperandSeparator
Can be overridden.- Returns:
-
getMemoryAccessSizeInfo
Can be overridden.- Parameters:
insn
-opnd
-- Returns:
-
getMemoryAccessPrefix
The default implementation returns the opening square bracket. Can be overridden.- Returns:
-
getMemoryAccessSuffix
The default implementation returns the closing square bracket. Can be overridden.- Returns:
-
getMemoryAccessSegmentInfo
The default implementation returns the empty string. Can be overridden.- Parameters:
insn
-opnd
-- Returns:
-
getInlineCommentString
The default implementation returns a semi-column string. Can be overridden.- Returns:
-
getMultiLineCommentBegin
The default implementation returns "slash-*". Can be overridden.- Returns:
-
getMultiLineCommentEnd
The default implementation returns "*-slash". Can be overridden.- Returns:
-
getRegisterName
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
Generate the disassembly header. The default implementation returns the boilerplate line "Code Disassembly".- Returns:
-
generateExtraSegmentHeader
-
generateExtraSectionHeader
-
generateExtraMethodComment
Generate an optional string that will be prepended to a function header comment. The default implementation returns null.- Parameters:
address
- function address- Returns:
-
generateExtraComment
Generate an optional string that will be displayed at the line instruction. The default implementation returns null.- Parameters:
insnAddress
- addressinstruction
- instruction. Can be null if no instruction is defined at this address.- Returns:
-
formatInstruction
Displays only pure assembly code: Mnemonic and Operands, without address and bytecode.- Parameters:
address
-insn
-out
-
-
formatPrefix
-
formatMnemonic
protected void formatMnemonic(long address, InsnType insn, boolean prependPrefix, CodeDocumentPart out) -
generateMnemonic
-
setMnemonicRightPaddingLength
public final void setMnemonicRightPaddingLength(int length) -
getMnemonicRightPaddingLength
public final int getMnemonicRightPaddingLength() -
formatOperands
-
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 neitherIInstructionOperandGeneric
orIInstructionOperandCMA
, 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
-
formatRelativeAddress
public final void formatRelativeAddress(IInstructionOperandGeneric opnd, long address, CodeDocumentPart out) -
formatAddress
Format an address regardinggetDefaultAddressFormatter()
- Parameters:
address
- address to representopnd
- optional; IFF address is a relative addressout
-
-
formatRegister
-
getDefaultNumberFormatter
-
getNumberFormatter
-
getNumberFormatter
-
getDefaultAddressFormatter
-
getBestClassIdForAddress
-
createItemIdForMnemonic
-
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, seeRegisterUtil
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()
-