ghidra.program.database.ProgramDB Java Examples

The following examples show how to use ghidra.program.database.ProgramDB. 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: AbstractRttiTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void setupRtti1_64(ProgramBuilder builder, long address, String typeDescriptorAddress,
		int numContainedBases, int mdisp, int pdisp, int vdisp, int attributes,
		String classHierarchyAddress) throws Exception {

	ProgramDB program = builder.getProgram();
	boolean bigEndian = program.getCompilerSpec().getDataOrganization().isBigEndian();
	Address typeDescriptorAddr = builder.addr(address);
	Address numContainedBasesAddr = builder.addr(address + 4);
	Address mDispAddr = builder.addr(address + 8);
	Address pDispAddr = builder.addr(address + 12);
	Address vDispAddr = builder.addr(address + 16);
	Address attributesAddr = builder.addr(address + 20);
	Address classHierarchyAddr = builder.addr(address + 24);
	builder.setBytes(typeDescriptorAddr.toString(),
		getHexAddressAsIbo32ByteString(builder, typeDescriptorAddress, bigEndian));
	builder.setBytes(numContainedBasesAddr.toString(),
		getIntAsByteString(numContainedBases, bigEndian));
	builder.setBytes(mDispAddr.toString(), getIntAsByteString(mdisp, bigEndian));
	builder.setBytes(pDispAddr.toString(), getIntAsByteString(pdisp, bigEndian));
	builder.setBytes(vDispAddr.toString(), getIntAsByteString(vdisp, bigEndian));
	builder.setBytes(attributesAddr.toString(), getIntAsByteString(attributes, bigEndian));
	builder.setBytes(classHierarchyAddr.toString(),
		getHexAddressAsIbo32ByteString(builder, classHierarchyAddress, bigEndian));
}
 
Example #2
Source File: ChangeFunctionTagCmd.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/******************************************************************************
 * PUBLIC METHODS
 ******************************************************************************/

@Override
public boolean applyTo(DomainObject obj) {
	ProgramDB program = (ProgramDB) obj;
	FunctionManagerDB functionManagerDB = (FunctionManagerDB) program.getFunctionManager();
	FunctionTagManager functionTagManager = functionManagerDB.getFunctionTagManager();
	FunctionTag tag = functionTagManager.getFunctionTag(tagName);

	if (tag == null) {
		errorMsg = "Function Tag not found: " + tagName;
		return false;
	}

	if (field == TAG_NAME_CHANGED) {
		tag.setName(newVal);
	}
	else {
		tag.setComment(newVal);
	}

	return true;
}
 
Example #3
Source File: RttiModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidRtti4_32NoFollowFlow() throws Exception {

	ProgramBuilder builder = build32BitX86();
	ProgramDB program = builder.getProgram();
	assertEquals(builder.addr(0x01000000L), program.getImageBase());

	// ---- Base ----
	// rtti4:  01003340 - 01003353
	//
	setupRtti4_32(builder, 0x01003340L, 0, 0, 0, "0x01005200", "0x01003368"); // 20 bytes

	//////////////
	// Now check that everything gets laid down correctly on the structures.
	//////////////
	checkRtti4ModelNoFollow(program, 0x01003340L, 0, 0, 0, 0x01005200L, 0x01003368L);
}
 
Example #4
Source File: RttiModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidRtti4_32NoFollowFlow() throws Exception {

	ProgramBuilder builder = build32BitX86();
	ProgramDB program = builder.getProgram();
	assertEquals(builder.addr(0x01000000L), program.getImageBase());

	// ---- Base ----
	// rtti4:  01003340 - 01003353
	//
	setupRtti4_32(builder, 0x01003340L, 0, 0, 0, "0x01005200", "0x0100"); // 20 bytes

	//////////////
	// Now check that everything gets laid down correctly on the structures.
	//////////////
	String errorMessage =
		"Data referencing RTTIClassHierarchyDescriptor data type isn't a loaded and initialized address 00000100.";
	Address address = addr(program, 0x01003340L);
	checkInvalidModel(new Rtti4Model(program, address, noFollowValidationOptions),
		errorMessage);
}
 
