Class DefaultEmulator

java.lang.Object
ghidra.app.emulator.DefaultEmulator
All Implemented Interfaces:
Emulator

public class DefaultEmulator extends Object implements Emulator
The default implementation of Emulator.

This class used to be named Emulator, until it was replaced by an interface extracted from this class. There is now a second implementation named AdaptedEmulator, which wraps the newer PcodeEmulator system. If you are developing a new use case based on p-code emulation, please consider using PcodeEmulator directly. There are several example scripts in the SystemEmulation module. If you are maintaining an existing use case currently based on Emulator, you will at least need to change new Emulator(...) to new DefaultEmulator(...). It is highly recommended to port to the newer PcodeEmulator. You may find the AdaptedEmulator useful during the transition, but that class is only transitional.

  • Constructor Details

  • Method Details

    • cloneMemory

      public MemoryState cloneMemory()
    • getMemoryBank

      public FilteredMemoryPageOverlay getMemoryBank(AddressSpace space, int ps)
    • dispose

      public void dispose()
      Description copied from interface: Emulator
      Clean up resources used by the emulator
      Specified by:
      dispose in interface Emulator
    • genAddress

      public Address genAddress(String addr)
    • getPC

      public long getPC()
      Description copied from interface: Emulator
      Get the value of the program counter
      Specified by:
      getPC in interface Emulator
      Returns:
      the value, i.e., offset in code space
    • getPCRegisterName

      public String getPCRegisterName()
      Description copied from interface: Emulator
      Get the name of the program counter register
      Specified by:
      getPCRegisterName in interface Emulator
      Returns:
      the name
    • getMemState

      public MemoryState getMemState()
      Description copied from interface: Emulator
      Get the memory state
      Specified by:
      getMemState in interface Emulator
      Returns:
      the state
    • getFilteredMemState

      public ghidra.app.emulator.FilteredMemoryState getFilteredMemState()
      Description copied from interface: Emulator
      Get the memory state, modified by all installed access filters
      Specified by:
      getFilteredMemState in interface Emulator
      Returns:
      the state
    • addMemoryAccessFilter

      public void addMemoryAccessFilter(MemoryAccessFilter filter)
      Description copied from interface: Emulator
      Add a filter on memory access
      Specified by:
      addMemoryAccessFilter in interface Emulator
      Parameters:
      filter - the filter
    • getBreakTable

      public BreakTableCallBack getBreakTable()
      Description copied from interface: Emulator
      Get the breakpoint table
      Specified by:
      getBreakTable in interface Emulator
      Returns:
      the breakpoint table
    • setExecuteAddress

      public void setExecuteAddress(long addressableWordOffset)
      Description copied from interface: Emulator
      Set the value of the program counter
      Specified by:
      setExecuteAddress in interface Emulator
      Parameters:
      addressableWordOffset - the word offset of the instruction to execute next.
    • getExecuteAddress

      public Address getExecuteAddress()
      Description copied from interface: Emulator
      Get current execution address (or the address of the next instruction to be executed)
      Specified by:
      getExecuteAddress in interface Emulator
      Returns:
      current execution address
    • getLastExecuteAddress

      public Address getLastExecuteAddress()
      Description copied from interface: Emulator
      Get the address of the last instruction executed (or the instructed currently being executed)
      Specified by:
      getLastExecuteAddress in interface Emulator
      Returns:
      the address
    • getDefaultContext

      public Set<String> getDefaultContext()
    • setHalt

      public void setHalt(boolean halt)
      Description copied from interface: Emulator
      Halt or un-halt the emulator
      Specified by:
      setHalt in interface Emulator
      Parameters:
      halt - true to halt
    • getHalt

      public boolean getHalt()
      Description copied from interface: Emulator
      Check if the emulator has been halted
      Specified by:
      getHalt in interface Emulator
      Returns:
      true if halted
    • executeInstruction

      public void executeInstruction(boolean stopAtBreakpoint, TaskMonitor monitor) throws CancelledException, LowlevelError, InstructionDecodeException
      Description copied from interface: Emulator
      Execute instruction at current address
      Specified by:
      executeInstruction in interface Emulator
      Parameters:
      stopAtBreakpoint - if true and breakpoint hits at current execution address execution will halt without executing instruction.
      Throws:
      CancelledException - if execution was cancelled
      LowlevelError
      InstructionDecodeException
    • isAtBreakpoint

      public boolean isAtBreakpoint()
      Specified by:
      isAtBreakpoint in interface Emulator
      Returns:
      true if halted at a breakpoint
    • getEmulateExecutionState

      public EmulateExecutionState getEmulateExecutionState()
      Description copied from interface: Emulator
      Get the low-level execution state

      This can be useful within a memory fault handler to determine if a memory read was associated with instruction parsing (i.e., EmulateExecutionState.INSTRUCTION_DECODE) or an actual emulated read (i.e., EmulateExecutionState.EXECUTE).

      Specified by:
      getEmulateExecutionState in interface Emulator
      Returns:
      emulator execution state. This can be useful within a memory fault handler to determine if a memory read was associated with instruction parsing (i.e., PCODE_EMIT) or normal an actual emulated read (i.e., EXECUTE).
    • isExecuting

      public boolean isExecuting()
      Specified by:
      isExecuting in interface Emulator
      Returns:
      true if emulator is busy executing an instruction
    • getLanguage

      public SleighLanguage getLanguage()
    • disassemble

      public List<String> disassemble(Integer count)
      Disassemble from the current execute address
      Parameters:
      count - number of contiguous instructions to disassemble
      Returns:
      list of instructions
    • getTickCount

      public int getTickCount()
    • getContextRegisterValue

      public RegisterValue getContextRegisterValue()
      Description copied from interface: Emulator
      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.

      Specified by:
      getContextRegisterValue in interface Emulator
      Returns:
      context as a RegisterValue object
    • setContextRegisterValue

      public void setContextRegisterValue(RegisterValue regValue)
      Description copied from interface: Emulator
      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.

      Specified by:
      setContextRegisterValue in interface Emulator
      Parameters:
      regValue - is the value to set context to
    • addProvider

      public void addProvider(MemoryLoadImage provider, AddressSetView view)
      Add memory load image provider
      Parameters:
      provider - memory load image provider
      view - memory region which corresponds to provider