Java Code Examples for ghidra.framework.plugintool.PluginTool#setStatusInfo()
The following examples show how to use
ghidra.framework.plugintool.PluginTool#setStatusInfo() .
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: GhidraScript.java From ghidra with Apache License 2.0 | 6 votes |
/** * Display a message in tools status bar. * <p> * This method is unavailable in headless mode. * * @param msg the text to display. * @param beep if true, causes the tool to beep. * @throws ImproperUseException if this method is run in headless mode */ public void setToolStatusMessage(String msg, boolean beep) throws ImproperUseException { if (isRunningHeadless()) { throw new ImproperUseException( "The setToolStatusMessage() method can only be used when running headed Ghidra."); } PluginTool tool = state.getTool(); if (tool == null) { if (beep) { printerr(msg); } return; } tool.setStatusInfo(msg, beep); }
Example 2
Source File: DeleteVarArgsAction.java From ghidra with Apache License 2.0 | 6 votes |
/** * Method called when the action is invoked. * @param ev details regarding the invocation of this action */ @Override public void actionPerformed(ListingActionContext context) { Function function = functionPlugin.getFunction(context); if ((function != null) && (function.hasVarArgs())) { Command command = new SetFunctionVarArgsCommand(function, false); PluginTool tool = functionPlugin.getTool(); Program program = context.getProgram(); if (!tool.execute(command, program)) { tool.setStatusInfo("Unable to delete function varArgs on " + "function: " + function.getName()); } } }
Example 3
Source File: AddVarArgsAction.java From ghidra with Apache License 2.0 | 6 votes |
@Override protected void actionPerformed(ListingActionContext context) { ProgramLocation loc = context.getLocation(); if ((loc instanceof FunctionSignatureFieldLocation) || (loc instanceof VariableLocation)) { Function function = functionPlugin.getFunction(context); if ((function != null) && (!function.hasVarArgs())) { Command command = new SetFunctionVarArgsCommand(function, true); PluginTool tool = functionPlugin.getTool(); Program program = context.getProgram(); if (!tool.execute(command, program)) { tool.setStatusInfo("Unable to add function varArgs on " + "function: " + function.getName()); } } } }
Example 4
Source File: CreateArrayAction.java From ghidra with Apache License 2.0 | 6 votes |
private void createArrayAtAddress(Program program, Address addr) { PluginTool tool = plugin.getTool(); Data data = program.getListing().getDataAt(addr); if (data == null) { tool.setStatusInfo("Create Array Failed! No data at " + addr); return; } DataType dt = data.getDataType(); int length = data.getLength(); int maxNoConflictElements = getMaxElementsThatFit(program, addr, length); int maxElements = getMaxElementsIgnoreExisting(program, addr, length); int numElements = getNumElements(dt, maxNoConflictElements, maxElements); // this signals that the user cancelled the operation if (numElements == Integer.MIN_VALUE) { return; } CreateArrayCmd cmd = new CreateArrayCmd(addr, numElements, dt, length); if (!tool.execute(cmd, program)) { tool.setStatusInfo(cmd.getStatusMsg()); } }
Example 5
Source File: CreateArrayAction.java From ghidra with Apache License 2.0 | 6 votes |
private void createArrayFromSelection(Program program, ProgramSelection sel) { PluginTool tool = plugin.getTool(); AddressRange range = sel.getFirstRange(); Address addr = sel.getMinAddress(); Data data = program.getListing().getDataAt(addr); if (data == null) { tool.setStatusInfo("Create Array Failed! No data at " + addr); return; } DataType dt = data.getDataType(); int dtLength = data.getLength(); int length = (int) range.getLength(); int numElements = length / dtLength; CreateArrayCmd cmd = new CreateArrayCmd(addr, numElements, dt, dtLength); if (!tool.execute(cmd, program)) { tool.setStatusInfo(cmd.getStatusMsg()); } }
Example 6
Source File: EditFunctionPurgeAction.java From ghidra with Apache License 2.0 | 5 votes |
private void showDialog(Function function) { int currentFunctionPurgeSize = function.getStackPurgeSize(); if (currentFunctionPurgeSize == Function.INVALID_STACK_DEPTH_CHANGE || currentFunctionPurgeSize == Function.UNKNOWN_STACK_DEPTH_CHANGE) { currentFunctionPurgeSize = 0; } NumberInputDialog numberInputDialog = new NumberInputDialog("Please Enter Function Purge", "Enter Function Purge", currentFunctionPurgeSize, -1048576, 1048576, false); numberInputDialog.setHelpLocation(new HelpLocation("FunctionPlugin", "Function_Purge")); if (!numberInputDialog.show()) { functionPlugin.getTool().setStatusInfo("User cancelled function purge"); return; } int newFunctionPurgeSize = numberInputDialog.getValue(); if (newFunctionPurgeSize != currentFunctionPurgeSize) { Command command = new SetFunctionPurgeCommand(function, newFunctionPurgeSize); PluginTool tool = functionPlugin.getTool(); Program program = function.getProgram(); if (!tool.execute(command, program)) { tool.setStatusInfo("Unable to set function purge on " + "function: " + function.getName()); } } }
Example 7
Source File: CreateArrayAction.java From ghidra with Apache License 2.0 | 5 votes |
private void createArrayInStructure(Program program, Address addr, int[] compPath) { PluginTool tool = plugin.getTool(); Data data = program.getListing().getDataContaining(addr); Data comp = null; if (data != null) { comp = data.getComponent(compPath); } if (comp == null) { tool.setStatusInfo("Create Array Failed! No data at " + addr); return; } DataType dt = comp.getDataType(); DataType parentDataType = comp.getParent().getBaseDataType(); if (!(parentDataType instanceof Structure)) { tool.setStatusInfo("Cannot create array here"); return; } Structure struct = (Structure) parentDataType; int maxElements = getMaxElements(struct, comp.getComponentIndex(), dt); int maxNoConflictElements = getMaxNoConflictElements(struct, comp.getComponentIndex(), dt); int numElements = getNumElements(dt, maxNoConflictElements, maxElements); Command cmd = new CreateArrayInStructureCmd(addr, numElements, dt, compPath); if (!tool.execute(cmd, program)) { tool.setStatusInfo(cmd.getStatusMsg()); } }
Example 8
Source File: CreateArrayAction.java From ghidra with Apache License 2.0 | 5 votes |
private void createArrayInStructure(Program program, InteriorSelection sel) { PluginTool tool = plugin.getTool(); ProgramLocation from = sel.getFrom(); Data data = program.getListing().getDataContaining(from.getAddress()); Data comp = null; if (data != null) { comp = data.getComponent(from.getComponentPath()); } if (comp == null) { tool.setStatusInfo("Create Array Failed! No data at " + from.getAddress()); return; } DataType dt = comp.getDataType(); DataType parentDataType = comp.getParent().getBaseDataType(); if (!(parentDataType instanceof Structure)) { tool.setStatusInfo("Cannot create array here"); return; } int length = sel.getByteLength(); int numElements = length / dt.getLength(); Command cmd = new CreateArrayInStructureCmd(from.getAddress(), numElements, dt, from.getComponentPath()); if (!tool.execute(cmd, program)) { tool.setStatusInfo(cmd.getStatusMsg()); } }
Example 9
Source File: ChooseDataTypeAction.java From ghidra with Apache License 2.0 | 5 votes |
private int getSizeForSelection(Program program, ProgramSelection selection) { PluginTool tool = plugin.getTool(); AddressRange range = selection.getFirstRange(); Address address = selection.getMinAddress(); Data data = program.getListing().getDataAt(address); if (data == null) { tool.setStatusInfo("Cannot set data type! No data at " + address); return -1; } return (int) range.getLength(); }
Example 10
Source File: CaptureFunctionDataTypesAction.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionContext context) { GTree gTree = (GTree) context.getContextObject(); TreePath selectionPath = gTree.getSelectionPath(); ArchiveNode node = (ArchiveNode) selectionPath.getLastPathComponent(); if (!node.getArchive().isModifiable()) { informNotModifiable(node); return; } Program program = plugin.getProgram(); AddressSetView currentSelection = plugin.getCurrentSelection(); if (currentSelection == null || currentSelection.isEmpty()) { currentSelection = program.getMemory(); } final DataTypeManager manager = node.getArchive().getDataTypeManager(); final PluginTool tool = plugin.getTool(); CaptureFunctionDataTypesCmd cmd = new CaptureFunctionDataTypesCmd(manager, currentSelection, new CaptureFunctionDataTypesListener() { @Override public void captureFunctionDataTypesCompleted( CaptureFunctionDataTypesCmd command) { tool.setStatusInfo("Captured function data types to \"" + manager.getName() + "\"."); } }); tool.executeBackgroundCommand(cmd, program); }
Example 11
Source File: FunctionReachabilityProvider.java From ghidra with Apache License 2.0 | 5 votes |
private boolean validateFunctions() { PluginTool tool = plugin.getTool(); String text = fromAddressField.getText(); if (isNumpty(text)) { tool.setStatusInfo("Must input two valid functions: 'from' address is empty", true); return false; } fromFunction = getFunction(text); if (fromFunction == null) { fromFunctionLabel.setText(""); tool.setStatusInfo( "Must input two valid functions: 'from' address is not in a function: " + text, true); return false; } fromFunctionLabel.setText(fromFunction.getName()); text = toAddressField.getText(); if (isNumpty(text)) { tool.setStatusInfo("Must input two valid functions: 'to' address is empty", true); return false; } toFunction = getFunction(text); if (toFunction == null) { toFunctionLabel.setText(""); tool.setStatusInfo( "Must input two valid functions: 'to' address is not in a function: " + text, true); return false; } toFunctionLabel.setText(toFunction.getName()); return true; }
Example 12
Source File: StackEditorPanel.java From ghidra with Apache License 2.0 | 4 votes |
@Override public void domainObjectRestored(DataTypeManagerDomainObject domainObject) { boolean reload = true; String objectType = "domain object"; if (domainObject instanceof Program) { objectType = "program"; } else if (domainObject instanceof DataTypeArchive) { objectType = "data type archive"; } DataTypeManager dtm = ((StackEditorModel) model).getOriginalDataTypeManager(); Composite originalDt = ((StackEditorModel) model).getOriginalComposite(); if (originalDt instanceof StackFrameDataType) { StackFrameDataType sfdt = (StackFrameDataType) originalDt; Function function = sfdt.getFunction(); if (function instanceof DatabaseObject) { if (!((DatabaseObject) function).checkIsValid()) { // Cancel Editor. provider.dispose(); PluginTool tool = ((StackEditorProvider) provider).getPlugin().getTool(); tool.setStatusInfo("Stack Editor was closed for " + provider.getName()); return; } } StackFrame stack = function.getStackFrame(); StackFrameDataType newSfdt = new StackFrameDataType(stack, dtm); if (!newSfdt.equals(((StackEditorModel) model).getViewComposite())) { originalDt = newSfdt; } } ((StackEditorModel) model).updateAndCheckChangeState(); if (model.hasChanges()) { String name = ((StackEditorModel) model).getTypeName(); // The user has modified the structure so prompt for whether or // not to reload the structure. String question = "The " + objectType + " \"" + domainObject.getName() + "\" has been restored.\n" + "\"" + model.getCompositeName() + "\" may have changed outside the editor.\n" + "Discard edits & reload the " + name + " Editor?"; String title = "Reload " + name + " Editor?"; int response = OptionDialog.showYesNoDialogWithNoAsDefaultButton(this, title, question); if (response != 1) { reload = false; } } if (reload) { cancelCellEditing(); // TODO // boolean lockState = model.isLocked(); // save the lock state model.load(originalDt, model.isOffline()); // reload the structure // model.setLocked(lockState); // restore the lock state model.updateAndCheckChangeState(); } else { ((StackEditorModel) model).refresh(); } }
Example 13
Source File: CreateStructureAction.java From ghidra with Apache License 2.0 | 4 votes |
private void createStructureInStructure(Program program, InteriorSelection sel) { PluginTool tool = plugin.getTool(); ProgramLocation from = sel.getFrom(); ProgramLocation to = sel.getTo(); Data data = program.getListing().getDataContaining(from.getAddress()); Data comp = null; if (data != null) { comp = data.getComponent(from.getComponentPath()); } if (comp == null) { tool.setStatusInfo("Create Structure Failed! No data at " + from.getAddress()); return; } DataType parentDataType = comp.getParent().getBaseDataType(); if (!(parentDataType instanceof Structure)) { tool.setStatusInfo("Cannot create structure here"); return; } Address newStructureAddress = from.getAddress(); int[] fromPath = from.getComponentPath(); int[] toPath = to.getComponentPath(); Structure tempStructure = null; try { tempStructure = StructureFactory.createStructureDataTypeInStrucuture(program, newStructureAddress, fromPath, toPath); } catch (Exception exc) { tool.setStatusInfo("Create structure failed: " + exc.getMessage()); return; } Structure userChoice = createStructureDialog.showCreateStructureDialog(program, tempStructure); if (userChoice != null) { CreateStructureInStructureCmd cmd = new CreateStructureInStructureCmd(userChoice, newStructureAddress, fromPath, toPath); if (!tool.execute(cmd, program)) { tool.setStatusInfo(cmd.getStatusMsg()); } else { plugin.updateRecentlyUsed(cmd.getNewDataType()); } } }
Example 14
Source File: CreateStructureAction.java From ghidra with Apache License 2.0 | 4 votes |
private void createStructureInProgram(Program program, ProgramSelection sel) { PluginTool tool = plugin.getTool(); if (sel.getNumAddressRanges() > 1) { tool.setStatusInfo("Can only create structure on contiguous selection"); return; } if (sel.getNumAddresses() > Integer.MAX_VALUE) { tool.setStatusInfo("Can't create structures greater than 0x7fffffff bytes"); return; } Data data = program.getListing().getDataContaining(sel.getMinAddress()); if (data == null) { tool.setStatusInfo("Create structure failed! No data at " + sel.getMinAddress()); return; } Address structureAddress = sel.getMinAddress(); int structureLength = (int) sel.getNumAddresses(); // create a temporary structure to compare with the data types // in the current sytem Structure tempStructure = null; try { tempStructure = StructureFactory.createStructureDataType(program, structureAddress, structureLength); } catch (Exception exc) { tool.setStatusInfo("Create structure failed: " + exc.getMessage()); return; } Structure userChoice = createStructureDialog.showCreateStructureDialog(program, tempStructure); // exit if the user cancels the operation if (userChoice != null) { CreateStructureCmd cmd = new CreateStructureCmd(userChoice, structureAddress); if (!tool.execute(cmd, program)) { tool.setStatusInfo(cmd.getStatusMsg()); } else { plugin.updateRecentlyUsed(cmd.getNewDataType()); } } }