Class DisassemblerContextImpl

java.lang.Object
ghidra.program.disassemble.DisassemblerContextImpl
All Implemented Interfaces:
DisassemblerContext, ProcessorContext, ProcessorContextView

public class DisassemblerContextImpl extends Object implements DisassemblerContext
Maintains processor state information during disassembly and analysis. Tracks register state associated with instruction flows. Within this context, a flow is defined as a contiguous range of instructions. Also, this context provides storage for context states at future flow addresses, which will be used when subsequent flowTo(Address) or flowStart(Address) calls are made with those addresses.
  • Constructor Details

    • DisassemblerContextImpl

      public DisassemblerContextImpl(ProgramContext programContext)
      Constructor for DisassemblerContext.
      Parameters:
      programContext - contains the values for registers at specific addresses store in the program.
  • Method Details

    • getProgramContext

      public ProgramContext getProgramContext()
    • getBaseContextRegister

      public Register getBaseContextRegister()
      Specified by:
      getBaseContextRegister in interface ProcessorContextView
      Returns:
      the base processor context register or null if one has not been defined
    • copyToFutureFlowState

      public RegisterValue copyToFutureFlowState(Address address)
      Saves the current processor state for when this context flows to the given address. Use this method if keeping separate flows from different flow from addresses is not important.
      Parameters:
      address - the address at which to save the current processor state.
      Returns:
      context register value which was copied
    • copyToFutureFlowState

      public RegisterValue copyToFutureFlowState(Address fromAddr, Address destAddr)
      Saves the current processor state flowing from the fromAddr, for when this context flows to the given address.
      Parameters:
      fromAddr - the address from which this flow originates.
      destAddr - the address at which to save the current processor state.
      Returns:
      context register value which was copied
    • mergeToFutureFlowState

      public ArrayList<RegisterValue> mergeToFutureFlowState(Address address)
      Saves the current processor state for when this context is later used at the given address. If the address already has a value, return the value on a collision list! Use this method if keeping separate flows from different flow from addresses is not important.
      Parameters:
      address - the address at which to save the current processor state.
    • mergeToFutureFlowState

      public ArrayList<RegisterValue> mergeToFutureFlowState(Address fromAddr, Address destAddr)
      Saves the current processor state flowing from the fromAddr to the destAddr for when this context is later used. If the address already has a value, return the value on a collision list!
      Parameters:
      fromAddr - the address from which this flow originated
      destAddr - the address at which to save the current processor state.
    • flowAbort

      public void flowAbort()
      Terminate active flow while preserving any accumulated future context. Any context commits resulting from a flowToAddress or flowEnd will be unaffected.
    • flowStart

      public void flowStart(Address address)
      Starts a new flow. Initializes the current state for all registers using any future flow state that has been set. Use this method if keeping separate flows from different flow from addresses is not important.
      Parameters:
      address - the starting address of a new instruction flow.
      Throws:
      IllegalStateException - if a previous flow was not ended.
    • flowStart

      public void flowStart(Address fromAddr, Address toAddr)
      Starts a new flow from an address to the new start. Initializes the current state for all registers using any future flow state that has been set flowing from the fromAddr.
      Parameters:
      fromAddr - address that this flow is flowing from.
      toAddr - the starting address of a new instruction flow.
      Throws:
      IllegalStateException - if a previous flow was not ended.
    • getFlowContextValue

      public RegisterValue getFlowContextValue(Address destAddr, boolean isFallThrough)
      Get flowed context value at arbitrary destination address without affecting state. Use this method if keeping separate flows from different flow from addresses is not important.
      Parameters:
      destAddr -
      isFallThrough -
      Returns:
      the flowed context value
    • getFlowContextValue

      public RegisterValue getFlowContextValue(Address fromAddr, Address destAddr, boolean isFallThrough)
      Get flowed context value at a destination address, that has been flowed from the fromAddr, without affecting state.
      Parameters:
      fromAddr - address that this flow is flowing from.
      destAddr - the starting address of a new instruction flow.
      Throws:
      IllegalStateException - if a previous flow was not ended.
    • flowToAddress

      public void flowToAddress(Address address)
      Continues the current flow at the given address. Checks for register values that have been stored in the future flow state. If any registers have saved future state, the current state for all registers is written to the program context upto the specified address(exclusive). The future flow state values are then loaded into the current context. Use this method if keeping separate flows from different flow from addresses is not important.
      Parameters:
      address - the address to flow to.
      Throws:
      IllegalStateException - if no flow was started.
    • flowToAddress

      public void flowToAddress(Address fromAddr, Address destAddr)
      Continues the current flow from an address to the given address. Checks for register values that have been stored in the future flow state. If any registers have saved future state, the current state for all registers is written to the program context upto the specified address(exclusive). The future flow state values are then loaded into the current context.
      Parameters:
      fromAddr - address that this flow is flowing from.
      destAddr - the starting address of a new instruction flow.
      Throws:
      IllegalStateException - if a previous flow was not ended.
    • flowEnd

      public void flowEnd(Address maxAddress)
      Ends the current flow. Unsaved register values will be saved up to and including max address.
      Parameters:
      maxAddress - the maximum address of an instruction flow. If maxAddress is null, or the current flow address has already advanced beyond maxAddress, then no save is performed.
      Throws:
      IllegalStateException - if a flow has not been started.
    • getRegisters

      public List<Register> getRegisters()
      Description copied from interface: ProcessorContextView
      Returns all the Registers for the processor as an unmodifiable list
      Specified by:
      getRegisters in interface ProcessorContextView
      Returns:
      all the Registers for the processor
    • getRegister

      public Register getRegister(String name)
      Description copied from interface: ProcessorContextView
      Get a Register given the name of a register
      Specified by:
      getRegister in interface ProcessorContextView
      Parameters:
      name - the name of the register.
      Returns:
      The register with the given name.
    • getRegisterValue

      public RegisterValue getRegisterValue(Register register)
      Description copied from interface: ProcessorContextView
      Get the RegisterValue for the given register.
      Specified by:
      getRegisterValue in interface ProcessorContextView
      Parameters:
      register - register to get the value for
      Returns:
      RegisterValue object containing the value of the register if a value exists, otherwise null.
    • getValue

      public BigInteger getValue(Register register, boolean signed)
      Description copied from interface: ProcessorContextView
      Get the contents of a processor register as a BigInteger object
      Specified by:
      getValue in interface ProcessorContextView
      Parameters:
      register - register to get the value for
      Returns:
      a BigInteger object containing the value of the register if a value exists, otherwise null.
    • setValue

      public void setValue(Register register, Address address, BigInteger newValue)
      Sets the value for the given register to be used when the flow advances to the given address using either the flowTo() or flowStart() methods. The new value has precedence over any existing value. Use this method if keeping separate flows from different flow from addresses is not important.
      Parameters:
      register - the register for which the value is to be saved.
      address - the future flow address to save the value.
      newValue - the value to save for future flow.
    • setValue

      public void setValue(Register register, Address fromAddr, Address toAddr, BigInteger newValue)
      Sets the value for the given register to be used when the flow advances to the given address using either the flowTo() or flowStart() methods. The new value has precedence over any existing value.
      Parameters:
      register - the register for which the value is to be saved.
      fromAddr - the address from which this flow originated
      toAddr - the future flow address to save the value.
      newValue - the value to save for future flow.
    • setFutureRegisterValue

      public void setFutureRegisterValue(Address address, RegisterValue value)
      Description copied from interface: DisassemblerContext
      Combines value with any previously saved future register value at address or any value stored in the program if there is no previously saved future value. Use this method when multiple flows to the same address don't matter or the flowing from address is unknown.
      When value has conflicting bits with the previously saved value, value will take precedence.
      If the register value is the value for the processor context register and a previously saved value does not exist, the user saved values in the stored context of the program will be used as existing value.
      Specified by:
      setFutureRegisterValue in interface DisassemblerContext
      Parameters:
      address - the address to store the register value
      value - the register value to store at the address
    • setFutureRegisterValue

      public void setFutureRegisterValue(Address fromAddr, Address toAddr, RegisterValue value)
      Description copied from interface: DisassemblerContext
      Combines value with any previously saved future register value at fromAddr/toAddr or any value stored in the program if there is no previously saved future value.
      When value has conflicting bits with the previously saved value, value will take precedence.
      If the register value is the value for the processor context register and a previously saved value does not exist, the user saved values in the stored context of the program will be used as existing value.
      Specified by:
      setFutureRegisterValue in interface DisassemblerContext
      Parameters:
      fromAddr - the address this value if flowing from
      toAddr - the address to store the register value
      value - the register value to store at the address
    • getAddress

      public Address getAddress()
      Returns the current flow address for this context.
    • hasValue

      public boolean hasValue(Register register)
      Description copied from interface: ProcessorContextView
      Returns true if a value is defined for the given register.
      Specified by:
      hasValue in interface ProcessorContextView
      Parameters:
      register - the register to check for a value.
      Returns:
      true if the given register has a value.
    • setValue

      public void setValue(Register register, BigInteger value)
      Description copied from interface: ProcessorContext
      Sets the value for a Register.
      Specified by:
      setValue in interface ProcessorContext
      Parameters:
      register - the register to have its value set
      value - the value for the register (null is not permitted).
    • clearRegister

      public void clearRegister(Register register)
      Description copied from interface: ProcessorContext
      Clears the register within this context.
      Specified by:
      clearRegister in interface ProcessorContext
      Parameters:
      register - register to be cleared.
    • setContextRegisterValue

      public void setContextRegisterValue(RegisterValue value, Address address)
      Modify the current context register value at the specified address. If current disassembly flow address equals specified address the current disassembly context will be changed, otherwise the future flow state will be changed. This differs from setValue(Register, Address, BigInteger) in that is can affect the current context state at the current address in a non-delayed fashion. Use this method if keeping separate flows from different flow from addresses is not important.
      Parameters:
      value - register value
      address - disassembly address
    • setContextRegisterValue

      public void setContextRegisterValue(RegisterValue value, Address fromAddr, Address toAddr)
      Modify the current context register value at the specified address. If current disassembly toAddr address equals specified address the current disassembly context will be changed, otherwise the future flow state flowing from the fromAddr will be changed. This differs from setValue(Register, Address, BigInteger) in that is can affect the current context state at the current address in a non-delayed fashion.
      Parameters:
      value - register value
      fromAddr - the address from which this flow originated
      toAddr - the future flow address to save the value.
    • setRegisterValue

      public void setRegisterValue(RegisterValue value)
      Description copied from interface: ProcessorContext
      Sets the specified register value within this context.
      Specified by:
      setRegisterValue in interface ProcessorContext
      Parameters:
      value - register value
    • getValue

      public BigInteger getValue(Register register, Address address, boolean signed)
      Returns the future register value at the specified address. If no future value is stored, it will return the value stored in the program. Use this method if keeping separate flows from different flow from addresses is not important.
      Parameters:
      register - the register to get a value for.
      address - the address at which to get a value.
      signed - if true, interpret the value as signed.
      Returns:
      the value of the register at the location, or null if a full value is not established.
    • getValue

      public BigInteger getValue(Register register, Address fromAddr, Address toAddr, boolean signed)
      Returns the future register value at the specified address that occurred because of a flow from the fromAddr. If no future value is stored, it will return the value stored in the program.
      Parameters:
      register - the register to get a value for.
      fromAddr - the address from which this flow originated.
      toAddr - the future flow address to save the value.
      signed - if true, interpret the value as signed.
      Returns:
      the value of the register at the location, or null if a full value is not established.
    • getRegisterValue

      public RegisterValue getRegisterValue(Register register, Address address)
      Returns the future RegisterValue at the specified address. If no future value is stored, it will return the value stored in the program. The value returned may not have a complete value for the requested register. Use this method if keeping separate flows from different flow from addresses is not important.
      Parameters:
      register - the register to get a value for.
      address - the address at which to get a value.
      Returns:
      a RegisterValue object if one has been stored in the future flow or the program. The RegisterValue object may have a "no value" state for the bits specified by the given register. Also, null may be returned if no value have been stored.
    • getRegisterValue

      public RegisterValue getRegisterValue(Register register, Address fromAddr, Address destAddr)
      Returns the future RegisterValue at the specified address that occurred because of a flow from the fromAddr. If no future value is stored, it will return the value stored in the program. The value returned may not have a complete value for the requested register.
      Parameters:
      register - the register to get a value for.
      fromAddr - the address from which the flow originated
      destAddr - the address at which to get a value.
      Returns:
      a RegisterValue object if one has been stored in the future flow or the program. The RegisterValue object may have a "no value" state for the bits specified by the given register. Also, null may be returned if no value have been stored.
    • getKnownFlowToAddresses

      public Address[] getKnownFlowToAddresses(Address toAddr)
      Returns an array of locations that have values that will flow to this location
      Parameters:
      toAddr - address that is the target of a flow to
      Returns:
      and array of known address flows to this location
    • isFlowActive

      public boolean isFlowActive()
      Returns true if a flow has been started and not yet ended.
      Returns:
      true if a flow has been started and not yet ended.