Java Code Examples for ghidra.program.model.address.AddressSet#add()
The following examples show how to use
ghidra.program.model.address.AddressSet#add() .
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: DisassemblerLargeSetTest.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testLargeDisjointPointsWithAlreadyDiassembledPoints() throws Exception { // disassemble the threaded flow AddressSet disassemble1 = disassembler.disassemble(addr(0x0), null, true); AddressSet disLocs = new AddressSet(); for (long i = 0; i < NUMCASES; i++) { disLocs.add(addr(i * CASESIZE)); } assertTrue(disassemble1.contains(disLocs)); AddressSet disLocs2 = new AddressSet(); for (long i = 0; i < NUMCASES; i++) { disLocs2.add(addr(i * CASESIZE)); disLocs2.add(addr(i * CASESIZE + 6)); } AddressSet disassemble2 = disassembler.disassemble(disLocs2, null, true); assertTrue(disassemble2.contains(disLocs2.subtract(disLocs))); }
Example 2
Source File: FollowFlowForwardTest.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testFollowAllFlowsFrom0x5020struct() { AddressSetView flowAddresses = getFlowsFrom(new AddressSet(addr(0x5020), addr(0x5029)), followAllFlows()); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0x90), addr(0xb4)); expectedAddresses.add(addr(0xb6), addr(0xbf)); expectedAddresses.add(addr(0x330), addr(0x331)); expectedAddresses.add(addr(0x360), addr(0x361)); expectedAddresses.add(addr(0x390), addr(0x391)); expectedAddresses.add(addr(0x5020), addr(0x5029)); expectedAddresses.add(addr(0x5040), addr(0x5043)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }
Example 3
Source File: SelectFunctionsScript.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void run() { monitor.setMessage("Selecting functions..."); AddressSet set = new AddressSet(); Listing listing = state.getCurrentProgram().getListing(); FunctionIterator iter = listing.getFunctions(true); int functionCount = 0; while (iter.hasNext() && !monitor.isCancelled()) { functionCount++; Function f = iter.next(); set.add(f.getBody()); println("Function Entry: "+f.getEntryPoint()); } println("Function Count: "+functionCount); createSelection(set); }
Example 4
Source File: DisassemblerLargeSetTest.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testLargeDisjointRangeCmd() throws Exception { // disassemble the threaded flow // AddressSet disassemble1 = disassembler.disassemble(addr(0x0), null, true); DisassembleCommand disassembleCommand = new DisassembleCommand(addr(0x0), null, true); disassembleCommand.applyTo(program); AddressSet disLocs = new AddressSet(); for (long i = 0; i < NUMCASES; i++) { disLocs.add(addr(i * CASESIZE)); } assertTrue(disassembleCommand.getDisassembledAddressSet().contains(disLocs)); AddressSet disLocs2 = new AddressSet(); for (long i = 0; i < NUMCASES; i++) { disLocs2.add(addr(i * CASESIZE)); disLocs2.add(addr(i * CASESIZE + 6), addr(i * CASESIZE + 10)); } //AddressSet disassemble2 = disassembler.disassemble(disLocs2, null, true); disassembleCommand = new DisassembleCommand(disLocs2, null, true); disassembleCommand.applyTo(program); assertTrue( disassembleCommand.getDisassembledAddressSet().contains(disLocs2.subtract(disLocs))); }
Example 5
Source File: EquatePlugin1Test.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testSetEquate_ApplyToWholeProgram() throws Exception { // put the cursor on a scalar putCursorOnOperand(0x010018d6, 0); // grab the dialog and select the radio button for 'apply to whole program' SetEquateDialog d = getSetEquatesDialog(); pressButtonByText(d, "Entire program"); String equateText = "Bob"; setEquateString(equateText, d); pressButtonByText(d, "OK"); flushProgramEvents(); // verify all scalars were changed AddressSet scalarAddresses = new AddressSet(); scalarAddresses.add(addr("10035be")); scalarAddresses.add(addr("100364c")); scalarAddresses.add(addr("1004ad6")); assertEquateAt(equateText, scalarAddresses); }
Example 6
Source File: FollowFlowBackwardTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testAllCallsBackFrom0x361() { AddressSetView flowAddresses = getFlowsTo(0x361, followAllCalls()); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0x9e), addr(0xb0)); expectedAddresses.add(addr(0x360), addr(0x361)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }
Example 7
Source File: FollowDelaySlotFlowTest.java From ghidra with Apache License 2.0 | 5 votes |
/** * 4: bral 14 ----+ * | * 10: or | * +- 12: brds 20 | * | 14: _or <-----+ * | 16: ret * | * +->20: ret * * branch into delay slot */ @Test public void testBackwardFlowWithBranchFromDelaySlot() throws Exception { programBuilder.addBytesBranch(4, 14); programBuilder.addBytesFallthrough(10); programBuilder.addBytesBranchWithDelaySlot(12, 20); programBuilder.addBytesReturn(16); programBuilder.addBytesReturn(20); programBuilder.disassemble(toHex(4), 2, false); programBuilder.disassemble(toHex(10), 6, false); programBuilder.disassemble(toHex(16), 2, false); programBuilder.disassemble(toHex(20), 2, false); Address addr = address(20); AddressSet addressSet = new AddressSet(addr); FlowType[] flowsNotToFollow = new FlowType[] {}; FollowFlow followFlow = new FollowFlow(program, addressSet, flowsNotToFollow); // FollowAllFlows AddressSet flowAddresses = followFlow.getFlowToAddressSet(TaskMonitorAdapter.DUMMY_MONITOR); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(address(10), address(15)); expectedAddresses.add(address(20), address(21)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }
Example 8
Source File: DiffApplyTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testApplyAllDiffsActionWithSimpleLabelMerge() throws Exception { openDiff_CloseWarningDialog(diffTestP1, diffTestP2); showApplySettings(); merge(labelApplyCB); invokeLater(selectAllDiffs); apply(); // FUTURE: Check that actually applied. AddressSet addrSet = new AddressSet(); // Comment Diffs addrSet.addRange(addr("1002040"), addr("1002040")); addrSet.addRange(addr("1002304"), addr("1002304")); addrSet.addRange(addr("1002306"), addr("1002306")); addrSet.addRange(addr("100230b"), addr("100230b")); addrSet.addRange(addr("1002312"), addr("1002312")); addrSet.addRange(addr("1002336"), addr("1002336")); addrSet.addRange(addr("1002346"), addr("1002346")); addrSet.addRange(addr("100238f"), addr("100238f")); addrSet.addRange(addr("1002395"), addr("1002395")); addrSet.addRange(addr("100239d"), addr("100239d")); addrSet.addRange(addr("10030d2"), addr("10030d2")); addrSet.addRange(addr("100355f"), addr("100355f")); // Label Diffs addrSet.addRange(addr("1002a01"), addr("1002a01")); addrSet.addRange(addr("1002a0c"), addr("1002a0c")); addrSet.addRange(addr("1002a0d"), addr("1002a0d")); // onlyInProgram1 addrSet.addRange(addr("00000200"), addr("000002ff")); // Conflicting Data Diffs addrSet.add(getPgmConflictDataDiffs()); checkDiffSelection(DiffUtility.getCodeUnitSet(addrSet, program)); }
Example 9
Source File: FollowDelaySlotFlowTest.java From ghidra with Apache License 2.0 | 5 votes |
/** * 4: bral 14 ----+ * | * 10: or | * +- 12: brds 20 | * | 14: _or <-----+ * | 16: ret * | * +->20: ret * * branch into delay slot */ @Test public void testBackwardFlowWithBranchIntoDelaySlot() throws Exception { programBuilder.addBytesBranch(4, 14); programBuilder.addBytesFallthrough(10); programBuilder.addBytesBranchWithDelaySlot(12, 20); programBuilder.addBytesReturn(16); programBuilder.addBytesReturn(20); programBuilder.disassemble(toHex(4), 2, false); programBuilder.disassemble(toHex(10), 6, false); programBuilder.disassemble(toHex(16), 2, false); programBuilder.disassemble(toHex(20), 2, false); Address addr = address(16); AddressSet addressSet = new AddressSet(addr); FlowType[] flowsNotToFollow = new FlowType[] {}; FollowFlow followFlow = new FollowFlow(program, addressSet, flowsNotToFollow); // FollowAllFlows AddressSet flowAddresses = followFlow.getFlowToAddressSet(TaskMonitorAdapter.DUMMY_MONITOR); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(address(4), address(5)); expectedAddresses.add(address(14), address(17)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }
Example 10
Source File: SelectionAction.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(SymbolTreeActionContext context) { AddressSet set = new AddressSet(); for (Symbol symbol : context.getSymbols()) { if (symbol.isExternal()) { continue; } Object symbolObject = symbol.getObject(); if (symbolObject instanceof Namespace) { Namespace namespace = (Namespace) symbolObject; set.add(namespace.getBody()); } else if (symbolObject instanceof Variable) { ProgramLocation loc = symbol.getProgramLocation(); set.addRange(loc.getAddress(), loc.getAddress()); } else if (symbolObject instanceof CodeUnit) { CodeUnit cu = (CodeUnit) symbolObject; set.addRange(cu.getMinAddress(), cu.getMaxAddress()); } } if (!set.isEmpty()) { plugin.firePluginEvent(new ProgramSelectionPluginEvent(plugin.getName(), new ProgramSelection(set), context.getProgram())); } }
Example 11
Source File: SelectByFlowPluginBackwardTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testFollowBackOnlyConditionalJumps() { ToolOptions flowOptions = tool.getOptions(GhidraOptions.CATEGORY_FLOW_OPTIONS); turnOffAllFollowFlow(flowOptions); followConditionalJumps(true, flowOptions); AddressSet selectionSet = new AddressSet(); selectionSet.add(addr(0x0a), addr(0x0a)); selectionSet.add(addr(0x0e), addr(0x0e)); selectionSet.add(addr(0x0f), addr(0x0f)); selectionSet.add(addr(0x26), addr(0x26)); selectionSet.add(addr(0x30), addr(0x30)); selectionSet.add(addr(0x60), addr(0x60)); selectionSet.add(addr(0x90), addr(0x90)); setSelection(selectionSet); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0x0), addr(0x07)); expectedAddresses.add(addr(0x0a), addr(0x0a)); expectedAddresses.add(addr(0x0e), addr(0x0f)); expectedAddresses.add(addr(0x25), addr(0x2e)); expectedAddresses.add(addr(0x30), addr(0x30)); expectedAddresses.add(addr(0x60), addr(0x60)); expectedAddresses.add(addr(0x90), addr(0x90)); ProgramSelection expectedSelection = new ProgramSelection(expectedAddresses); performAction(selectLimitedFlowsToAction, getActionContext(), true); ProgramSelection currentSelection = codeBrowserPlugin.getCurrentSelection(); assertEquals(new MySelection(expectedSelection), new MySelection(currentSelection)); }
Example 12
Source File: SelectByFlowPluginForwardTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testFollowOnlyPointers2() { ToolOptions flowOptions = tool.getOptions(GhidraOptions.CATEGORY_FLOW_OPTIONS); turnOffAllFollowFlow(flowOptions); followPointers(true, flowOptions); AddressSet selectionSet = new AddressSet(); selectionSet.add(addr(0x190), addr(0x190)); selectionSet.add(addr(0x290), addr(0x290)); selectionSet.add(addr(0x390), addr(0x390)); setSelection(selectionSet); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0x190), addr(0x191)); expectedAddresses.add(addr(0x290), addr(0x291)); expectedAddresses.add(addr(0x390), addr(0x391)); expectedAddresses.add(addr(0x5034), addr(0x5037)); expectedAddresses.add(addr(0x5040), addr(0x504b)); // CodeBrowser expands selection to the code unit. expectedAddresses.add(addr(0x5030), addr(0x503b)); expectedAddresses.add(addr(0x5040), addr(0x504b)); ProgramSelection expectedSelection = new ProgramSelection(expectedAddresses); performAction(selectLimitedFlowsFromAction, getActionContext(), true); ProgramSelection currentSelection = codeBrowserPlugin.getCurrentSelection(); assertEquals(new MySelection(expectedSelection), new MySelection(currentSelection)); }
Example 13
Source File: FollowFlowForwardTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testFollowPointers0x290() { AddressSetView flowAddresses = getFlowsFrom(0x290, followOnlyPointers()); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0x290), addr(0x291)); expectedAddresses.add(addr(0x5034), addr(0x5037)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }
Example 14
Source File: FollowFlowBackwardTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testComputedCallsBackFrom0x391() { AddressSetView flowAddresses = getFlowsTo(0x391, followOnlyComputedCalls()); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0xb5), addr(0xbe)); expectedAddresses.add(addr(0x390), addr(0x391)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }
Example 15
Source File: FollowFlowBackwardTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testFollowAllFlowsBackFrom0x2f() { AddressSetView flowAddresses = getFlowsTo(0x2f, followAllFlows()); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0x0), addr(0x2f)); expectedAddresses.add(addr(0x30), addr(0x5e)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }
Example 16
Source File: FollowFlowBackwardTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testFollowAllFlowsBackFrom0x331() { AddressSetView flowAddresses = getFlowsTo(0x331, followAllFlows()); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0x0), addr(0x2e)); expectedAddresses.add(addr(0x30), addr(0x5e)); expectedAddresses.add(addr(0x90), addr(0xa5)); expectedAddresses.add(addr(0x330), addr(0x331)); expectedAddresses.add(addr(0x5008), addr(0x500b)); expectedAddresses.add(addr(0x5024), addr(0x5027)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }
Example 17
Source File: FollowFlowBackwardTest.java From ghidra with Apache License 2.0 | 3 votes |
@Test public void testConditionalJumpsBackFrom0x5f() { AddressSetView flowAddresses = getFlowsTo(0x5f, followOnlyConditionalJumps()); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0x53), addr(0x5f)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }
Example 18
Source File: FollowFlowBackwardTest.java From ghidra with Apache License 2.0 | 3 votes |
@Test public void testFollowAllFlowsBackFrom0x5020() { AddressSetView flowAddresses = getFlowsTo(0x5020, followAllFlows()); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0x5020), addr(0x5020)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }
Example 19
Source File: MergeUtilities.java From ghidra with Apache License 2.0 | 3 votes |
/** * Adds addresses to autoChanges where there are changes in the myDiffs set, * but none in the latestDiffs set. * Adds addresses to conflictChanges where there are changes in the myDiffs * set and also some changes in the latestDiffs set. * @param latestDiffs the address set of the changes in LATEST. * @param myDiffs the address set of the changes in MY. * @param autoChanges address set for the myDiffs non-conflicting changes. * @param conflictChanges address set for the myDiffs conflicting changes */ public static void adjustSets(AddressSetView latestDiffs, AddressSetView myDiffs, AddressSet autoChanges, AddressSet conflictChanges) { AddressSet diffAutoChanges = new AddressSet(myDiffs); diffAutoChanges.delete(latestDiffs); AddressSet diffConflictChanges = new AddressSet(myDiffs); diffConflictChanges = diffConflictChanges.intersect(latestDiffs); autoChanges.add(diffAutoChanges); conflictChanges.add(diffConflictChanges); }
Example 20
Source File: FollowFlowForwardTest.java From ghidra with Apache License 2.0 | 3 votes |
@Test public void testFollowComputedJump0x0() { AddressSetView flowAddresses = getFlowsFrom(0x0, followOnlyComputedJumps()); AddressSet expectedAddresses = new AddressSet(); expectedAddresses.add(addr(0x0), addr(0x9)); assertEquals(new MySelection(expectedAddresses), new MySelection(flowAddresses)); }