Class AssemblyDefaultContext
- java.lang.Object
-
- ghidra.app.plugin.assembler.sleigh.sem.AssemblyDefaultContext
-
- All Implemented Interfaces:
DisassemblerContext
,ProcessorContext
,ProcessorContextView
,DefaultProgramContext
public class AssemblyDefaultContext extends java.lang.Object implements DisassemblerContext, DefaultProgramContext
A class that computes the default context for a language, and acts as a pseudo context This class helps maintain context consistency when performing both assembly and disassembly.
-
-
Field Summary
Fields Modifier and Type Field Description protected Address
at
protected AssemblyPatternBlock
curctx
protected static DbgTimer
dbg
protected AssemblyPatternBlock
defctx
protected SleighLanguage
lang
-
Constructor Summary
Constructors Modifier Constructor Description AssemblyDefaultContext(SleighLanguage lang)
Compute the default context at most addresses for the given languageprotected
AssemblyDefaultContext(SleighLanguage lang, Address at)
Compute the default context at the given address for the given language
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearRegister(Register register)
Clears the register within this context.Register
getBaseContextRegister()
AssemblyPatternBlock
getDefault()
Get the default value of the context registerAssemblyPatternBlock
getDefaultAt(Address addr)
Compute the default value of the context register at the given addressRegisterValue
getDefaultValue(Register register, Address address)
Returns the default value of a register at a given address.Register
getRegister(java.lang.String name)
Get a Register given the name of a registerRegister[]
getRegisters()
Returns all the Registers for the processorRegisterValue
getRegisterValue(Register register)
Get the RegisterValue for the given register.java.math.BigInteger
getValue(Register register, boolean signed)
Get the contents of a processor register as a BigInteger objectboolean
hasValue(Register register)
Returns true if a value is defined for the given register.void
setContextRegister(byte[] val)
Set the value of the pseudo context register If the provided value has length less than the register, it will be left aligned, and the remaining bytes will be set to unknown (masked out).void
setDefaultValue(RegisterValue registerValue, Address start, Address end)
Associates a default value with the given register over the given range.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, java.math.BigInteger value)
Sets the value for a Register.
-
-
-
Field Detail
-
lang
protected final SleighLanguage lang
-
at
protected final Address at
-
curctx
protected AssemblyPatternBlock curctx
-
defctx
protected AssemblyPatternBlock defctx
-
dbg
protected static final DbgTimer dbg
-
-
Constructor Detail
-
AssemblyDefaultContext
public AssemblyDefaultContext(SleighLanguage lang)
Compute the default context at most addresses for the given language- Parameters:
lang
- the language
-
AssemblyDefaultContext
protected AssemblyDefaultContext(SleighLanguage lang, Address at)
Compute the default context at the given address for the given language- Parameters:
lang
- the languageat
- the address
-
-
Method Detail
-
setContextRegister
public void setContextRegister(byte[] val)
Set the value of the pseudo context register If the provided value has length less than the register, it will be left aligned, and the remaining bytes will be set to unknown (masked out).- Parameters:
val
- the value of the register
-
getDefault
public AssemblyPatternBlock getDefault()
Get the default value of the context register- Returns:
- the value as a pattern block for assembly
-
getDefaultAt
public AssemblyPatternBlock getDefaultAt(Address addr)
Compute the default value of the context register at the given address- Parameters:
addr
- the addres- Returns:
- the value as a pattern block for assembly
-
setValue
public void setValue(Register register, java.math.BigInteger value) throws ContextChangeException
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).- Throws:
ContextChangeException
- an illegal attempt to change context was made
-
setRegisterValue
public void setRegisterValue(RegisterValue value) throws ContextChangeException
Description copied from interface:ProcessorContext
Sets the specified register value within this context.- Specified by:
setRegisterValue
in interfaceProcessorContext
- Parameters:
value
- register value- Throws:
ContextChangeException
- an illegal attempt to change context was made
-
clearRegister
public void clearRegister(Register register) throws ContextChangeException
Description copied from interface:ProcessorContext
Clears the register within this context.- Specified by:
clearRegister
in interfaceProcessorContext
- Parameters:
register
- register to be cleared.- Throws:
ContextChangeException
- an illegal attempt to change context was made
-
getBaseContextRegister
public Register getBaseContextRegister()
- Specified by:
getBaseContextRegister
in interfaceProcessorContextView
- Returns:
- the base processor context register or null if one has not been defined
-
getRegisters
public Register[] getRegisters()
Description copied from interface:ProcessorContextView
Returns all the Registers for the processor- 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.
-
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.
-
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.
-
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.
-
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
-
setDefaultValue
public void setDefaultValue(RegisterValue registerValue, Address start, Address end)
Description copied from interface:DefaultProgramContext
Associates a default value with the given register over the given range.- Specified by:
setDefaultValue
in interfaceDefaultProgramContext
- Parameters:
registerValue
- the register for which to associate a default value.start
- the start address.end
- the end address (inclusive)
-
getDefaultValue
public RegisterValue getDefaultValue(Register register, Address address)
Description copied from interface:DefaultProgramContext
Returns the default value of a register at a given address.- Specified by:
getDefaultValue
in interfaceDefaultProgramContext
- Parameters:
register
- the register for which to get a default value.address
- the address at which to get a default value.- Returns:
- the default value of the register at the given address or null if no default value has been assigned.
-
-