Java Code Examples for ghidra.util.Msg#showError()
The following examples show how to use
ghidra.util.Msg#showError() .
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: IsolateVariableTask.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void commit() throws DuplicateNameException, InvalidInputException { // Split out the specific instance into its own symbol Varnode vn = tokenAtCursor.getVarnode(); try { HighVariable highVariable = highFunction.splitOutMergeGroup(vn.getHigh(), vn); highSymbol = highVariable.getSymbol(); } catch (PcodeException e) { Msg.showError(this, tool.getToolFrame(), "New Variable Failed", e.getMessage()); return; } DataType dataType = highSymbol.getDataType(); if (Undefined.isUndefined(dataType)) { // An undefined datatype will not be considered typelocked. Since the new variable // needs to be typelocked we use an unsigned integer of equivalent size dataType = AbstractIntegerDataType.getUnsignedDataType(dataType.getLength(), program.getDataTypeManager()); } // Create the new variable, typelocking in a new data-type HighFunctionDBUtil.updateDBVariable(highSymbol, newName, dataType, srcType); }
Example 2
Source File: AddExternalReferenceNameAction.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(ActionContext context) { InputDialog dialog = new InputDialog("New External Program", "Enter Name"); dialog.setHelpLocation(new HelpLocation("ReferencesPlugin", "Add_External_Program_Name")); provider.getTool().showDialog(dialog, provider); if (dialog.isCanceled()) { return; } String newExternalName = dialog.getValue().trim(); if (newExternalName.isEmpty()) { Msg.showError(this, dialog.getComponent(), "Invalid Input", "External program name cannot be empty"); return; } AddExternalNameCmd cmd = new AddExternalNameCmd(newExternalName, SourceType.USER_DEFINED); provider.getTool().execute(cmd, provider.getProgram()); }
Example 3
Source File: ApplicationKeyManagerFactory.java From ghidra with Apache License 2.0 | 6 votes |
/** * Set user keystore file path (e.g., certificate file with private key). * This method will have no effect if the keystore had been set via the system * property and an error will be displayed. Otherwise, the keystore will * be updated and the key manager re-initialized. The user preference will be * updated unless a failure occurred while attempting to open the keystore. * This change will take immediate effect for the current executing application, * however, it may still be superseded by a system property setting when running * the application in the future. See {@link #getKeyStore()}. * @param path keystore file path * @param savePreference if true will be saved as user preference * @throws IOException if file or certificate error occurs */ public static synchronized void setKeyStore(String path, boolean savePreference) throws IOException { if (System.getProperty(KEYSTORE_PATH_PROPERTY) != null) { Msg.showError(ApplicationKeyManagerFactory.class, null, "Set KeyStore Failed", "KeyStore was set via system property and can not be changed"); return; } path = prunePath(path); try { boolean keyInitialized = getKeyManagerWrapper().init(path); if (savePreference && (path == null || keyInitialized)) { Preferences.setProperty(KEYSTORE_PATH_PROPERTY, path); Preferences.store(); } } catch (CancelledException e) { // ignore - keystore left unchanged } }
Example 4
Source File: GhidraThreadGroup.java From ghidra with Apache License 2.0 | 6 votes |
/** * Handle any uncaught throwable/exception. * @param t throwable */ public static void handleUncaughtException(Throwable t) { if (t instanceof DomainObjectException) { t = t.getCause(); } if (t instanceof TerminatedTransactionException) { Msg.showError( GhidraThreadGroup.class, null, "Terminated Transaction", "Transaction has been terminated!\n \n" + "All open transactions must be closed before a new transaction will be allowed.\n" + "Try cancelling all long running tasks.\n \n" + "Note that this error may be repeated until all running tasks are terminated."); return; } if (t instanceof DomainObjectLockedException) { Msg.showError(GhidraThreadGroup.class, null, "Transaction Not Allowed", t.getMessage() + "\n \n" + "No modifications are permitted until the locking process has completed."); return; } // pass up for more generic exception handling SwingExceptionHandler.handleUncaughtException(t); }
Example 5
Source File: DataTreeClipboardUtils.java From ghidra with Apache License 2.0 | 6 votes |
/** * Pushes the GTreeNodes in the specified TreePath array to the clipboard. * * @param tree DataTree that contains the GTreeNodes * @param paths array of TreePaths containing nodes to be pushed to clipboard. */ public static void setClipboardContents(DataTree tree, TreePath[] paths) { clearCuttables(); Clipboard clipboard = GClipboard.getSystemClipboard(); List<GTreeNode> list = new ArrayList<>(); for (TreePath element : paths) { GTreeNode node = (GTreeNode) element.getLastPathComponent(); list.add(node); } GTreeNodeTransferable contents = new GTreeNodeTransferable(tree.getDragNDropHandler(), list); try { clipboard.setContents(contents, DATATREE_CLIPBOARD_OWNER); } catch (IllegalStateException ise) { // this can happen when other applications are accessing the system clipboard Msg.showError(DataTreeClipboardUtils.class, tree, "Unable to Access Clipboard", "Unable to perform cut/copy operation on the system clipboard. The " + "clipboard may just be busy at this time. Please try again."); } }
Example 6
Source File: SymbolMerger.java From ghidra with Apache License 2.0 | 6 votes |
private void resolveRename(long originalSymbolID, int chosenConflictOption) throws DuplicateNameException, InvalidInputException, CircularDependencyException { Symbol original = originalSymTab.getSymbol(originalSymbolID); Symbol latest = latestSymTab.getSymbol(originalSymbolID); Symbol my = mySymTab.getSymbol(originalSymbolID); long resultID; Symbol result = null; try { resultID = getResultIDFromOriginalID(originalSymbolID); result = resultSymTab.getSymbol(resultID); } catch (NoValueException e) { String msg = "Failed to rename symbol '" + original.getName(true) + "'."; Msg.showError(this, null, "Rename Symbol Error", msg); } if ((chosenConflictOption & KEEP_LATEST) != 0) { renameSymbol(resultPgm, result, latestPgm, latest); } else if ((chosenConflictOption & KEEP_MY) != 0) { renameSymbol(resultPgm, result, myPgm, my); } }
Example 7
Source File: WorkspacePanel.java From ghidra with Apache License 2.0 | 6 votes |
/** * adds a new empty workspace to the project with the name of the * workspace set by the user; called from the Workspace menu. */ void addWorkspace() { // query the user for the name of the workspace InputDialog nameDialog = new InputDialog("Create New Workspace", "Workspace Name", ToolManager.DEFAULT_WORKSPACE_NAME); plugin.getTool().showDialog(nameDialog, (Component) null); if (nameDialog.isCanceled()) { return; // user canceled } String workspaceName = nameDialog.getValue(); try { ToolManager tm = activeProject.getToolManager(); tm.createWorkspace(workspaceName); } catch (DuplicateNameException e) { String msg = "Workspace named: " + workspaceName + " already exists."; Msg.showError(getClass(), plugin.getTool().getToolFrame(), "Workspace Name Exists", msg); } }
Example 8
Source File: JungToGDirectedGraphAdapter.java From ghidra with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public GDirectedGraph<V, E> emptyCopy() { if (delegate instanceof GDirectedGraph) { return ((GDirectedGraph) delegate).emptyCopy(); } Class<? extends Graph> clazz = delegate.getClass(); try { Constructor<? extends Graph> constructor = clazz.getConstructor((Class<?>[]) null); Graph newGraph = constructor.newInstance((Object[]) null); return new JungToGDirectedGraphAdapter(newGraph); } catch (Exception e) { // shouldn't happen Msg.showError(this, null, "Error Creating Graph", "Unable to create a new instance of graph: " + clazz, e); return null; } }
Example 9
Source File: ToolActionManager.java From ghidra with Apache License 2.0 | 5 votes |
private void addDefaultTool(String filename) { try { InputStream is = ResourceManager.getResourceAsStream(filename); addToolTemplate(is, filename); } catch (Exception e) { Msg.showError(this, null, "Error", "Error loading default tool: " + filename, e); } }
Example 10
Source File: AnalysisOptionsDialog.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void okCallback() { try { panel.applyChanges(); doAnalysis = true; close(); } catch (Exception e) { Msg.showError(this, panel, "Error Setting Analysis Options", e.getMessage(), e); } }
Example 11
Source File: FindChangedFunctionsScript.java From ghidra with Apache License 2.0 | 5 votes |
@Override protected void run() throws Exception { Project project = state.getProject(); if (project == null) { throw new RuntimeException("No project open"); } // Prompt the user to load the two programs that will be analyzed. // This will only allow you to select programs from the currently-open // project in Ghidra, so import them if you haven't already. Program p1 = askProgram("Program1_Version1"); Program p2 = askProgram("Program1_Version2"); // Make sure the selected programs are not open and locked by Ghidra. If so, // warn the user. if (areProgramsLocked(p1, p2)) { Msg.showError(this, null, "Program is locked!", "One of the programs you selected is locked by Ghidra. Please correct and try again."); return; } // Create a new VT session createVersionTrackingSession("new session", p1, p2); runCorrelator("Exact Function Instructions Match"); Set<String> functionNames = getSourceFunctions(); Collection<VTMatch> matches = getMatchesFromLastRunCorrelator(); for (VTMatch vtMatch : matches) { Function function = getSourceFunction(vtMatch); functionNames.remove(function.getName()); println("Found exact match for " + function.getName()); } for (String functionName : functionNames) { println("Did not find exact match for: " + functionName); } }
Example 12
Source File: ProgramGraphPlugin.java From ghidra with Apache License 2.0 | 5 votes |
private void graph(String actionName, String modelName, boolean showCode) { try { CodeBlockModel model = blockModelService.getNewModelByName(modelName, currentProgram, true); BlockGraphTask task = new BlockGraphTask(actionName, graphEntryPointNexus, showCode, reuseGraph, appendToGraph, tool, currentSelection, model, defaultGraphService); task.setCodeLimitPerBlock(codeLimitPerBlock); new TaskLauncher(task, tool.getToolFrame()); } catch (NotFoundException e) { Msg.showError(this, null, "Error That Can't Happen", "Can't find a block model from a name that we got from the existing block models!"); } }
Example 13
Source File: SaveArchiveAction.java From ghidra with Apache License 2.0 | 5 votes |
private void saveFileArchive(FileArchive archive) { try { archive.save(); } catch (IOException ioe) { Msg.showError(this, plugin.getProvider().getComponent(), "Unable to Save File", "Unexpected exception attempting to save archive: " + archive, ioe); } }
Example 14
Source File: ExtensionTableModel.java From ghidra with Apache License 2.0 | 5 votes |
/** * Overridden to handle the case where a user has toggled the installation column * checkbox. */ @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { super.setValueAt(aValue, rowIndex, columnIndex); // We only care about the install column here, as it's the only one that // is editable. if (columnIndex != INSTALLED_COL) { return; } // If the user does not have write permissions on the installation dir, they cannot // install. ResourceFile installDir = Application.getApplicationLayout().getExtensionInstallationDir(); if (!installDir.canWrite()) { Msg.showError(this, null, "Permissions Error", "Cannot install/uninstall extensions: Invalid write permissions on installation directory.\n" + "See the \"Ghidra Extension Notes\" section of the Ghidra Installation Guide for more information."); return; } boolean install = ((Boolean) aValue).booleanValue(); ExtensionDetails extension = getSelectedExtension(rowIndex); if (install) { if (ExtensionUtils.install(extension, true)) { modelChanged = true; } } else { if (ExtensionUtils.removeStateFiles(extension)) { modelChanged = true; } } refreshTable(); }
Example 15
Source File: SwingUpdateManager.java From ghidra with Apache License 2.0 | 5 votes |
private void doWork() { try { clientRunnable.run(); } catch (Throwable t) { // catch exceptions so we don't kill the timer Msg.showError(this, null, "Unexpected Exception", "Unexpected exception in Swing Update Manager", t); } isWorking = false; // we need to clear the buffering flag after the minDelay has passed, so start the timer scheduleCheckForWork(); }
Example 16
Source File: FSBDirNode.java From ghidra with Apache License 2.0 | 5 votes |
@Override public List<GTreeNode> generateChildren(TaskMonitor monitor) throws CancelledException { try (RefdFile dir = FileSystemService.getInstance().getRefdFile(fsrl, monitor)) { return FSBNode.getNodesFromFileList(dir.file.getListing()); } catch (IOException e) { Msg.showError(this, null, "loadChildren", e); } return Collections.emptyList(); }
Example 17
Source File: ProgramTreeModelListener.java From ghidra with Apache License 2.0 | 4 votes |
/** * Called when a node changes; update the Group name for the node being changed. */ @Override public void treeNodesChanged(TreeModelEvent e) { ProgramNode node = (ProgramNode) e.getTreePath().getLastPathComponent(); int[] indices = e.getChildIndices(); if (indices != null) { node = (ProgramNode) node.getChildAt(indices[0]); } String newName = node.getUserObject().toString().trim(); if (newName.isEmpty()) { node.setUserObject(node.getName()); Msg.showError(this, null, "Rename Failed", "Please enter a name."); // maintain the editing state SystemUtilities.runSwingLater(() -> tree.rename()); return; } Group group = node.getGroup(); String oldName = group.getName(); if (newName.equals(oldName)) { return; // name hasn't changed } RenameCmd cmd = new RenameCmd(tree.getTreeName(), (group instanceof ProgramModule), oldName, newName); if (tree.getTool().execute(cmd, tree.getProgram())) { StringKeyIndexer nameIndexer = tree.getNameIndexer(); nameIndexer.remove(oldName); nameIndexer.put(newName); } else { node.setUserObject(node.getName()); Msg.showError(this, tree, "Rename Failed", cmd.getStatusMsg()); // maintain the editing state SystemUtilities.runSwingLater(() -> tree.rename()); } tree.setEditable(false); }
Example 18
Source File: SymbolMerger.java From ghidra with Apache License 2.0 | 4 votes |
private void processAdds(TaskMonitor monitor) throws CancelledException { updateProgressMessage("Processing added symbols..."); monitor.setMessage("Symbol Merge: Processing added symbols..."); int len = myAddIDs.length; monitor.initialize(len); for (int i = 0; i < len; i++) { monitor.checkCanceled(); incrementProgress(1); monitor.incrementProgress(1); long id = myAddIDs[i]; Symbol mySym = mySymTab.getSymbol(id); if (myHash.contains(id)) { continue; // It's already resolved } if (mySym == null) { continue; } SymbolType myType = mySym.getSymbolType(); // Symbol types. // CLASS, EXTERNAL, FUNCTION, GLOBAL, GLOBAL_VAR, LIBRARY, // LOCAL_VAR, NAMESPACE, PARAMETER if (!mySym.isExternal() && ((myType == SymbolType.FUNCTION) || (myType == SymbolType.LOCAL_VAR) || (myType == SymbolType.PARAMETER))) { // Try to add processAddedFunctionSymbol(mySym); } else if ((myType != SymbolType.LABEL) && (myType != SymbolType.CLASS) && (myType != SymbolType.NAMESPACE)) { continue; } // Otherwise, auto merge the add. (AUTO_MERGE) try { // Try to add SymbolType mySymbolType = mySym.getSymbolType(); if (mySym.isExternal() && mySymbolType == SymbolType.LABEL) { continue; // External should have already been handled in ExternalMerger. } addSymbol(mySym); updateProgressMessage("Adding symbol: " + mySym.getName(true)); monitor.setMessage("Symbol Merge: Added symbol " + i + " of " + len + "..."); } catch (UsrException e) { String msg = "Failed to add '" + mySym.getName(true) + "'."; Msg.showError(this, null, "Add Symbol Error", msg); } } monitor.setProgress(len); updateProgressMessage(DEFAULT_PROGRESS_MESSAGE); }
Example 19
Source File: SyncAction.java From ghidra with Apache License 2.0 | 4 votes |
private void showRequiresArchiveOpenMessage(String archiveName) { Msg.showError(getClass(), plugin.getTool().getToolFrame(), getOperationName() + " Failed", "Archive \"" + archiveName + "\" must be open for editing."); }
Example 20
Source File: OverridePrototypeAction.java From ghidra with Apache License 2.0 | 4 votes |
@Override protected void decompilerActionPerformed(DecompilerActionContext context) { Function func = context.getFunction(); Program program = func.getProgram(); PcodeOp op = getCallOp(program, context.getTokenAtCursor()); Function calledfunc = getCalledFunction(program, op); boolean varargs = false; if (calledfunc != null) { varargs = calledfunc.hasVarArgs(); } if ((op.getOpcode() == PcodeOp.CALL) && !varargs) { if (OptionDialog.showOptionDialog(context.getDecompilerPanel(), "Warning : Localized Override", "Incorrect information entered here may hide other good information.\n" + "For direct calls, it is usually better to alter the prototype on the function\n" + "itself, rather than overriding the local call. Proceed anyway?", "Proceed") != 1) { return; } } Address addr = op.getSeqnum().getTarget(); String name = "func"; // Default if we don't have a real name String conv = program.getCompilerSpec().getDefaultCallingConvention().getName(); if (calledfunc != null) { name = calledfunc.getName(); conv = calledfunc.getCallingConventionName(); } String signature = generateSignature(op, name); PluginTool tool = context.getTool(); ProtoOverrideDialog dialog = new ProtoOverrideDialog(tool, func, signature, conv); // dialog.setHelpLocation( new HelpLocation( getOwner(), "Edit_Function_Signature" ) ); tool.showDialog(dialog); FunctionDefinition fdef = dialog.getFunctionDefinition(); if (fdef == null) { return; } int transaction = program.startTransaction("Override Signature"); boolean commit = false; try { HighFunctionDBUtil.writeOverride(func, addr, fdef); commit = true; } catch (Exception e) { Msg.showError(getClass(), context.getDecompilerPanel(), "Override Signature Failed", "Error overriding signature: " + e); } finally { program.endTransaction(transaction, commit); } }