Java Code Examples for ghidra.app.services.GoToService#goTo()
The following examples show how to use
ghidra.app.services.GoToService#goTo() .
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: GotoPreviousFunctionAction.java From ghidra with Apache License 2.0 | 6 votes |
@Override protected void actionPerformed(NavigatableActionContext context) { Address address = context.getAddress(); Program program = context.getProgram(); Function function = getPreviousFunction(program, address); if (function == null) { return; } GoToService service = tool.getService(GoToService.class); if (service != null) { FunctionSignatureFieldLocation location = new FunctionSignatureFieldLocation(program, function.getEntryPoint(), null, 0, function.getPrototypeString(false, false)); Navigatable navigatable = context.getNavigatable(); service.goTo(navigatable, location, navigatable.getProgram()); } else { tool.setStatusInfo("Can't find Go To Service!"); } }
Example 2
Source File: ByteViewerPlugin3Test.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testNotVisible() throws Exception { GoToService goToService = tool.getService(GoToService.class); Address addr = getAddr(0x01002000); goToService.goTo(addr); final ByteViewerComponent c = panel.getCurrentComponent(); ByteBlockInfo info = c.getViewerCursorLocation(); assertEquals(cbPlugin.getCurrentAddress(), convertToAddr(info)); showComponent(false); addr = getAddr(0x01002500); goToService.goTo(addr); showComponent(true); info = c.getViewerCursorLocation(); assertEquals(addr, convertToAddr(info)); }
Example 3
Source File: DragonHelper.java From dragondance with GNU General Public License v3.0 | 6 votes |
public static boolean goToAddress(long addr) { GoToService gotoService = tool.getService(GoToService.class); if (gotoService==null) return false; if (!isValidExecutableSectionAddress(addr)) { showWarning("%x is not valid offset.",addr); return false; } if (getInstructionNoThrow(getAddress(addr),true) == null) { return false; } return gotoService.goTo(getAddress(addr)); }
Example 4
Source File: InstructionTable.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { GoToService gs = plugin.getTool().getService(GoToService.class); // Only go somewhere if something is actually in the table. If it's empty this makes // no sense. Note that the plugin.getInstructions() call can never be null, so no // need to check that here. if (dialog.getSearchData().getInstructions().size() <= 0) { return; } // We have something in the table, so navigate to the first instruction. If the // first instruction address is null, this means the instruction was likely loaded // manually (hence no actual location in the listing). In this case, just search // for the first instance of this instruction and navigate there. If search returns // no results, display a message to the user. Address firstAddr = dialog.getSearchData().getInstructions().get(0).getAddr(); if (firstAddr != null) { gs.goTo(firstAddr); } else { if (dialog.getMessagePanel() != null) { dialog.getMessagePanel().setMessageText( "Instruction was loaded manually, no address in the listing to navigate to.", Color.BLUE); } } }
Example 5
Source File: SymbolAnnotatedStringHandler.java From ghidra with Apache License 2.0 | 5 votes |
@Override public boolean handleMouseClick(String[] annotationParts, Navigatable sourceNavigatable, ServiceProvider serviceProvider) { String symbolText = annotationParts[1]; Program program = sourceNavigatable.getProgram(); List<Symbol> symbols = getSymbols(symbolText, program); GoToService goToService = serviceProvider.getService(GoToService.class); // try going to the symbol first if (!symbols.isEmpty()) { QueryData data = new QueryData(symbols.get(0).getName(), true); return goToService.goToQuery(sourceNavigatable, null, data, null, null); } // try going to the address Address address = program.getAddressFactory().getAddress(symbolText); if (address != null) { return goToService.goTo(sourceNavigatable, address); } Msg.showInfo(getClass(), null, "Invalid symbol text: " + symbolText, "Unable to locate a symbol for \"" + symbolText + "\""); return false; }
Example 6
Source File: ProgramTreePlugin1Test.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testGoToUsingGoToService() { setTreeView("Main Tree"); ProgramNode funcNode = root.getChild("Functions"); visitNode(funcNode); ProgramNode sscanfNode = funcNode.getChild("sscanf"); setViewPaths(new TreePath[] { sscanfNode.getTreePath() }); GoToService goToService = tool.getService(GoToService.class); goToService.goTo(new ProgramLocation(program, sscanfNode.getFragment().getMinAddress())); assertPluginViewAppliedToTool(); }
Example 7
Source File: NextRangeAction.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(NavigatableActionContext context) { Address goToAddress = getGoToAddress(context); GoToService service = tool.getService(GoToService.class); if (service != null) { service.goTo(context.getNavigatable(), goToAddress); } }
Example 8
Source File: ByteViewerPlugin1Test.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testSetSelectionWithMouse() throws Exception { loadViews("Ascii", "Octal"); ByteViewerComponent c = panel.getCurrentComponent(); GoToService goToService = tool.getService(GoToService.class); goToService.goTo(addr(0x01001004)); Point startPoint = c.getCursorPoint(); goToByte("0x010010bc"); Point endPoint = c.getCursorPoint(); dragMouse(c, 1, startPoint.x, startPoint.y, endPoint.x, endPoint.y, 0); waitForSwing(); ByteBlockSelection sel = c.getViewerSelection(); ByteViewerComponent octal = findComponent(panel, "Octal"); assertTrue(byteBlockSelectionEquals(sel, octal.getViewerSelection())); ProgramSelection psel = cbPlugin.getCurrentSelection(); ByteBlockSelection bsel = panel.getViewerSelection(); // convert bsel to an address set AddressSet set = ((ProgramByteBlockSet) plugin.getProvider().getByteBlockSet()).getAddressSet(bsel); assertTrue(psel.hasSameAddresses(set)); }
Example 9
Source File: ByteViewerPlugin2Test.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testMemoryBlockDeletedNotInView() throws Exception { // delete a memory block that is not showing in the view // remove code browser plugin so the cursor position does not // get changed because of location events that the code browser // generates. SwingUtilities.invokeAndWait(() -> tool.removePlugins(new Plugin[] { cbPlugin })); env.showTool(); Address addr = getAddr(0x0f001000); GoToService goToService = tool.getService(GoToService.class); goToService.goTo(new ProgramLocation(program, addr)); waitForPostedSwingRunnables(); ByteViewerComponent c = panel.getCurrentComponent(); FieldLocation loc = c.getCursorLocation(); assertEquals(getFieldLocation(addr), loc); MemoryBlock block = memory.getBlock(getAddr(0x01001000)); int transactionID = program.startTransaction("Test"); memory.removeBlock(block, TaskMonitorAdapter.DUMMY_MONITOR); program.endTransaction(transactionID, true); program.flushEvents(); loc = getFieldLocation(addr); // cursor position should not be affected assertEquals(loc, c.getCursorLocation()); }
Example 10
Source File: ByteViewerPlugin2Test.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testMemoryBlockExpandDown() throws Exception { SwingUtilities.invokeAndWait(() -> tool.removePlugins(new Plugin[] { cbPlugin })); // expand block down: create a block, then join to its predecessor env.showTool(); Address addr = getAddr(0x01001000); MemoryBlock block = memory.getBlock(addr); GoToService goToService = tool.getService(GoToService.class); goToService.goTo(new ProgramLocation(program, addr)); Address newaddr = getAddr(0x01003000L); int transactionID = program.startTransaction("Test"); MemoryBlock newblock = memory.createInitializedBlock(".test", newaddr, 0x100, (byte) 0, null, false); memory.join(block, newblock); program.endTransaction(transactionID, true); program.flushEvents(); ByteViewerComponent c = panel.getCurrentComponent(); FieldLocation loc = getFieldLocation(newaddr); ByteField field = c.getField(loc.getIndex(), loc.getFieldNum()); assertNotNull(field); loc = c.getCursorLocation(); // cursor should remain where it was before the block expansion assertEquals(getFieldLocation(addr), loc); }
Example 11
Source File: ByteViewerPlugin2Test.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testMemoryBlockExpandUp() throws Exception { // expand up: create a block, then join to its successor SwingUtilities.invokeAndWait(() -> tool.removePlugins(new Plugin[] { cbPlugin })); env.showTool(); Address addr = getAddr(0x01001000); MemoryBlock block = memory.getBlock(addr); GoToService goToService = tool.getService(GoToService.class); goToService.goTo(new ProgramLocation(program, addr)); Address newaddr = getAddr(0x01000500); int transactionID = program.startTransaction("Test"); MemoryBlock newblock = memory.createInitializedBlock(".test", newaddr, 0xb00, (byte) 0, null, false); memory.join(newblock, block); program.endTransaction(transactionID, true); program.flushEvents(); ByteViewerComponent c = panel.getCurrentComponent(); FieldLocation loc = getFieldLocation(newaddr); ByteField field = c.getField(loc.getIndex(), loc.getFieldNum()); assertNotNull(field); loc = c.getCursorLocation(); // cursor should remain where it was before the block expansion assertEquals(getFieldLocation(addr), loc); // there should be no separator above the current location field = c.getField(loc.getIndex().subtract(BigInteger.ONE), 0); assertTrue(!field.getText().equals("..")); }
Example 12
Source File: PreviousRangeAction.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(NavigatableActionContext context) { Address goToAddress = getGoToAddress(context); GoToService service = tool.getService(GoToService.class); if (service != null) { service.goTo(context.getNavigatable(), goToAddress); } }
Example 13
Source File: ByteViewerPluginFormatsTest.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testDisassembledRecognition2() throws Exception { // verify that when data is created, the dingbat char changes to '.' env.showTool(); ByteViewerOptionsDialog dialog = launchByteViewerOptions(); setViewSelected(dialog, "Disassembled", true); pressButtonByText(dialog.getComponent(), "OK"); waitForSwing(); ByteViewerComponent c = findComponent(panel, "Disassembled"); panel.setCurrentView(c); GoToService goToService = tool.getService(GoToService.class); goToService.goTo(new ProgramLocation(program, getAddr(01001530))); waitForSwing(); int transactionID = program.startTransaction("test"); Address addr = getAddr(0x01001530); for (int i = 0; i < 5; i++) { listing.createData(addr, new ByteDataType(), 1); addr = addr.add(1); } program.endTransaction(transactionID, true); program.flushEvents(); waitForSwing(); addr = getAddr(0x01001530); for (int i = 0; i < 5; i++) { FieldLocation loc = getFieldLocation(addr); ByteField field = c.getField(loc.getIndex(), loc.getFieldNum()); assertEquals(".", field.getText()); addr = addr.add(1); } }
Example 14
Source File: CommentsPluginTest.java From ghidra with Apache License 2.0 | 4 votes |
/** * Test that when using the GoTo service the edit comments action * is enabled. * * @since Tracker Id 354 */ @Test public void testGoToEditCommentEnablement() throws Exception { openX86ProgramInTool(); // create function at 0x1008040 Address functionAddress = addr(0x1008040); addFunction("TestFunc", 0x1008040, 0x20); Address startAddress = addr(0x01006420); GoToService service = tool.getService(GoToService.class); // make sure we are starting on a known address service.goTo(startAddress); // in order to catch the bug for which this test was written we need // to call the goToQuery() method of the GoToService because that // method call results in a generic ProgramLocation event being // generated, whereas the goTo() methods will use a more specific // location, like an AddressFieldLocation Address nextAddress = startAddress.next(); service.goToQuery(startAddress, new QueryData(nextAddress.toString(), false), null, null); // this call would fail before the fix was in place assertTrue("The edit comments action is not enabled after using " + "the GoToService.", editAction.isEnabledForContext(browser.getProvider().getActionContext(null)) && editAction.isEnabled()); // now go to a function location and make sure the action is disabled assertTrue("Unable to use the code browser to go to a function " + "signature location.", browser.goToField(functionAddress, FunctionSignatureFieldFactory.FIELD_NAME, 0, 0)); assertTrue( "The edit comments action is not enabled when the current " + "program location is on a comment editable location.", editAction.isEnabledForContext(browser.getProvider().getActionContext(null)) && editAction.isEnabled()); assertTrue("Unable to use the code browser to go to a function " + "signature location.", browser.goToField(functionAddress, VariableCommentFieldFactory.FIELD_NAME, 0, 0)); assertTrue( "The edit comments action is enabled over a variable " + "location when editing these comments is covered by a different " + "action.", !editAction.isEnabledForContext(browser.getProvider().getActionContext(null))); }
Example 15
Source File: OverviewColorComponent.java From ghidra with Apache License 2.0 | 4 votes |
protected void gotoAddress(Address address) { GoToService gotoService = tool.getService(GoToService.class); if (gotoService != null) { gotoService.goTo(address); } }
Example 16
Source File: OperandFieldMouseHandler.java From ghidra with Apache License 2.0 | 4 votes |
private boolean checkMemRefs(Navigatable navigatable, CodeUnit codeUnit, OperandFieldLocation loc, ServiceProvider serviceProvider) { Address refAddr = loc.getRefAddress(); if (refAddr == null || !refAddr.isMemoryAddress()) { return false; } Reference[] refs = codeUnit.getOperandReferences(loc.getOperandIndex()); Address[] addrs = getAddressesForReferences(refs, codeUnit, serviceProvider); if (addrs.length == 0) { return false; } if (addrs.length > 1) { List<OutgoingReferenceEndpoint> outgoingReferences = new ArrayList<>(); for (int i = 0; i < refs.length; i++) { Reference ref = refs[i]; boolean offcut = ReferenceUtils.isOffcut(codeUnit.getProgram(), ref.getToAddress()); outgoingReferences.add(new OutgoingReferenceEndpoint(ref, addrs[i], offcut)); } IncomingReferencesTableModel model = new IncomingReferencesTableModel("Operand", serviceProvider, codeUnit.getProgram(), outgoingReferences, null); TableService service = serviceProvider.getService(TableService.class); Navigatable nav = NavigationUtils.getActiveNavigatable(); String addressString = codeUnit.getMinAddress().toString(); service.showTable("Operand References for " + addressString, "Operands", model, "References", nav); return true; } // 1 address found Address gotoAddr = addrs[0]; if (gotoAddr == null) { return false; } GoToService goToService = serviceProvider.getService(GoToService.class); return goToService.goTo(navigatable, codeUnit.getProgram(), gotoAddr, codeUnit.getAddress()); }
Example 17
Source File: LocationReferencesProvider.java From ghidra with Apache License 2.0 | 4 votes |
private void goTo(ProgramLocation loc, Program theProgram) { GoToService goToService = tool.getService(GoToService.class); goToService.goTo(loc, theProgram); }
Example 18
Source File: ByteViewerPlugin3Test.java From ghidra with Apache License 2.0 | 4 votes |
@Test public void testSetVisible() throws Exception { GoToService goToService = tool.getService(GoToService.class); goToService.goTo(getAddr(0x01001004)); final ByteViewerComponent c = panel.getCurrentComponent(); ByteBlockInfo info = c.getViewerCursorLocation(); assertEquals(cbPlugin.getCurrentAddress(), convertToAddr(info)); // make a selection in the Code Browser Point startPoint = c.getCursorPoint(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { FieldLocation loc = getFieldLocation(getAddr(0x010010bc)); c.setCursorPosition(loc.getIndex(), loc.getFieldNum(), loc.getRow(), loc.getCol()); } }); Point endPoint = c.getCursorPoint(); dragMouse(c, 1, startPoint.x, startPoint.y, endPoint.x, endPoint.y, 0); waitForPostedSwingRunnables(); ProgramSelection psel = cbPlugin.getCurrentSelection(); ByteBlockSelection bsel = panel.getViewerSelection(); // convert bsel to an address set AddressSet set = ((ProgramByteBlockSet) plugin.getProvider().getByteBlockSet()).getAddressSet(bsel); assertTrue(psel.hasSameAddresses(set)); info = c.getViewerCursorLocation(); // hide the byte viewer showComponent(false); // show the byte viewer showComponent(true); // the location and selection should be intact CodeUnit cu = program.getListing().getCodeUnitContaining(convertToAddr(info)); assertEquals(cbPlugin.getCurrentAddress(), cu.getMinAddress()); psel = cbPlugin.getCurrentSelection(); bsel = panel.getViewerSelection(); // convert bsel to an address set set = ((ProgramByteBlockSet) plugin.getProvider().getByteBlockSet()).getAddressSet(bsel); assertTrue(psel.hasSameAddresses(set)); }
Example 19
Source File: NextPreviousBookmarkAction.java From ghidra with Apache License 2.0 | 4 votes |
private void gotoAddress(GoToService service, Navigatable navigatable, Address address) { service.goTo(navigatable, address); }
Example 20
Source File: DataTypePreviewPluginTest.java From ghidra with Apache License 2.0 | 4 votes |
@Test public void testPreviewOrgChange() throws Exception { DTPPTableModel model = plugin.getTableModel(); GoToService gotoService = plugin.getGoToService(); model.removeAll(); // Default size specified by DataOrganization // shortSize = 2; // integerSize = 4; // longSize = 4; // defaultAlignment = 1; plugin.addDataType(IntegerDataType.dataType); plugin.addDataType(LongDataType.dataType); plugin.addDataType(ShortDataType.dataType); Structure struct = new StructureDataType("test", 0); struct.setInternallyAligned(true); struct.add(IntegerDataType.dataType, "intField", ""); struct.add(LongDataType.dataType, "longField", ""); struct.add(ShortDataType.dataType, "shortField", ""); plugin.addDataType(struct); assertEquals(6, model.getRowCount()); Program program = buildProgram(); DataOrganizationImpl dataOrganization = (DataOrganizationImpl) program.getDataTypeManager().getDataOrganization(); dataOrganization.setLongSize(8); env.open(program); gotoService.goTo(addr(program, 0x100df26)); // TODO: The below values have not been confirmed, since variation in DataOrganization is not yet supported by this plugin assertEquals("680054h", model.getValueAt(0, DTPPTableModel.PREVIEW_COL));// 4-byte int assertEquals("20006500680054h", model.getValueAt(1, DTPPTableModel.PREVIEW_COL));// 8-byte long assertEquals("54h", model.getValueAt(2, DTPPTableModel.PREVIEW_COL));// 2-byte short assertEquals("680054h", model.getValueAt(3, DTPPTableModel.PREVIEW_COL));// 4-byte int at offset 0 assertEquals("61004D00200065h", model.getValueAt(4, DTPPTableModel.PREVIEW_COL));// 8-byte long at offset 4 assertEquals("72h", model.getValueAt(5, DTPPTableModel.PREVIEW_COL));// 2-byte short at offset 12 // deactivate program plugin.getTool().firePluginEvent(new ProgramActivatedPluginEvent("Test", null)); waitForPostedSwingRunnables(); // NOTE: Altering data organization on-the-fly is not supported dataOrganization.setDefaultAlignment(2); dataOrganization.setShortSize(3); dataOrganization.setIntegerSize(3); dataOrganization.setLongSize(6); // activate program plugin.getTool().firePluginEvent(new ProgramActivatedPluginEvent("Test", program)); waitForPostedSwingRunnables(); gotoService.goTo(addr(program, 0x100df26)); assertEquals("680054h", model.getValueAt(0, DTPPTableModel.PREVIEW_COL));// 3-byte int assertEquals("6500680054h", model.getValueAt(1, DTPPTableModel.PREVIEW_COL));// 6-byte long assertEquals("680054h", model.getValueAt(2, DTPPTableModel.PREVIEW_COL));// 3-byte short assertEquals("680054h", model.getValueAt(3, DTPPTableModel.PREVIEW_COL));// 3-byte int at offset 0 assertEquals("4D00200065h", model.getValueAt(4, DTPPTableModel.PREVIEW_COL));// 6-byte long at offset 4 assertEquals("720061h", model.getValueAt(5, DTPPTableModel.PREVIEW_COL));// 3-byte short at offset 10 }