Java Code Examples for ghidra.program.database.ProgramDB#getDBHandle()
The following examples show how to use
ghidra.program.database.ProgramDB#getDBHandle() .
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: AddressSetPropertyMapDB.java From ghidra with Apache License 2.0 | 6 votes |
public static AddressSetPropertyMapDB getPropertyMap(ProgramDB program, String mapName, ErrorHandler errHandler, AddressMap addrMap, Lock lock) { lock.acquire(); try { String tableName = AddressSetPropertyMapDB.TABLE_PREFIX + mapName; DBHandle dbh = program.getDBHandle(); if (dbh.getTable(tableName) != null) { return new AddressSetPropertyMapDB(program, mapName, program, addrMap, lock); } } finally { lock.release(); } return null; }
Example 2
Source File: AddressSetPropertyMapDB.java From ghidra with Apache License 2.0 | 6 votes |
public static AddressSetPropertyMapDB createPropertyMap(ProgramDB program, String mapName, ErrorHandler errHandler, AddressMap addrMap, Lock lock) throws DuplicateNameException { lock.acquire(); try { DBHandle dbh = program.getDBHandle(); String tableName = AddressSetPropertyMapDB.TABLE_PREFIX + mapName; if (dbh.getTable(tableName) != null) { throw new DuplicateNameException( "Address Set Property Map named " + mapName + " already exists."); } return new AddressSetPropertyMapDB(program, mapName, program, addrMap, lock); } finally { lock.release(); } }
Example 3
Source File: AddressSetPropertyMapDB.java From ghidra with Apache License 2.0 | 5 votes |
private AddressSetPropertyMapDB(ProgramDB program, String mapName, ErrorHandler errHandler, AddressMap addrMap, Lock lock) { this.program = program; this.mapName = mapName; this.lock = lock; propertyMap = new AddressRangeMapDB(program.getDBHandle(), program.getAddressMap(), program.getLock(), MY_PREFIX + mapName, errHandler, BooleanField.class, true); }
Example 4
Source File: TestProgramManager.java From ghidra with Apache License 2.0 | 5 votes |
/** * Save a program to the cached program store. A SaveAs will be performed on the * program to its cached storage location. * @param progName program name * @param program program object * @param replace if true any existing cached database with the same name will be replaced * @param monitor task monitor * @throws DuplicateNameException if already cached */ public void saveToCache(String progName, ProgramDB program, boolean replace, TaskMonitor monitor) throws IOException, DuplicateNameException, CancelledException { if (progName.endsWith(".gzf")) { progName = progName.substring(0, progName.length() - 4); } if (testPrograms.containsKey(progName)) { if (!replace) { throw new DuplicateNameException(progName + " already cached"); } testPrograms.remove(progName); } File dbDir = new File(getDbTestDir(), NamingUtilities.mangle(progName) + ".db"); FileUtilities.deleteDir(dbDir); dbDir.mkdirs(); DBHandle dbh = program.getDBHandle(); BufferFile bfile = PrivateDatabase.createDatabase(dbDir, null, dbh.getBufferSize()); program.getDBHandle().saveAs(bfile, true, monitor); testPrograms.put(progName, new PrivateDatabase(dbDir)); Msg.info(this, "Stored unpacked program in TestEnv cache: " + progName); }
Example 5
Source File: AddressIndexPrimaryKeyIteratorTest.java From ghidra with Apache License 2.0 | 4 votes |
@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()); }