Package ghidra.program.disassemble
Class DisassemblerContextImpl
java.lang.Object
ghidra.program.disassemble.DisassemblerContextImpl
- All Implemented Interfaces:
DisassemblerContext
,ProcessorContext
,ProcessorContextView
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
ConstructorDescriptionDisassemblerContextImpl
(ProgramContext programContext) Constructor for DisassemblerContext. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clearRegister
(Register register) Clears the register within this context.copyToFutureFlowState
(Address address) Saves the current processor state for when this context flows to the given address.copyToFutureFlowState
(Address fromAddr, Address destAddr) Saves the current processor state flowing from the fromAddr, for when this context flows to the given address.void
Terminate active flow while preserving any accumulated future context.void
Ends the current flow.void
Starts a new flow.void
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.Returns the current flow address for this context.getFlowContextValue
(Address destAddr, boolean isFallThrough) Get flowed context value at arbitrary destination address without affecting state.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 locationgetRegister
(String name) Get a Register given the name of a registerReturns all the Registers for the processor as an unmodifiable listgetRegisterValue
(Register register) Get the RegisterValue for the given register.getRegisterValue
(Register register, Address address) Returns the future RegisterValue at the specified address.getRegisterValue
(Register register, Address fromAddr, Address destAddr) Returns the future RegisterValue at the specified address that occurred because of a flow from the fromAddr.Get the contents of a processor register as a BigInteger objectReturns the future register value at the specified address.Returns the future register value at the specified address that occurred because of a flow from the fromAddr.boolean
Returns true if a value is defined for the given register.boolean
Returns true if a flow has been started and not yet ended.mergeToFutureFlowState
(Address address) Saves the current processor state for when this context is later used at the given address.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, 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, 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, BigInteger value) Sets the value for a Register.
-
Constructor Details
-
DisassemblerContextImpl
Constructor for DisassemblerContext.- Parameters:
programContext
- contains the values for registers at specific addresses store in the program.
-
-
Method Details
-
getProgramContext
-
getBaseContextRegister
- Specified by:
getBaseContextRegister
in interfaceProcessorContextView
- Returns:
- the base processor context register or null if one has not been defined
-
copyToFutureFlowState
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Returns the current flow address for this context. -
hasValue
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
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
Description copied from interface:ProcessorContext
Clears the register within this context.- Specified by:
clearRegister
in interfaceProcessorContext
- Parameters:
register
- register to be cleared.
-
setContextRegisterValue
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
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
Description copied from interface:ProcessorContext
Sets the specified register value within this context.- Specified by:
setRegisterValue
in interfaceProcessorContext
- Parameters:
value
- register value
-
getValue
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
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
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
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
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.
-