Package ghidra.pcode.emu.taint.state

# Class TaintPcodeExecutorStatePiece

java.lang.Object
ghidra.pcode.exec.AbstractLongOffsetPcodeExecutorStatePiece<byte[],TaintVec,TaintSpace>
ghidra.pcode.emu.taint.state.TaintPcodeExecutorStatePiece

All Implemented Interfaces:
  `PcodeExecutorStatePiece<byte[],TaintVec>`

public class TaintPcodeExecutorStatePiece extends AbstractLongOffsetPcodeExecutorStatePiece<byte[],TaintVec,TaintSpace>
The taint state piece

The framework-provided class from which this derives expects us to implement state for each address space using a separate storage object. We do this by providing `TaintSpace`, which is where all the taint storage logic is actually located. We then use a map `spaceMap` to lazily create a keep each of those spaces.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface ghidra.pcode.exec.PcodeExecutorStatePiece

  `PcodeExecutorStatePiece.Reason`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final Map<AddressSpace,TaintSpace>`
  `spaceMap`
  A lazily-populated map of address space to taint storage.

  ### Fields inherited from class ghidra.pcode.exec.AbstractLongOffsetPcodeExecutorStatePiece

  `addressArithmetic, arithmetic, cb, language, uniqueSpace`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TaintPcodeExecutorStatePiece(Language language, PcodeArithmetic<byte[]> addressArithmetic, PcodeArithmetic<TaintVec> arithmetic, PcodeStateCallbacks cb)`
  Create a state piece
  `TaintPcodeExecutorStatePiece(Language language, PcodeArithmetic<byte[]> addressArithmetic, PcodeStateCallbacks cb)`
  Create the taint piece

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Erase the entire state or piece
  `TaintPcodeExecutorStatePiece`
  `fork(PcodeStateCallbacks cb)`
  Create a deep copy of this state
  `MemBuffer`
  `getConcreteBuffer(Address address, PcodeArithmetic.Purpose purpose)`
  Bind a buffer of concrete bytes at the given start address
  `protected TaintSpace`
  `getForSpace(AddressSpace space, boolean toWrite)`
  Get the internal space for the given address space
  `protected TaintVec`
  `getFromSpace(TaintSpace space, long offset, int size, PcodeExecutorStatePiece.Reason reason, PcodeStateCallbacks cb)`
  Get a value from the given space
  `Map.Entry<Long,TaintVec>`
  `getNextEntryInternal(AddressSpace space, long offset)`
  Get the entry at a given offset (without issuing callbacks)
  `protected Map<Register,TaintVec>`
  `getRegisterValuesFromSpace(TaintSpace space, List<Register> registers)`
  Can the given space for register values, as in `AbstractLongOffsetPcodeExecutorStatePiece.getRegisterValues()`
  `protected void`
  `setInSpace(TaintSpace space, long offset, int size, TaintVec val, PcodeStateCallbacks cb)`
  Set a value in the given space

  ### Methods inherited from class ghidra.pcode.exec.AbstractLongOffsetPcodeExecutorStatePiece

  `checkSize, forkMap, getAddressArithmetic, getArithmetic, getFromNullSpace, getLanguage, getRegisterValues, getUnique, getVar, getVar, getVarInternal, getVarInternal, getVarInternal, setUnique, setVar, setVar, setVarInternal, setVarInternal, setVarInternal, streamPieces`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface ghidra.pcode.exec.PcodeExecutorStatePiece

  `checkRange, getNextEntryInternal, getVar, getVar, getVar, inspectBigInteger, inspectByte, inspectConcrete, inspectInt, inspectLong, inspectRegisterValue, inspectShort, quantizeOffset, setBigInteger, setByte, setConcrete, setInt, setLong, setRegisterValue, setRegisterValue, setShort, setVar, setVar, setVar`

- ## Field Details

  - ### spaceMap

    protected final Map<AddressSpace,TaintSpace> spaceMap
    A lazily-populated map of address space to taint storage.

- ## Constructor Details

  - ### TaintPcodeExecutorStatePiece

    public TaintPcodeExecutorStatePiece(Language language, PcodeArithmetic<byte[]> addressArithmetic, PcodeArithmetic<TaintVec> arithmetic, PcodeStateCallbacks cb)
    Create a state piece
    Parameters:
      `language` - the emulator's language
      `addressArithmetic` - the arithmetic for the address type
      `arithmetic` - the arithmetic for the value type
      `cb` - callbacks to receive emulation events

  - ### TaintPcodeExecutorStatePiece

    public TaintPcodeExecutorStatePiece(Language language, PcodeArithmetic<byte[]> addressArithmetic, PcodeStateCallbacks cb)
    Create the taint piece
    Parameters:
      `language` - the language of the emulator
      `addressArithmetic` - the address arithmetic, likely taken from the concrete piece
      `cb` - callbacks to receive emulation events

