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

The following examples show how to use ghidra.program.database.ProgramDB#endTransaction() . 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: 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 3
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 4
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 5
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 6
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti0Cmd_32NoFollowFlow() throws Exception {

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

	setupRtti32CompleteFlow(builder);

	CreateTypeDescriptorBackgroundCmd rtti0Cmd = new CreateTypeDescriptorBackgroundCmd(
		addr(program, 0x01005200L), 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, 0x01003340L);
	checkNoData(program, 0x01003368L);
	checkNoData(program, 0x01003390L);
	checkNoData(program, 0x010033a8L);
	checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");
	checkNoData(program, 0x010032f0L);
}
 
Example 7
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 8
Source File: VTMatchApplyTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void createInstruction(Address address, ProgramDB program, int length) {
	int txID = program.startTransaction("Creating instruction");
	boolean commit = false;
	try {
		// Create instruction here. 
		DisassembleCommand cmd = new DisassembleCommand(address,
			new AddressSet(address, address.add(length)), false);
		cmd.applyTo(program);

		commit = true;
	}
	finally {
		program.endTransaction(txID, commit);
	}
}
 
Example 9
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 10
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti0Cmd_64FollowFlow() throws Exception {

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

	setupRtti64CompleteFlow(builder);

	CreateTypeDescriptorBackgroundCmd rtti0Cmd = new CreateTypeDescriptorBackgroundCmd(
		addr(program, 0x101005200L), defaultValidationOptions, defaultApplyOptions);

	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 11
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti1Cmd_64FollowFlow() throws Exception {

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

	setupRtti64CompleteFlow(builder);

	CreateRtti1BackgroundCmd rtti1Cmd = new CreateRtti1BackgroundCmd(
		addr(program, 0x1010033a8L), defaultValidationOptions, defaultApplyOptions);

	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, 0x101003340L);
	checkNoData(program, 0x101003368L);
	checkNoData(program, 0x101003390L);
	checkRtti1Data(program, 0x1010033a8L);
	checkTypeDescriptorData(program, 0x101005200L, 16, 16, ".?AVBase@@");
	checkNoData(program, 0x1010032f0L);
}
 
Example 12
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 13
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 14
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti0Cmd_32FollowFlow() throws Exception {

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

	setupRtti32CompleteFlow(builder);

	CreateTypeDescriptorBackgroundCmd rtti0Cmd = new CreateTypeDescriptorBackgroundCmd(
		addr(program, 0x01005200L), defaultValidationOptions, defaultApplyOptions);

	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, 0x01003340L);
	checkNoData(program, 0x01003368L);
	checkNoData(program, 0x01003390L);
	checkNoData(program, 0x010033a8L);
	checkTypeDescriptorData(program, 0x01005200L, 8, 16, ".?AVBase@@");
	checkNoData(program, 0x010032f0L);
}
 
Example 15
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti1Cmd_32FollowFlow() throws Exception {

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

	setupRtti32CompleteFlow(builder);

	CreateRtti1BackgroundCmd rtti1Cmd = new CreateRtti1BackgroundCmd(addr(program, 0x010033a8L),
		defaultValidationOptions, defaultApplyOptions);

	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);
	checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");
	checkNoData(program, 0x010032f0L);
}
 
Example 16
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidRtti2Cmd_32FollowFlow() 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, defaultValidationOptions, defaultApplyOptions);

	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);
	checkRtti1Data(program, 0x010033a8L);
	checkTypeDescriptorData(program, 0x01005200L, 8, 12, ".?AVBase@@");
	checkNoData(program, 0x010032f0L);
}
 
Example 17
Source File: RttiCreateCmdTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testValidRtti4Cmd_32NoFollowFlow() 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, noFollowValidationOptions, noFollowApplyOptions);

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

	CreateRtti4BackgroundCmd rtti4Cmd3 =
		new CreateRtti4BackgroundCmd(addr(program, 0x01003240L), 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, 0x01003340L);
	checkNoData(program, 0x01003368L);
	checkNoData(program, 0x01003390L);
	checkNoData(program, 0x010033a8L);
	checkNoData(program, 0x01003200L);
	checkNoData(program, 0x010032f0L);

	// ---- check Shape ----
	checkRtti4Data(program, 0x01003354L);
	checkNoData(program, 0x01003378L);
	checkNoData(program, 0x01003394L);
	checkNoData(program, 0x010033c4L);
	checkNoData(program, 0x01003214L);
	checkNoData(program, 0x01003230L);

	// ---- check Circle ----
	checkRtti4Data(program, 0x01003240L);
	checkNoData(program, 0x01003268L);
	checkNoData(program, 0x01003290L);
	checkNoData(program, 0x010032a8L);
	checkNoData(program, 0x010033e0L);
	checkNoData(program, 0x010031f0);
}
 
Example 18
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 19
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 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 });
}