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

The following examples show how to use ghidra.program.database.ProgramDB#startTransaction() . 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: AbstractCreateDataTypeModelTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void setExecFormatAndCompiler(ProgramBuilder builder, String execFormat,
		String compiler) {
	ProgramDB program = builder.getProgram();
	int txID = program.startTransaction("Setting format and compiler.");
	boolean commit = false;
	try {
		if (execFormat != null) {
			program.setExecutableFormat(execFormat);
		}
		if (compiler != null) {
			program.setCompiler(compiler);
		}
		commit = true;
	}
	finally {
		program.endTransaction(txID, commit);
	}
}
 
Example 2
Source File: SymbolUtilities2Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	TestEnv env = new TestEnv();
	LanguageService ls = DefaultLanguageService.getLanguageService();
	Language i8051 = ls.getDefaultLanguage(TestProcessorConstants.PROCESSOR_8051);
	program = new ProgramDB("Test", i8051, i8051.getDefaultCompilerSpec(), this);
	env.dispose();
	space = program.getAddressFactory().getDefaultAddressSpace();
	Memory memory = program.getMemory();
	transactionID = program.startTransaction("Test");
	memory.createInitializedBlock("test", addr(0), 5000, (byte) 0,
		TaskMonitorAdapter.DUMMY_MONITOR, false);
	symbolTable = program.getSymbolTable();
	refMgr = program.getReferenceManager();
	listing = program.getListing();
}
 
Example 3
Source File: MemBlockDBTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	Language language = getLanguage("Toy:BE:64:default");
	CompilerSpec compilerSpec = language.getDefaultCompilerSpec();
	program = new ProgramDB("Test", language, compilerSpec, this);
	ptxID = program.startTransaction("test");

	handle = new DBHandle();

	txID = handle.startTransaction();

	addressFactory = language.getAddressFactory();
	AddressMapDB addrMap = (AddressMapDB) program.getAddressMap();
	Lock lock = new Lock("Test");
	int openMode = DBConstants.CREATE;
	mem = new MemoryMapDB(handle, addrMap, openMode, true, lock);

	MemoryMapDBAdapter adapter =
		new MemoryMapDBAdapterV3(handle, mem, MAX_SUB_BLOCK_SIZE, true);
	FileBytesAdapter fileBytesAdapter = new FileBytesAdapterV0(handle, true);

	mem.init(adapter, fileBytesAdapter);
	mem.setProgram(program);

}
 
Example 4
Source File: AbstractCreateDataTypeModelTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void setImageBase(ProgramBuilder builder, long imageBase)
		throws AddressOverflowException, LockException, IllegalStateException {
	ProgramDB program = builder.getProgram();
	int txID = program.startTransaction("Setting image base.");
	boolean commit = false;
	try {
		program.setImageBase(builder.addr(imageBase), true);
		commit = true;
	}
	finally {
		program.endTransaction(txID, commit);
	}
}
 
Example 5
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti2Cmd_64NoFollowFlow() throws Exception {

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

	setupRtti64CompleteFlow(builder);

	CreateRtti2BackgroundCmd rtti2Cmd = new CreateRtti2BackgroundCmd(
		addr(program, 0x101003390L), 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, 0x101003340L);
	checkNoData(program, 0x101003368L);
	checkRtti2Data(program, 0x101003390L, 1);
	checkNoData(program, 0x1010033a8L);
	checkNoData(program, 0x101003200L);
	checkNoData(program, 0x1010032f0L);
}
 
Example 6
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti3Cmd_64NoFollowFlow() throws Exception {

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

	setupRtti64CompleteFlow(builder);

	CreateRtti3BackgroundCmd rtti3Cmd = new CreateRtti3BackgroundCmd(
		addr(program, 0x101003368L), noFollowValidationOptions, noFollowApplyOptions);

	int txID = program.startTransaction("Creating RTTI");
	boolean commit = false;
	try {
		boolean applied = rtti3Cmd.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, 0x101003340L);
	checkRtti3Data(program, 0x101003368L);
	checkNoData(program, 0x101003390L);
	checkNoData(program, 0x1010033a8L);
	checkNoData(program, 0x101003200L);
	checkNoData(program, 0x1010032f0L);
}
 