Example #5
Source File: FromAdapterSharedTable.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
RefList getRefList(ProgramDB program, DBObjectCache<RefList> cache, Address from, long fromAddr)
		throws IOException {

	LongField fromField = new LongField(fromAddr);

	RefList fromRefs = new RefListV0(fromAddr, addrMap, program, cache, true);

	RecordIterator iter = table.indexIterator(OLD_FROM_ADDR_COL, fromField, fromField, true);
	while (iter.hasNext()) {
		Record rec = iter.next();

		boolean isUser = rec.getBooleanValue(OLD_USER_DEFINED_COL);
		SourceType source = isUser ? SourceType.USER_DEFINED : SourceType.DEFAULT;

		fromRefs.addRef(from, addrMap.decodeAddress(rec.getLongValue(OLD_TO_ADDR_COL)),
			RefTypeFactory.get((byte) rec.getShortValue(OLD_REF_TYPE_COL)),
			rec.getShortValue(OLD_OP_INDEX_COL), rec.getLongValue(OLD_SYMBOL_ID_COL),
			rec.getBooleanValue(OLD_IS_PRIMARY_COL), source, false, false, 0);

	}
	if (fromRefs.isEmpty()) {
		return null;
	}
	return fromRefs;
}
 
Example #6
Source File: BigRefListV0.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Construct reference list for existing record
 * @param rec existing refList record
 * @param adapter entry record storage adapter
 * @param addrMap address map for encoding/decoding addresses
 * @param program
 * @param cache RefList object cache
 * @param isFrom true for from-adapter use, false for to-adapter use
 */
BigRefListV0(Record rec, RecordAdapter adapter, AddressMap addrMap, ProgramDB program,
		DBObjectCache<RefList> cache, boolean isFrom) throws IOException {
	super(rec.getKey(), addrMap.decodeAddress(rec.getKey()), adapter, addrMap, program, cache,
		isFrom);
	if (rec.getBinaryData(ToAdapter.REF_DATA_COL) != null) {
		throw new IllegalArgumentException("Invalid reference record");
	}
	String tableName = BASE_TABLE_NAME + Long.toHexString(rec.getKey());
	table = program.getDBHandle().getTable(tableName);
	if (table == null) {
		throw new IOException("BigRefList table not found for " + address + " (" + tableName +
			")");
	}
	if (!isFrom) {
		refLevel = rec.getByteValue(ToAdapter.REF_LEVEL_COL);
	}
	record = rec;
}
 
Example #7
Source File: MnemonicSearchPluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	env = new TestEnv();
	tool = env.getTool();
	tool.addPlugin(ProgramTreePlugin.class.getName());
	tool.addPlugin(CodeBrowserPlugin.class.getName());
	tool.addPlugin(MarkerManagerPlugin.class.getName());
	tool.addPlugin(MemSearchPlugin.class.getName());
	tool.addPlugin(MnemonicSearchPlugin.class.getName());
	plugin = env.getPlugin(MnemonicSearchPlugin.class);
	cb = env.getPlugin(CodeBrowserPlugin.class);
	program = (ProgramDB) buildProgram();

	ProgramManager pm = tool.getService(ProgramManager.class);
	pm.openProgram(program.getDomainFile());

	searchMnemonicOperandsNoConstAction =
		getAction(plugin, "Include Operands (except constants)");
	searchMnemonicNoOperandsNoConstAction = getAction(plugin, "Exclude Operands");
	searchMnemonicOperandsConstAction = getAction(plugin, "Include Operands");

	env.showTool();
}
 
Example #8
Source File: RttiModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidRtti2Model_64NoFollowFlow() throws Exception {

	ProgramBuilder builder = build64BitX86();
	ProgramDB program = builder.getProgram();
	assertEquals(builder.addr(0x101000000L), program.getImageBase());

	// ---- Base ----
	// rtti2:  101003390 - 101003393
	//
	setupRtti2_64(builder, 0x101003390L, new String[] { "0x1010033a8" }); // 4 bytes

	setupInstructions64(builder);

	//////////////
	// Now check that everything gets laid down correctly on the structures.
	//////////////

	// ---- check Base ----
	checkRtti2ModelNoFollow(program, 0x101003390L, new long[] { 0x1010033a8L });
}
 
