Package ghidra.app.util.pcode
Class AbstractPcodeFormatter<T,A extends ghidra.app.util.pcode.Appender<T>>
java.lang.Object
ghidra.app.util.pcode.AbstractPcodeFormatter<T,A>
- Type Parameters:
T
- the type of this formatter's output, e.g.,String
A
- the type of the appender
- All Implemented Interfaces:
PcodeFormatter<T>
- Direct Known Subclasses:
AttributedStringPcodeFormatter
,PcodeFrame.MyFormatter
,PcodeProgram.MyFormatter
,StringPcodeFormatter
public abstract class AbstractPcodeFormatter<T,A extends ghidra.app.util.pcode.Appender<T>>
extends Object
implements PcodeFormatter<T>
An abstract p-code formatter which can take a list of p-code ops or op templates and consistently
format them. The general pattern is to extend this class and specify another class which extends
an
AbstractAppender
. In most cases, it is only necessary to override
formatOpTemplate(Appender, OpTpl)
. Otherwise, most formatting logic is implemented by
the appender.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static enum
A result instructing the formatter whether or not to continue -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract A
createAppender
(Language language, boolean indent) Create the appender for a formatting invocationprotected void
formatAddress
(A appender, AddressSpace addrSpace, ConstTpl offset, ConstTpl size) Format a memory variableprotected void
formatCallOtherName
(A appender, VarnodeTpl input0) Format a p-code userop name (CALLOTHER)protected void
formatConstant
(A appender, ConstTpl offset, ConstTpl size) Format a constantprotected void
formatInput
(A appender, int opcode, int opIndex, VarnodeTpl input) Format an input varnodeprotected boolean
formatLabelInput
(A appender, VarnodeTpl input0) Try to format a local label (e.g.,instr_next
)protected void
formatMemoryInput
(A appender, VarnodeTpl input0, VarnodeTpl input1) Format the memory location for a LOAD or STORE opprotected AbstractPcodeFormatter.FormatResult
formatOpTemplate
(A appender, OpTpl op) Format a single op templateprotected void
formatOutput
(A appender, int opcode, VarnodeTpl output) Format an output varnodeprotected void
formatSize
(A appender, ConstTpl size) Format a size indicatorformatTemplates
(Language language, List<OpTpl> pcodeOpTemplates) Format the p-code op templatesprotected void
formatUnique
(A appender, ConstTpl offset, ConstTpl size) Format a unique variableprotected void
formatVarnode
(A appender, int opcode, int opIndex, VarnodeTpl vTpl) Format a varnodeprotected void
formatVarnodeNice
(A appender, AddressSpace space, ConstTpl offset, ConstTpl size) Format a varnode in nice (non-raw) formprotected void
formatVarnodeRaw
(A appender, AddressSpace space, ConstTpl offset, ConstTpl size) Format a varnode in raw formprotected boolean
Check if this formatter is configured to display raw p-codeprotected static boolean
isLineLabel
(OpTpl template) Check if the given template represents a line labelMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ghidra.app.util.pcode.PcodeFormatter
formatOps, formatOps
-
Constructor Details
-
AbstractPcodeFormatter
public AbstractPcodeFormatter()
-
-
Method Details
-
createAppender
Create the appender for a formatting invocation- Parameters:
language
- the language of the p-code to formatindent
- indicates whether each line should be indented to accommodate line labels- Returns:
- the new appender
-
isFormatRaw
protected boolean isFormatRaw()Check if this formatter is configured to display raw p-code- Returns:
- true if displaying raw, false otherwise
-
formatTemplates
Description copied from interface:PcodeFormatter
Format the p-code op templates- Specified by:
formatTemplates
in interfacePcodeFormatter<T>
- Parameters:
language
- the language generating the p-codepcodeOpTemplates
- the templates- Returns:
- the formatted result
-
formatOpTemplate
Format a single op template- Parameters:
appender
- the appender to receive the formatted textop
- the template to format- Returns:
- instructions to continue or terminate. The loop in
formatTemplates(Language, List)
is terminated if this method returnsAbstractPcodeFormatter.FormatResult.TERMINATE
.
-
formatOutput
Format an output varnode- Parameters:
appender
- the appender to receive the formatted textopcode
- the op's opcodeoutput
- the varnode to format
-
formatInput
Format an input varnode- Parameters:
appender
- the appender to receive the formatted textopcode
- the op's opcodeopIndex
- the operand's indexinput
- the varnode to format
-
formatVarnode
Format a varnode- Parameters:
appender
- the appender to receive the formatted textopcode
- the op's opcodeopIndex
- the operand's index (-1 is output, 0 is first input)vTpl
- the varnode to format
-
formatVarnodeNice
Format a varnode in nice (non-raw) form- Parameters:
appender
- the appender to receive the formatted textspace
- the address space of the varnodeoffset
- the offset in the address spacesize
- the size in bytes
-
formatVarnodeRaw
Format a varnode in raw form- Parameters:
appender
- the appender to receive the formatted textspace
- the address space of the varnodeoffset
- the offset in the address spacesize
- the size in bytes
-
formatUnique
Format a unique variable- Parameters:
appender
- the appender to receive the formatted textoffset
- the offset in unique spacesize
- the size in bytes
-
formatAddress
Format a memory variable- Parameters:
appender
- the appender to receive the formatted textaddrSpace
- the address space of the variableoffset
- the offset in the address spacesize
- the size in bytes
-
formatConstant
Format a constant- Parameters:
appender
- the appender to receive the formatted textoffset
- the value of the constantsize
- the size in bytes
-
formatSize
Format a size indicator- Parameters:
appender
- the appender to receive the formatted textsize
- the size in bytes
-
formatCallOtherName
Format a p-code userop name (CALLOTHER)- Parameters:
appender
- the appender to receive the formatted textinput0
- the constant varnode giving the userop id
-
formatLabelInput
Try to format a local label (e.g.,instr_next
)- Parameters:
appender
- the appender to receive the formatted textinput0
- the relative jump varnode- Returns:
- true if the varnode was formatted, false if not
-
formatMemoryInput
Format the memory location for a LOAD or STORE op- Parameters:
appender
- the appender to receive the formatted textinput0
- the const varnode giving the address space idinput1
- the varnode giving the address offset
-
isLineLabel
Check if the given template represents a line labelThe
PcodeOp.PTRADD
op is ordinarily only use in high p-code. We reuse (read "abuse") it to hold a display slot for line labels later referred to inPcodeOp.BRANCH
andPcodeOp.CBRANCH
ops. This method checks if the given op template is one of those placeholders.- Parameters:
template
- the op template- Returns:
- true if it's a line label
-