ghidra.app.services.GoToService Java Examples
The following examples show how to use
ghidra.app.services.GoToService.
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: OperandFieldMouseHandler.java From ghidra with Apache License 2.0 | 6 votes |
private boolean checkExternalReference(Navigatable navigatable, CodeUnit codeUnit, OperandFieldLocation loc, GoToService goToService) { Address refAddr = loc.getRefAddress(); if (refAddr == null || !refAddr.isExternalAddress()) { return checkExternalThunkFunctionReference(navigatable, codeUnit, loc, goToService); } Program program = codeUnit.getProgram(); Symbol s = program.getSymbolTable().getPrimarySymbol(refAddr); if (s == null) { return false; } ExternalLocation extLoc = program.getExternalManager().getExternalLocation(s); return goToService.goToExternalLocation(extLoc, true); }
Example #2
Source File: TableChooserDialog.java From ghidra with Apache License 2.0 | 6 votes |
private JPanel buildMainPanel() { JPanel panel = new JPanel(new BorderLayout()); createTableModel(); TableChooserDialogPanel tablePanel = new TableChooserDialogPanel(model); table = tablePanel.getTable(); GoToService goToService = tool.getService(GoToService.class); if (goToService != null) { navigatable = navigatable == null ? goToService.getDefaultNavigatable() : navigatable; navigatable.addNavigatableListener(this); table.installNavigation(goToService, navigatable); } table.getSelectionModel().addListSelectionListener( e -> setOkEnabled(table.getSelectedRowCount() > 0)); GhidraTableFilterPanel<AddressableRowObject> filterPanel = new GhidraTableFilterPanel<>(table, model); panel.add(tablePanel, BorderLayout.CENTER); panel.add(filterPanel, BorderLayout.SOUTH); return panel; }
Example #3
Source File: ByteViewerPlugin2Test.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testMemoryBlockDeletedInView() throws Exception { // delete a memory block that is showing in the view SwingUtilities.invokeAndWait(() -> tool.removePlugins(new Plugin[] { cbPlugin })); env.showTool(); Address addr = getAddr(0x0f001000); MemoryBlock block = memory.getBlock(addr); 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); int transactionID = program.startTransaction("Test"); memory.removeBlock(block, TaskMonitorAdapter.DUMMY_MONITOR); program.endTransaction(transactionID, true); program.flushEvents(); addr = getAddr(0x0f002000); loc = getFieldLocation(addr); // cursor should be positioned at next address after deleted block assertEquals(loc, c.getCursorLocation()); }
Example #4
Source File: GotoNextFunctionAction.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 = getNextFunction(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 #5
Source File: CommentFieldMouseHandler.java From ghidra with Apache License 2.0 | 6 votes |
@Override public boolean fieldElementClicked(Object clickedObject, Navigatable sourceNavigatable, ProgramLocation location, MouseEvent mouseEvent, ServiceProvider serviceProvider) { if (mouseEvent.getClickCount() != 2 || mouseEvent.getButton() != MouseEvent.BUTTON1) { return false; } String[] comments = getComment(location); int commentRow = getCommentRow(location); int column = getCommentColumn(location); if (comments.length == 0) { return false; // some comment location may have no comments, like plate comments } if (commentRow < 0) { return false; // Plate field locations can return negative values when clicking above // the border } String clickedWord = StringUtilities.findWord(StringUtilities.convertTabsToSpaces(comments[commentRow]), column, GoToService.VALID_GOTO_CHARS); return checkWord(clickedWord, serviceProvider, sourceNavigatable); }
Example #6
Source File: FunctionCallGraphPlugin.java From ghidra with Apache License 2.0 | 6 votes |
void handleProviderLocationChanged(ProgramLocation location) { // For snapshots // if (provider != connectedProvider) { // return; // } GoToService goTo = tool.getService(GoToService.class); if (goTo == null) { return; } // do later so the current event processing can finish SystemUtilities.runSwingLater(() -> { goTo.goTo(location); }); }
Example #7
Source File: OperandFieldMouseHandler.java From ghidra with Apache License 2.0 | 6 votes |
/** * Navigate to the variable, when directly supplied by the field location * * @param navigatable the navigatable to which we should navigate * @param loc the source location * @param goToService the GoTo service * @return true if we decide to attempt navigation */ private boolean goToExplicitOperandVariable(Navigatable navigatable, OperandFieldLocation loc, GoToService goToService) { VariableOffset variableOffset = loc.getVariableOffset(); if (variableOffset != null) { Variable variable = variableOffset.getVariable(); if (variable != null) { goToService.goTo(navigatable, new VariableNameFieldLocation(navigatable.getProgram(), variable, 0), navigatable.getProgram()); return true; } } return false; }
Example #8
Source File: PcodeFieldMouseHandler.java From ghidra with Apache License 2.0 | 6 votes |
protected boolean checkWord(String wordString, ServiceProvider serviceProvider, Navigatable sourceNavigatable) { if (wordString == null) { return false; } ProgramLocation location = sourceNavigatable.getLocation(); GoToService goToService = serviceProvider.getService(GoToService.class); if (goToService == null) { return false; } QueryData queryData = new QueryData(wordString, false); return goToService.goToQuery(sourceNavigatable, location.getAddress(), queryData, null, null); }
Example #9
Source File: TableServicePlugin.java From ghidra with Apache License 2.0 | 6 votes |
@Override public <T> TableComponentProvider<T> showTableWithMarkers(String title, String tableTypeName, GhidraProgramTableModel<T> model, Color markerColor, ImageIcon markerIcon, String windowSubMenu, Navigatable navigatable) { GoToService gotoService = tool.getService(GoToService.class); if (gotoService != null && navigatable == null) { navigatable = gotoService.getDefaultNavigatable(); } MarkerService markerService = tool.getService(MarkerService.class); Program program = model.getProgram(); TableComponentProvider<T> cp = new TableComponentProvider<>(this, title, tableTypeName, model, program.getDomainFile().getName(), gotoService, markerService, markerColor, markerIcon, windowSubMenu, navigatable); addProvider(program, cp); return cp; }
Example #10
Source File: TableServicePlugin.java From ghidra with Apache License 2.0 | 6 votes |
@Override public <T> TableComponentProvider<T> showTable(String title, String tableTypeName, GhidraProgramTableModel<T> model, String windowSubMenu, Navigatable navigatable) { GoToService gotoService = tool.getService(GoToService.class); if (gotoService != null && navigatable == null) { navigatable = gotoService.getDefaultNavigatable(); } Program program = model.getProgram(); TableComponentProvider<T> cp = new TableComponentProvider<>(this, title, tableTypeName, model, program.getDomainFile().getName(), gotoService, windowSubMenu, navigatable); addProvider(program, cp); return cp; }
Example #11
Source File: OperandFieldMouseHandler.java From ghidra with Apache License 2.0 | 6 votes |
private boolean goToRegisterVariable(Navigatable navigatable, CodeUnit codeUnit, OperandFieldLocation loc, GoToService goToService) { Address refAddr = loc.getRefAddress(); Address cuAddr = codeUnit.getMinAddress(); if (refAddr == null || refAddr.isStackAddress()) { return false; } Program p = codeUnit.getProgram(); Register reg = p.getRegister(refAddr, 1); if (reg == null) { return false; } Variable variable = p.getFunctionManager().getReferencedVariable(cuAddr, refAddr, reg.getMinimumByteSize(), !isWrite((Instruction) codeUnit, loc.getOperandIndex(), reg)); if (variable == null) { return false; } ProgramLocation pl = new VariableNameFieldLocation(navigatable.getProgram(), variable, 0); goToService.goTo(navigatable, pl, navigatable.getProgram()); return true; }
Example #12
Source File: SampleSearchTableProvider.java From ghidra with Apache License 2.0 | 6 votes |
private JComponent build(SampleSearcher searcher) { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); model = new SampleSearchTableModel(searcher, plugin.getTool()); filterTable = new GhidraFilterTable<>(model); GhidraTable table = ((GhidraTable) filterTable.getTable()); GoToService goToService = tool.getService(GoToService.class); if (goToService != null) { table.installNavigation(goToService, goToService.getDefaultNavigatable()); } table.setNavigateOnSelectionEnabled(true); panel.add(filterTable); return panel; }
Example #13
Source File: NavigateToFunctionAction.java From ghidra with Apache License 2.0 | 6 votes |
/** * Constructor * * @param provider the function comparison provider containing this action */ public NavigateToFunctionAction(MultiFunctionComparisonProvider provider) { super("Navigate To Selected Function", provider.getName()); goToService = provider.getTool().getService(GoToService.class); setEnabled(true); setSelected(false); ToolBarData newToolBarData = new ToolBarData(NAV_FUNCTION_ICON); setToolBarData(newToolBarData); setDescription( HTMLUtilities.toHTML("Toggle <b>On</b> means to navigate to whatever " + "function is selected in the comparison panel, when focus changes or" + "a new function is selected.")); setHelpLocation( new HelpLocation(MultiFunctionComparisonPanel.HELP_TOPIC, "Navigate_To_Function")); addFocusListeners(provider); addChangeListeners(provider); }
Example #14
Source File: OperandFieldMouseHandler.java From ghidra with Apache License 2.0 | 6 votes |
private boolean checkOperandFieldLocation(Navigatable navigatable, CodeUnit codeUnit, OperandFieldLocation loc, ServiceProvider serviceProvider) { GoToService goToService = serviceProvider.getService(GoToService.class); if (goToService == null) { return false; } int opIndex = loc.getOperandIndex(); if (checkVariableReference(navigatable, codeUnit, loc, goToService) || checkExternalReference(navigatable, codeUnit, loc, goToService) || checkMemRefs(navigatable, codeUnit, loc, serviceProvider)) { return true; } return checkOpObject(navigatable, codeUnit, opIndex, loc.getSubOperandIndex(), goToService); }
Example #15
Source File: AddressAnnotatedStringHandler.java From ghidra with Apache License 2.0 | 6 votes |
@Override public boolean handleMouseClick(String[] annotationParts, Navigatable sourceNavigatable, ServiceProvider serviceProvider) { GoToService goToService = serviceProvider.getService(GoToService.class); Program program = sourceNavigatable.getProgram(); String addressText = annotationParts[1]; Address address = program.getAddressFactory().getAddress(addressText); if (address != null) { return goToService.goTo(sourceNavigatable, address); } Msg.showInfo(getClass(), null, "No address: " + addressText, "Unable to locate address \"" + addressText + "\""); return false; }
Example #16
Source File: SearchTextPlugin2Test.java From ghidra with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { env = new TestEnv(); program = buildProgram(); tool = env.launchDefaultTool(program); plugin = env.getPlugin(SearchTextPlugin.class); goToService = tool.getService(GoToService.class); searchAction = getAction(plugin, "Search Text"); cbPlugin = env.getPlugin(CodeBrowserPlugin.class); provider = cbPlugin.getProvider(); env.getPlugin(TableServicePlugin.class); dialog = getDialog(); container = dialog.getComponent(); }
Example #17
Source File: LocationReferencesPlugin.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void findAndDisplayAppliedDataTypeAddresses(Composite dataType, String fieldName) { ProgramManager programManagerService = tool.getService(ProgramManager.class); GoToService goToService = tool.getService(GoToService.class); Program program = programManagerService.getCurrentProgram(); if (program == null) { Msg.showInfo(this, null, "Find References To...", "You must have a program open in order to use the 'Find References To...' action"); return; // cannot find references to a data type if there is no open program } ProgramLocation genericLocation = new GenericCompositeDataTypeProgramLocation(program, dataType, fieldName); LocationDescriptor locationDescriptor = getLocationDescriptor(genericLocation); Navigatable navigatable = goToService.getDefaultNavigatable(); LocationReferencesProvider provider = findProvider(locationDescriptor, navigatable); showProvider(program, provider, locationDescriptor, navigatable); }
Example #18
Source File: LocationReferencesPlugin.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void findAndDisplayAppliedDataTypeAddresses(DataType dataType) { ProgramManager programManagerService = tool.getService(ProgramManager.class); GoToService goToService = tool.getService(GoToService.class); Program program = programManagerService.getCurrentProgram(); if (program == null) { Msg.showInfo(this, null, "Find References To...", "You must have a program open in order to use the 'Find References To...' action"); return; // cannot find references to a data type if there is no open program } ProgramLocation genericLocation = new GenericDataTypeProgramLocation(program, dataType); LocationDescriptor locationDescriptor = getLocationDescriptor(genericLocation); Navigatable navigatable = goToService.getDefaultNavigatable(); LocationReferencesProvider provider = findProvider(locationDescriptor, navigatable); showProvider(program, provider, locationDescriptor, navigatable); }
Example #19
Source File: LocationReferencesPanel.java From ghidra with Apache License 2.0 | 6 votes |
private void buildPanel() { tableModel = new LocationReferencesTableModel(locationReferencesProvider); tablePanel = new GhidraThreadedTablePanel<>(tableModel, 250); table = tablePanel.getTable(); table.setHTMLRenderingEnabled(true); table.setPreferredScrollableViewportSize(new Dimension(300, 120)); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); setLayout(new BorderLayout(10, 10)); PluginTool tool = locationReferencesProvider.getTool(); GoToService goToService = tool.getService(GoToService.class); table.installNavigation(goToService, goToService.getDefaultNavigatable()); GhidraTableFilterPanel<LocationReference> tableFilterPanel = new GhidraTableFilterPanel<>(table, tableModel); add(tablePanel, BorderLayout.CENTER); add(tableFilterPanel, BorderLayout.SOUTH); }
Example #20
Source File: ReferencesPlugin.java From ghidra with Apache License 2.0 | 5 votes |
@Override protected void init() { goToService = tool.getService(GoToService.class); programMgr = tool.getService(ProgramManager.class); cuFormat = new BrowserCodeUnitFormat(tool); symbolInspector = new SymbolInspector(tool, null); }
Example #21
Source File: OperandFieldMouseHandler.java From ghidra with Apache License 2.0 | 5 votes |
private boolean checkExternalThunkFunctionReference(Navigatable navigatable, CodeUnit codeUnit, OperandFieldLocation loc, GoToService goToService) { Address refAddr = loc.getRefAddress(); if (refAddr == null) { return false; } Program program = codeUnit.getProgram(); Symbol s = program.getSymbolTable().getPrimarySymbol(refAddr); if (s == null) { return false; } SymbolType type = s.getSymbolType(); if (type != SymbolType.FUNCTION) { return false; } Function refFunction = (Function) s.getObject(); Function thunked = refFunction.getThunkedFunction(true); if (thunked == null) { return false; } if (thunked.getBody().contains(codeUnit.getAddress())) { // this handles the unlikely case where the user double-clicks a reference to a // local thunk label--don't navigate externally return false; } Symbol thunkedSymbol = thunked.getSymbol(); ExternalLocation extLoc = program.getExternalManager().getExternalLocation(thunkedSymbol); boolean success = goToService.goToExternalLocation(extLoc, true); return success; }
Example #22
Source File: NavigationUtils.java From ghidra with Apache License 2.0 | 5 votes |
public static void setSelection(PluginTool tool, Navigatable navigatable, ProgramSelection selection) { if (navigatable == null) { GoToService service = tool.getService(GoToService.class); if (service == null) { return; // can't do anything here } } SystemUtilities.runIfSwingOrPostSwingLater(() -> { navigatable.setSelection(selection); tool.contextChanged(null); }); }
Example #23
Source File: ShowInstructionInfoPluginTest.java From ghidra with Apache License 2.0 | 5 votes |
/** * Moves the program location to the given address and returns the * instruction at that location. * * @param addressString The address location to move to. * @return The instruction at the new location or null if there is no * instruction. */ private Instruction changeLocationToAddress(String addressString) throws Exception { CodeBrowserPlugin cbp = env.getPlugin(CodeBrowserPlugin.class); final Address address = program.getAddressFactory().getAddress(addressString); final GoToService goToService = tool.getService(GoToService.class); runSwing(() -> goToService.goTo(new AddressFieldLocation(program, address))); waitForPostedSwingRunnables(); cbp.updateNow(); ListingActionContext context = (ListingActionContext) cbp.getProvider().getActionContext(null); return (Instruction) invokeInstanceMethod("getInstructionForContext", plugin, new Class[] { ListingActionContext.class }, new Object[] { context }); }
Example #24
Source File: EquateTableProvider.java From ghidra with Apache License 2.0 | 5 votes |
void setGoToService(GoToService service) { if (service != null) { referencesTable.installNavigation(service, service.getDefaultNavigatable()); } else { referencesTable.removeNavigation(); } }
Example #25
Source File: NextPreviousBookmarkAction.java From ghidra with Apache License 2.0 | 5 votes |
private void gotoAddress(NavigatableActionContext listingActionContext, Address address) { if (address == null) { tool.setStatusInfo("Unable to locate another " + getNavigationTypeName() + " past the current range, in the current direction."); return; } tool.clearStatusInfo(); GoToService service = tool.getService(GoToService.class); if (service != null) { Navigatable navigatable = listingActionContext.getNavigatable(); gotoAddress(service, navigatable, address); } }
Example #26
Source File: DualListingServiceProvider.java From ghidra with Apache License 2.0 | 5 votes |
@Override public <T> T getService(Class<T> serviceClass) { if (serviceClass == GoToService.class) { return serviceClass.cast(dualListingGoToService); } return serviceProvider.getService(serviceClass); }
Example #27
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 #28
Source File: NextPrevAddressPlugin.java From ghidra with Apache License 2.0 | 5 votes |
private Navigatable getNavigatable(ActionContext context) { if (context instanceof NavigatableActionContext) { Navigatable navigatable = ((NavigatableActionContext) context).getNavigatable(); if (!navigatable.isConnected()) { return navigatable; } } GoToService service = tool.getService(GoToService.class); if (service != null) { return service.getDefaultNavigatable(); } return null; }
Example #29
Source File: RelocationTablePlugin.java From ghidra with Apache License 2.0 | 5 votes |
@Override protected void init() { goToService = tool.getService(GoToService.class); provider = new RelocationProvider(this); createActions(); }
Example #30
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); } } }