Example 7
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti0Cmd_64NoFollowFlow() throws Exception {

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

	setupRtti64CompleteFlow(builder);

	CreateTypeDescriptorBackgroundCmd rtti0Cmd = new CreateTypeDescriptorBackgroundCmd(
		addr(program, 0x101005200L), noFollowValidationOptions, noFollowApplyOptions);

	int txID = program.startTransaction("Creating RTTI");
	boolean commit = false;
	try {
		boolean applied = rtti0Cmd.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, 0x101003340L);
	checkNoData(program, 0x101003368L);
	checkNoData(program, 0x101003390L);
	checkNoData(program, 0x1010033a8L);
	checkTypeDescriptorData(program, 0x101005200L, 16, 16, ".?AVBase@@");
	checkNoData(program, 0x1010032f0L);
}
 
Example 8
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti1Cmd_32NoFollowFlow() throws Exception {

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

	setupRtti32CompleteFlow(builder);

	CreateRtti1BackgroundCmd rtti1Cmd = new CreateRtti1BackgroundCmd(addr(program, 0x010033a8L),
		noFollowValidationOptions, noFollowApplyOptions);

	int txID = program.startTransaction("Creating RTTI");
	boolean commit = false;
	try {
		boolean applied = rtti1Cmd.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);
	checkNoData(program, 0x01003390L);
	checkRtti1Data(program, 0x010033a8L);
	checkNoData(program, 0x01003200L);
	checkNoData(program, 0x010032f0L);
}
 
Example 9
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 10
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti3Cmd_32NoFollowFlow() throws Exception {

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

	setupRtti32CompleteFlow(builder);

	CreateRtti3BackgroundCmd rtti3Cmd = new CreateRtti3BackgroundCmd(addr(program, 0x01003368L),
		noFollowValidationOptions, noFollowApplyOptions);

	int txID = program.startTransaction("Creating RTTI");
	boolean commit = false;
	try {
		boolean applied = rtti3Cmd.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);
	checkRtti3Data(program, 0x01003368L);
	checkNoData(program, 0x01003390L);
	checkNoData(program, 0x010033a8L);
	checkNoData(program, 0x01003200L);
	checkNoData(program, 0x010032f0L);
}
 
Example 11
Source File: OptionsDBTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	builder = new ProgramBuilder();
	ProgramDB program = builder.getProgram();
	txID = program.startTransaction("Test");
	options = new OptionsDB(program);
}
 
Example 12
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti3Cmd_64FollowFlow() throws Exception {

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

	setupRtti64CompleteFlow(builder);

	CreateRtti3BackgroundCmd rtti3Cmd = new CreateRtti3BackgroundCmd(
		addr(program, 0x101003368L), defaultValidationOptions, defaultApplyOptions);

	int txID = program.startTransaction("Creating RTTI");
	boolean commit = false;
	try {
		boolean applied = rtti3Cmd.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, 0x101003340L);
	checkRtti3Data(program, 0x101003368L);
	checkRtti2Data(program, 0x101003390L, 1);
	checkRtti1Data(program, 0x1010033a8L);
	checkTypeDescriptorData(program, 0x101005200L, 16, 16, ".?AVBase@@");
	checkNoData(program, 0x1010032f0L);
}
 
Example 13
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 14
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti3Cmd_32FollowFlow() throws Exception {

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

	setupRtti32CompleteFlow(builder);

	CreateRtti3BackgroundCmd rtti3Cmd = new CreateRtti3BackgroundCmd(addr(program, 0x01003368L),
		defaultValidationOptions, defaultApplyOptions);

	int txID = program.startTransaction("Creating RTTI");
	boolean commit = false;
	try {
		boolean applied = rtti3Cmd.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);
	checkRtti3Data(program, 0x01003368L);
	checkRtti2Data(program, 0x01003390L, 1);
	checkRtti1Data(program, 0x010033a8L);
	checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");
	checkNoData(program, 0x010032f0L);
}
 
Example 15
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");
}
 
