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.
  • Constructor Details

    • AbstractPcodeFormatter

      public AbstractPcodeFormatter()
  • Method Details

    • createAppender

      protected abstract A createAppender(Language language, boolean indent)
      Create the appender for a formatting invocation
      Parameters:
      language - the language of the p-code to format
      indent - 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

      public T formatTemplates(Language language, List<OpTpl> pcodeOpTemplates)
      Description copied from interface: PcodeFormatter
      Format the p-code op templates
      Specified by:
      formatTemplates in interface PcodeFormatter<T>
      Parameters:
      language - the language generating the p-code
      pcodeOpTemplates - the templates
      Returns:
      the formatted result
    • formatOpTemplate

      protected AbstractPcodeFormatter.FormatResult formatOpTemplate(A appender, OpTpl op)
      Format a single op template
      Parameters:
      appender - the appender to receive the formatted text
      op - the template to format
      Returns:
      instructions to continue or terminate. The loop in formatTemplates(Language, List) is terminated if this method returns AbstractPcodeFormatter.FormatResult.TERMINATE.
    • formatOutput

      protected void formatOutput(A appender, int opcode, VarnodeTpl output)
      Format an output varnode
      Parameters:
      appender - the appender to receive the formatted text
      opcode - the op's opcode
      output - the varnode to format
    • formatInput

      protected void formatInput(A appender, int opcode, int opIndex, VarnodeTpl input)
      Format an input varnode
      Parameters:
      appender - the appender to receive the formatted text
      opcode - the op's opcode
      opIndex - the operand's index
      input - the varnode to format
    • formatVarnode

      protected void formatVarnode(A appender, int opcode, int opIndex, VarnodeTpl vTpl)
      Format a varnode
      Parameters:
      appender - the appender to receive the formatted text
      opcode - the op's opcode
      opIndex - the operand's index (-1 is output, 0 is first input)
      vTpl - the varnode to format
    • formatVarnodeNice

      protected void formatVarnodeNice(A appender, AddressSpace space, ConstTpl offset, ConstTpl size)
      Format a varnode in nice (non-raw) form
      Parameters:
      appender - the appender to receive the formatted text
      space - the address space of the varnode
      offset - the offset in the address space
      size - the size in bytes
    • formatVarnodeRaw

      protected void formatVarnodeRaw(A appender, AddressSpace space, ConstTpl offset, ConstTpl size)
      Format a varnode in raw form
      Parameters:
      appender - the appender to receive the formatted text
      space - the address space of the varnode
      offset - the offset in the address space
      size - the size in bytes
    • formatUnique

      protected void formatUnique(A appender, ConstTpl offset, ConstTpl size)
      Format a unique variable
      Parameters:
      appender - the appender to receive the formatted text
      offset - the offset in unique space
      size - the size in bytes
    • formatAddress

      protected void formatAddress(A appender, AddressSpace addrSpace, ConstTpl offset, ConstTpl size)
      Format a memory variable
      Parameters:
      appender - the appender to receive the formatted text
      addrSpace - the address space of the variable
      offset - the offset in the address space
      size - the size in bytes
    • formatConstant

      protected void formatConstant(A appender, ConstTpl offset, ConstTpl size)
      Format a constant
      Parameters:
      appender - the appender to receive the formatted text
      offset - the value of the constant
      size - the size in bytes
    • formatSize

      protected void formatSize(A appender, ConstTpl size)
      Format a size indicator
      Parameters:
      appender - the appender to receive the formatted text
      size - the size in bytes
    • formatCallOtherName

      protected void formatCallOtherName(A appender, VarnodeTpl input0)
      Format a p-code userop name (CALLOTHER)
      Parameters:
      appender - the appender to receive the formatted text
      input0 - the constant varnode giving the userop id
    • formatLabelInput

      protected boolean formatLabelInput(A appender, VarnodeTpl input0)
      Try to format a local label (e.g., instr_next)
      Parameters:
      appender - the appender to receive the formatted text
      input0 - the relative jump varnode
      Returns:
      true if the varnode was formatted, false if not
    • formatMemoryInput

      protected void formatMemoryInput(A appender, VarnodeTpl input0, VarnodeTpl input1)
      Format the memory location for a LOAD or STORE op
      Parameters:
      appender - the appender to receive the formatted text
      input0 - the const varnode giving the address space id
      input1 - the varnode giving the address offset
    • isLineLabel

      protected static boolean isLineLabel(OpTpl template)
      Check if the given template represents a line label

      The 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 in PcodeOp.BRANCH and PcodeOp.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