Package ghidra.program.database.code
Class InstructionDB
- java.lang.Object
-
- ghidra.program.database.DatabaseObject
-
- ghidra.program.database.code.InstructionDB
-
- All Implemented Interfaces:
InstructionContext
,ProcessorContext
,ProcessorContextView
,CodeUnit
,Instruction
,MemBuffer
public class InstructionDB extends DatabaseObject implements Instruction, InstructionContext
Database implementation for an Instruction.
-
-
Field Summary
Fields Modifier and Type Field Description protected long
addr
protected Address
address
protected byte[]
bytes
protected ChangeManager
changeMgr
protected CodeManager
codeMgr
protected Address
endAddr
protected int
length
protected Lock
lock
protected ProgramDB
program
protected ReferenceManager
refMgr
-
Fields inherited from class ghidra.program.database.DatabaseObject
key
-
Fields inherited from interface ghidra.program.model.listing.CodeUnit
COMMENT_PROPERTY, DEFINED_DATA_PROPERTY, EOL_COMMENT, INSTRUCTION_PROPERTY, MNEMONIC, NO_COMMENT, PLATE_COMMENT, POST_COMMENT, PRE_COMMENT, REPEATABLE_COMMENT, SPACE_PROPERTY
-
Fields inherited from interface ghidra.program.model.listing.Instruction
INVALID_DEPTH_CHANGE
-
-
Constructor Summary
Constructors Constructor Description InstructionDB(CodeManager codeMgr, DBObjectCache<? extends ghidra.program.database.code.CodeUnitDB> cache, Address address, long addr, InstructionPrototype proto, byte flags)
Construct a new InstructionDB.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMnemonicReference(Address refAddr, RefType refType, SourceType sourceType)
Add a reference to the mnemonic for this code unit.void
addOperandReference(int opIndex, Address refAddr, RefType type, SourceType sourceType)
Add a memory reference to the operand at the given index.void
clearFallThroughOverride()
Restores this instruction's fallthrough address back to the default fallthrough for this instruction.void
clearRegister(Register register)
Clears the register within this context.int
compareTo(Address a)
Compares the given address to the address range of this node.boolean
contains(Address testAddr)
Returns true if address is contained in the range of this codeUnitboolean
equals(java.lang.Object obj)
Return true if obj is equal to this.Address
getAddress()
Get the Address which corresponds to the offset 0.Address
getAddress(int opIndex)
Get the Address for the given operand index if one exists.java.lang.String
getAddressString(boolean showBlockName, boolean pad)
Get the string representation of the starting address for this code unit.Register
getBaseContextRegister()
java.math.BigInteger
getBigInteger(int offset, int size, boolean signed)
returns the value at the given offset, taking into account the endianess.byte
getByte(int offset)
Get one byte from memory at the current position plus offset.byte[]
getBytes()
Get the bytes that make up this code unit.int
getBytes(byte[] b, int offset)
Reads b.length bytes from this memory buffer starting at the address of this memory buffer plus the given memoryBufferOffset from that position.void
getBytesInCodeUnit(byte[] buffer, int bufferOffset)
Copies max(buffer.length, code unit length) bytes into buffer starting at location offset in buffer.java.lang.String
getComment(int commentType)
Get the comment for the given typejava.lang.String[]
getCommentAsArray(int commentType)
Get the comment for the given type and parse it into an array of strings such that each line is its own string.Address
getDefaultFallThrough()
Get the default fallthrough for this instruction.int
getDefaultFallThroughOffset()
Get default fall-through offset in bytes from start of instruction to the fallthrough instruction.Address[]
getDefaultFlows()
Get an array of Address objects for all default flows established by the underlying instruction prototype.java.lang.String
getDefaultOperandRepresentation(int opIndex)
Get the operand representation for the given operand index without markup.java.util.List<java.lang.Object>
getDefaultOperandRepresentationList(int opIndex)
Get the operand representation for the given operand index.int
getDelaySlotDepth()
Get the number of delay slot instructions for this argument.ExternalReference
getExternalReference(int opIndex)
Gets the external reference (if any) at the opIndexAddress
getFallFrom()
Get the Address for the instruction that fell through to this instruction.Address
getFallThrough()
Get the fallthrough for this instruction, factoring in any fallthrough override and delay slotted instructions.FlowOverride
getFlowOverride()
Returns the flow override which may have been set on this instruction.Address[]
getFlows()
Get an array of Address objects for all flows other than a fall-through.FlowType
getFlowType()
Get the flow type of this instruction (how this instruction flows to the next instruction).java.lang.Object[]
getInputObjects()
Get the Input objects used by this instruction.InstructionContext
getInstructionContext()
int
getInt(int offset)
returns the int at the given offset, taking into account the endianess.int
getIntProperty(java.lang.String name)
Get the int property for name.java.lang.String
getLabel()
Get the label for this code unit.int
getLength()
Get length of this code unit.long
getLong(int offset)
returns the long at the given offset, taking into account the endianess.Address
getMaxAddress()
Get the ending address for this code unit.MemBuffer
getMemBuffer()
Get the read-only memory buffer containing the instruction bytes.Memory
getMemory()
Get the Memory object actually used by the MemBuffer.Address
getMinAddress()
Get the starting address for this code unit.Reference[]
getMnemonicReferences()
Get references for the mnemonic for this code unit.java.lang.String
getMnemonicString()
Get the mnemonic for this code unit, e.g., MOV, JMPInstruction
getNext()
Get the instruction following this one in address order.int
getNumOperands()
Get the number of operands for this code unit.Saveable
getObjectProperty(java.lang.String name)
Get the object property for name; returns null if there is no name property for this code unit.Reference[]
getOperandReferences(int opIndex)
Get the references for the operand index.RefType
getOperandRefType(int opIndex)
Get the operand reference type for the given operand index.int
getOperandType(int opIndex)
Get the type of a specific operand.java.lang.Object[]
getOpObjects(int opIndex)
Get objects used by this operand (Address, Scalar, Register ...)RegisterValue
getOriginalPrototypeContext(Register baseContextReg)
Get the original context used to establish the shared prototypeParserContext
getParserContext()
Get the instruction parser context for the instruction which corresponds to this context object.ParserContext
getParserContext(Address instructionAddress)
Get the instruction parser context which corresponds to the specified instruction address.PcodeOp[]
getPcode()
Get an array of PCode operations (micro code) that this instruction performs.PcodeOp[]
getPcode(boolean includeOverrides)
Get an array of PCode operations (micro code) that this instruction performs.PcodeOp[]
getPcode(int opIndex)
Get an array of PCode operations (micro code) that a particular operand performs to compute its value.protected int
getPreferredCacheLength()
Instruction
getPrevious()
Get the instruction before this one in address order.Reference
getPrimaryReference(int index)
Get the primary reference for the operand index.Symbol
getPrimarySymbol()
Get the Primary Symbol for this code unit.ProcessorContextView
getProcessorContext()
Get the read-only processor context containing the context-register state state at the corresponding instruction.Program
getProgram()
Returns the program that generated this CodeUnit.InstructionPrototype
getPrototype()
Get the prototype for this instruction.ReferenceIterator
getReferenceIteratorTo()
Get an iterator over all references TO this code unit.Reference[]
getReferencesFrom()
Get ALL memory references FROM this code unit.Register
getRegister(int opIndex)
If operand is a pure Register, return the register.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.lang.Object[]
getResultObjects()
Get the Result objects produced/affected by this instruction These would probably only be Register or AddressScalar
getScalar(int opIndex)
Returns the scalar at the given operand index.java.lang.String
getSeparator(int opIndex)
Get the separator strings between an operand.short
getShort(int offset)
returns the short at the given offset, taking into account the endianess.java.lang.String
getStringProperty(java.lang.String name)
Get the string property for name; returns null if there is no name property for this code unit.Symbol[]
getSymbols()
Get the Symbols for this code unit.java.math.BigInteger
getValue(Register register, boolean signed)
Get the contents of a processor register as a BigInteger objectboolean
getVoidProperty(java.lang.String name)
Returns whether this code unit is marked as having the name property.protected boolean
hasBeenDeleted(Record rec)
Perform any refresh necessary and determine if this code unit has been deleted.boolean
hasFallthrough()
Returns true if this instruction has a fall-through flow.int
hashCode()
boolean
hasProperty(java.lang.String name)
Returns true if the codeunit has the given property defined.boolean
hasValue(Register register)
Returns true if a value is defined for the given register.boolean
isBigEndian()
Returns true if the underlying bytes are in big-endian order, false if they are little endian.boolean
isFallthrough()
Returns true if this instruction has no execution flow other than fall-through.boolean
isFallThroughOverridden()
Returns true if this instructions fallthrough has been overriden.boolean
isInDelaySlot()
Return true if this instruction was disassembled in a delay slotboolean
isSuccessor(CodeUnit codeUnit)
Return true if the given CodeUnit follows directly after this code unit.java.util.Iterator<java.lang.String>
propertyNames()
Get an iterator over the property names.protected boolean
refresh()
Tells the object to refresh its state from the database.protected boolean
refresh(Record record)
Tells the object to refresh its state from the database using the specified record if not null.protected void
refreshIfNeeded()
Check this code units validity when the lock/checkIsValid is not used and refresh if necessary.void
removeExternalReference(int opIndex)
Remove external reference (if any) at the given opIndex opIndex the index of the operand from which to remove any external reference.void
removeMnemonicReference(Address refAddr)
Remove a reference to the mnemonic for this code unit.void
removeOperandReference(int opIndex, Address refAddr)
Remove a reference to the operand.void
removeProperty(java.lang.String name)
Remove the property with the given name from this code unit.void
setComment(int commentType, java.lang.String comment)
Set the comment for the given comment type.void
setCommentAsArray(int commentType, java.lang.String[] comment)
Set the comment (with each line in its own string) for the given comment typevoid
setFallThrough(Address fallThroughAddr)
Overrides the instruction's default fallthrough address to the given address.void
setFlowOverride(FlowOverride flow)
Set the flow override for this instruction.void
setPrimaryMemoryReference(Reference ref)
Sets a memory reference to be the primary reference at its address/opIndex location.void
setProperty(java.lang.String name)
Set the named property.void
setProperty(java.lang.String name, int value)
Set the named property with the given value at the address of this codeunit.void
setProperty(java.lang.String name, Saveable value)
Set the named property with the given value at the address of this codeunit.void
setProperty(java.lang.String name, java.lang.String value)
Set the named property with the given value at the address of this codeunit.void
setRegisterReference(int opIndex, Register reg, SourceType sourceType, RefType refType)
Sets a register reference at theoffset
on the specified operand index, which effectively substitutes the previous operation interpretation
NOTE: If another reference was previously set on the operand, then it will be replaced with this register referencevoid
setRegisterValue(RegisterValue value)
Sets the specified register value within this context.void
setStackReference(int opIndex, int offset, SourceType sourceType, RefType refType)
Sets a stack reference at theoffset
on the specified operand index, which effectively substitutes the previous operation interpretation
NOTE: If another reference was previously set on the operand, then it will be replaced with this stack referencevoid
setValue(Register register, java.math.BigInteger value)
Sets the value for a Register.java.lang.String
toString()
Returns a string that represents this code unit with default markup.void
visitProperty(PropertyVisitor visitor, java.lang.String propertyName)
Invokes the visit() method of the specified PropertyVisitor if the named property exists for this code unit.-
Methods inherited from class ghidra.program.database.DatabaseObject
checkDeleted, checkIsValid, checkIsValid, getKey, isDeleted, isInvalid, keyChanged, setInvalid, validate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ghidra.program.model.listing.CodeUnit
addMnemonicReference, addOperandReference, compareTo, contains, getAddressString, getBytes, getBytesInCodeUnit, getComment, getCommentAsArray, getExternalReference, getIntProperty, getLabel, getLength, getMaxAddress, getMinAddress, getMnemonicReferences, getObjectProperty, getOperandReferences, getPrimaryReference, getPrimarySymbol, getProgram, getReferenceIteratorTo, getReferencesFrom, getStringProperty, getSymbols, getVoidProperty, hasProperty, isSuccessor, propertyNames, removeExternalReference, removeMnemonicReference, removeOperandReference, removeProperty, setComment, setCommentAsArray, setPrimaryMemoryReference, setProperty, setProperty, setProperty, setProperty, setRegisterReference, setStackReference, visitProperty
-
Methods inherited from interface ghidra.program.model.lang.InstructionContext
getAddress
-
Methods inherited from interface ghidra.program.model.mem.MemBuffer
getAddress, getBigInteger, getByte, getBytes, getInt, getLong, getMemory, getShort, getUnsignedByte, getUnsignedInt, getUnsignedShort, getVarLengthInt, getVarLengthUnsignedInt, isBigEndian, isInitializedMemory
-
Methods inherited from interface ghidra.program.model.lang.ProcessorContext
clearRegister, setRegisterValue, setValue
-
Methods inherited from interface ghidra.program.model.lang.ProcessorContextView
getBaseContextRegister, getRegister, getRegisters, getRegisterValue, getValue, hasValue
-
-
-
-
Field Detail
-
codeMgr
protected CodeManager codeMgr
-
address
protected Address address
-
addr
protected long addr
-
endAddr
protected Address endAddr
-
length
protected int length
-
refMgr
protected ReferenceManager refMgr
-
program
protected ProgramDB program
-
bytes
protected byte[] bytes
-
changeMgr
protected ChangeManager changeMgr
-
lock
protected Lock lock
-
-
Constructor Detail
-
InstructionDB
public InstructionDB(CodeManager codeMgr, DBObjectCache<? extends ghidra.program.database.code.CodeUnitDB> cache, Address address, long addr, InstructionPrototype proto, byte flags)
Construct a new InstructionDB.- Parameters:
codeMgr
- code managercache
- code unit cacheaddress
- min address of this instructionaddr
- database keyproto
- instruction prototypeprotoID
- ID for the prototype
-
-
Method Detail
-
refresh
protected boolean refresh(Record record)
Description copied from class:DatabaseObject
Tells the object to refresh its state from the database using the specified record if not null. NOTE: The default implementation ignores the record and invokes refresh(). Implementations of this method must take care if multiple database tables are used since the record supplied could correspond to another object. In some cases it may be best not to override this method or ignore the record provided.- Parameters:
record
- valid record associated with object's key (optional, may be null to force record lookup or other refresh technique)- Returns:
- true if the object was able to refresh itself. Return false if record is null and object was deleted. Objects that extend this class must implement a refresh method. If an object can never refresh itself, then it should always return false.
-
getPreferredCacheLength
protected int getPreferredCacheLength()
-
hasBeenDeleted
protected boolean hasBeenDeleted(Record rec)
Perform any refresh necessary and determine if this code unit has been deleted. If a record has been provided, it may be used to facilitate a refresh without performing a record query from the database- Parameters:
rec
- optional record which corresponds to code unit. A null record does NOT indicate existence and a record query may be required.- Returns:
- true if removal of code unit has been confirmed
-
getDelaySlotDepth
public int getDelaySlotDepth()
Description copied from interface:Instruction
Get the number of delay slot instructions for this argument. This should be 0 for instructions which don't have a delay slot. This is used to support the delay slots found on some RISC processors such as SPARC and the PA-RISC. This returns an integer instead of a boolean in case some other processor executes more than one instruction from a delay slot.- Specified by:
getDelaySlotDepth
in interfaceInstruction
-
getOriginalPrototypeContext
public RegisterValue getOriginalPrototypeContext(Register baseContextReg)
Get the original context used to establish the shared prototype- Parameters:
baseContextReg
-- Returns:
- prototype context value
-
getFallFrom
public Address getFallFrom()
Description copied from interface:Instruction
Get the Address for the instruction that fell through to this instruction. This is useful for handling instructions that are found in a delay slot.- Specified by:
getFallFrom
in interfaceInstruction
-
getFallThrough
public Address getFallThrough()
Description copied from interface:Instruction
Get the fallthrough for this instruction, factoring in any fallthrough override and delay slotted instructions.- Specified by:
getFallThrough
in interfaceInstruction
- Returns:
- fall-through address or null if instruction has no fallthrough
-
getFlows
public Address[] getFlows()
Description copied from interface:Instruction
Get an array of Address objects for all flows other than a fall-through. This will include any flow references which have been added to the instruction.- Specified by:
getFlows
in interfaceInstruction
- Returns:
- flow addresses or null if there are no flows
-
getDefaultFlows
public Address[] getDefaultFlows()
Description copied from interface:Instruction
Get an array of Address objects for all default flows established by the underlying instruction prototype. References are ignored.- Specified by:
getDefaultFlows
in interfaceInstruction
- Returns:
- flow addresses or null if there are no flows
-
getFlowType
public FlowType getFlowType()
Description copied from interface:Instruction
Get the flow type of this instruction (how this instruction flows to the next instruction).- Specified by:
getFlowType
in interfaceInstruction
-
getNext
public Instruction getNext()
Description copied from interface:Instruction
Get the instruction following this one in address order.- Specified by:
getNext
in interfaceInstruction
-
getOperandRefType
public RefType getOperandRefType(int opIndex)
Description copied from interface:Instruction
Get the operand reference type for the given operand index.- Specified by:
getOperandRefType
in interfaceInstruction
- Parameters:
opIndex
- operand index
-
getSeparator
public java.lang.String getSeparator(int opIndex)
Description copied from interface:Instruction
Get the separator strings between an operand. The separator string for 0 are the characters before the first operand. The separator string for numOperands+1 are the characters after the last operand.- Specified by:
getSeparator
in interfaceInstruction
- Parameters:
opIndex
- valid values are 0 thru numOperands+1- Returns:
- separator string, or null if there is no string
-
getDefaultOperandRepresentation
public java.lang.String getDefaultOperandRepresentation(int opIndex)
Description copied from interface:Instruction
Get the operand representation for the given operand index without markup.- Specified by:
getDefaultOperandRepresentation
in interfaceInstruction
- Parameters:
opIndex
- operand index- Returns:
- operand represented as a string.
-
getDefaultOperandRepresentationList
public java.util.List<java.lang.Object> getDefaultOperandRepresentationList(int opIndex)
Description copied from interface:Instruction
Get the operand representation for the given operand index. A list of Register, Address, Scalar, Character and String objects is returned - without markup!- Specified by:
getDefaultOperandRepresentationList
in interfaceInstruction
- Parameters:
opIndex
- operand index- Returns:
- ArrayList of pieces of the operand representation. Unsupported languages may return null.
-
getOperandType
public int getOperandType(int opIndex)
Description copied from interface:Instruction
Get the type of a specific operand.- Specified by:
getOperandType
in interfaceInstruction
- Parameters:
opIndex
- the index of the operand. (zero based)- Returns:
- the type of the operand.
-
getOpObjects
public java.lang.Object[] getOpObjects(int opIndex)
Description copied from interface:Instruction
Get objects used by this operand (Address, Scalar, Register ...)- Specified by:
getOpObjects
in interfaceInstruction
- Parameters:
opIndex
- index of the operand.
-
getPrevious
public Instruction getPrevious()
Description copied from interface:Instruction
Get the instruction before this one in address order.- Specified by:
getPrevious
in interfaceInstruction
-
getPrototype
public InstructionPrototype getPrototype()
Description copied from interface:Instruction
Get the prototype for this instruction.- Specified by:
getPrototype
in interfaceInstruction
-
getRegister
public Register getRegister(int opIndex)
Description copied from interface:Instruction
If operand is a pure Register, return the register.- Specified by:
getRegister
in interfaceInstruction
- Parameters:
opIndex
- index of the operand.- Returns:
- A register if the operand represents a register.
-
getInputObjects
public java.lang.Object[] getInputObjects()
Description copied from interface:Instruction
Get the Input objects used by this instruction. These could be Scalars, Registers, Addresses- Specified by:
getInputObjects
in interfaceInstruction
- Returns:
- an array of objects that are used by this instruction
-
getResultObjects
public java.lang.Object[] getResultObjects()
Description copied from interface:Instruction
Get the Result objects produced/affected by this instruction These would probably only be Register or Address- Specified by:
getResultObjects
in interfaceInstruction
- Returns:
- an array of objects that are affected by this instruction
-
isInDelaySlot
public boolean isInDelaySlot()
Description copied from interface:Instruction
Return true if this instruction was disassembled in a delay slot- Specified by:
isInDelaySlot
in interfaceInstruction
-
getAddress
public Address getAddress(int opIndex)
Description copied from interface:CodeUnit
Get the Address for the given operand index if one exists. Data objects have one operand (the value).- Specified by:
getAddress
in interfaceCodeUnit
- Parameters:
opIndex
- index of the operand.- Returns:
- An addres if the operand represents a fully qualified address (given the context), or if the operand is a Scalar treated as an address. Null is returned if no address or scalar exists on that operand.
-
toString
public java.lang.String toString()
Returns a string that represents this code unit with default markup. Only the mnemonic and operands are included.- See Also:
for full mark-up formatting
-
getMnemonicString
public java.lang.String getMnemonicString()
Description copied from interface:CodeUnit
Get the mnemonic for this code unit, e.g., MOV, JMP- Specified by:
getMnemonicString
in interfaceCodeUnit
-
getNumOperands
public int getNumOperands()
Description copied from interface:CodeUnit
Get the number of operands for this code unit.- Specified by:
getNumOperands
in interfaceCodeUnit
-
getScalar
public Scalar getScalar(int opIndex)
Description copied from interface:CodeUnit
Returns the scalar at the given operand index. Data objects have one operand (the value).
-
equals
public boolean equals(java.lang.Object obj)
Return true if obj is equal to this.
-
getFlowOverride
public FlowOverride getFlowOverride()
Description copied from interface:Instruction
Returns the flow override which may have been set on this instruction.- Specified by:
getFlowOverride
in interfaceInstruction
-
setFlowOverride
public void setFlowOverride(FlowOverride flow)
Description copied from interface:Instruction
Set the flow override for this instruction.- Specified by:
setFlowOverride
in interfaceInstruction
-
getPcode
public PcodeOp[] getPcode()
Description copied from interface:Instruction
Get an array of PCode operations (micro code) that this instruction performs. Flow overrides are not factored into pcode.- Specified by:
getPcode
in interfaceInstruction
- Returns:
- an array of Pcode operations, a zero length array if the language does not support PCode
-
getPcode
public PcodeOp[] getPcode(boolean includeOverrides)
Description copied from interface:Instruction
Get an array of PCode operations (micro code) that this instruction performs. NOTE: If includeOverrides is true, unique temporary varnodes may be produced which vary in size to those produced for other instructions. If your analysis is sensitive to this you should consider usingInstructionPrototype#getPcode(ghidra.program.model.mem.MemBuffer, ProcessorContext, FlowOverride, ghidra.program.model.address.UniqueAddressFactory)
instead with your ownUniqueAddressFactory
to prevent duplication within your scope of analysis. by this method may not be suitable for use with certain analysis- Specified by:
getPcode
in interfaceInstruction
- Parameters:
includeOverrides
- if true any flow overrides will be factored into generated pcode.- Returns:
- an array of Pcode operations, a zero length array if the language does not support PCode
-
getPcode
public PcodeOp[] getPcode(int opIndex)
Description copied from interface:Instruction
Get an array of PCode operations (micro code) that a particular operand performs to compute its value.- Specified by:
getPcode
in interfaceInstruction
- Parameters:
opIndex
- index of the operand to retrieve PCode- Returns:
- an array of PCode operations, a zero length array if the language does not support PCode
-
isFallThroughOverridden
public boolean isFallThroughOverridden()
Description copied from interface:Instruction
Returns true if this instructions fallthrough has been overriden.- Specified by:
isFallThroughOverridden
in interfaceInstruction
-
clearFallThroughOverride
public void clearFallThroughOverride()
Description copied from interface:Instruction
Restores this instruction's fallthrough address back to the default fallthrough for this instruction.- Specified by:
clearFallThroughOverride
in interfaceInstruction
-
setFallThrough
public void setFallThrough(Address fallThroughAddr)
Description copied from interface:Instruction
Overrides the instruction's default fallthrough address to the given address. The given address may be null to indicate that the instruction has no fallthrough.- Specified by:
setFallThrough
in interfaceInstruction
- Parameters:
fallThroughAddr
- the address to be used as this instructions fallthrough address. May be null.
-
getDefaultFallThrough
public Address getDefaultFallThrough()
Description copied from interface:Instruction
Get the default fallthrough for this instruction. This accounts for any instructions contained with delay slots.- Specified by:
getDefaultFallThrough
in interfaceInstruction
- Returns:
- fall-through address or null if instruction has no default fallthrough
-
getDefaultFallThroughOffset
public int getDefaultFallThroughOffset()
Description copied from interface:Instruction
Get default fall-through offset in bytes from start of instruction to the fallthrough instruction. This accounts for any instructions contained with delay slots.- Specified by:
getDefaultFallThroughOffset
in interfaceInstruction
- Returns:
- default fall-through offset or zero (0) if instruction has no fallthrough
-
hasFallthrough
public boolean hasFallthrough()
Description copied from interface:Instruction
Returns true if this instruction has a fall-through flow.- Specified by:
hasFallthrough
in interfaceInstruction
-
isFallthrough
public boolean isFallthrough()
Description copied from interface:Instruction
Returns true if this instruction has no execution flow other than fall-through.- Specified by:
isFallthrough
in interfaceInstruction
-
getProcessorContext
public ProcessorContextView getProcessorContext()
Description copied from interface:InstructionContext
Get the read-only processor context containing the context-register state state at the corresponding instruction. This is primarily used during the parse phase to provide the initial context-register state.- Specified by:
getProcessorContext
in interfaceInstructionContext
-
getMemBuffer
public MemBuffer getMemBuffer()
Description copied from interface:InstructionContext
Get the read-only memory buffer containing the instruction bytes. Its position will correspond to the instruction address.- Specified by:
getMemBuffer
in interfaceInstructionContext
- Returns:
- instruction memory buffer
-
getParserContext
public ParserContext getParserContext() throws MemoryAccessException
Description copied from interface:InstructionContext
Get the instruction parser context for the instruction which corresponds to this context object.- Specified by:
getParserContext
in interfaceInstructionContext
- Returns:
- the instruction parser context for the instruction which corresponds to this context object.
- Throws:
MemoryAccessException
- if memory error occurred while resolving instruction details.
-
getInstructionContext
public InstructionContext getInstructionContext()
- Specified by:
getInstructionContext
in interfaceInstruction
-
getParserContext
public ParserContext getParserContext(Address instructionAddress) throws UnknownContextException, MemoryAccessException
Description copied from interface:InstructionContext
Get the instruction parser context which corresponds to the specified instruction address. This may be obtained via either caching or by parsing the instruction at the specified address. The returned ParserContext may be cast to the prototype's implementation without checking. This method will throw an UnknownContextException if a compatible ParserContext is not found at the specified address.- Specified by:
getParserContext
in interfaceInstructionContext
- Returns:
- the instruction parser context at the specified instruction address
- Throws:
UnknownContextException
- if the instruction at the specified address was not previously parsed or attempting to instantiate context resulted in an exception.MemoryAccessException
- if memory error occurred while resolving instruction details.
-
refresh
protected boolean refresh()
Description copied from class:DatabaseObject
Tells the object to refresh its state from the database.- Specified by:
refresh
in classDatabaseObject
- Returns:
- true if the object was able to refresh itself. Return false if the object was deleted. Objects that extend this class must implement a refresh method. If an object can never refresh itself, then it should always return false.
-
refreshIfNeeded
protected void refreshIfNeeded()
Check this code units validity when the lock/checkIsValid is not used and refresh if necessary.
-
addMnemonicReference
public void addMnemonicReference(Address refAddr, RefType refType, SourceType sourceType)
Description copied from interface:CodeUnit
Add a reference to the mnemonic for this code unit.- Specified by:
addMnemonicReference
in interfaceCodeUnit
- Parameters:
refAddr
- address to add as a reference.refType
- the type of reference to add.sourceType
- the source of this reference
-
addOperandReference
public void addOperandReference(int opIndex, Address refAddr, RefType type, SourceType sourceType)
Description copied from interface:CodeUnit
Add a memory reference to the operand at the given index.- Specified by:
addOperandReference
in interfaceCodeUnit
- Parameters:
opIndex
- operand indexrefAddr
- reference addresstype
- the reference type to be added.sourceType
- the source of this reference- See Also:
CodeUnit.addOperandReference(int, ghidra.program.model.address.Address, ghidra.program.model.symbol.RefType, SourceType)
-
compareTo
public int compareTo(Address a)
Description copied from interface:CodeUnit
Compares the given address to the address range of this node.
-
contains
public boolean contains(Address testAddr)
Description copied from interface:CodeUnit
Returns true if address is contained in the range of this codeUnit
-
getAddressString
public java.lang.String getAddressString(boolean showBlockName, boolean pad)
Description copied from interface:CodeUnit
Get the string representation of the starting address for this code unit.- Specified by:
getAddressString
in interfaceCodeUnit
- Parameters:
showBlockName
- true if the string should include the memory block namepad
- if true, the address will be padded with leading zeros. Even if pad is false, the string will be padded to make the address string contain at least 4 digits.- Returns:
- string representation of address
-
isBigEndian
public boolean isBigEndian()
Description copied from interface:MemBuffer
Returns true if the underlying bytes are in big-endian order, false if they are little endian.- Specified by:
isBigEndian
in interfaceMemBuffer
- Returns:
- true if the underlying bytes are in big-endian order, false if they are little endian.
-
getShort
public short getShort(int offset) throws MemoryAccessException
Description copied from interface:MemBuffer
returns the short at the given offset, taking into account the endianess.- Specified by:
getShort
in interfaceMemBuffer
- Parameters:
offset
- the offset from the membuffers origin (the address that it is set at)- Returns:
- the short at the given offset, taking into account the endianess.
- Throws:
MemoryAccessException
- if a 2-byte short value cannot be read at the specified offset
-
getInt
public int getInt(int offset) throws MemoryAccessException
Description copied from interface:MemBuffer
returns the int at the given offset, taking into account the endianess.- Specified by:
getInt
in interfaceMemBuffer
- Parameters:
offset
- the offset from the membuffers origin (the address that it is set at)- Returns:
- the int at the given offset, taking into account the endianess.
- Throws:
MemoryAccessException
- if a 4-byte integer value cannot be read at the specified offset
-
getLong
public long getLong(int offset) throws MemoryAccessException
Description copied from interface:MemBuffer
returns the long at the given offset, taking into account the endianess.- Specified by:
getLong
in interfaceMemBuffer
- Parameters:
offset
- the offset from the membuffers origin (the address that it is set at)- Returns:
- the long at the given offset, taking into account the endianess.
- Throws:
MemoryAccessException
- if a 8-byte long value cannot be read at the specified offset
-
getBigInteger
public java.math.BigInteger getBigInteger(int offset, int size, boolean signed) throws MemoryAccessException
Description copied from interface:MemBuffer
returns the value at the given offset, taking into account the endianess.- Specified by:
getBigInteger
in interfaceMemBuffer
- Parameters:
offset
- the offset from the membuffers origin (the address that it is set at)size
- the number of bytes to include in the valuesigned
- true if value should be treated as a signed twos-compliment value.- Returns:
- the value at the given offset, taking into account the endianess.
- Throws:
MemoryAccessException
- if the request size value cannot be read at the specified offset
-
getComment
public java.lang.String getComment(int commentType)
Description copied from interface:CodeUnit
Get the comment for the given type- Specified by:
getComment
in interfaceCodeUnit
- Parameters:
commentType
- either EOL_COMMENT, PRE_COMMENT, POST_COMMENT, or REPEATABLE_COMMENT- Returns:
- the comment string of the appropriate type or null if no comment of that type exists for this codeunit
-
getCommentAsArray
public java.lang.String[] getCommentAsArray(int commentType)
Description copied from interface:CodeUnit
Get the comment for the given type and parse it into an array of strings such that each line is its own string.- Specified by:
getCommentAsArray
in interfaceCodeUnit
- Parameters:
commentType
- either EOL_COMMENT, PRE_COMMENT, POST_COMMENT, or REPEATABLE_COMMENT- Returns:
- an array of strings where each item in the array is a line of text in the comment. If there is no comment of the requested type, an empty array is returned.
-
getExternalReference
public ExternalReference getExternalReference(int opIndex)
Description copied from interface:CodeUnit
Gets the external reference (if any) at the opIndex- Specified by:
getExternalReference
in interfaceCodeUnit
- Parameters:
opIndex
- the operand index to look for external references- Returns:
- the external reference at the operand or null if none exists.
-
getIntProperty
public int getIntProperty(java.lang.String name) throws NoValueException
Description copied from interface:CodeUnit
Get the int property for name.- Specified by:
getIntProperty
in interfaceCodeUnit
- Parameters:
name
- the name of the property- Throws:
NoValueException
- if there is not name property for this code unit
-
getLabel
public java.lang.String getLabel()
Description copied from interface:CodeUnit
Get the label for this code unit.
-
getLength
public int getLength()
Description copied from interface:CodeUnit
Get length of this code unit.
-
getMaxAddress
public Address getMaxAddress()
Description copied from interface:CodeUnit
Get the ending address for this code unit.- Specified by:
getMaxAddress
in interfaceCodeUnit
-
getMinAddress
public Address getMinAddress()
Description copied from interface:CodeUnit
Get the starting address for this code unit.- Specified by:
getMinAddress
in interfaceCodeUnit
-
getAddress
public Address getAddress()
Description copied from interface:MemBuffer
Get the Address which corresponds to the offset 0.- Specified by:
getAddress
in interfaceMemBuffer
- Returns:
- the current address of offset 0.
-
getMnemonicReferences
public Reference[] getMnemonicReferences()
Description copied from interface:CodeUnit
Get references for the mnemonic for this code unit.- Specified by:
getMnemonicReferences
in interfaceCodeUnit
- Returns:
- an array of memory references. A zero length array will be returned if there are no references for the mnemonic.
-
getObjectProperty
public Saveable getObjectProperty(java.lang.String name)
Description copied from interface:CodeUnit
Get the object property for name; returns null if there is no name property for this code unit.- Specified by:
getObjectProperty
in interfaceCodeUnit
- Parameters:
name
- the name of the property
-
getOperandReferences
public Reference[] getOperandReferences(int opIndex)
Description copied from interface:CodeUnit
Get the references for the operand index.- Specified by:
getOperandReferences
in interfaceCodeUnit
- Parameters:
opIndex
- operand index (0 is the first operand)
-
getPrimaryReference
public Reference getPrimaryReference(int index)
Description copied from interface:CodeUnit
Get the primary reference for the operand index.- Specified by:
getPrimaryReference
in interfaceCodeUnit
- Parameters:
index
- operand index (0 is the first operand)
-
getPrimarySymbol
public Symbol getPrimarySymbol()
Description copied from interface:CodeUnit
Get the Primary Symbol for this code unit.- Specified by:
getPrimarySymbol
in interfaceCodeUnit
-
getProgram
public Program getProgram()
Description copied from interface:CodeUnit
Returns the program that generated this CodeUnit.- Specified by:
getProgram
in interfaceCodeUnit
-
getReferencesFrom
public Reference[] getReferencesFrom()
Description copied from interface:CodeUnit
Get ALL memory references FROM this code unit.- Specified by:
getReferencesFrom
in interfaceCodeUnit
- Returns:
- an array of memory references from this codeUnit or an empty array if there are no references.
-
getReferenceIteratorTo
public ReferenceIterator getReferenceIteratorTo()
Description copied from interface:CodeUnit
Get an iterator over all references TO this code unit.- Specified by:
getReferenceIteratorTo
in interfaceCodeUnit
-
getStringProperty
public java.lang.String getStringProperty(java.lang.String name)
Description copied from interface:CodeUnit
Get the string property for name; returns null if there is no name property for this code unit.- Specified by:
getStringProperty
in interfaceCodeUnit
- Parameters:
name
- the name of the property
-
getSymbols
public Symbol[] getSymbols()
Description copied from interface:CodeUnit
Get the Symbols for this code unit.- Specified by:
getSymbols
in interfaceCodeUnit
-
getVoidProperty
public boolean getVoidProperty(java.lang.String name)
Description copied from interface:CodeUnit
Returns whether this code unit is marked as having the name property.- Specified by:
getVoidProperty
in interfaceCodeUnit
- Parameters:
name
- the name of the property
-
hasProperty
public boolean hasProperty(java.lang.String name)
Description copied from interface:CodeUnit
Returns true if the codeunit has the given property defined.- Specified by:
hasProperty
in interfaceCodeUnit
- Parameters:
name
- the name of the property
-
isSuccessor
public boolean isSuccessor(CodeUnit codeUnit)
Description copied from interface:CodeUnit
Return true if the given CodeUnit follows directly after this code unit.- Specified by:
isSuccessor
in interfaceCodeUnit
- Parameters:
codeUnit
- the codeUnit being tested to see if it follows this codeUnit.
-
propertyNames
public java.util.Iterator<java.lang.String> propertyNames()
Description copied from interface:CodeUnit
Get an iterator over the property names.- Specified by:
propertyNames
in interfaceCodeUnit
-
removeExternalReference
public void removeExternalReference(int opIndex)
Description copied from interface:CodeUnit
Remove external reference (if any) at the given opIndex opIndex the index of the operand from which to remove any external reference.- Specified by:
removeExternalReference
in interfaceCodeUnit
-
removeMnemonicReference
public void removeMnemonicReference(Address refAddr)
Description copied from interface:CodeUnit
Remove a reference to the mnemonic for this code unit.- Specified by:
removeMnemonicReference
in interfaceCodeUnit
- Parameters:
refAddr
- the address to remove as a reference.
-
removeOperandReference
public void removeOperandReference(int opIndex, Address refAddr)
Description copied from interface:CodeUnit
Remove a reference to the operand.- Specified by:
removeOperandReference
in interfaceCodeUnit
- Parameters:
opIndex
- operand indexrefAddr
- address referencing the operand
-
removeProperty
public void removeProperty(java.lang.String name)
Description copied from interface:CodeUnit
Remove the property with the given name from this code unit.- Specified by:
removeProperty
in interfaceCodeUnit
- Parameters:
name
- the name of the property
-
setComment
public void setComment(int commentType, java.lang.String comment)
Description copied from interface:CodeUnit
Set the comment for the given comment type. Passing null clears the comment- Specified by:
setComment
in interfaceCodeUnit
- Parameters:
commentType
- either EOL_COMMENT, PRE_COMMENT, POST_COMMENT, or REPEATABLE_COMMENTcomment
- comment for code unit; null clears the comment
-
setCommentAsArray
public void setCommentAsArray(int commentType, java.lang.String[] comment)
Description copied from interface:CodeUnit
Set the comment (with each line in its own string) for the given comment type- Specified by:
setCommentAsArray
in interfaceCodeUnit
- Parameters:
commentType
- either EOL_COMMENT, PRE_COMMENT, POST_COMMENT, or REPEATABLE_COMMENTcomment
- an array of strings where each string is a single line of the comment.
-
setPrimaryMemoryReference
public void setPrimaryMemoryReference(Reference ref)
Description copied from interface:CodeUnit
Sets a memory reference to be the primary reference at its address/opIndex location. The primary reference is the one that is used in the getOperandRepresentation() method.- Specified by:
setPrimaryMemoryReference
in interfaceCodeUnit
- Parameters:
ref
- the reference to be set as primary.
-
setProperty
public void setProperty(java.lang.String name, int value)
Description copied from interface:CodeUnit
Set the named property with the given value at the address of this codeunit.- Specified by:
setProperty
in interfaceCodeUnit
- Parameters:
name
- the name of the property.value
- value to be stored.
-
setProperty
public void setProperty(java.lang.String name, Saveable value)
Description copied from interface:CodeUnit
Set the named property with the given value at the address of this codeunit.- Specified by:
setProperty
in interfaceCodeUnit
- Parameters:
name
- the name of the property.value
- value to be stored.
-
setProperty
public void setProperty(java.lang.String name, java.lang.String value)
Description copied from interface:CodeUnit
Set the named property with the given value at the address of this codeunit.- Specified by:
setProperty
in interfaceCodeUnit
- Parameters:
name
- the name of the property.value
- value to be stored.
-
setProperty
public void setProperty(java.lang.String name)
Description copied from interface:CodeUnit
Set the named property. This method is used for "void" properites. The property is either set or not set - there is no value- Specified by:
setProperty
in interfaceCodeUnit
- Parameters:
name
- the name of the property.
-
setStackReference
public void setStackReference(int opIndex, int offset, SourceType sourceType, RefType refType)
Description copied from interface:CodeUnit
Sets a stack reference at theoffset
on the specified operand index, which effectively substitutes the previous operation interpretation
NOTE: If another reference was previously set on the operand, then it will be replaced with this stack reference- Specified by:
setStackReference
in interfaceCodeUnit
- Parameters:
opIndex
- the index of the operand to set this stack referenceoffset
- the (+/-) offset from stack base addresssourceType
- the source of this referencerefType
- type of reference, RefType.READ,WRITE,PTR...
-
setRegisterReference
public void setRegisterReference(int opIndex, Register reg, SourceType sourceType, RefType refType)
Description copied from interface:CodeUnit
Sets a register reference at theoffset
on the specified operand index, which effectively substitutes the previous operation interpretation
NOTE: If another reference was previously set on the operand, then it will be replaced with this register reference- Specified by:
setRegisterReference
in interfaceCodeUnit
- Parameters:
opIndex
- the index of the operand to set this register referencereg
- a registersourceType
- the source of this referencerefType
- type of reference, RefType.READ,WRITE,PTR...
-
visitProperty
public void visitProperty(PropertyVisitor visitor, java.lang.String propertyName)
Description copied from interface:CodeUnit
Invokes the visit() method of the specified PropertyVisitor if the named property exists for this code unit.- Specified by:
visitProperty
in interfaceCodeUnit
- Parameters:
visitor
- the class implementing the PropertyVisitor interface.propertyName
- the name of the property to be visited.
-
getBytes
public int getBytes(byte[] b, int offset)
Description copied from interface:MemBuffer
Reads b.length bytes from this memory buffer starting at the address of this memory buffer plus the given memoryBufferOffset from that position. The actual number of bytes may be fewer if bytes can't be read.- Specified by:
getBytes
in interfaceMemBuffer
- Parameters:
b
- the buffer into which bytes will be placedoffset
- the offset in this memory buffer from which to start reading bytes.- Returns:
- the number of bytes read which may be fewer than b.length if available bytes are exhausted or no bytes are available at the specified offset.
-
getBytes
public byte[] getBytes() throws MemoryAccessException
Description copied from interface:CodeUnit
Get the bytes that make up this code unit.- Specified by:
getBytes
in interfaceCodeUnit
- Returns:
- an array of bytes that are in memory at the codeunits address. The array length is the same as the codeUnits length
- Throws:
MemoryAccessException
- if the full number of bytes could not be read.
-
getByte
public byte getByte(int offset) throws MemoryAccessException
Description copied from interface:MemBuffer
Get one byte from memory at the current position plus offset.- Specified by:
getByte
in interfaceMemBuffer
- Parameters:
offset
- the displacement from the current position.- Returns:
- the data at offset from the current position.
- Throws:
MemoryAccessException
- if memory cannot be read at the specified offset
-
getMemory
public Memory getMemory()
Description copied from interface:MemBuffer
Get the Memory object actually used by the MemBuffer.
-
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.
-
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
-
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
-
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
-
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.
-
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
-
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.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getBytesInCodeUnit
public void getBytesInCodeUnit(byte[] buffer, int bufferOffset) throws MemoryAccessException
Description copied from interface:CodeUnit
Copies max(buffer.length, code unit length) bytes into buffer starting at location offset in buffer.- Specified by:
getBytesInCodeUnit
in interfaceCodeUnit
- Parameters:
buffer
- byte array to copy intobufferOffset
- offset in byte array the copy will start- Throws:
MemoryAccessException
- if the full number of bytes could not be read.
-
-