Example 16
Source File: GoToPluginTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private Program buildProgram_X86(String name) throws Exception {

		ClassicSampleX86ProgramBuilder builder =
			new ClassicSampleX86ProgramBuilder(name, false, this);

		//
		// Labels
		//
		builder.createLabel("0x010012f0", "comdlg32.dll_PageSetupDlgW");
		builder.createLabel("0x0100def8", "rsrc_String_3_3fe");
		builder.createLabel("0x0100e2f8", "rsrc_String_1_24a");
		builder.createLabel("0x0100eb90", "rsrc_String_4_5c8");

		//
		// String data
		//
		// "fSavePageSettings"
		builder.setBytes("0x10015a4", "66 00 53 00 61 00 76 00 65 00 50 00 61 00 67 00 65 00 " +
			"53 00 65 00 74 00 74 00 69 00 6e 00 67 00 73 00");
		// "GDI32.dll"
		builder.setBytes("0x010070bc", "47 44 49 33 32 2e 64 6c 6c 00");

		// create an arbitrary reference in order to create a default label
		builder.applyDataType("0x010070bc", new TerminatedStringDataType(), 1);
		builder.createMemoryReadReference("0x01006420", "0x010070bc");
		builder.setBytes("0x1002000", "01 02 03 04 05 06 07 08");
		builder.applyDataType("0x1002000", new PointerDataType());
		builder.createExternalReference("0x1002000", "extlib", "rand", 0);
		//
		// Local variable for testing go to
		//

		ProgramDB p = builder.getProgram();
		int txID = p.startTransaction("All Local Variable");
		try {
			FunctionManager fm = p.getFunctionManager();
			Function f = fm.getFunctionAt(builder.addr("0x01006420"));
			ByteDataType dt = new ByteDataType();
			Variable var = new LocalVariableImpl("bob.local", 0, dt, builder.addr("0x01006421"), p);
			f.addLocalVariable(var, SourceType.USER_DEFINED);

		}
		finally {
			p.endTransaction(txID, true);
		}

		return p;
	}
 
Example 17
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testValidRtti4Cmd_64CompleteFlow() throws Exception {

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

	setupRtti64CompleteFlow(builder);

	List<MemoryBlock> rtti4Blocks = ProgramMemoryUtil.getMemoryBlocksStartingWithName(program,
		program.getMemory(), ".rdata", TaskMonitor.DUMMY);

	CreateRtti4BackgroundCmd rtti4Cmd =
		new CreateRtti4BackgroundCmd(addr(program, 0x101003340L), rtti4Blocks,
			defaultValidationOptions, defaultApplyOptions);

	CreateRtti4BackgroundCmd rtti4Cmd2 =
		new CreateRtti4BackgroundCmd(addr(program, 0x101003354L), rtti4Blocks,
			defaultValidationOptions, defaultApplyOptions);

	CreateRtti4BackgroundCmd rtti4Cmd3 =
		new CreateRtti4BackgroundCmd(addr(program, 0x10100324cL), rtti4Blocks,
			defaultValidationOptions, defaultApplyOptions);

	int txID = program.startTransaction("Creating RTTI");
	boolean commit = false;
	try {
		boolean applied = rtti4Cmd.applyTo(program);
		assertTrue(applied);

		boolean applied2 = rtti4Cmd2.applyTo(program);
		assertTrue(applied2);

		boolean applied3 = rtti4Cmd3.applyTo(program);
		assertTrue(applied3);
		commit = true;
	}
	finally {
		program.endTransaction(txID, commit);
	}

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

	// ---- check Base ----
	checkRtti4Data(program, 0x101003340L);
	checkRtti3Data(program, 0x101003368L);
	checkRtti2Data(program, 0x101003390L, 1);
	checkRtti1Data(program, 0x1010033a8L);
	checkTypeDescriptorData(program, 0x101005200L, 16, 16, ".?AVBase@@");
	checkVfTableData(program, 0x1010032f0L, 0x101003340L, 0x1010032f8L,
		new long[] { 0x101001200L, 0x101001280L });

	// ---- check Shape ----
	checkRtti4Data(program, 0x101003354L);
	checkRtti3Data(program, 0x101003378L);
	checkRtti2Data(program, 0x101003394L, 2);
	checkRtti1Data(program, 0x1010033c4L);
	checkTypeDescriptorData(program, 0x101005220L, 16, 16, ".?AVShape@@");
	checkVfTableData(program, 0x1010031b0L, 0x101003354L, 0x1010031b8L,
		new long[] { 0x101001214L, 0x101001230L });

	// ---- check Circle ----
	checkRtti4Data(program, 0x10100324cL);
	checkRtti3Data(program, 0x101003268L);
	checkRtti2Data(program, 0x101003290L, 3);
	checkRtti1Data(program, 0x1010032a8L);
	checkTypeDescriptorData(program, 0x1010053e0L, 16, 16, ".?AVCircle@@");
	checkVfTableData(program, 0x1010031d0L, 0x10100324cL, 0x1010031d8L,
		new long[] { 0x101001260L, 0x1010012a0L, 0x101001120L });

}
 
