Package ghidra.program.util
Class VarnodeContext
- java.lang.Object
-
- ghidra.program.util.VarnodeContext
-
- All Implemented Interfaces:
ProcessorContext,ProcessorContextView
public class VarnodeContext extends java.lang.Object implements ProcessorContext
-
-
Field Summary
Fields Modifier and Type Field Description protected AddressFactoryaddrFactoryprotected java.util.HashMap<Varnode,AddressSet>allLastSetAddressBAD_ADDRESSstatic intBAD_SPACE_ID_VALUEprotected java.util.HashSet<Varnode>clearValsprotected AddresscurrentAddressprotected InstructioncurrentInstructionbooleandebugprotected booleanhitDestprotected booleankeepTempUniqueValuesprotected java.util.HashMap<Varnode,Address>lastSetprotected java.util.HashMap<Varnode,Varnode>memoryValsprotected static NotFoundExceptionnotFoundExcprotected DisassemblerContextImploffsetContextprotected Programprogramprotected ProgramContextprogramContextprotected Varnode[]retVarnodesprotected DisassemblerContextImplspaceContextprotected RegisterstackRegprotected VarnodestackVarnodeprotected java.util.HashMap<Varnode,Varnode>tempUniqueValsprotected VarnodeTranslatortrans
-
Constructor Summary
Constructors Constructor Description VarnodeContext(Program program, ProgramContext programContext, ProgramContext spaceProgramContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Varnodeadd(Varnode val1, Varnode val2, ContextEvaluator evaluator)Add two varnodes together to get a new value This could create a new space and return a varnode pointed into that spaceVarnodeand(Varnode val1, Varnode val2, ContextEvaluator evaluator)voidclearReadExecutableCode()voidclearRegister(Register reg)Clears the register within this context.voidcopy(Varnode out, Varnode in, boolean mustClearAll, ContextEvaluator evaluator)Copy the varnode with as little manipulation as possible.voidcopyToFutureFlowState(Address fromAddr, Address toAddr)VarnodecreateBadVarnode()VarnodecreateConstantVarnode(long value, int size)VarnodecreateVarnode(long value, int spaceID, int size)VarnodecreateVarnode(java.math.BigInteger bigVal, java.math.BigInteger spaceVal, int size)VarnodeextendValue(Varnode out, Varnode[] in, boolean signExtend, ContextEvaluator evaluator)Extend a constant value if it can be extended.voidflowEnd(Address address)voidflowStart(Address fromAddr, Address toAddr)voidflowToAddress(Address fromAddr, Address toAddr)intgetAddressSpace(java.lang.String name)RegistergetBaseContextRegister()longgetConstant(Varnode vnode, ContextEvaluator evaluator)InstructiongetCurrentInstruction(Address addr)booleangetDebug()Address[]getKnownFlowToAddresses(Address toAddr)AddressgetLastSetLocation(Register reg, java.math.BigInteger bval)return the location that this register was last set This is a transient thing, so it should only be used as a particular flow is being processed...AddressgetLastSetLocation(Varnode rvar, java.math.BigInteger bval)return the location that this varnode was last set This is a transient thing, so it should only be used as a particular flow is being processed...RegistergetRegister(Varnode vnode)Return a register given a varnodeRegistergetRegister(java.lang.String name)Get a Register given the name of a registerRegister[]getRegisters()Returns all the Registers for the processorRegisterValuegetRegisterValue(Register register)Get the RegisterValue for the given register.RegisterValuegetRegisterValue(Register reg, Address toAddr)RegisterValuegetRegisterValue(Register reg, Address fromAddr, Address toAddr)AddressRangeIteratorgetRegisterValueAddressRanges(Register reg)VarnodegetRegisterVarnode(Register register)VarnodegetRegisterVarnodeValue(Register register)VarnodegetRegisterVarnodeValue(Register reg, Address fromAddr, Address toAddr, boolean signed)get the value of a register as a varnode (value, space, size)Varnode[]getReturnVarnode(Function targetFunc)RegistergetStackRegister()VarnodegetStackVarnode()java.math.BigIntegergetValue(Register register, boolean signed)Get the contents of a processor register as a BigInteger objectVarnodegetValue(Varnode varnode, boolean signed, ContextEvaluator evaluator)VarnodegetValue(Varnode varnode, ContextEvaluator evaluator)VarnodegetVarnode(int spaceID, long offset, int size)VarnodegetVarnode(Varnode space, Varnode offset, int size, ContextEvaluator evaluator)booleanhasValue(Register register)Returns true if a value is defined for the given register.booleanhasValueOverRange(Register reg, java.math.BigInteger bval, AddressSet set)protected booleanisReadOnly(Address addr)Check if a symbol is read_only.protected booleanisRegister(Varnode varnode)booleanisStackSymbolicSpace(Varnode varnode)Return true if this varnode is stored in the symbolic stack spacebooleanisSymbol(Varnode node)booleanisSymbolicSpace(int spaceID)booleanisSymbolicSpace(AddressSpace space)Varnodeleft(Varnode val1, Varnode val2, ContextEvaluator evaluator)booleanmergeToFutureFlowState(Address fromAddr, Address toAddr)protected java.lang.Stringprint(Varnode rvnode)voidpropogateResults(boolean clearContext)Propogate any results that are in the value cache.voidpropogateValue(Register reg, Varnode node, Varnode val, Address address)voidputValue(Varnode out, Varnode result, boolean mustClear)booleanreadExecutableCode()voidsetCurrentInstruction(Instruction instr)voidsetDebug(boolean debugOn)voidsetFutureRegisterValue(Address address, RegisterValue regVal)voidsetReadExecutableCode()voidsetRegisterValue(RegisterValue value)Sets the specified register value within this context.voidsetValue(Register register, java.math.BigInteger value)Sets the value for a Register.Varnodesubtract(Varnode val1, Varnode val2, ContextEvaluator evaluator)Subtract two varnodes to get a new value This could create a new space and return a varnode pointed into that space
-
-
-
Field Detail
-
BAD_ADDRESS
public Address BAD_ADDRESS
-
BAD_SPACE_ID_VALUE
public static final int BAD_SPACE_ID_VALUE
- See Also:
- Constant Field Values
-
offsetContext
protected DisassemblerContextImpl offsetContext
-
spaceContext
protected DisassemblerContextImpl spaceContext
-
keepTempUniqueValues
protected boolean keepTempUniqueValues
-
clearVals
protected java.util.HashSet<Varnode> clearVals
-
allLastSet
protected java.util.HashMap<Varnode,AddressSet> allLastSet
-
program
protected Program program
-
trans
protected VarnodeTranslator trans
-
retVarnodes
protected Varnode[] retVarnodes
-
stackVarnode
protected Varnode stackVarnode
-
stackReg
protected Register stackReg
-
notFoundExc
protected static final NotFoundException notFoundExc
-
hitDest
protected boolean hitDest
-
addrFactory
protected AddressFactory addrFactory
-
programContext
protected ProgramContext programContext
-
currentAddress
protected Address currentAddress
-
currentInstruction
protected Instruction currentInstruction
-
debug
public boolean debug
-
-
Constructor Detail
-
VarnodeContext
public VarnodeContext(Program program, ProgramContext programContext, ProgramContext spaceProgramContext)
-
-
Method Detail
-
setDebug
public void setDebug(boolean debugOn)
-
getDebug
public boolean getDebug()
-
setCurrentInstruction
public void setCurrentInstruction(Instruction instr)
-
getCurrentInstruction
public Instruction getCurrentInstruction(Address addr)
-
getBaseContextRegister
public Register getBaseContextRegister()
- Specified by:
getBaseContextRegisterin interfaceProcessorContextView- Returns:
- the base processor context register or null if one has not been defined
-
flowEnd
public void flowEnd(Address address)
-
setFutureRegisterValue
public void setFutureRegisterValue(Address address, RegisterValue regVal)
-
getReturnVarnode
public Varnode[] getReturnVarnode(Function targetFunc)
- Parameters:
targetFunc- function to get a returning varnode for NOTE: this only gets one, unless there is custom storage on the called function there may be bonded ones in the default convention!- Returns:
- varnode that represents where functions place their return value
-
getStackVarnode
public Varnode getStackVarnode()
- Returns:
- Varnode that represents the stack register
-
isStackSymbolicSpace
public boolean isStackSymbolicSpace(Varnode varnode)
Return true if this varnode is stored in the symbolic stack space
-
getStackRegister
public Register getStackRegister()
- Returns:
- Register that represents the stack register
-
getValue
public Varnode getValue(Varnode varnode, ContextEvaluator evaluator) throws NotFoundException
- Throws:
NotFoundException
-
getValue
public Varnode getValue(Varnode varnode, boolean signed, ContextEvaluator evaluator) throws NotFoundException
- Throws:
NotFoundException
-
isReadOnly
protected boolean isReadOnly(Address addr)
Check if a symbol is read_only.- Parameters:
sym- - symbol to checkaddr- - address of the symbol- Returns:
- true if the block is read_only, and there are no write references.
-
createVarnode
public Varnode createVarnode(long value, int spaceID, int size)
-
createConstantVarnode
public Varnode createConstantVarnode(long value, int size)
-
createBadVarnode
public Varnode createBadVarnode()
-
createVarnode
public Varnode createVarnode(java.math.BigInteger bigVal, java.math.BigInteger spaceVal, int size)
-
readExecutableCode
public boolean readExecutableCode()
-
setReadExecutableCode
public void setReadExecutableCode()
-
clearReadExecutableCode
public void clearReadExecutableCode()
-
propogateResults
public void propogateResults(boolean clearContext)
Propogate any results that are in the value cache.- Parameters:
clearContext- true if the cache should be cleared. The propogation could be for flow purposes, and the processing of the instruction is finished, so it's effects should be kept.
-
propogateValue
public void propogateValue(Register reg, Varnode node, Varnode val, Address address)
-
getLastSetLocation
public Address getLastSetLocation(Register reg, java.math.BigInteger bval)
return the location that this register was last set This is a transient thing, so it should only be used as a particular flow is being processed...- Parameters:
reg- register to find last set locationbval- value to look for to differentiate set locations, null if don't care- Returns:
- address that the register was set.
-
getLastSetLocation
public Address getLastSetLocation(Varnode rvar, java.math.BigInteger bval)
return the location that this varnode was last set This is a transient thing, so it should only be used as a particular flow is being processed...- Parameters:
reg-- Returns:
- address that the register was set.
-
getVarnode
public Varnode getVarnode(int spaceID, long offset, int size)
-
getConstant
public long getConstant(Varnode vnode, ContextEvaluator evaluator) throws NotFoundException
- Throws:
NotFoundException
-
getVarnode
public Varnode getVarnode(Varnode space, Varnode offset, int size, ContextEvaluator evaluator) throws NotFoundException
- Throws:
NotFoundException
-
getRegisterVarnodeValue
public Varnode getRegisterVarnodeValue(Register reg, Address fromAddr, Address toAddr, boolean signed)
get the value of a register as a varnode (value, space, size)- Parameters:
reg- register to get value foraddress- location for valuesigned- true if signed- Returns:
- null if the register has no value
-
print
protected java.lang.String print(Varnode rvnode)
-
getRegisterValue
public RegisterValue getRegisterValue(Register reg, Address toAddr)
-
getRegisterValue
public RegisterValue getRegisterValue(Register reg, Address fromAddr, Address toAddr)
-
getRegisterValueAddressRanges
public AddressRangeIterator getRegisterValueAddressRanges(Register reg)
-
hasValueOverRange
public boolean hasValueOverRange(Register reg, java.math.BigInteger bval, AddressSet set)
-
copy
public void copy(Varnode out, Varnode in, boolean mustClearAll, ContextEvaluator evaluator) throws NotFoundException
Copy the varnode with as little manipulation as possible. Try to keep whatever partical state there is intact if a real value isn't required.- Parameters:
out- varnode to put it inin- varnode to copy from.evaluator-- Throws:
NotFoundException
-
add
public Varnode add(Varnode val1, Varnode val2, ContextEvaluator evaluator) throws NotFoundException
Add two varnodes together to get a new value This could create a new space and return a varnode pointed into that space- Parameters:
val1- first valueval2- second value- Returns:
- varnode that could be a constant, or an offset into a space
- Throws:
NotFoundException- if any constant is needed not known
-
isRegister
protected boolean isRegister(Varnode varnode)
-
and
public Varnode and(Varnode val1, Varnode val2, ContextEvaluator evaluator) throws NotFoundException
- Throws:
NotFoundException
-
left
public Varnode left(Varnode val1, Varnode val2, ContextEvaluator evaluator) throws NotFoundException
- Throws:
NotFoundException
-
getAddressSpace
public int getAddressSpace(java.lang.String name)
-
subtract
public Varnode subtract(Varnode val1, Varnode val2, ContextEvaluator evaluator) throws NotFoundException
Subtract two varnodes to get a new value This could create a new space and return a varnode pointed into that space- Parameters:
val1- first valueval2- second value- Returns:
- varnode that could be a constant, or an offset into a space
- Throws:
NotFoundException- if any constant is needed not known
-
extendValue
public Varnode extendValue(Varnode out, Varnode[] in, boolean signExtend, ContextEvaluator evaluator) throws NotFoundException
Extend a constant value if it can be extended.- Parameters:
out- varnode to extend into (for size)in- varnode value to extend the size- Returns:
- Throws:
NotFoundException
-
clearRegister
public void clearRegister(Register reg)
Description copied from interface:ProcessorContextClears the register within this context.- Specified by:
clearRegisterin interfaceProcessorContext- Parameters:
reg- register to be cleared.
-
getRegister
public Register getRegister(java.lang.String name)
Description copied from interface:ProcessorContextViewGet a Register given the name of a register- Specified by:
getRegisterin 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:ProcessorContextViewGet the RegisterValue for the given register.- Specified by:
getRegisterValuein interfaceProcessorContextView- Parameters:
register- register to get the value for- Returns:
- RegisterValue object containing the value of the register if a value exists, otherwise null.
-
getRegisters
public Register[] getRegisters()
Description copied from interface:ProcessorContextViewReturns all the Registers for the processor- Specified by:
getRegistersin interfaceProcessorContextView- Returns:
- all the Registers for the processor
-
getValue
public java.math.BigInteger getValue(Register register, boolean signed)
Description copied from interface:ProcessorContextViewGet the contents of a processor register as a BigInteger object- Specified by:
getValuein 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.
-
hasValue
public boolean hasValue(Register register)
Description copied from interface:ProcessorContextViewReturns true if a value is defined for the given register.- Specified by:
hasValuein interfaceProcessorContextView- Parameters:
register- the register to check for a value.- Returns:
- true if the given register has a value.
-
setRegisterValue
public void setRegisterValue(RegisterValue value)
Description copied from interface:ProcessorContextSets the specified register value within this context.- Specified by:
setRegisterValuein interfaceProcessorContext- Parameters:
value- register value
-
setValue
public void setValue(Register register, java.math.BigInteger value)
Description copied from interface:ProcessorContextSets the value for a Register.- Specified by:
setValuein interfaceProcessorContext- Parameters:
register- the register to have its value setvalue- the value for the register (null is not permitted).
-
isSymbol
public boolean isSymbol(Varnode node)
-
isSymbolicSpace
public boolean isSymbolicSpace(AddressSpace space)
-
isSymbolicSpace
public boolean isSymbolicSpace(int spaceID)
-
-