Java Code Examples for ghidra.program.model.address.AddressSetView#getMaxAddress()
The following examples show how to use
ghidra.program.model.address.AddressSetView#getMaxAddress() .
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: CommentsDBAdapterV1.java From ghidra with Apache License 2.0 | 5 votes |
@Override AddressKeyIterator getKeys(AddressSetView set, boolean forward) throws IOException { if (forward) { return new AddressKeyIterator(commentTable, addrMap, set, set.getMinAddress(), true); } return new AddressKeyIterator(commentTable, addrMap, set, set.getMaxAddress(), false); }
Example 2
Source File: CommentsDBAdapterV0.java From ghidra with Apache License 2.0 | 5 votes |
/** * @see ghidra.program.database.code.CommentsDBAdapter#getKeys(ghidra.program.model.address.AddressSetView, boolean) */ @Override public AddressKeyIterator getKeys(AddressSetView set, boolean forward) throws IOException { if (forward) { return new AddressKeyIterator(commentTable, addrMap, set, set.getMinAddress(), true); } return new AddressKeyIterator(commentTable, addrMap, set, set.getMaxAddress(), false); }
Example 3
Source File: GroupHistoryInfo.java From ghidra with Apache License 2.0 | 5 votes |
private static Map<AddressHasher, FGVertex> hashVerticesByStartAndEndAddress( FunctionGraph functionGraph) { Map<AddressHasher, FGVertex> map = new HashMap<>(); Graph<FGVertex, FGEdge> graph = functionGraph; Collection<FGVertex> vertices = graph.getVertices(); for (FGVertex vertex : vertices) { AddressSetView addresses = vertex.getAddresses(); Address minAddress = addresses.getMinAddress(); Address maxAddress = addresses.getMaxAddress(); map.put(new AddressHasher(minAddress, maxAddress), vertex); } return map; }
Example 4
Source File: GroupVertexSerializer.java From ghidra with Apache License 2.0 | 5 votes |
private static Map<AddressHasher, FGVertex> hashVerticesByStartAndEndAddress( FunctionGraph functionGraph) { Map<AddressHasher, FGVertex> map = new HashMap<>(); Set<FGVertex> vertices = functionGraph.getUngroupedVertices(); for (FGVertex vertex : vertices) { AddressSetView addresses = vertex.getAddresses(); Address minAddress = addresses.getMinAddress(); Address maxAddress = addresses.getMaxAddress(); map.put(new AddressHasher(minAddress, maxAddress), vertex); } return map; }
Example 5
Source File: FunctionGraphGroupVertices1Test.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testSetUserText_WithPersistence() { FGData graphData = graphFunction("01002cf5"); FunctionGraph functionGraph = graphData.getFunctionGraph(); Graph<FGVertex, FGEdge> graph = functionGraph; Set<FGVertex> ungroupedVertices = selectVertices(functionGraph, "01002d2b" /* Another Local*/, "01002d1f" /* MyLocal */); Set<FGEdge> ungroupedEdges = getEdges(graph, ungroupedVertices); assertEquals("Did not grab all known edges for vertices", 4, ungroupedEdges.size()); String groupVertexText = "Test Text"; group(ungroupedVertices, groupVertexText); assertVerticesRemoved(graph, ungroupedVertices); assertEdgesRemoved(graph, ungroupedEdges); // -1 because one one of the edges was between two of the vertices being grouped int expectedGroupedEdgeCount = ungroupedEdges.size() - 1; GroupedFunctionGraphVertex groupedVertex = validateNewGroupedVertexFromVertices( functionGraph, ungroupedVertices, expectedGroupedEdgeCount); AddressSetView addresses = groupedVertex.getAddresses(); Address minAddress = addresses.getMinAddress(); Address maxAddress = addresses.getMaxAddress(); graphData = triggerPersistenceAndReload("01002cf5"); waitForAnimation();// the re-grouping may be using animation, which runs after the graph is loaded functionGraph = graphData.getFunctionGraph(); graph = functionGraph; FGVertex vertex = functionGraph.getVertexForAddress(minAddress); assertTrue(vertex instanceof GroupedFunctionGraphVertex); assertEquals(maxAddress, vertex.getAddresses().getMaxAddress()); groupedVertex = (GroupedFunctionGraphVertex) vertex; assertEquals("User-defined grouped vertex text was not restored after graph reload", groupVertexText, groupedVertex.getUserText()); }
Example 6
Source File: AbstractDemanglerAnalyzer.java From ghidra with Apache License 2.0 | 5 votes |
@Override public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log) throws CancelledException { DemanglerOptions options = getOptions(); if (!validateOptions(options, log)) { log.error(getName(), "Invalid demangler options--cannot demangle"); return false; } monitor.initialize(100); SymbolTable symbolTable = program.getSymbolTable(); SymbolIterator it = symbolTable.getPrimarySymbolIterator(set, true); while (it.hasNext()) { monitor.checkCanceled(); Symbol symbol = it.next(); if (skipSymbol(symbol)) { continue; } Address address = symbol.getAddress(); String mangled = cleanSymbol(address, symbol.getName()); DemangledObject demangled = demangle(mangled, options, log); if (demangled != null) { apply(program, address, demangled, options, log, monitor); } Address min = set.getMinAddress(); Address max = set.getMaxAddress(); int distance = (int) (address.getOffset() - min.getOffset()); int percent = (int) ((distance / max.getOffset()) * 100); monitor.setProgress(percent); } return true; }
Example 7
Source File: FunctionGraphGroupVertices1Test.java From ghidra with Apache License 2.0 | 4 votes |
@Test public void testGroupingPersistence_WhenOneOfTheGroupIsAGroup() throws Exception { // // This test seeks to ensure that groups within groups are persisted and restored. // FGData graphData = graphFunction("01002cf5"); FunctionGraph functionGraph = graphData.getFunctionGraph(); Graph<FGVertex, FGEdge> graph = functionGraph; Set<FGVertex> ungroupedVertices = selectVertices(functionGraph, "01002d2b" /* Another Local*/, "01002d1f" /* MyLocal */); Set<FGEdge> ungroupedEdges = getEdges(graph, ungroupedVertices); //printEdges(ungroupedEdges); group(ungroupedVertices); // -1 because one one of the edges was between two of the vertices being grouped int expectedGroupedEdgeCount = ungroupedEdges.size() - 1; GroupedFunctionGraphVertex innerGroupedVertex = validateNewGroupedVertexFromVertices( functionGraph, ungroupedVertices, expectedGroupedEdgeCount); assertVerticesRemoved(graph, ungroupedVertices); assertEdgesRemoved(graph, ungroupedEdges); AddressSetView addresses = innerGroupedVertex.getAddresses(); Address innerMinAddress = addresses.getMinAddress(); Address innerMaxAddress = addresses.getMaxAddress(); // // Now group the group vertex with another vertex // Set<FGVertex> outerUngroupedVertices = selectVertices(functionGraph, "01002d0f" /* LAB_01002d0f */, "01002d1f" /* Grouped Vertex */); Set<FGEdge> outerUngroupedEdges = getEdges(graph, outerUngroupedVertices); //printEdges(outerUngroupedEdges); group(outerUngroupedVertices); // 5 edges expected: // -ungrouped vertex: 1 in, 1 out // -grouped vertex : 1 in, 2 out expectedGroupedEdgeCount = 5; GroupedFunctionGraphVertex outerGroupedVertex = validateNewGroupedVertexFromVertices( functionGraph, outerUngroupedVertices, expectedGroupedEdgeCount); assertVerticesRemoved(graph, outerUngroupedVertices); assertEdgesRemoved(graph, outerUngroupedEdges); AddressSetView outerAddresses = outerGroupedVertex.getAddresses(); Address secondMinAddress = outerAddresses.getMinAddress(); Address secondMaxAddress = outerAddresses.getMaxAddress(); graphData = triggerPersistenceAndReload("01002cf5"); waitForAnimation();// the re-grouping may be using animation, which runs after the graph is loaded functionGraph = graphData.getFunctionGraph(); graph = functionGraph; FGVertex vertex = functionGraph.getVertexForAddress(secondMinAddress); assertTrue(vertex instanceof GroupedFunctionGraphVertex); assertEquals(secondMaxAddress, vertex.getAddresses().getMaxAddress()); outerGroupedVertex = (GroupedFunctionGraphVertex) vertex; // outerUngroupedVertices = // selectVertices(functionGraph, "01002d0f" /* LAB_01002d0f */, "01002d1f" /* Grouped Vertex */); // outerUngroupedEdges = getEdges(graph, outerUngroupedVertices); //printEdges(outerUngroupedEdges); ungroup(outerGroupedVertex); vertex = functionGraph.getVertexForAddress(innerMinAddress); assertTrue(vertex instanceof GroupedFunctionGraphVertex); assertEquals(innerMaxAddress, vertex.getAddresses().getMaxAddress()); innerGroupedVertex = (GroupedFunctionGraphVertex) vertex; //printEdges(outerUngroupedEdges); assertEdgesAdded(functionGraph, outerUngroupedEdges); ungroup(innerGroupedVertex); assertEdgesAdded(functionGraph, ungroupedEdges); }
Example 8
Source File: FunctionGraphGroupVertices1Test.java From ghidra with Apache License 2.0 | 4 votes |
@Override protected void doTestRestoringWhenCodeBlocksHaveChanged_WillRegroup() { // // Tests the behavior of how group vertices are restored when one or more of the vertices // inside of the grouped vertex is no longer available when the graph attempts to restore // the group vertex user settings (i.e., when restarting Ghidra, the previously grouped // vertices should reappear). // // In this test, we will be mutating a group of 3 nodes such // that one of the nodes has been split into two. This leaves 2 vertices to // be found by the regrouping algorithm. Furthermore, the regrouping *will* still // take place, as at least two vertices cannot be found. // // // Pick a function and group some nodes. // FGData graphData = graphFunction("01002cf5"); FunctionGraph functionGraph = graphData.getFunctionGraph(); Set<FGVertex> ungroupedVertices = selectVertices(functionGraph, "01002d11" /* LAB_01002d11 */, "01002cf5" /* ghidra */, "01002d1f" /* MyLocal */); group(ungroupedVertices); // 5 edges expected: // -01002cf5: 2 out // -01002d11: 2 in, (1 out that was removed) // -01002d1f: 2 out (1 in that was removed) int expectedGroupedEdgeCount = 6; GroupedFunctionGraphVertex groupedVertex = validateNewGroupedVertexFromVertices( functionGraph, ungroupedVertices, expectedGroupedEdgeCount); AddressSetView addresses = groupedVertex.getAddresses(); Address minAddress = addresses.getMinAddress(); Address maxAddress = addresses.getMaxAddress(); // // Ideally, we would like to save, close and re-open the program so that we can get // a round-trip saving and reloading. However, in the test environment, we cannot save // our programs. So, we will instead just navigate away from the current function, clear // the cache (to make sure that we read the settings again), and then verify that the // data saved in the program has been used to re-group. // graphFunction("0100415a"); clearCache(); // // Add a label to trigger a code block change // Address labelAddress = createLabel("01002d18");// in the middle of the LAB_01002d11 code block // // Relaunch the graph, which will use the above persisted group settings... // graphData = graphFunction("01002cf5"); waitForAnimation();// the re-grouping may be using animation, which runs after the graph is loaded functionGraph = graphData.getFunctionGraph(); FGVertex expectedGroupVertex = functionGraph.getVertexForAddress(minAddress); assertTrue(expectedGroupVertex instanceof GroupedFunctionGraphVertex); assertEquals(maxAddress, expectedGroupVertex.getAddresses().getMaxAddress()); // ...we expect that the two original grouped vertices have again been grouped... FGVertex splitVertex = functionGraph.getVertexForAddress(getAddress("01002d11") /* LAB_01002d11 */); assertTrue("The split vertex should not have been regrouped", !(splitVertex instanceof GroupedFunctionGraphVertex)); FGVertex unchangedVertex = functionGraph.getVertexForAddress(getAddress("01002cf5") /* ghidra */); assertTrue("An unchanged vertex should have been regrouped: " + unchangedVertex, (unchangedVertex instanceof GroupedFunctionGraphVertex)); unchangedVertex = functionGraph.getVertexForAddress(getAddress("01002d1f") /* MyLocal */); assertTrue("An unchanged vertex should have been regrouped: " + unchangedVertex, (unchangedVertex instanceof GroupedFunctionGraphVertex)); // ...but the newly created code block has not FGVertex newlyCreatedVertex = functionGraph.getVertexForAddress(labelAddress); assertNotNull(newlyCreatedVertex); }