Example #9
Source File: ToAdapterSharedTable.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
RefList getRefList(ProgramDB program, DBObjectCache<RefList> cache, Address to, long toAddr)
		throws IOException {
	LongField toField = new LongField(toAddr);

	RefList toRefs = new RefListV0(toAddr, addrMap, program, cache, false);

	RecordIterator iter = table.indexIterator(OLD_TO_ADDR_COL, toField, toField, true);
	while (iter.hasNext()) {
		Record rec = iter.next();

		boolean isUser = rec.getBooleanValue(OLD_USER_DEFINED_COL);
		SourceType source = isUser ? SourceType.USER_DEFINED : SourceType.DEFAULT;

		toRefs.addRef(addrMap.decodeAddress(rec.getLongValue(OLD_FROM_ADDR_COL)), to,
			RefTypeFactory.get((byte) rec.getShortValue(OLD_REF_TYPE_COL)),
			rec.getShortValue(OLD_OP_INDEX_COL), rec.getLongValue(OLD_SYMBOL_ID_COL),
			rec.getBooleanValue(OLD_IS_PRIMARY_COL), source, false, false, 0);

	}
	if (toRefs.isEmpty()) {
		return null;
	}
	return toRefs;
}
 
Example #10
Source File: SymbolMergeManager3Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected void createAnalyzedFunction(ProgramDB program, String entryPoint, String name) {
	Address addr = addr(program, entryPoint);
	try {
		CreateFunctionCmd functionCmd =
			new CreateFunctionCmd(name, addr, null, SourceType.ANALYSIS);
		assertTrue("Failed to create function " + name + " @ " + addr,
			functionCmd.applyTo(program));
		Function newFunction = program.getFunctionManager().getFunctionAt(addr);
		assertNotNull(newFunction);
		FunctionStackAnalysisCmd analyzeCmd = new FunctionStackAnalysisCmd(addr, true);
		assertTrue("Failed to analyze stack for " + name + " @ " + addr,
			analyzeCmd.applyTo(program));
	}
	catch (Exception e) {
		e.printStackTrace();
		Assert.fail("Can't create analyzed function @ " + entryPoint + e.getMessage());
	}
}
 
Example #11
Source File: EHModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidV3FuncInfo32() throws Exception {
	ProgramBuilder builder = build32BitX86();
	ProgramDB program = builder.getProgram();
	setupV3FuncInfo32(builder, 0x01001340, EHFunctionInfoModel.EH_MAGIC_NUMBER_V3, 1,
		"0x01001364", 1, "0x0100136c", 1, "0x01001380", "0x01001388", 0x1);
	Address address = builder.addr(0x01001340);
	EHFunctionInfoModel model =
		new EHFunctionInfoModel(program, address, defaultValidationOptions);
	model.validate();
	model.validateCounts(1000);
	model.validateLocationsInSameBlock();
	assertEquals(address, model.getAddress());
	assertEquals(0, model.getBbtFlags());
	assertEquals(EHFunctionInfoModel.EH_MAGIC_NUMBER_V3, model.getMagicNumber());
	assertEquals(1, model.getUnwindCount());
	assertEquals(builder.addr(0x01001364), model.getUnwindMapAddress());
	assertEquals(1, model.getTryBlockCount());
	assertEquals(builder.addr(0x0100136c), model.getTryBlockMapAddress());
	assertEquals(1, model.getIPToStateCount());
	assertEquals(builder.addr(0x01001380), model.getIPToStateMapAddress());
	assertEquals(builder.addr(0x01001388), model.getESTypeListAddress());
	assertEquals(1, model.getEHFlags());
}
 
Example #12
Source File: RttiModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidRtti0_32NoFollowFlow() throws Exception {

	ProgramBuilder builder = build32BitX86();
	ProgramDB program = builder.getProgram();
	assertEquals(builder.addr(0x01000000L), program.getImageBase());

	// ---- Base ----
	// rtti0:  01003200 - 01003213
	//
	setupRtti0_32(builder, 0x01005200L, "0x01003280", "0x00000000", ".?AVBase@@"); // 4 + 4 + 11 bytes + 1 align = 20

	//////////////
	// Now check that everything gets laid down correctly on the structures.
	//////////////
	checkRtti0ModelNoFollow(program, 0x01005200L, 0x01003280L, 0x0L, ".?AVBase@@");
}
 
