Class PcodeOp

java.lang.Object
ghidra.program.model.pcode.PcodeOp
Direct Known Subclasses:
PcodeOpAST, PcodeOpRaw

public class PcodeOp extends Object
Pcode Op describes a generic machine operation. You can think of it as the microcode for a specific processor's instruction set. There are a finite number of PcodeOp's that theoretically can define the operations for any given processor. Pcode have An operation code Some number of input parameter varnodes possible output varnode
  • Field Details

  • Constructor Details

    • PcodeOp

      public PcodeOp(SequenceNumber sq, int op, int numinputs, Varnode out)
      Constructor - pcode part of sequence of pcodes, some number of inputs, output
      Parameters:
      sq - place in sequence of pcode
      op - pcode operation
      numinputs - number of inputs to operation, actual inputs not defined yet.
      out - output from operation
    • PcodeOp

      public PcodeOp(SequenceNumber sq, int op, Varnode[] in, Varnode out)
      Constructor - pcode part of sequence of pcodes, inputs, outputs
      Parameters:
      sq - place in sequence of pcode
      op - pcode operation
      in - inputs to operation
      out - output from operation
    • PcodeOp

      public PcodeOp(Address a, int sequencenumber, int op, Varnode[] in, Varnode out)
      Constructor - inputs and outputs
      Parameters:
      a - address pcode is attached to
      sequencenumber - unique sequence number for the specified address.
      op - pcode operation
      in - inputs to operation
      out - output from operation
    • PcodeOp

      public PcodeOp(Address a, int sequencenumber, int op, Varnode[] in)
      Constructor - no output
      Parameters:
      a - address pcode is attached to
      sequencenumber - id within a single address
      op - operation pcode performs
      in - inputs from pcode operation
    • PcodeOp

      public PcodeOp(Address a, int sequencenumber, int op)
      Constructor - no inputs, output
      Parameters:
      a - address pcode is attached to
      sequencenumber - id within a single address
      op - pcode operation
  • Method Details

    • getOpcode

      public final int getOpcode()
      Returns:
      pcode operation code
    • getNumInputs

      public final int getNumInputs()
      Returns:
      number of input varnodes
    • getInputs

      public final Varnode[] getInputs()
      Returns:
      get input varnodes
    • getInput

      public final Varnode getInput(int i)
      Parameters:
      i - the i'th input varnode
      Returns:
      the i'th input varnode
    • getOutput

      public final Varnode getOutput()
      Returns:
      get output varnodes
    • getSlot

      public final int getSlot(Varnode vn)
      Assuming vn is an input to this op, return its input slot number
      Parameters:
      vn - is the input varnode
      Returns:
      the slot number
    • getMnemonic

      public final String getMnemonic()
      Returns:
      get the string representation for the pcode operation
    • isDead

      public boolean isDead()
      Check if the pcode has been determined to be a dead operation.
      Returns:
      true if the pcode has been determined to have no effect in the context it is used
    • isAssignment

      public final boolean isAssignment()
      Returns:
      true if the pcode assigns a value to an output varnode
    • isCommutative

      public final boolean isCommutative()
      Return true if the PcodeOp is commutative. If true, the operation has exactly two inputs that can be switched without affecting the output.
      Returns:
      true if the operation is commutative
    • getSeqnum

      public final SequenceNumber getSeqnum()
      Returns:
      the sequence number this pcode is within some number of pcode
    • getBasicIter

      public Iterator<PcodeOp> getBasicIter()
    • getInsertIter

      public Iterator<Object> getInsertIter()
    • getParent

      public PcodeBlockBasic getParent()
      Returns:
      the pcode basic block this pcode belongs to
    • setOpcode

      public final void setOpcode(int o)
      Set the pcode operation code
      Parameters:
      o - pcode operation code
    • setInput

      public final void setInput(Varnode vn, int slot)
      Set/Replace an input varnode at the given slot.
      Parameters:
      vn - varnode to replace
      slot - index of input varnode to be replaced
    • removeInput

      public final void removeInput(int slot)
      Remove a varnode at the given slot from the list of input varnodes
      Parameters:
      slot - index of input varnode to remove
    • insertInput

      public final void insertInput(Varnode vn, int slot)
      Insert an input varnode at the given index of input varnodes
      Parameters:
      vn - varnode to insert
      slot - insert index in input varnode list
    • setTime

      public final void setTime(int t)
      Set a unique number for pcode ops that are attached to the same address
      Parameters:
      t - unique id
    • setOrder

      public final void setOrder(int ord)
      Set relative position information of PcodeOps within a basic block, may change as basic block is edited.
      Parameters:
      ord - relative position of pcode op in basic block
    • setOutput

      public final void setOutput(Varnode vn)
      Set the output varnode for the pcode operation.
      Parameters:
      vn - new output varnode
    • encodeRaw

      public void encodeRaw(Encoder encoder, AddressFactory addrFactory) throws IOException
      Encode just the opcode and input/output Varnode data for this PcodeOp to a stream as an \ element
      Parameters:
      encoder - is the stream encoder
      addrFactory - is a factory for looking up encoded address spaces
      Throws:
      IOException - for errors in the underlying stream
    • decode

      public static PcodeOp decode(Decoder decoder, PcodeFactory pfact) throws DecoderException
      Decode p-code from a stream
      Parameters:
      decoder - is the stream decoder
      pfact - factory used to create p-code correctly
      Returns:
      new PcodeOp
      Throws:
      DecoderException - if encodings are invalid
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getMnemonic

      public static final String getMnemonic(int op)
      Get string representation for p-code operation
      Parameters:
      op - operation code
      Returns:
      String representation of p-code operation
    • getOpcode

      public static int getOpcode(String s) throws UnknownInstructionException
      Get the p-code op code for the given mnemonic string.
      Parameters:
      s - is the mnemonic string
      Returns:
      the op code
      Throws:
      UnknownInstructionException - if there is no matching mnemonic
    • isCommutative

      public static boolean isCommutative(int opcode)
      Return true if the given opcode represents a commutative operation. If true, the operation has exactly two inputs that can be switched without affecting the output.
      Parameters:
      opcode - is the opcode
      Returns:
      true if the operation is commutative