Package ghidra.program.model.listing
Interface CodeUnit
- All Superinterfaces:
MemBuffer
,PropertySet
- All Known Subinterfaces:
Data
,Instruction
- All Known Implementing Classes:
DataStub
,InstructionDB
,InstructionStub
,JitPassage.DecodeErrorInstruction
,PseudoData
,PseudoInstruction
Interface common to both instructions and data.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Any comment property.static final String
Property name for code units that are defined datastatic final int
Deprecated, for removal: This API element is subject to removal in a future version.static final String
Property name for code units that are instructionsstatic final int
Indicator for a mnemonic (versus an operand).static final int
Deprecated, for removal: This API element is subject to removal in a future version.useCommentType.POST
static final int
Deprecated, for removal: This API element is subject to removal in a future version.useCommentType.POST
static final int
Deprecated, for removal: This API element is subject to removal in a future version.useCommentType.PRE
static final int
Deprecated, for removal: This API element is subject to removal in a future version.static final String
Property name for vertical space formatting -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMnemonicReference
(Address refAddr, RefType refType, SourceType sourceType) Add a reference to the mnemonic for this code unit.void
addOperandReference
(int index, Address refAddr, RefType type, SourceType sourceType) Add a memory reference to the operand at the given index.int
Compares the given address to the address range of this node.boolean
Returns true if address is contained in the range of this codeUnit.getAddress
(int opIndex) Get the Address for the given operand index if one exists.getAddressString
(boolean showBlockName, boolean pad) Get the string representation of the starting address for this code unit.byte[]
getBytes()
Get the bytes that make up this code unit.void
getBytesInCodeUnit
(byte[] buffer, int bufferOffset) Copies max(buffer.length, code unit length) bytes into buffer starting at location offset in buffer.default String
getComment
(int commentType) Deprecated, for removal: This API element is subject to removal in a future version.usegetComment(CommentType)
insteadgetComment
(CommentType type) Get the comment for the given typedefault String[]
getCommentAsArray
(int commentType) Deprecated, for removal: This API element is subject to removal in a future version.usegetCommentAsArray(CommentType)
insteadString[]
getCommentAsArray
(CommentType type) Get the comment for the given type and parse it into an array of strings such that each line is its own string.getExternalReference
(int opIndex) Gets the external reference (if any) at the opIndexgetLabel()
Returns the label for this code unit..int
Get length of this code unit.Returns the ending address for this code unit..Returns the starting address for this code unit..Get references for the mnemonic for this code unit.Returns the mnemonic for this code unit, e.g., MOV, JMP.int
Returns the number of operands for this code unit..getOperandReferences
(int index) Returns the references for the operand index..getPrimaryReference
(int index) Returns the primary reference for the operand index..Returns the Primary Symbol for this code unit..Returns the program that generated this CodeUnit..Returns an iterator over all references TO this code unit..Get ALL memory references FROM this code unit.getScalar
(int opIndex) Returns the scalar at the given operand index.Symbol[]
Returns the Symbols for this code unit..void
removeExternalReference
(int opIndex) Remove external reference (if any) at the given opIndexvoid
removeMnemonicReference
(Address refAddr) Remove a reference to the mnemonic for this code unit.void
removeOperandReference
(int index, Address refAddr) Remove a reference to the operand.default void
setComment
(int commentType, String comment) Deprecated, for removal: This API element is subject to removal in a future version.usesetComment(CommentType, String)
insteadvoid
setComment
(CommentType type, String comment) Set the comment for the given comment type.default void
setCommentAsArray
(int commentType, String[] comment) Deprecated, for removal: This API element is subject to removal in a future version.usesetCommentAsArray(CommentType, String[])
insteadvoid
setCommentAsArray
(CommentType type, String[] comment) Set the comment (with each line in its own string) for the given comment typevoid
Sets a memory reference to be the primary reference at its address/opIndex location.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
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 referenceMethods inherited from interface ghidra.program.model.mem.MemBuffer
getAddress, getBigInteger, getByte, getBytes, getInputStream, getInputStream, getInt, getLong, getMemory, getShort, getUnsignedByte, getUnsignedInt, getUnsignedShort, getVarLengthInt, getVarLengthUnsignedInt, isBigEndian, isInitializedMemory
Methods inherited from interface ghidra.program.model.util.PropertySet
getIntProperty, getObjectProperty, getStringProperty, getVoidProperty, hasProperty, propertyNames, removeProperty, setProperty, setProperty, setProperty, setProperty
-
Field Details
-
MNEMONIC
static final int MNEMONICIndicator for a mnemonic (versus an operand).- See Also:
-
EOL_COMMENT
Deprecated, for removal: This API element is subject to removal in a future version.useCommentType.EOL
comment type for end of line- See Also:
-
PRE_COMMENT
Deprecated, for removal: This API element is subject to removal in a future version.useCommentType.PRE
comment type that goes before a code unit- See Also:
-
POST_COMMENT
Deprecated, for removal: This API element is subject to removal in a future version.useCommentType.POST
comment type that follows after a code unit- See Also:
-
PLATE_COMMENT
Deprecated, for removal: This API element is subject to removal in a future version.useCommentType.POST
Property name for plate comment type- See Also:
-
REPEATABLE_COMMENT
Deprecated, for removal: This API element is subject to removal in a future version.Property name for repeatable comment type- See Also:
-
COMMENT_PROPERTY
Any comment property.- See Also:
-
SPACE_PROPERTY
Property name for vertical space formatting- See Also:
-
INSTRUCTION_PROPERTY
Property name for code units that are instructions- See Also:
-
DEFINED_DATA_PROPERTY
Property name for code units that are defined data- See Also:
-
-
Method Details
-
getAddressString
Get the string representation of the starting address for this code unit.- 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
-
getLabel
String getLabel()Returns the label for this code unit..- Returns:
- the label for this code unit.
-
getSymbols
Symbol[] getSymbols()Returns the Symbols for this code unit..- Returns:
- the Symbols for this code unit.
- Throws:
ConcurrentModificationException
- if this object is no longer valid.
-
getPrimarySymbol
Symbol getPrimarySymbol()Returns the Primary Symbol for this code unit..- Returns:
- the Primary Symbol for this code unit.
- Throws:
ConcurrentModificationException
- if this object is no longer valid.
-
getMinAddress
Address getMinAddress()Returns the starting address for this code unit..- Returns:
- the starting address for this code unit.
-
getMaxAddress
Address getMaxAddress()Returns the ending address for this code unit..- Returns:
- the ending address for this code unit.
-
getMnemonicString
String getMnemonicString()Returns the mnemonic for this code unit, e.g., MOV, JMP.- Returns:
- the mnemonic for this code unit, e.g., MOV, JMP
-
getComment
Deprecated, for removal: This API element is subject to removal in a future version.usegetComment(CommentType)
insteadGet the comment for the given type- 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
- Throws:
IllegalArgumentException
- if type is not one of the three types of comments supported
-
getComment
Get the comment for the given type- Parameters:
type
-comment type
- Returns:
- the comment string of the appropriate type or null if no comment of that type exists for this code unit
-
getCommentAsArray
Deprecated, for removal: This API element is subject to removal in a future version.usegetCommentAsArray(CommentType)
insteadGet the comment for the given type and parse it into an array of strings such that each line is its own string.- 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.
- Throws:
IllegalArgumentException
- if type is not one of the three types of comments supported
-
getCommentAsArray
Get the comment for the given type and parse it into an array of strings such that each line is its own string.- Parameters:
type
-comment type
- 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.
-
setComment
Deprecated, for removal: This API element is subject to removal in a future version.usesetComment(CommentType, String)
insteadSet the comment for the given comment type. Passingnull
clears the comment- Parameters:
commentType
- either EOL_COMMENT, PRE_COMMENT, POST_COMMENT, or REPEATABLE_COMMENTcomment
- comment for code unit; null clears the comment- Throws:
IllegalArgumentException
- if type is not one of the three types of comments supported
-
setComment
Set the comment for the given comment type. Passingnull
clears the comment- Parameters:
type
-comment type
comment
- comment for code unit; null clears the comment
-
setCommentAsArray
@Deprecated(forRemoval=true, since="11.4") default void setCommentAsArray(int commentType, String[] comment) Deprecated, for removal: This API element is subject to removal in a future version.usesetCommentAsArray(CommentType, String[])
insteadSet the comment (with each line in its own string) for the given comment type- 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.- Throws:
IllegalArgumentException
- if type is not one of the three types of comments supported
-
setCommentAsArray
Set the comment (with each line in its own string) for the given comment type- Parameters:
type
-comment type
comment
- an array of strings where each string is a single line of the comment.- Throws:
IllegalArgumentException
- if type is not one of the three types of comments supported
-
getLength
int getLength()Get length of this code unit. NOTE: If aninstruction length-override
is set this method will return the reduced length.- Returns:
- code unit length
-
getBytes
Get the bytes that make up this code unit. NOTE: If aninstruction length-override
is set this method will not return all bytes associated with theinstruction prototype
.- 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.
-
getBytesInCodeUnit
Copies max(buffer.length, code unit length) bytes into buffer starting at location offset in buffer.- 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.
-
contains
Returns true if address is contained in the range of this codeUnit.- Parameters:
testAddr
- the address to test.- Returns:
- true if address is contained in the range of this codeUnit
-
compareTo
Compares the given address to the address range of this node.- Parameters:
addr
- address to compare.- Returns:
- a negative integer if this addr is greater than the maximum range address zero if addr is in the range a positive integer if addr is less than minimum range address
-
addMnemonicReference
Add a reference to the mnemonic for this code unit.- Parameters:
refAddr
- address to add as a reference.refType
- the type of reference to add.sourceType
- the source of this reference
-
removeMnemonicReference
Remove a reference to the mnemonic for this code unit.- Parameters:
refAddr
- the address to remove as a reference.
-
getMnemonicReferences
Reference[] getMnemonicReferences()Get references for the mnemonic for this code unit.- Returns:
- an array of memory references. A zero length array will be returned if there are no references for the mnemonic.
-
getOperandReferences
Returns the references for the operand index..- Parameters:
index
- operand index (0 is the first operand)- Returns:
- the references for the operand index.
-
getPrimaryReference
Returns the primary reference for the operand index..- Parameters:
index
- operand index (0 is the first operand)- Returns:
- the primary reference for the operand index.
-
addOperandReference
Add a memory reference to the operand at the given index.- Parameters:
index
- operand indexrefAddr
- reference addresstype
- the reference type to be added.sourceType
- the source of this reference
-
removeOperandReference
Remove a reference to the operand.- Parameters:
index
- operand indexrefAddr
- address referencing the operand
-
getReferencesFrom
Reference[] getReferencesFrom()Get ALL memory references FROM this code unit.- Returns:
- an array of memory references from this codeUnit or an empty array if there are no references.
-
getReferenceIteratorTo
ReferenceIterator getReferenceIteratorTo()Returns an iterator over all references TO this code unit..- Returns:
- an iterator over all references TO this code unit.
-
getProgram
Program getProgram()Returns the program that generated this CodeUnit..- Returns:
- the program that generated this CodeUnit.
-
getExternalReference
Gets the external reference (if any) at the opIndex- Parameters:
opIndex
- the operand index to look for external references- Returns:
- the external reference at the operand or null if none exists.
-
removeExternalReference
void removeExternalReference(int opIndex) Remove external reference (if any) at the given opIndex- Parameters:
opIndex
- the index of the operand from which to remove any external reference.
-
setPrimaryMemoryReference
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.- Parameters:
ref
- the reference to be set as primary.
-
setStackReference
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- 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
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- 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...
-
getNumOperands
int getNumOperands()Returns the number of operands for this code unit..- Returns:
- the number of operands for this code unit.
-
getAddress
Get the Address for the given operand index if one exists. Data objects have one operand (the value).- 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.
-
getScalar
Returns the scalar at the given operand index. Data objects have one operand (the value).- Parameters:
opIndex
- index of the operand.- Returns:
- the scalar at the given operand index or null if no scalar exists at that index.
-
CommentType.EOL