Example 18
Source File: AddressIndexPrimaryKeyIteratorTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Before
	public void setUp() throws Exception {
		TestEnv env = new TestEnv();
		LanguageService ls = getLanguageService();
		Language language = ls.getDefaultLanguage(TestProcessorConstants.PROCESSOR_SPARC);
		program = new ProgramDB("TestProgram", language, language.getDefaultCompilerSpec(), this);
		env.dispose();

//		program = new ProgramDB("TestProgram", new SparcV8Language(),this); 
		space = program.getAddressFactory().getDefaultAddressSpace();
		memMap = program.getMemory();
		addrMap = (AddressMap) getInstanceField("addrMap", memMap);
		transactionID = program.startTransaction("Test");

		// Create fragmented memory
		memMap.createInitializedBlock("Block1", addr(0x8000), 0x10, (byte) 0, null, false);// startKey: 0x0
		memMap.createUninitializedBlock("Block2", addr(0x5000), 0x10, false);// startKey: 0x10000
		memMap.createBitMappedBlock("Block3", addr(0x9000), addr(0x5000), 0x10, false);// startKey: 0x20000
		memMap.createUninitializedBlock("Block4", addr(0x3000), 0x10, false);// startKey: 0x30000

		// Create table with indexed address column
		Schema schema =
			new Schema(0, "id", new Class[] { LongField.class }, new String[] { "addr" });
		DBHandle handle = program.getDBHandle();
		myTable = handle.createTable("MyTable", schema, new int[] { 0 });

		assertTrue(memMap.contains(addr(0x3000)));
		assertTrue(memMap.contains(addr(0x5000)));
		assertTrue(memMap.contains(addr(0x8000)));
		assertTrue(memMap.contains(addr(0x9000)));
		assertTrue(!memMap.contains(addr(0x100)));

		int cnt = 0;
		AddressRangeIterator ranges = memMap.getAddressRanges();
		while (ranges.hasNext()) {
			AddressRange r = ranges.next();
			Address a = r.getMinAddress();
			Address maxAddr = r.getMaxAddress();
			while (a.compareTo(maxAddr) <= 0) {
				long addrKey = addrMap.getKey(a, true);
				Record rec = schema.createRecord(myTable.getKey());
				rec.setLongValue(0, addrKey);
				myTable.putRecord(rec);
				a = a.add(1);
				++cnt;
			}
		}
		assertEquals(0x40, cnt);
		assertEquals(0x40, myTable.getRecordCount());
	}
 
