Java Code Examples for ghidra.program.database.ProgramDB#getReferenceManager()
The following examples show how to use
ghidra.program.database.ProgramDB#getReferenceManager() .
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: SymbolUtilities1Test.java From ghidra with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { TestEnv env = new TestEnv(); LanguageService ls = DefaultLanguageService.getLanguageService(); Language x86 = ls.getDefaultLanguage(TestProcessorConstants.PROCESSOR_X86); CompilerSpec windows = x86.getCompilerSpecByID(new CompilerSpecID("windows")); program = new ProgramDB("Test", x86, windows, 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 2
Source File: SymbolUtilities2Test.java From ghidra with Apache License 2.0 | 6 votes |
@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: CallTreePluginTest.java From ghidra with Apache License 2.0 | 5 votes |
private boolean createReference(long from, long to) { ProgramDB p = builder.getProgram(); ReferenceManager rm = p.getReferenceManager(); Reference existing = rm.getReference(addr(from), addr(to), 0); if (existing != null) { return false; } builder.createMemoryCallReference("0x" + Long.toHexString(from), "0x" + Long.toHexString(to)); return true; }
Example 4
Source File: RefMergerStackTest.java From ghidra with Apache License 2.0 | 5 votes |
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 5
Source File: RefMergerStackTest.java From ghidra with Apache License 2.0 | 5 votes |
private void changeStackRefOffset(ProgramDB program, String fromAddr, int opIndex, int offset, SourceType source) { 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(), source); }
Example 6
Source File: AbstractCodeBrowserNavigationTest.java From ghidra with Apache License 2.0 | 4 votes |
private Program buildProgram() throws Exception { builder = new ToyProgramBuilder("Test", true, this); builder.createMemory(".text", "0x1001000", 0x6600); builder.createMemory(".data", "0x1008000", 0x600); builder.createMemory(".rsrc", "0x100a000", 0x5400); builder.createMemory(".bound_import.table", "0xf0000428", 0xa8); builder.createMemory(".debug_data", "0xf0001300", 0x1c); builder.setBytes("0x1002000", "01 00 30 00"); builder.applyDataType("0x1002000", DWordDataType.dataType, 1); builder.setBytes("0x1002010", "11 00 00 00"); builder.applyDataType("0x1002010", DWordDataType.dataType, 1); builder.createExternalFunction("0x1001888", "ADVAPI32.dll", "IsTextUnicode"); builder.applyDataType("0x1001000", PointerDataType.dataType, 1); builder.createExternalReference("0x1001000", "ADVAPI32.dll", "IsTextUnicode", 0); // linkage location builder.createExternalReference("0x1001020", "ADVAPI32.dll", "IsTextUnicode", 0); // without pointer builder.addBytesBranch("1004000", "1004010"); builder.addBytesBranch("1004030", "1004010"); builder.addBytesBranch("1004040", "1004010"); builder.disassemble("1004000", 1); builder.disassemble("1004030", 1); builder.disassemble("1004040", 1); builder.addBytesFallthrough("0x1006000"); builder.addBytesMoveImmediate("1006002", (byte) 0x12); builder.addBytesLoad("1006004", 0, 1); builder.addBytesReturn("1006006"); builder.disassemble("1006000", 8); Function func = builder.createFunction("0x1006000"); builder.createRegisterReference("0x1006002", RefType.WRITE, "r0", SourceType.USER_DEFINED, 0); // note: as of this writing, analysis was placing a reference from this address. The test // is also placing a reference there. Drop the analysis ref and keep the test ref. ProgramDB p = builder.getProgram(); ReferenceManager rm = p.getReferenceManager(); Reference[] refs = rm.getReferencesFrom(builder.addr("0x1006004")); for (Reference reference : refs) { builder.deleteReference(reference); } builder.createMemoryReference("0x1006004", "0x1005012", RefType.WRITE, SourceType.USER_DEFINED, 1); builder.addFunctionVariable(func, new LocalVariableImpl("foo", 2, ByteDataType.dataType, builder.getRegister("r0"), builder.getProgram())); builder.createFunction("0x1006100"); builder.createFunction("0x1006200"); builder.addBytesMoveImmediate("0x1004050", (byte) 0xb5); builder.createMemoryReference("0x1004050", "0x1008010", RefType.DATA, SourceType.USER_DEFINED, 0); builder.createMemoryReference("0x1004050", "0x1008020", RefType.DATA, SourceType.USER_DEFINED, 0); builder.createMemoryReference("0x1004050", "0x1008030", RefType.DATA, SourceType.USER_DEFINED, 0); builder.createMemoryReference("0x1004050", "0x1008040", RefType.DATA, SourceType.USER_DEFINED, 0); builder.createMemoryReference("0x1004050", "0x1008050", RefType.DATA, SourceType.USER_DEFINED, 0); builder.createMemoryReference("0x1004050", "0x1008060", RefType.DATA, SourceType.USER_DEFINED, 0); builder.createMemoryReference("0x1004050", "0x1008070", RefType.DATA, SourceType.USER_DEFINED, 0); builder.createMemoryReference("0x1004050", "0x1008080", RefType.DATA, SourceType.USER_DEFINED, 0); builder.createMemoryReference("0x1004050", "0x1008090", RefType.DATA, SourceType.USER_DEFINED, 0); return builder.getProgram(); }