Example #13
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 #14
Source File: RttiModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidVfTable_32NoFollowFlow() throws Exception {

	ProgramBuilder builder = build32BitX86();
	ProgramDB program = builder.getProgram();
	assertEquals(builder.addr(0x01000000L), program.getImageBase());

	// ---- Base ----
	// vfTbl:  010032f0 - 010032fb
	//
	setupVfTable_32(builder, 0x010032f0L, "0x01003340",
		new String[] { "0x01001200", "0x01001280" }); // 12 bytes

	// instructions
	setupCode32Bytes(builder, "0x01001200");
	setupCode32Bytes(builder, "0x01001280");

	//////////////
	// Now check that everything gets laid down correctly on the structures.
	//////////////
	checkVfTableNoFollowModel(program, 0x010032f0L, 0x01003340L, 0x010032f4L,
		new long[] { 0x01001200L, 0x01001280L });
}
 
Example #15
Source File: AbstractEHTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void setupTryBlock64(ProgramBuilder builder, long address, int tryLow, int tryHigh,
		int catchHigh, int handlerCount, String handlerAddress) throws Exception {
	ProgramDB program = builder.getProgram();
	boolean bigEndian = program.getCompilerSpec().getDataOrganization().isBigEndian();
	Address tryLowCompAddr = builder.addr(address);
	Address tryHighCompAddr = builder.addr(address + 4);
	Address catchHighCompAddr = builder.addr(address + 8);
	Address handlerCountCompAddr = builder.addr(address + 12);
	Address handlerCompAddr = builder.addr(address + 16);
	builder.setBytes(tryLowCompAddr.toString(), getIntAsByteString(tryLow, bigEndian));
	builder.setBytes(tryHighCompAddr.toString(), getIntAsByteString(tryHigh, bigEndian));
	builder.setBytes(catchHighCompAddr.toString(), getIntAsByteString(catchHigh, bigEndian));
	builder.setBytes(handlerCountCompAddr.toString(),
		getIntAsByteString(handlerCount, bigEndian));
	builder.setBytes(handlerCompAddr.toString(),
		getHexAddressAsIbo32ByteString(builder, handlerAddress, bigEndian));
}
 
Example #16
Source File: XrefViewerTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private ProgramDB buildProgram() throws Exception {
	builder = new ProgramBuilder("notepad", ProgramBuilder._TOY, this);

	builder.createMemory(".text", "0x1001000", 0x6600);
	builder.createEntryPoint("1001000", "entrypoint");
	builder.createEmptyFunction(null, "1001005", 40, null);
	builder.setBytes("1001005", "ff 74 24 04", true);
	builder.setBytes("10010a0", "ff 15 d4 10 00 01", true);

	builder.createMemoryReference("1001005", "1001007", RefType.DATA, SourceType.DEFAULT, 0);
	builder.createMemoryReference("1001009", "1001007", RefType.DATA, SourceType.DEFAULT, 0);
	builder.createMemoryReadReference("1001009", "1001005");

	// structure at 100100b
	builder.createMemoryReference("1001005", "100100f", RefType.DATA, SourceType.DEFAULT, 0);
	builder.createMemoryReference("1001002", "100100f", RefType.DATA, SourceType.DEFAULT, 0);

	return builder.getProgram();
}
 
Example #17
Source File: AbstractEHTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void setupTryBlock32(ProgramBuilder builder, long address, int tryLow, int tryHigh,
		int catchHigh, int handlerCount, String handlerAddress) throws Exception {
	ProgramDB program = builder.getProgram();
	boolean bigEndian = program.getCompilerSpec().getDataOrganization().isBigEndian();
	Address tryLowCompAddr = builder.addr(address);
	Address tryHighCompAddr = builder.addr(address + 4);
	Address catchHighCompAddr = builder.addr(address + 8);
	Address handlerCountCompAddr = builder.addr(address + 12);
	Address handlerCompAddr = builder.addr(address + 16);
	builder.setBytes(tryLowCompAddr.toString(), getIntAsByteString(tryLow, bigEndian));
	builder.setBytes(tryHighCompAddr.toString(), getIntAsByteString(tryHigh, bigEndian));
	builder.setBytes(catchHighCompAddr.toString(), getIntAsByteString(catchHigh, bigEndian));
	builder.setBytes(handlerCountCompAddr.toString(),
		getIntAsByteString(handlerCount, bigEndian));
	builder.setBytes(handlerCompAddr.toString(),
		getHexAddress32AsByteString(handlerAddress, bigEndian));
}
 