- ## Method Details

  - ### fork

    public TaintPcodeExecutorStatePiece fork(PcodeStateCallbacks cb)
    Description copied from interface: `PcodeExecutorStatePiece`
    Create a deep copy of this state
    Parameters:
      `cb` - callbacks to receive emulation events
    Returns:
      the copy

  - ### getConcreteBuffer

    public MemBuffer getConcreteBuffer(Address address, PcodeArithmetic.Purpose purpose)
    Description copied from interface: `PcodeExecutorStatePiece`
    Bind a buffer of concrete bytes at the given start address
    Parameters:
      `address` - the start address
      `purpose` - the reason why the emulator needs a concrete value
    Returns:
      a buffer

  - ### getForSpace

    protected TaintSpace getForSpace(AddressSpace space, boolean toWrite)
    Get the internal space for the given address space

    Here, we just follow the pattern: delegate to the space map.

    Specified by:
      `getForSpace` in class `AbstractLongOffsetPcodeExecutorStatePiece<byte[],TaintVec,TaintSpace>`
    Parameters:
      `space` - the address space
      `toWrite` - in case internal spaces are generated lazily, this indicates the space must be present, because it is going to be written to.
    Returns:
      the space, or `null`

  - ### setInSpace

    protected void setInSpace(TaintSpace space, long offset, int size, TaintVec val, PcodeStateCallbacks cb)
    Set a value in the given space

    Because the super class places no bound on `<S>`, we have to provide the delegation to the storage space.

    Specified by:
      `setInSpace` in class `AbstractLongOffsetPcodeExecutorStatePiece<byte[],TaintVec,TaintSpace>`
    Parameters:
      `space` - the address space
      `offset` - the offset within the space
      `size` - the number of bytes to write (the size of the value)
      `val` - the value to store
      `cb` - callbacks to receive emulation events

  - ### getFromSpace

    protected TaintVec getFromSpace(TaintSpace space, long offset, int size, PcodeExecutorStatePiece.Reason reason, PcodeStateCallbacks cb)
    Get a value from the given space

    Because the super class places no bound on `<S>`, we have to provide the delegation to the storage space.

    Specified by:
      `getFromSpace` in class `AbstractLongOffsetPcodeExecutorStatePiece<byte[],TaintVec,TaintSpace>`
    Parameters:
      `space` - the address space
      `offset` - the offset within the space
      `size` - the number of bytes to read (the size of the value)
      `reason` - the reason for reading state
      `cb` - callbacks to receive emulation events
    Returns:
      the read value

  - ### getRegisterValuesFromSpace

    protected Map<Register,TaintVec> getRegisterValuesFromSpace(TaintSpace space, List<Register> registers)
    Description copied from class: `AbstractLongOffsetPcodeExecutorStatePiece`
    Can the given space for register values, as in `AbstractLongOffsetPcodeExecutorStatePiece.getRegisterValues()`
    Specified by:
      `getRegisterValuesFromSpace` in class `AbstractLongOffsetPcodeExecutorStatePiece<byte[],TaintVec,TaintSpace>`
    Parameters:
      `space` - the space to scan
      `registers` - the registers known to be in the corresponding address space
    Returns:
      the map of registers to values

  - ### clear

    public void clear()
    Description copied from interface: `PcodeExecutorStatePiece`
    Erase the entire state or piece

    This is generally only useful when the state is itself a cache to another object. This will ensure the state is reading from that object rather than a stale cache. If this is not a cache, this could in fact clear the whole state, and the machine using it will be left in the dark.

  - ### getNextEntryInternal

    public Map.Entry<Long,TaintVec> getNextEntryInternal(AddressSpace space, long offset)
    Description copied from interface: `PcodeExecutorStatePiece`
    Get the entry at a given offset (without issuing callbacks)

    (Optional operation) For pieces where each value is effective over a range, it is common to use an internal map (vice a byte array). When serializing the state, or otherwise seeking a complete examination, it is useful to retrieve those internal entries. This returns the next entry at or after the given offset within the given space. NOTE the returned entry must be for the given space. If no such entry exists, return `null`.

    Parameters:
      `space` - the address space
      `offset` - the offset within the space
    Returns:
      the entry or null