Package ghidra.program.database
Class ProgramBuilder
java.lang.Object
ghidra.program.database.ProgramBuilder
- Direct Known Subclasses:
ClassicSampleX86ProgramBuilder
,ToyProgramBuilder
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
protected static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
-
Constructor Summary
ConstructorDescriptionConstruct program builder using the big-endian Toy language and default compiler spec.ProgramBuilder
(String name, Language language) Construct program builder using a full language object rather than a language id stringProgramBuilder
(String name, String languageName) Construct program builder using specified language and default compiler spec.ProgramBuilder
(String name, String languageName, Object consumer) Construct program builder using specified language and default compiler specProgramBuilder
(String name, String languageName, String compilerSpecID, Object consumer) Construct program builder using specified language -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCategory
(CategoryPath path) void
addDataType
(DataType dt) void
addr
(long offset) void
analyze()
Perform complete analysis on the built program.void
applyDataType
(String addressString, DataType dt) void
applyDataType
(String addressString, DataType dt, int n) Creates a data instance at the specified address, repeatedN
times.void
applyFixedLengthDataType
(String addressString, DataType dt, int length) void
applyStringDataType
(String addressString, AbstractStringDataType dt, int n) Creates a sting data type instance at the specified address, repeatedN
times.void
bindExternalLibrary
(String libraryName, String pathname) void
clearCodeUnits
(String startAddressString, String endAddressString, boolean clearContext) createBookmark
(String address, String bookmarkType, String category, String comment) createClassNamespace
(String name, String parentNamespace, SourceType type) void
createComment
(String address, String comment, int commentType) createEmptyFunction
(String name, String address, int size, DataType returnType, boolean varargs, boolean inline, boolean noReturn, Parameter... params) createEmptyFunction
(String name, String address, int size, DataType returnType, Parameter... params) createEmptyFunction
(String name, String namespace, String callingConventionName, boolean customStorage, String address, int bodySize, DataType returnType, Parameter... params) createEmptyFunction
(String name, String namespace, String address, int bodySize, DataType returnType, Parameter... params) createEmptyFunction
(String name, String namespace, String callingConventionName, String address, int size, DataType returnType, DataType... paramTypes) void
createEncodedString
(String address, String string, Charset encoding, boolean nullTerminate) createEntryPoint
(String addressString, String name) createEquate
(String address, String name, long value, int opIndex) createExternalFunction
(String extAddress, String libName, String functionName) createExternalFunction
(String extAddress, String libName, String functionName, String originalName) void
createExternalLibraries
(String... libraryNames) void
createExternalReference
(String fromAddress, String libraryName, String externalLabel, int opIndex) void
createExternalReference
(String fromAddress, String libraryName, String externalLabel, String extAddress, int opIndex) void
createExternalReference
(String fromAddress, String libraryName, String externalLabel, String extAddress, int opIndex, RefType refType, SourceType sourceType) void
createFragment
(String treeName, String modulePath, String fragmentName, String startAddr, String endAddr) createFunction
(String addressString) Creates a function by examining the instructions to find the body.void
createFunctionComment
(String entryPointAddress, String comment) createLabel
(String addressString, String name) createLabel
(String addressString, String name, String namespace) createLibrary
(String libraryName) createLibrary
(String libraryName, SourceType type) void
createLocalVariable
(Function function, String name, DataType dt, int stackOffset) createMemory
(String name, String address, int size) createMemory
(String name, String address, int size, String comment) createMemory
(String name, String address, int size, String comment, byte initialValue) createMemoryCallReference
(String fromAddress, String toAddress) createMemoryJumpReference
(String fromAddress, String toAddress) createMemoryReadReference
(String fromAddress, String toAddress) createMemoryReference
(String fromAddress, String toAddress, RefType refType, SourceType sourceType) createMemoryReference
(String fromAddress, String toAddress, RefType refType, SourceType sourceType, int opIndex) createNamespace
(String namespace) createNamespace
(String namespace, SourceType type) createNamespace
(String namespace, String parentNamespace, SourceType type) createOffsetMemReference
(String fromAddress, String toAddress, int offset, RefType refType, SourceType sourceType, int opIndex) createOverlayMemory
(String name, String address, int size) void
createProgramTree
(String treeName) createRegisterReference
(String fromAddress, RefType refType, String registerName, SourceType sourceType, int opIndex) createRegisterReference
(String fromAddress, String registerName, int opIndex) createStackReference
(String fromAddress, RefType refType, int stackOffset, SourceType sourceType, int opIndex) createString
(String address, byte[] stringBytes, Charset charset, DataType dataType) createString
(String address, String string, Charset charset, boolean nullTerminate, DataType dataType) createUninitializedMemory
(String name, String address, int size) void
deleteFunction
(String address) void
deleteReference
(Reference reference) void
void
disassemble
(AddressSetView set, boolean followFlows) void
disassemble
(String addressString, int length) void
disassemble
(String addressString, int length, boolean followFlows) void
disassembleArm
(String addressString, int length, boolean thumb) void
dispose()
protected void
protected void
endTransaction
(boolean commit) getNamespace
(String namespace) getNamespace
(String namespace, Address address) getOrCreateModule
(String treeName, String modulePath) Get the constructed program.getRegister
(String regName) void
setAnalysisEnabled
(String name, boolean enabled) void
This prevents the 'ask to analyze' dialog from showing when called withtrue
void
void
Sets the bytes starting atstringAddress
to the byte values inbytes
and then optionally disassembling.void
Sets the bytes starting ataddress
to the values encoded inbyteString
.void
Sets the bytes starting ataddress
to the values encoded inbyteString
and then optionally disassembling.void
setChanged
(boolean changed) void
setExecute
(MemoryBlock block, boolean e) void
setFallthrough
(String from, String to) void
setIntProperty
(String address, String propertyName, int value) void
void
setObjectProperty
(String address, String propertyName, Saveable value) void
setProperty
(String name, Object value) void
setRead
(MemoryBlock block, boolean r) void
setRecordChanges
(boolean enabled) void
setRegisterValue
(String registerName, String startAddress, String endAddress, long value) void
setStringProperty
(String address, String propertyName, String value) void
setWrite
(MemoryBlock block, boolean w) protected void
void
-
Field Details
-
_ARM
- See Also:
-
_AARCH64
- See Also:
-
_X86
- See Also:
-
_X86_16_REAL_MODE
- See Also:
-
_X64
- See Also:
-
_8051
- See Also:
-
_SPARC64
- See Also:
-
_MIPS
- See Also:
-
_MIPS_6432
- See Also:
-
_PPC_32
- See Also:
-
_PPC_6432
- See Also:
-
_PPC_64
- See Also:
-
_TOY_BE
- See Also:
-
_TOY_BE_POSITIVE
- See Also:
-
_TOY_LE
- See Also:
-
_TOY_WORDSIZE2_BE
- See Also:
-
_TOY_WORDSIZE2_LE
- See Also:
-
_TOY64_BE
- See Also:
-
_TOY64_LE
- See Also:
-
_TOY
- See Also:
-
_TOY_LANGUAGE_PREFIX
- See Also:
-
-
Constructor Details
-
ProgramBuilder
Construct program builder using the big-endian Toy language and default compiler spec. This builder object will be the program consumer and must be disposed to properly release the program.- Throws:
Exception
- if there is an exception creating the program
-
ProgramBuilder
Construct program builder using specified language and default compiler spec. This builder object will be the program consumer and must be disposed to properly release the program.- Parameters:
name
- program namelanguageName
- supported language ID (includes all Toy language IDs)- Throws:
Exception
- if there is an exception creating the program
-
ProgramBuilder
Construct program builder using specified language and default compiler spec- Parameters:
name
- program namelanguageName
- supported language ID (includes all Toy language IDs)consumer
- program consumer (if null this builder will be used as consumer and must be disposed to release program)- Throws:
Exception
- if there is an exception creating the program
-
ProgramBuilder
public ProgramBuilder(String name, String languageName, String compilerSpecID, Object consumer) throws Exception Construct program builder using specified language- Parameters:
name
- program namelanguageName
- supported language ID (includes all Toy language IDs)compilerSpecID
- compiler specification ID (if null default spec will be used)consumer
- program consumer (if null this builder will be used as consumer and must be disposed to release program)- Throws:
Exception
- if there is an exception creating the program
-
ProgramBuilder
Construct program builder using a full language object rather than a language id string- Parameters:
name
- program namelanguage
- Language object- Throws:
Exception
- if there is an exception creating the program
-
-
Method Details
-
analyze
public void analyze()Perform complete analysis on the built program. Limited analysis may already have been performed during disassembly - so it may not be necessary to do complete analysis -
getProgram
Get the constructed program. If this builder was not constructed with a consumer, the caller should dispose the builder after either the program is no longer in use, or a new consumer has been added to the program (e.g., program opened in a tool or another consumer explicitly added).- Returns:
- constructed program
-
getLanguage
-
getCompilerSpec
-
getRegister
-
addr
-
addr
-
dispose
public void dispose() -
setName
-
withTransaction
-
startTransaction
protected void startTransaction() -
endTransaction
protected void endTransaction() -
endTransaction
protected void endTransaction(boolean commit) -
setRecordChanges
public void setRecordChanges(boolean enabled) -
setAnalyzed
public void setAnalyzed()This prevents the 'ask to analyze' dialog from showing when called withtrue
-
createMemory
-
createMemory
-
createMemory
public MemoryBlock createMemory(String name, String address, int size, String comment, byte initialValue) -
createUninitializedMemory
-
createOverlayMemory
-
setBytes
Sets the bytes starting ataddress
to the values encoded inbyteString
.- Parameters:
address
- String containing numeric value, preferably hex encoded: "0x1004000"byteString
- String containing 2 digit hex values, separated by ' ' space chars or by comma ',' chars: "12 05 ff". SeeNumericUtilities.parseHexLong(String)
.- Throws:
Exception
- if there is an exception applying the bytes
-
setBytes
Sets the bytes starting ataddress
to the values encoded inbyteString
and then optionally disassembling.- Parameters:
address
- String containing numeric value, preferably hex encoded: "0x1004000"byteString
- String containing 2 digit hex values, separated by ' ' space chars or by comma ',' chars: "12 05 ff". SeeNumericUtilities.parseHexLong(String)
.disassemble
- boolean flag.- Throws:
Exception
- if there is an exception applying the bytes
-
setBytes
- Throws:
Exception
-
setBytes
Sets the bytes starting atstringAddress
to the byte values inbytes
and then optionally disassembling.- Parameters:
stringAddress
- String containing numeric value, preferably hex encoded: "0x1004000"bytes
- array of bytes to copy into the memory buffer at the addresss.disassemble
- boolean flag. Seedisassemble(String, int)
- Throws:
Exception
- if there is an exception applying the bytes
-
setRead
-
setWrite
-
setExecute
-
disassemble
-
disassemble
-
disassemble
-
disassemble
-
disassembleArm
-
clearCodeUnits
public void clearCodeUnits(String startAddressString, String endAddressString, boolean clearContext) throws Exception - Throws:
Exception
-
createLabel
-
createLabel
-
createFunction
Creates a function by examining the instructions to find the body.- Parameters:
addressString
- the address- Returns:
- the function
-
addFunctionVariable
- Throws:
Exception
-
createEmptyFunction
-
createEmptyFunction
public Function createEmptyFunction(String name, String address, int size, DataType returnType, boolean varargs, boolean inline, boolean noReturn, Parameter... params) throws Exception - Throws:
Exception
-
createEmptyFunction
public Function createEmptyFunction(String name, String namespace, String address, int bodySize, DataType returnType, Parameter... params) throws Exception - Throws:
Exception
-
createEmptyFunction
public Function createEmptyFunction(String name, String namespace, String callingConventionName, boolean customStorage, String address, int bodySize, DataType returnType, Parameter... params) throws Exception - Throws:
Exception
-
createEmptyFunction
public Function createEmptyFunction(String name, String namespace, String callingConventionName, String address, int size, DataType returnType, DataType... paramTypes) throws Exception - Throws:
Exception
-
deleteFunction
- Throws:
Exception
-
createLibrary
public Library createLibrary(String libraryName) throws DuplicateNameException, InvalidInputException -
createLibrary
public Library createLibrary(String libraryName, SourceType type) throws DuplicateNameException, InvalidInputException -
createNamespace
-
getNamespace
-
getNamespace
-
createNamespace
-
createNamespace
-
createClassNamespace
public Namespace createClassNamespace(String name, String parentNamespace, SourceType type) throws Exception - Throws:
Exception
-
applyFixedLengthDataType
-
applyDataType
-
applyDataType
Creates a data instance at the specified address, repeatedN
times. Any conflicting Data will be overwritten. -
applyStringDataType
Creates a sting data type instance at the specified address, repeatedN
times.- Parameters:
addressString
- address.dt
-AbstractStringDataType
string type to place at address.n
- repeat count.
-
deleteReference
-
createMemoryReadReference
-
createMemoryCallReference
-
createMemoryJumpReference
-
createMemoryReference
public Reference createMemoryReference(String fromAddress, String toAddress, RefType refType, SourceType sourceType) -
createMemoryReference
public Reference createMemoryReference(String fromAddress, String toAddress, RefType refType, SourceType sourceType, int opIndex) -
createOffsetMemReference
public Reference createOffsetMemReference(String fromAddress, String toAddress, int offset, RefType refType, SourceType sourceType, int opIndex) -
createStackReference
public Reference createStackReference(String fromAddress, RefType refType, int stackOffset, SourceType sourceType, int opIndex) -
createRegisterReference
-
createRegisterReference
public Reference createRegisterReference(String fromAddress, RefType refType, String registerName, SourceType sourceType, int opIndex) -
createEntryPoint
-
createBookmark
-
createEncodedString
public void createEncodedString(String address, String string, Charset encoding, boolean nullTerminate) throws Exception - Throws:
Exception
-
createString
public Data createString(String address, String string, Charset charset, boolean nullTerminate, DataType dataType) throws Exception - Throws:
Exception
-
createString
public Data createString(String address, byte[] stringBytes, Charset charset, DataType dataType) throws Exception - Throws:
Exception
-
setProperty
-
setAnalysisEnabled
-
addDataType
-
addCategory
-
createProgramTree
- Throws:
Exception
-
createFragment
public void createFragment(String treeName, String modulePath, String fragmentName, String startAddr, String endAddr) throws Exception - Throws:
Exception
-
getOrCreateModule
- Throws:
Exception
-
createEquate
-
createComment
-
createFunctionComment
-
setFallthrough
-
createExternalLibraries
- Throws:
Exception
-
bindExternalLibrary
- Throws:
Exception
-
createExternalReference
public void createExternalReference(String fromAddress, String libraryName, String externalLabel, int opIndex) throws Exception - Throws:
Exception
-
createExternalReference
public void createExternalReference(String fromAddress, String libraryName, String externalLabel, String extAddress, int opIndex) throws Exception - Throws:
Exception
-
createExternalReference
public void createExternalReference(String fromAddress, String libraryName, String externalLabel, String extAddress, int opIndex, RefType refType, SourceType sourceType) throws Exception - Throws:
Exception
-
createExternalFunction
public ExternalLocation createExternalFunction(String extAddress, String libName, String functionName) throws Exception - Throws:
Exception
-
createExternalFunction
public ExternalLocation createExternalFunction(String extAddress, String libName, String functionName, String originalName) throws Exception - Throws:
Exception
-
createLocalVariable
public void createLocalVariable(Function function, String name, DataType dt, int stackOffset) throws Exception - Throws:
Exception
-
setRegisterValue
public void setRegisterValue(String registerName, String startAddress, String endAddress, long value) throws Exception - Throws:
Exception
-
setIntProperty
- Throws:
Exception
-
setStringProperty
- Throws:
Exception
-
setObjectProperty
- Throws:
Exception
-
setChanged
public void setChanged(boolean changed)
-