Example #18
Source File: EHModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidV1FuncInfo64NonVS() throws Exception {
	ProgramBuilder builder = build64BitX86NonVS();
	ProgramDB program = builder.getProgram();
	setupV1FuncInfo64(builder, 0x101003340L, EHFunctionInfoModel.EH_MAGIC_NUMBER_V1, 3,
		"0x101003368", 2, "0x101003380", 4, "0x1010033d0", 0x00000200);
	Address address = builder.addr(0x101003340L);
	EHFunctionInfoModel model =
		new EHFunctionInfoModel(program, address, defaultValidationOptions);
	try {
		model.validate();
	}
	catch (InvalidDataTypeException e) {
		assertEquals("FuncInfo data type model is only valid for Visual Studio windows PE.",
			e.getMessage());
	}
}
 
Example #19
Source File: AbstractRttiTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void setupRtti4_64(ProgramBuilder builder, long address, int signature, int offset,
		int cdOffset, String typeDescriptorAddress, String classDescriptorAddress)
		throws Exception {
	ProgramDB program = builder.getProgram();
	boolean bigEndian = program.getCompilerSpec().getDataOrganization().isBigEndian();
	Address signatureAddr = builder.addr(address);
	Address offsetAddr = builder.addr(address + 4);
	Address cdOffsetAddr = builder.addr(address + 8);
	Address typeDescriptorAddr = builder.addr(address + 12);
	Address classDescriptorAddr = builder.addr(address + 16);
	builder.setBytes(signatureAddr.toString(), getIntAsByteString(signature, bigEndian));
	builder.setBytes(offsetAddr.toString(), getIntAsByteString(offset, bigEndian));
	builder.setBytes(cdOffsetAddr.toString(), getIntAsByteString(cdOffset, bigEndian));
	String typeDescriptorBytes =
		getHexAddressAsIbo32ByteString(builder, typeDescriptorAddress, bigEndian);
	builder.setBytes(typeDescriptorAddr.toString(), typeDescriptorBytes);
	String classDescriptorBytes =
		getHexAddressAsIbo32ByteString(builder, classDescriptorAddress, bigEndian);
	builder.setBytes(classDescriptorAddr.toString(), classDescriptorBytes);
}
 
Example #20
Source File: AbstractCreateDataTypeModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void checkArrayData(ProgramDB program, long address, DataType elementDt,
		int numElements) {
	Listing listing = program.getListing();
	Data data = listing.getDataAt(addr(program, address));
	DataType dataType = data.getDataType();
	if (!(dataType instanceof Array)) {
		fail("Data type " + dataType.getName() + " isn't an array.");
	}
	Array array = (Array) dataType;
	assertEquals(numElements, array.getNumElements());
	String name = dataType.getName();
	assertEquals(elementDt.getName() + "[" + numElements + "]", name);
	int expectedDtLength = elementDt.getLength() * numElements;
	assertEquals(expectedDtLength, expectedDtLength);

	DataType baseDataType = array.getDataType();
	assertTrue(baseDataType.isEquivalent(elementDt));
}
 
Example #21
Source File: AbstractRttiTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void setupRtti3_64(ProgramBuilder builder, long address, int signature,
		int attributes, int numBaseClasses, String baseClassArrayAddress) throws Exception {
	ProgramDB program = builder.getProgram();
	boolean bigEndian = program.getCompilerSpec().getDataOrganization().isBigEndian();
	Address signatureAddr = builder.addr(address);
	Address attributesAddr = builder.addr(address + 4);
	Address numBaseClassesAddr = builder.addr(address + 8);
	Address baseClassArrayAddr = builder.addr(address + 12);
	builder.setBytes(signatureAddr.toString(), getIntAsByteString(signature, bigEndian));
	builder.setBytes(attributesAddr.toString(), getIntAsByteString(attributes, bigEndian));
	builder.setBytes(numBaseClassesAddr.toString(),
		getIntAsByteString(numBaseClasses, bigEndian));
	String baseClassArrayAddrBytes =
		getHexAddressAsIbo32ByteString(builder, baseClassArrayAddress, bigEndian);
	builder.setBytes(baseClassArrayAddr.toString(), baseClassArrayAddrBytes);
}
 
Example #22
Source File: UIUtil.java    From Ghidra-Switch-Loader with ISC License 6 votes vote down vote up
public static void sortProgramTree(Program program)
{
    ProgramDB db = (ProgramDB)program;
    ProgramModule programTreeModule = db.getTreeManager().getRootModule("Program Tree");
    
    if (programTreeModule == null)
        return;
    
    try 
    {
        sortModule(programTreeModule);
    } 
    catch (NotFoundException e) 
    {
    }
}
 
