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 AddressFactory
addrFactory
protected java.util.HashMap<Varnode,AddressSet>
allLastSet
Address
BAD_ADDRESS
static int
BAD_SPACE_ID_VALUE
protected java.util.HashSet<Varnode>
clearVals
protected Address
currentAddress
protected Instruction
currentInstruction
boolean
debug
protected boolean
hitDest
protected boolean
keepTempUniqueValues
protected java.util.HashMap<Varnode,Address>
lastSet
protected java.util.Stack<java.util.HashMap<Varnode,Varnode>>
memoryVals
protected static NotFoundException
notFoundExc
protected DisassemblerContextImpl
offsetContext
protected Program
program
protected ProgramContext
programContext
protected Varnode[]
retVarnodes
protected DisassemblerContextImpl
spaceContext
protected Register
stackReg
protected Varnode
stackVarnode
protected java.util.HashMap<Varnode,Varnode>
tempUniqueVals
protected VarnodeTranslator
trans
-
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 Varnode
add(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 spaceVarnode
and(Varnode val1, Varnode val2, ContextEvaluator evaluator)
void
clearReadExecutableCode()
void
clearRegister(Register reg)
Clears the register within this context.void
copy(Varnode out, Varnode in, boolean mustClearAll, ContextEvaluator evaluator)
Copy the varnode with as little manipulation as possible.void
copyToFutureFlowState(Address fromAddr, Address toAddr)
Varnode
createBadVarnode()
Varnode
createConstantVarnode(long value, int size)
Varnode
createVarnode(long value, int spaceID, int size)
Varnode
createVarnode(java.math.BigInteger bigVal, java.math.BigInteger spaceVal, int size)
Varnode
extendValue(Varnode out, Varnode[] in, boolean signExtend, ContextEvaluator evaluator)
Extend a constant value if it can be extended.void
flowEnd(Address address)
void
flowStart(Address fromAddr, Address toAddr)
void
flowToAddress(Address fromAddr, Address toAddr)
int
getAddressSpace(java.lang.String name)
Register
getBaseContextRegister()
long
getConstant(Varnode vnode, ContextEvaluator evaluator)
Instruction
getCurrentInstruction(Address addr)
boolean
getDebug()
Address[]
getKnownFlowToAddresses(Address toAddr)
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...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...protected Varnode
getMemoryValue(Varnode varnode)
Search the value state stack for the first occurence of the set valueRegister
getRegister(Varnode vnode)
Return a register given a varnodeRegister
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 reg, Address toAddr)
RegisterValue
getRegisterValue(Register reg, Address fromAddr, Address toAddr)
AddressRangeIterator
getRegisterValueAddressRanges(Register reg)
Varnode
getRegisterVarnode(Register register)
Varnode
getRegisterVarnodeValue(Register register)
Varnode
getRegisterVarnodeValue(Register reg, Address fromAddr, Address toAddr, boolean signed)
get the value of a register as a varnode (value, space, size)Varnode[]
getReturnVarnode(Function targetFunc)
Register
getStackRegister()
Varnode
getStackVarnode()
java.math.BigInteger
getValue(Register register, boolean signed)
Get the contents of a processor register as a BigInteger objectVarnode
getValue(Varnode varnode, boolean signed, ContextEvaluator evaluator)
Varnode
getValue(Varnode varnode, ContextEvaluator evaluator)
Varnode
getVarnode(int spaceID, long offset, int size)
Varnode
getVarnode(Varnode space, Varnode offset, int size, ContextEvaluator evaluator)
boolean
hasValue(Register register)
Returns true if a value is defined for the given register.boolean
hasValueOverRange(Register reg, java.math.BigInteger bval, AddressSet set)
protected boolean
isReadOnly(Address addr)
Check if the symbol at the address is read_only.protected boolean
isRegister(Varnode varnode)
boolean
isStackSymbolicSpace(Varnode varnode)
Return true if this varnode is stored in the symbolic stack spaceboolean
isSymbol(Varnode node)
boolean
isSymbolicSpace(int spaceID)
boolean
isSymbolicSpace(AddressSpace space)
Varnode
left(Varnode val1, Varnode val2, ContextEvaluator evaluator)
boolean
mergeToFutureFlowState(Address fromAddr, Address toAddr)
Varnode
or(Varnode val1, Varnode val2, ContextEvaluator evaluator)
void
popMemState()
protected java.lang.String
print(Varnode rvnode)
void
propogateResults(boolean clearContext)
Propogate any results that are in the value cache.void
propogateValue(Register reg, Varnode node, Varnode val, Address address)
void
pushMemState()
protected void
putMemoryValue(Varnode out, Varnode value)
Put the value for the varnode on the top of the memory state stackvoid
putValue(Varnode out, Varnode result, boolean mustClear)
boolean
readExecutableCode()
void
setCurrentInstruction(Instruction instr)
void
setDebug(boolean debugOn)
void
setFutureRegisterValue(Address address, RegisterValue regVal)
void
setReadExecutableCode()
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.Varnode
subtract(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:
getBaseContextRegister
in 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
-
getMemoryValue
protected Varnode getMemoryValue(Varnode varnode)
Search the value state stack for the first occurence of the set value- Parameters:
varnode
- varnode to search for a value- Returns:
- first value found on stack, null otherwise
-
putMemoryValue
protected void putMemoryValue(Varnode out, Varnode value)
Put the value for the varnode on the top of the memory state stack- Parameters:
out
- varnode for the valuevalue
- value to store for the varnode
-
isReadOnly
protected boolean isReadOnly(Address addr)
Check if the symbol at the address is read_only.- Parameters:
addr
- - 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:
rvar
- the register varnodebval
- this parameter is unused.- 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 forfromAddr
- from addresstoAddr
- to addresssigned
- true if signed- Returns:
- the register value or null
-
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
-
or
public Varnode or(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:ProcessorContext
Clears the register within this context.- Specified by:
clearRegister
in interfaceProcessorContext
- Parameters:
reg
- register to be cleared.
-
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.
-
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
-
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.
-
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.
-
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
-
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).
-
isSymbol
public boolean isSymbol(Varnode node)
-
isSymbolicSpace
public boolean isSymbolicSpace(AddressSpace space)
-
isSymbolicSpace
public boolean isSymbolicSpace(int spaceID)
-
pushMemState
public void pushMemState()
-
popMemState
public void popMemState()
-
-