Class Emulate

java.lang.Object
ghidra.pcode.emulate.Emulate
Direct Known Subclasses:
ModifiedPcodeThread.GlueEmulate

public class Emulate extends Object
A SLEIGH based implementation of the Emulate interface

This implementation uses a Translate object to translate machine instructions into pcode and caches pcode ops for later use by the emulator. The pcode is cached as soon as the execution address is set, either explicitly, or via branches and fallthrus. There are additional methods for inspecting the pcode ops in the current instruction as a sequence.

  • Constructor Details

    • Emulate

      public Emulate(SleighLanguage lang, MemoryState s, BreakTable b)
      Creates a new Emulate object
      Parameters:
      lang - is the SLEIGH language
      s - is the MemoryState the emulator should manipulate
      b - is the table of breakpoints the emulator should invoke
  • Method Details

    • dispose

      public void dispose()
    • getLanguage

      public Language getLanguage()
    • isInstructionStart

      public boolean isInstructionStart()
      Since the emulator can single step through individual pcode operations, the machine state may be halted in the middle of a single machine instruction, unlike conventional debuggers. This routine can be used to determine if execution is actually at the beginning of a machine instruction.
      Returns:
      true if the next pcode operation is at the start of the instruction translation
    • getExecutionState

      public EmulateExecutionState getExecutionState()
      Returns the current emulator execution state.
      Returns:
      the current emulator execution state
    • getExecuteAddress

      public Address getExecuteAddress()
      Returns the currently executing machine address.
      Returns:
      the currently executing machine address
    • getLastExecuteAddress

      public Address getLastExecuteAddress()
      Returns the last address.
      Returns:
      the last address
    • getNewDisassemblerContext

      public EmulateDisassemblerContext getNewDisassemblerContext()
    • getContextRegisterValue

      public RegisterValue getContextRegisterValue()
      Returns the current context register value. The context value returned reflects its state when the previously executed instruction was parsed/executed. The context value returned will feed into the next instruction to be parsed with its non-flowing bits cleared and any future context state merged in. If no instruction has been executed, the explicitly set context will be returned. A null value is returned if no context register is defined by the language or initial context has not been set.
    • setContextRegisterValue

      public void setContextRegisterValue(RegisterValue regValue)
      Sets the context register value at the current execute address. The Emulator should not be running when this method is invoked. Only flowing context bits should be set, as non-flowing bits will be cleared prior to parsing on instruction. In addition, any future context state set by the pcode emitter will take precedence over context set using this method. This method is primarily intended to be used to establish the initial context state.
      Parameters:
      regValue -
    • fallthruOp

      public void fallthruOp()
      Update the iterator into the current pcode cache, and if necessary, generate the pcode for the fallthru instruction and reset the iterator.
    • executeConditionalBranch

      public void executeConditionalBranch(PcodeOpRaw op)
    • executeBranch

      public void executeBranch(PcodeOpRaw op)
      Since the full instruction is cached, we can do relative branches properly
      Parameters:
      op - is the particular branch op being executed
    • executeCallother

      public void executeCallother(PcodeOpRaw op) throws UnimplementedCallOtherException
      Give instuctionStateModifier first shot at executing custom pcodeop, if not supported look for a breakpoint for the given user-defined op and invoke it. If it doesn't exist, or doesn't replace the action, throw an exception
      Parameters:
      op - is the particular user-defined op being executed
      Throws:
      UnimplementedCallOtherException
    • setExecuteAddress

      public void setExecuteAddress(Address addr)
      Set the current execution address and cache the pcode translation of the machine instruction at that address
      Parameters:
      addr - is the address where execution should continue
    • executeInstruction

      public void executeInstruction(boolean stopAtBreakpoint, TaskMonitor monitor) throws CancelledException, LowlevelError, InstructionDecodeException
      This routine executes an entire machine instruction at once, as a conventional debugger step function would do. If execution is at the start of an instruction, the breakpoints are checked and invoked as needed for the current address. If this routine is invoked while execution is in the middle of a machine instruction, execution is continued until the current instruction completes.
      Parameters:
      stopAtBreakpoint -
      monitor -
      Throws:
      CancelledException
      LowlevelError
      InstructionDecodeException
    • getMemoryState

      public MemoryState getMemoryState()
      Returns the memory state object which this emulator uses.
      Returns:
      the memory state object which this emulator uses
    • executeLoad

      public void executeLoad(PcodeOpRaw op)
      This routine performs a standard pcode load operation on the memory state
      Parameters:
      op - is the particular load op being executed
    • executeStore

      public void executeStore(PcodeOpRaw op)
      This routine performs a standard pcode store operation on the memory state
      Parameters:
      op - is the particular store op being executed
    • executeBranchind

      public void executeBranchind(PcodeOpRaw op)
      This routine performs a standard pcode branch indirect operation on the memory state
      Parameters:
      op - is the particular branchind op being executed
    • executeCall

      public void executeCall(PcodeOpRaw op)
      This routine performs a standard pcode call operation on the memory state
      Parameters:
      op - is the particular call op being executed
    • executeCallind

      public void executeCallind(PcodeOpRaw op)
      This routine performs a standard pcode call indirect operation on the memory state
      Parameters:
      op - is the particular callind op being executed
    • executeMultiequal

      public void executeMultiequal(PcodeOpRaw op)
      This kind of pcode op should not come up in ordinary emulation, so this routine throws an exception.
      Parameters:
      op - is the particular multiequal op being executed
    • executeIndirect

      public void executeIndirect(PcodeOpRaw op)
      This kind of pcode op should not come up in ordinary emulation, so this routine throws an exception.
      Parameters:
      op - is the particular indirect op being executed