Package ghidra.program.model.listing
Interface CodeUnit
- 
- All Superinterfaces:
- MemBuffer
 - All Known Subinterfaces:
- Data,- Instruction
 - All Known Implementing Classes:
- DataStub,- InstructionDB,- InstructionStub,- PseudoData,- PseudoInstruction
 
 public interface CodeUnit extends MemBuffer Interface common to both instructions and data.
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringCOMMENT_PROPERTYAny comment property.static java.lang.StringDEFINED_DATA_PROPERTYProperty name for code units that are defined datastatic intEOL_COMMENTcomment type for end of linestatic java.lang.StringINSTRUCTION_PROPERTYProperty name for code units that are instructionsstatic intMNEMONICIndicator for a mnemonic (versus an operand).static intNO_COMMENTstatic intPLATE_COMMENTProperty name for plate comment typestatic intPOST_COMMENTcomment type that follows after a code unitstatic intPRE_COMMENTcomment type that goes before a code unitstatic intREPEATABLE_COMMENTProperty name for repeatable comment typestatic java.lang.StringSPACE_PROPERTYProperty name for vertical space formatting
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddMnemonicReference(Address refAddr, RefType refType, SourceType sourceType)Add a reference to the mnemonic for this code unit.voidaddOperandReference(int index, Address refAddr, RefType type, SourceType sourceType)Add a memory reference to the operand at the given index.intcompareTo(Address addr)Compares the given address to the address range of this node.booleancontains(Address testAddr)Returns true if address is contained in the range of this codeUnitAddressgetAddress(int opIndex)Get the Address for the given operand index if one exists.java.lang.StringgetAddressString(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.voidgetBytesInCodeUnit(byte[] buffer, int bufferOffset)Copies max(buffer.length, code unit length) bytes into buffer starting at location offset in buffer.java.lang.StringgetComment(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.ExternalReferencegetExternalReference(int opIndex)Gets the external reference (if any) at the opIndexintgetIntProperty(java.lang.String name)Get the int property for name.java.lang.StringgetLabel()Get the label for this code unit.intgetLength()Get length of this code unit.AddressgetMaxAddress()Get the ending address for this code unit.AddressgetMinAddress()Get the starting address for this code unit.Reference[]getMnemonicReferences()Get references for the mnemonic for this code unit.java.lang.StringgetMnemonicString()Get the mnemonic for this code unit, e.g., MOV, JMPintgetNumOperands()Get the number of operands for this code unit.SaveablegetObjectProperty(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 index)Get the references for the operand index.ReferencegetPrimaryReference(int index)Get the primary reference for the operand index.SymbolgetPrimarySymbol()Get the Primary Symbol for this code unit.ProgramgetProgram()Returns the program that generated this CodeUnit.ReferenceIteratorgetReferenceIteratorTo()Get an iterator over all references TO this code unit.Reference[]getReferencesFrom()Get ALL memory references FROM this code unit.ScalargetScalar(int opIndex)Returns the scalar at the given operand index.java.lang.StringgetStringProperty(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.booleangetVoidProperty(java.lang.String name)Returns whether this code unit is marked as having the name property.booleanhasProperty(java.lang.String name)Returns true if the codeunit has the given property defined.booleanisSuccessor(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.voidremoveExternalReference(int opIndex)Remove external reference (if any) at the given opIndex opIndex the index of the operand from which to remove any external reference.voidremoveMnemonicReference(Address refAddr)Remove a reference to the mnemonic for this code unit.voidremoveOperandReference(int index, Address refAddr)Remove a reference to the operand.voidremoveProperty(java.lang.String name)Remove the property with the given name from this code unit.voidsetComment(int commentType, java.lang.String comment)Set the comment for the given comment type.voidsetCommentAsArray(int commentType, java.lang.String[] comment)Set the comment (with each line in its own string) for the given comment typevoidsetPrimaryMemoryReference(Reference ref)Sets a memory reference to be the primary reference at its address/opIndex location.voidsetProperty(java.lang.String name)Set the named property.voidsetProperty(java.lang.String name, int value)Set the named property with the given value at the address of this codeunit.voidsetProperty(java.lang.String name, Saveable value)Set the named property with the given value at the address of this codeunit.voidsetProperty(java.lang.String name, java.lang.String value)Set the named property with the given value at the address of this codeunit.voidsetRegisterReference(int opIndex, Register reg, SourceType sourceType, RefType refType)Sets a register reference at theoffseton 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 referencevoidsetStackReference(int opIndex, int offset, SourceType sourceType, RefType refType)Sets a stack reference at theoffseton 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 referencevoidvisitProperty(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 interface ghidra.program.model.mem.MemBuffergetAddress, getBigInteger, getByte, getBytes, getInt, getLong, getMemory, getShort, getUnsignedByte, getUnsignedInt, getUnsignedShort, getVarLengthInt, getVarLengthUnsignedInt, isBigEndian, isInitializedMemory
 
- 
 
- 
- 
- 
Field Detail- 
MNEMONICstatic final int MNEMONIC Indicator for a mnemonic (versus an operand).- See Also:
- Constant Field Values
 
 - 
NO_COMMENTstatic final int NO_COMMENT - See Also:
- Constant Field Values
 
 - 
EOL_COMMENTstatic final int EOL_COMMENT comment type for end of line- See Also:
- Constant Field Values
 
 - 
PRE_COMMENTstatic final int PRE_COMMENT comment type that goes before a code unit- See Also:
- Constant Field Values
 
 - 
POST_COMMENTstatic final int POST_COMMENT comment type that follows after a code unit- See Also:
- Constant Field Values
 
 - 
PLATE_COMMENTstatic final int PLATE_COMMENT Property name for plate comment type- See Also:
- Constant Field Values
 
 - 
REPEATABLE_COMMENTstatic final int REPEATABLE_COMMENT Property name for repeatable comment type- See Also:
- Constant Field Values
 
 - 
COMMENT_PROPERTYstatic final java.lang.String COMMENT_PROPERTY Any comment property.- See Also:
- Constant Field Values
 
 - 
SPACE_PROPERTYstatic final java.lang.String SPACE_PROPERTY Property name for vertical space formatting- See Also:
- Constant Field Values
 
 - 
INSTRUCTION_PROPERTYstatic final java.lang.String INSTRUCTION_PROPERTY Property name for code units that are instructions- See Also:
- Constant Field Values
 
 - 
DEFINED_DATA_PROPERTYstatic final java.lang.String DEFINED_DATA_PROPERTY Property name for code units that are defined data- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getAddressStringjava.lang.String getAddressString(boolean showBlockName, boolean pad)Get the string representation of the starting address for this code unit.- Parameters:
- showBlockName- true if the string should include the memory block name
- pad- 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
 
 - 
setPropertyvoid setProperty(java.lang.String name, Saveable value)Set the named property with the given value at the address of this codeunit.- Parameters:
- name- the name of the property.
- value- value to be stored.
 
 - 
setPropertyvoid setProperty(java.lang.String name, java.lang.String value)Set the named property with the given value at the address of this codeunit.- Parameters:
- name- the name of the property.
- value- value to be stored.
 
 - 
setPropertyvoid setProperty(java.lang.String name, int value)Set the named property with the given value at the address of this codeunit.- Parameters:
- name- the name of the property.
- value- value to be stored.
 
 - 
setPropertyvoid setProperty(java.lang.String name) Set the named property. This method is used for "void" properites. The property is either set or not set - there is no value- Parameters:
- name- the name of the property.
 
 - 
getObjectPropertySaveable getObjectProperty(java.lang.String name) Get the object property for name; returns null if there is no name property for this code unit.- Parameters:
- name- the name of the property
 
 - 
getStringPropertyjava.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.- Parameters:
- name- the name of the property
 
 - 
getIntPropertyint getIntProperty(java.lang.String name) throws NoValueExceptionGet the int property for name.- Parameters:
- name- the name of the property
- Throws:
- NoValueException- if there is not name property for this code unit
 
 - 
hasPropertyboolean hasProperty(java.lang.String name) Returns true if the codeunit has the given property defined.- Parameters:
- name- the name of the property
 
 - 
getVoidPropertyboolean getVoidProperty(java.lang.String name) Returns whether this code unit is marked as having the name property.- Parameters:
- name- the name of the property
 
 - 
propertyNamesjava.util.Iterator<java.lang.String> propertyNames() Get an iterator over the property names.
 - 
removePropertyvoid removeProperty(java.lang.String name) Remove the property with the given name from this code unit.- Parameters:
- name- the name of the property
 
 - 
visitPropertyvoid visitProperty(PropertyVisitor visitor, java.lang.String propertyName) Invokes the visit() method of the specified PropertyVisitor if the named property exists for this code unit.- Parameters:
- visitor- the class implementing the PropertyVisitor interface.
- propertyName- the name of the property to be visited.
 
 - 
getLabeljava.lang.String getLabel() Get the label for this code unit.
 - 
getSymbolsSymbol[] getSymbols() Get the Symbols for this code unit.- Throws:
- java.util.ConcurrentModificationException- if this object is no longer valid.
 
 - 
getPrimarySymbolSymbol getPrimarySymbol() Get the Primary Symbol for this code unit.- Throws:
- java.util.ConcurrentModificationException- if this object is no longer valid.
 
 - 
getMinAddressAddress getMinAddress() Get the starting address for this code unit.
 - 
getMaxAddressAddress getMaxAddress() Get the ending address for this code unit.
 - 
getMnemonicStringjava.lang.String getMnemonicString() Get the mnemonic for this code unit, e.g., MOV, JMP
 - 
getCommentjava.lang.String getComment(int commentType) Get 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:
- java.lang.IllegalArgumentException- if type is not one of the three types of comments supported
 
 - 
getCommentAsArrayjava.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.- 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:
- java.lang.IllegalArgumentException- if type is not one of the three types of comments supported
 
 - 
setCommentvoid setComment(int commentType, java.lang.String comment)Set the comment for the given comment type. Passing null clears the comment- Parameters:
- commentType- either EOL_COMMENT, PRE_COMMENT, POST_COMMENT, or REPEATABLE_COMMENT
- comment- comment for code unit; null clears the comment
- Throws:
- java.lang.IllegalArgumentException- if type is not one of the three types of comments supported
 
 - 
setCommentAsArrayvoid setCommentAsArray(int commentType, java.lang.String[] comment)Set 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_COMMENT
- comment- an array of strings where each string is a single line of the comment.
- Throws:
- java.lang.IllegalArgumentException- if type is not one of the three types of comments supported
 
 - 
isSuccessorboolean isSuccessor(CodeUnit codeUnit) Return true if the given CodeUnit follows directly after this code unit.- Parameters:
- codeUnit- the codeUnit being tested to see if it follows this codeUnit.
 
 - 
getLengthint getLength() Get length of this code unit.
 - 
getBytesbyte[] getBytes() throws MemoryAccessExceptionGet the bytes that make up this code unit.- 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.
 
 - 
getBytesInCodeUnitvoid getBytesInCodeUnit(byte[] buffer, int bufferOffset) throws MemoryAccessExceptionCopies max(buffer.length, code unit length) bytes into buffer starting at location offset in buffer.- Parameters:
- buffer- byte array to copy into
- bufferOffset- offset in byte array the copy will start
- Throws:
- MemoryAccessException- if the full number of bytes could not be read.
 
 - 
containsboolean contains(Address testAddr) Returns true if address is contained in the range of this codeUnit- Parameters:
- testAddr- the address to test.
 
 - 
compareToint compareTo(Address addr) 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
 
 - 
addMnemonicReferencevoid addMnemonicReference(Address refAddr, RefType refType, SourceType sourceType) 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
 
 - 
removeMnemonicReferencevoid removeMnemonicReference(Address refAddr) Remove a reference to the mnemonic for this code unit.- Parameters:
- refAddr- the address to remove as a reference.
 
 - 
getMnemonicReferencesReference[] 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.
 
 - 
getOperandReferencesReference[] getOperandReferences(int index) Get the references for the operand index.- Parameters:
- index- operand index (0 is the first operand)
 
 - 
getPrimaryReferenceReference getPrimaryReference(int index) Get the primary reference for the operand index.- Parameters:
- index- operand index (0 is the first operand)
 
 - 
addOperandReferencevoid addOperandReference(int index, Address refAddr, RefType type, SourceType sourceType)Add a memory reference to the operand at the given index.- Parameters:
- index- operand index
- refAddr- reference address
- type- the reference type to be added.
- sourceType- the source of this reference
 
 - 
removeOperandReferencevoid removeOperandReference(int index, Address refAddr)Remove a reference to the operand.- Parameters:
- index- operand index
- refAddr- address referencing the operand
 
 - 
getReferencesFromReference[] 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.
 
 - 
getReferenceIteratorToReferenceIterator getReferenceIteratorTo() Get an iterator over all references TO this code unit.
 - 
getProgramProgram getProgram() Returns the program that generated this CodeUnit.
 - 
getExternalReferenceExternalReference getExternalReference(int opIndex) 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.
 
 - 
removeExternalReferencevoid 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.
 - 
setPrimaryMemoryReferencevoid setPrimaryMemoryReference(Reference ref) 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.
 
 - 
setStackReferencevoid setStackReference(int opIndex, int offset, SourceType sourceType, RefType refType)Sets a stack reference at theoffseton 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 reference
- offset- the (+/-) offset from stack base address
- sourceType- the source of this reference
- refType- type of reference, RefType.READ,WRITE,PTR...
 
 - 
setRegisterReferencevoid setRegisterReference(int opIndex, Register reg, SourceType sourceType, RefType refType)Sets a register reference at theoffseton 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 reference
- reg- a register
- sourceType- the source of this reference
- refType- type of reference, RefType.READ,WRITE,PTR...
 
 - 
getNumOperandsint getNumOperands() Get the number of operands for this code unit.
 - 
getAddressAddress getAddress(int opIndex) 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.
 
 - 
getScalarScalar getScalar(int opIndex) 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.
 
 
- 
 
-