Java Code Examples for ghidra.program.database.ProgramDB#getDataTypeManager()

The following examples show how to use ghidra.program.database.ProgramDB#getDataTypeManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OldFunctionManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Actually does the work of upgrading the old program function manager.
 * @param upgradeProgram the program to upgrade
 * @param monitor the task monitor to allow the user to cancel the upgrade
 * @throws CancelledException if the user cancels the upgrade
 * @throws IOException if an i/o error occurs
 */
public void upgrade(ProgramDB upgradeProgram, TaskMonitor monitor)
		throws CancelledException, IOException {

	if (this.program != null) {
		throw new AssertException("Function manager already upgraded");
	}
	this.program = upgradeProgram;
	dataManager = upgradeProgram.getDataTypeManager();

	monitor.setMessage("Upgrading Functions...");
	monitor.initialize(getFunctionCount());
	int cnt = 0;

	OldFunctionIteratorDB iter = getFunctions();
	while (iter.hasNext()) {
		monitor.checkCanceled();
		upgradeFunction(iter.next());
		monitor.setProgress(++cnt);
	}
	dispose();
}
 
Example 2
Source File: AbstractRttiTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void checkVfTableData(ProgramDB program, long metaPointerAddress, long rtti4Address,
		long vfTableAddress, long[] vfAddresses) {
	PointerDataType pointerDataType = new PointerDataType(program.getDataTypeManager());
	checkSimpleData(program, metaPointerAddress, pointerDataType);
	checkSimpleData(program, rtti4Address, Rtti4Model.getDataType(program));
	checkArrayData(program, vfTableAddress, pointerDataType, vfAddresses.length);
	// Check for specific function pointer values?
	Memory memory = program.getMemory();
	AddressSetView loadedAndInitializedAddressSet = memory.getLoadedAndInitializedAddressSet();
	for (long vfAddress : vfAddresses) {
		Address vfAddr = addr(program, vfAddress);
		String failureMessage = "VF Address " + vfAddr +
			" isn't in loaded and initialized memory of program " + program.getName() + ".";
		assertTrue(failureMessage, loadedAndInitializedAddressSet.contains(vfAddr));
	}
}
 
Example 3
Source File: AbstractRttiTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
protected void checkRtti2Data(ProgramDB program, long address, int numEntries) {
	DataType expectedDataType =
		MSDataTypeUtils.is64Bit(program) ? new ImageBaseOffset32DataType()
				: new PointerDataType(Rtti1Model.getDataType(program),
					program.getDataTypeManager());
	checkArrayData(program, address, expectedDataType, numEntries);
}
 
Example 4
Source File: FollowFlowProgramBuilder.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private int createStructureWithPointer(String name, int startOfStruct, int to) throws Exception {
	int thisStructureSize = 12;
	int thisPointerSize = 4;
	int pointerOffset = 4;

	byte[] bytes = new byte[thisPointerSize];
	dataConverter.getBytes(to, bytes);

	String structureStart = "0x" + Integer.toHexString(startOfStruct);
	String pointerStart = "0x" + Integer.toHexString(startOfStruct + pointerOffset);
	String structureEnd = "0x" + Integer.toHexString(startOfStruct + thisStructureSize - 1);
	String toAddress = "0x" + Integer.toHexString(to);

	clearCodeUnits(structureStart, structureEnd, false);
	setBytes(pointerStart, bytes, false);
	startTransaction();
	ProgramDB program = getProgram();
	Listing listing = program.getListing();
	Structure struct = new StructureDataType(name, thisStructureSize, program.getDataTypeManager());
	struct.replaceAtOffset(0, new FloatDataType(), 4, null, null);
	struct.replaceAtOffset(pointerOffset, new Pointer32DataType(), 4, null, null);
	listing.createData(addr(startOfStruct), struct);
	createMemoryReference(pointerStart, toAddress, RefType.DATA, SourceType.ANALYSIS, 0);
	endTransaction();

	return thisPointerSize; // pointer size in bytes.
}
 
Example 5
Source File: FollowFlowProgramBuilder.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private int createStructureWith2Pointers(String name, int startOfStruct, int to, int secondTo)
		throws Exception {
	int thisStructureSize = 12;
	int pointerSize = 4;
	int pointerOffset = 4;

	byte[] bytes = new byte[pointerSize];
	dataConverter.getBytes(to, bytes);

	String structureStart = "0x" + Integer.toHexString(startOfStruct);
	String pointerStart = "0x" + Integer.toHexString(startOfStruct + pointerOffset);
	String pointer2Start =
		"0x" + Integer.toHexString(startOfStruct + pointerOffset + pointerSize);
	String structureEnd = "0x" + Integer.toHexString(startOfStruct + thisStructureSize - 1);
	String toAddress = "0x" + Integer.toHexString(to);
	String toAddress2 = "0x" + Integer.toHexString(secondTo);

	clearCodeUnits(structureStart, structureEnd, false);
	setBytes(pointerStart, bytes, false);
	dataConverter.getBytes(secondTo, bytes);
	setBytes(pointerStart + pointerSize, bytes, false);
	startTransaction();
	ProgramDB program = getProgram();
	Listing listing = program.getListing();
	Structure struct = new StructureDataType(name, thisStructureSize, program.getDataTypeManager());
	struct.replaceAtOffset(0, new FloatDataType(), 4, null, null);
	struct.replaceAtOffset(pointerOffset, new Pointer32DataType(), 4, null, null);
	struct.replaceAtOffset(pointerOffset + pointerSize, new Pointer32DataType(), 4, null, null);
	listing.createData(addr(startOfStruct), struct);
	createMemoryReference(pointerStart, toAddress, RefType.DATA, SourceType.ANALYSIS, 0);
	createMemoryReference(pointer2Start, toAddress2, RefType.DATA, SourceType.ANALYSIS, 0);
	endTransaction();

	return pointerSize; // pointer size in bytes.
}
 
Example 6
Source File: AbstractFunctionParameterMarkupItemTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
protected DataType createIntDataType(ProgramDB program) {
	int transaction = -1;
	try {
		transaction = program.startTransaction("Test - Create Data Type");
		DataTypeManagerDB dataTypeManager = program.getDataTypeManager();
		DataType dataType = new IntegerDataType(dataTypeManager);
		return dataTypeManager.addDataType(dataType, DataTypeConflictHandler.DEFAULT_HANDLER);
	}
	finally {
		program.endTransaction(transaction, true);
	}
}
 
Example 7
Source File: AbstractFunctionParameterMarkupItemTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
protected DataType createByteDataType(ProgramDB program) {
	DataTypeManagerDB dataTypeManager = program.getDataTypeManager();
	DataType dataType = new ByteDataType(dataTypeManager);
	return dataTypeManager.addDataType(dataType, DataTypeConflictHandler.DEFAULT_HANDLER);
}