Example 19
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testValidRtti4Cmd_64NoFollowFlow() throws Exception {

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

	setupRtti64CompleteFlow(builder);

	List<MemoryBlock> rtti4Blocks = ProgramMemoryUtil.getMemoryBlocksStartingWithName(program,
		program.getMemory(), ".rdata", TaskMonitor.DUMMY);

	CreateRtti4BackgroundCmd rtti4Cmd =
		new CreateRtti4BackgroundCmd(addr(program, 0x101003340L), rtti4Blocks,
			noFollowValidationOptions, noFollowApplyOptions);

	CreateRtti4BackgroundCmd rtti4Cmd2 =
		new CreateRtti4BackgroundCmd(addr(program, 0x101003354L), rtti4Blocks,
			noFollowValidationOptions, noFollowApplyOptions);

	CreateRtti4BackgroundCmd rtti4Cmd3 =
		new CreateRtti4BackgroundCmd(addr(program, 0x10100324cL), rtti4Blocks,
			noFollowValidationOptions, noFollowApplyOptions);

	int txID = program.startTransaction("Creating RTTI");
	boolean commit = false;
	try {
		boolean applied = rtti4Cmd.applyTo(program);
		assertTrue(applied);

		boolean applied2 = rtti4Cmd2.applyTo(program);
		assertTrue(applied2);

		boolean applied3 = rtti4Cmd3.applyTo(program);
		assertTrue(applied3);
		commit = true;
	}
	finally {
		program.endTransaction(txID, commit);
	}

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

	// ---- check Base ----
	checkRtti4Data(program, 0x101003340L);
	checkNoData(program, 0x101003368L);
	checkNoData(program, 0x101003390L);
	checkNoData(program, 0x1010033a8L);
	checkNoData(program, 0x101003200L);
	checkNoData(program, 0x1010032f0L);

	// ---- check Shape ----
	checkRtti4Data(program, 0x101003354L);
	checkNoData(program, 0x101003378L);
	checkNoData(program, 0x101003394L);
	checkNoData(program, 0x1010033c4L);
	checkNoData(program, 0x101003220L);
	checkNoData(program, 0x1010031b0L);

	// ---- check Circle ----
	checkRtti4Data(program, 0x10100324cL);
	checkNoData(program, 0x101003268L);
	checkNoData(program, 0x101003290L);
	checkNoData(program, 0x1010032a8L);
	checkNoData(program, 0x1010033e0L);
	checkNoData(program, 0x1010031d0L);

}
 
Example 20
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testValidRtti4Cmd_32CompleteFlow() throws Exception {

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

	setupRtti32CompleteFlow(builder);

	List<MemoryBlock> rtti4Blocks = ProgramMemoryUtil.getMemoryBlocksStartingWithName(program,
		program.getMemory(), ".rdata", TaskMonitor.DUMMY);

	CreateRtti4BackgroundCmd rtti4Cmd = new CreateRtti4BackgroundCmd(addr(program, 0x01003340L),
		rtti4Blocks, defaultValidationOptions, defaultApplyOptions);

	CreateRtti4BackgroundCmd rtti4Cmd2 = new CreateRtti4BackgroundCmd(
		addr(program, 0x01003354L), rtti4Blocks, defaultValidationOptions, defaultApplyOptions);

	CreateRtti4BackgroundCmd rtti4Cmd3 = new CreateRtti4BackgroundCmd(
		addr(program, 0x01003240L), rtti4Blocks, defaultValidationOptions, defaultApplyOptions);

	int txID = program.startTransaction("Creating RTTI");
	boolean commit = false;
	try {
		boolean applied = rtti4Cmd.applyTo(program);
		assertTrue(applied);

		boolean applied2 = rtti4Cmd2.applyTo(program);
		assertTrue(applied2);

		boolean applied3 = rtti4Cmd3.applyTo(program);
		assertTrue(applied3);
		commit = true;
	}
	finally {
		program.endTransaction(txID, commit);
	}

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

	// ---- check Base ----
	checkRtti4Data(program, 0x01003340L);
	checkRtti3Data(program, 0x01003368L);
	checkRtti2Data(program, 0x01003390L, 1);
	checkRtti1Data(program, 0x010033a8L);
	checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");
	checkVfTableData(program, 0x010032f0L, 0x01003340L, 0x010032f4L,
		new long[] { 0x01001200L, 0x01001280L });

	// ---- check Shape ----
	checkRtti4Data(program, 0x01003354L);
	checkRtti3Data(program, 0x01003378L);
	checkRtti2Data(program, 0x01003394L, 2);
	checkRtti1Data(program, 0x010033c4L);
	checkTypeDescriptorData(program, 0x01005214L, 8, 12, ".?AVShape@@");
	checkVfTableData(program, 0x01003230L, 0x01003354L, 0x01003234L,
		new long[] { 0x01001214L, 0x01001230L });

	// ---- check Circle ----
	checkRtti4Data(program, 0x01003240L);
	checkRtti3Data(program, 0x01003268L);
	checkRtti2Data(program, 0x01003290L, 3);
	checkRtti1Data(program, 0x010032a8L);
	checkTypeDescriptorData(program, 0x010053e0L, 8, 16, ".?AVCircle@@");
	checkVfTableData(program, 0x010031f0, 0x01003240L, 0x010031f4L,
		new long[] { 0x01001260L, 0x010012a0L });
}