Package ghidra.program.database
Class ProgramBuilder
java.lang.Object
ghidra.program.database.ProgramBuilder
- Direct Known Subclasses:
ClassicSampleX86ProgramBuilder,ToyProgramBuilder
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceProgramBuilder.ExceptionalSupplier<R,E extends Exception> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionConstruct 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 TypeMethodDescriptionvoidaddCategory(CategoryPath path) voidaddDataType(DataType dt) voidaddr(long offset) voidanalyze()Perform complete analysis on the built program.voidapplyDataType(String addressString, DataType dt) voidapplyDataType(String addressString, DataType dt, int n) Creates a data instance at the specified address, repeatedNtimes.voidapplyFixedLengthDataType(String addressString, DataType dt, int length) voidapplyStringDataType(String addressString, AbstractStringDataType dt, int n) Creates a sting data type instance at the specified address, repeatedNtimes.voidbindExternalLibrary(String libraryName, String pathname) voidclearCodeUnits(String startAddressString, String endAddressString, boolean clearContext) createBookmark(String address, String bookmarkType, String category, String comment) createClassNamespace(String name, String parentNamespace, SourceType type) voidcreateComment(String address, String comment, int commentType) Deprecated, for removal: This API element is subject to removal in a future version.voidcreateComment(String address, String comment, CommentType 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) voidcreateEncodedString(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) voidcreateExternalLibraries(String... libraryNames) voidcreateExternalReference(String fromAddress, String libraryName, String externalLabel, int opIndex) voidcreateExternalReference(String fromAddress, String libraryName, String externalLabel, String extAddress, int opIndex) voidcreateExternalReference(String fromAddress, String libraryName, String externalLabel, String extAddress, int opIndex, RefType refType, SourceType sourceType) createFileBytes(int size) voidcreateFragment(String treeName, String modulePath, String fragmentName, String startAddr, String endAddr) createFunction(String addressString) Creates a function by examining the instructions to find the body.voidcreateFunctionComment(String entryPointAddress, String comment) createLabel(String addressString, String name) createLabel(String addressString, String name, String namespace) createLibrary(String libraryName) createLibrary(String libraryName, SourceType type) voidcreateLocalVariable(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) createMemory(String name, String address, FileBytes fileBytes, int size) 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) voidcreateProgramTree(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) voiddeleteFunction(String address) voiddeleteReference(Reference reference) voidvoiddisassemble(AddressSetView set, boolean followFlows) voiddisassemble(String addressString, int length) voiddisassemble(String addressString, int length, boolean followFlows) voiddisassembleArm(String addressString, int length, boolean thumb) voiddispose()protected voidprotected voidendTransaction(boolean commit) getNamespace(String namespace) getNamespace(String namespace, Address address) getOrCreateModule(String treeName, String modulePath) Get the constructed program.getRegister(String regName) voidsetAnalysisEnabled(String name, boolean enabled) voidThis prevents the 'ask to analyze' dialog from showing when called withtruevoidvoidSets the bytes starting atstringAddressto the byte values inbytesand then optionally disassembling.voidSets the bytes starting ataddressto the values encoded inbyteString.voidSets the bytes starting ataddressto the values encoded inbyteStringand then optionally disassembling.voidsetChanged(boolean changed) voidsetExecute(MemoryBlock block, boolean e) voidsetFallthrough(String from, String to) voidsetIntProperty(String address, String propertyName, int value) voidvoidsetObjectProperty(String address, String propertyName, Saveable value) voidsetProperty(String name, Object value) voidsetRead(MemoryBlock block, boolean r) voidsetRecordChanges(boolean enabled) voidsetRegisterValue(String registerName, String startAddress, String endAddress, long value) voidsetStringProperty(String address, String propertyName, String value) voidsetWrite(MemoryBlock block, boolean w) protected void<R,E extends Exception>
Rtx(ProgramBuilder.ExceptionalSupplier<R, E> s) <E extends Exception>
voidtx(ExceptionalCallback<E> c) 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
-
createMemory
public MemoryBlock createMemory(String name, String address, int size, String comment, byte initialValue) -
createUninitializedMemory
-
createOverlayMemory
-
setBytes
Sets the bytes starting ataddressto 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 ataddressto the values encoded inbyteStringand 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 atstringAddressto the byte values inbytesand 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 GhidraClass createClassNamespace(String name, String parentNamespace, SourceType type) throws Exception - Throws:
Exception
-
applyFixedLengthDataType
-
applyDataType
-
applyDataType
Creates a data instance at the specified address, repeatedNtimes. Any conflicting Data will be overwritten. -
applyStringDataType
Creates a sting data type instance at the specified address, repeatedNtimes.- Parameters:
addressString- address.dt-AbstractStringDataTypestring 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
@Deprecated(forRemoval=true, since="11.4") public void createComment(String address, String comment, int commentType) Deprecated, for removal: This API element is subject to removal in a future version. -
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) -
createFileBytes
- Throws:
Exception
-
tx
-
tx
-