Example #23
Source File: AbstractCreateDataTypeModelTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void checkTypeName(ProgramDB program, long address, String expectedTypeName) {
	TypeDescriptorModel typeDescriptorModel =
		new TypeDescriptorModel(program, addr(program, address), defaultValidationOptions);
	try {
		String typeName = typeDescriptorModel.getTypeName();
		assertEquals(expectedTypeName, typeName);
	}
	catch (InvalidDataTypeException e) {
		fail("Couldn't get type name for TypeDescriptor @ " + address);
	}
}
 
Example #24
Source File: AbstractLocationReferencesTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected Program getProgram() throws Exception {
	builder = new ClassicSampleX86ProgramBuilder();
	ProgramDB p = builder.getProgram();
	configureProgram();
	return p;
}
 
Example #25
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti2Cmd_32NoFollowFlow() throws Exception {

	ProgramBuilder builder = build32BitX86();
	ProgramDB program = builder.getProgram();
	assertEquals(builder.addr(0x01000000L), program.getImageBase());

	setupRtti32CompleteFlow(builder);

	CreateRtti2BackgroundCmd rtti2Cmd = new CreateRtti2BackgroundCmd(addr(program, 0x01003390L),
		1, noFollowValidationOptions, noFollowApplyOptions);

	int txID = program.startTransaction("Creating RTTI");
	boolean commit = false;
	try {
		boolean applied = rtti2Cmd.applyTo(program);
		assertTrue(applied);
		commit = true;
	}
	finally {
		program.endTransaction(txID, commit);
	}

	//////////////
	// Now check that everything gets laid down correctly on the structures.
	//////////////

	// ---- check Base ----
	checkNoData(program, 0x01003340L);
	checkNoData(program, 0x01003368L);
	checkRtti2Data(program, 0x01003390L, 1);
	checkNoData(program, 0x010033a8L);
	checkNoData(program, 0x01003200L);
	checkNoData(program, 0x010032f0L);
}
 
Example #26
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 #27
Source File: AbstractRttiTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
protected void setupVfTable_64(ProgramBuilder builder, long address, String metaPtrString,
		String[] rtti1Addresses) throws Exception {
	ProgramDB program = builder.getProgram();
	boolean bigEndian = program.getCompilerSpec().getDataOrganization().isBigEndian();
	Address metaPointerAddr = builder.addr(address);
	long startOffset = address + 8;
	builder.setBytes(metaPointerAddr.toString(),
		getHexAddress64AsByteString(metaPtrString, bigEndian));
	for (int i = 0; i < rtti1Addresses.length; i++) {
		Address rtti1Addr = builder.addr(startOffset + (i * 8));
		builder.setBytes(rtti1Addr.toString(),
			getHexAddress64AsByteString(rtti1Addresses[i], bigEndian));
	}
}
 
Example #28
Source File: RefMergerStackTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void changeStackRefOffset(ProgramDB program, String fromAddr, int opIndex, int offset) {
	Address fromAddress = addr(program, fromAddr);
	ReferenceManager refMgr = program.getReferenceManager();
	Reference[] refs = refMgr.getReferencesFrom(addr(program, fromAddr), opIndex);
	assertEquals(1, refs.length);
	refMgr.addStackReference(fromAddress, opIndex, offset, refs[0].getReferenceType(),
		refs[0].getSource());
}
 
Example #29
Source File: DeleteFunctionTagCmd.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/******************************************************************************
 * PUBLIC METHODS
 ******************************************************************************/

@Override
public boolean applyTo(DomainObject obj, TaskMonitor monitor) {

	ProgramDB program = (ProgramDB) obj;
	FunctionManagerDB functionManager = (FunctionManagerDB) program.getFunctionManager();
	FunctionTag tag = functionManager.getFunctionTagManager().getFunctionTag(tagName);

	if (tag != null) {
		tag.delete();
	}

	return true;
}
 
Example #30
Source File: FileBytesTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	tempDir = createTempDirectory("FileBytesTest");
	FileBytesAdapter.setMaxBufferSize(MAX_BUFFER_SIZE_FOR_TESTING);
	Language language = getLanguage("Toy:BE:64:default");
	CompilerSpec compilerSpec = language.getDefaultCompilerSpec();
	program = new ProgramDB("Test", language, compilerSpec, this);

	mem = program.getMemory();
	transactionID = program.startTransaction("Test");
}