Package ghidra.program.disassemble
Class DisassemblerContextImpl
- java.lang.Object
-
- ghidra.program.disassemble.DisassemblerContextImpl
-
- All Implemented Interfaces:
DisassemblerContext
,ProcessorContext
,ProcessorContextView
public class DisassemblerContextImpl extends java.lang.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 Summary
Constructors Constructor Description DisassemblerContextImpl(ProgramContext programContext)
Constructor for DisassemblerContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearRegister(Register register)
Clears the register within this context.RegisterValue
copyToFutureFlowState(Address address)
Saves the current processor state for when this context flows to the given address.RegisterValue
copyToFutureFlowState(Address fromAddr, Address destAddr)
Saves the current processor state flowing from the fromAddr, for when this context flows to the given address.void
flowAbort()
Terminate active flow while preserving any accumulated future context.void
flowEnd(Address maxAddress)
Ends the current flow.void
flowStart(Address address)
Starts a new flow.void
flowStart(Address fromAddr, Address toAddr)
Starts a new flow from an address to the new start.void
flowToAddress(Address address)
Continues the current flow at the given address.void
flowToAddress(Address fromAddr, Address destAddr)
Continues the current flow from an address to the given address.Address
getAddress()
Returns the current flow address for this context.Register
getBaseContextRegister()
RegisterValue
getFlowContextValue(Address destAddr, boolean isFallThrough)
Get flowed context value at arbitrary destination address without affecting state.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.Address[]
getKnownFlowToAddresses(Address toAddr)
Returns an array of locations that have values that will flow to this locationProgramContext
getProgramContext()
Register
getRegister(java.lang.String name)
Get a Register given the name of a registerjava.util.List<Register>
getRegisters()
Returns all the Registers for the processor as an unmodifiable listRegisterValue
getRegisterValue(Register register)
Get the RegisterValue for the given register.RegisterValue
getRegisterValue(Register register, Address address)
Returns the future RegisterValue at the specified address.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.java.math.BigInteger
getValue(Register register, boolean signed)
Get the contents of a processor register as a BigInteger objectjava.math.BigInteger
getValue(Register register, Address address, boolean signed)
Returns the future register value at the specified address.java.math.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.boolean
hasValue(Register register)
Returns true if a value is defined for the given register.boolean
isFlowActive()
Returns true if a flow has been started and not yet ended.java.util.ArrayList<RegisterValue>
mergeToFutureFlowState(Address address)
Saves the current processor state for when this context is later used at the given address.java.util.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.void
setContextRegisterValue(RegisterValue value, Address address)
Modify the current context register value at the specified address.void
setContextRegisterValue(RegisterValue value, Address fromAddr, Address toAddr)
Modify the current context register value at the specified address.void
setFutureRegisterValue(Address fromAddr, Address toAddr, RegisterValue value)
Combinesvalue
with any previously saved future register value atfromAddr/toAddr
or any value stored in the program if there is no previously saved future value.void
setFutureRegisterValue(Address address, RegisterValue value)
Combinesvalue
with any previously saved future register value ataddress
or any value stored in the program if there is no previously saved future value.void
setRegisterValue(RegisterValue value)
Sets the specified register value within this context.void
setValue(Register register, Address fromAddr, Address toAddr, java.math.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.void
setValue(Register register, Address address, java.math.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.void
setValue(Register register, java.math.BigInteger value)
Sets the value for a Register.
-
-
-
Constructor Detail
-
DisassemblerContextImpl
public DisassemblerContextImpl(ProgramContext programContext)
Constructor for DisassemblerContext.- Parameters:
programContext
- contains the values for registers at specific addresses store in the program.
-
-
Method Detail
-
getProgramContext
public ProgramContext getProgramContext()
-
getBaseContextRegister
public Register getBaseContextRegister()
- Specified by:
getBaseContextRegister
in interfaceProcessorContextView
- 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 java.util.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 java.util.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 originateddestAddr
- 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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.IllegalStateException
- if a flow has not been started.
-
getRegisters
public java.util.List<Register> getRegisters()
Description copied from interface:ProcessorContextView
Returns all the Registers for the processor as an unmodifiable list- Specified by:
getRegisters
in interfaceProcessorContextView
- Returns:
- all the Registers for the processor
-
getRegister
public Register getRegister(java.lang.String name)
Description copied from interface:ProcessorContextView
Get a Register given the name of a register- Specified by:
getRegister
in interfaceProcessorContextView
- 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 interfaceProcessorContextView
- 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 java.math.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 interfaceProcessorContextView
- 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, java.math.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, java.math.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 originatedtoAddr
- 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
Combinesvalue
with any previously saved future register value ataddress
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.
Whenvalue
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 interfaceDisassemblerContext
- Parameters:
address
- the address to store the register valuevalue
- the register value to store at the address
-
setFutureRegisterValue
public void setFutureRegisterValue(Address fromAddr, Address toAddr, RegisterValue value)
Description copied from interface:DisassemblerContext
Combinesvalue
with any previously saved future register value atfromAddr/toAddr
or any value stored in the program if there is no previously saved future value.
Whenvalue
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 interfaceDisassemblerContext
- Parameters:
fromAddr
- the address this value if flowing fromtoAddr
- the address to store the register valuevalue
- 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 interfaceProcessorContextView
- Parameters:
register
- the register to check for a value.- Returns:
- true if the given register has a value.
-
setValue
public void setValue(Register register, java.math.BigInteger value)
Description copied from interface:ProcessorContext
Sets the value for a Register.- Specified by:
setValue
in interfaceProcessorContext
- Parameters:
register
- the register to have its value setvalue
- 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 interfaceProcessorContext
- 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 fromsetValue(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 valueaddress
- 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 fromsetValue(Register, Address, BigInteger)
in that is can affect the current context state at the current address in a non-delayed fashion.- Parameters:
value
- register valuefromAddr
- the address from which this flow originatedtoAddr
- 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 interfaceProcessorContext
- Parameters:
value
- register value
-
getValue
public java.math.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 java.math.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 originateddestAddr
- 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.
-
-