mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
Merge remote-tracking branch
'origin/GP-1195-dragonmacher-decompiler-edit-label-action--SQUASHED' Also fixed some bad characters (Closes #1751)
This commit is contained in:
commit
1ebf208b94
5 changed files with 120 additions and 25 deletions
|
@ -43,7 +43,7 @@ import ghidra.util.Msg;
|
|||
packageName = CorePluginPackage.NAME,
|
||||
category = PluginCategoryNames.CODE_VIEWER,
|
||||
shortDescription = "Edit Labels",
|
||||
description = "This plugin provides actions and dialogs for adding, removing and editing labels in the code browser",
|
||||
description = "This plugin provides actions and dialogs for adding, removing and editing labels",
|
||||
servicesRequired = { GoToService.class }
|
||||
)
|
||||
//@formatter:on
|
||||
|
@ -56,8 +56,7 @@ public class LabelMgrPlugin extends Plugin {
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugintool
|
||||
* reference to the tool
|
||||
* @param tool the tool
|
||||
*/
|
||||
public LabelMgrPlugin(PluginTool tool) {
|
||||
super(tool);
|
||||
|
@ -65,9 +64,6 @@ public class LabelMgrPlugin extends Plugin {
|
|||
setupActions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creation of the Label Mgr plugin actions.
|
||||
*/
|
||||
private void setupActions() {
|
||||
DockingAction addLabelAction = new AddLabelAction(this);
|
||||
tool.addAction(addLabelAction); // add the plugin action
|
||||
|
@ -92,10 +88,6 @@ public class LabelMgrPlugin extends Plugin {
|
|||
tool.addAction(allHistoryAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the necessary dialogs for this plugin. The dialogs are Name Label
|
||||
* and Choose Alias.
|
||||
*/
|
||||
AddEditDialog getAddEditDialog() {
|
||||
if (addEditDialog == null) {
|
||||
addEditDialog = new AddEditDialog("", tool);
|
||||
|
@ -118,9 +110,10 @@ public class LabelMgrPlugin extends Plugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* Removes the label or alias that the cursor is over from the current label
|
||||
* field. If an exception is caught during the removal of the label or
|
||||
* alias, a message is written to the status area.
|
||||
* Removes the label or alias that the cursor is over from the current label field. If an
|
||||
* exception is caught during the removal of the label or alias, a message is written to the
|
||||
* status area.
|
||||
* @param context the action context
|
||||
*/
|
||||
protected void removeLabelCallback(ListingActionContext context) {
|
||||
Symbol s = getSymbol(context);
|
||||
|
@ -136,6 +129,7 @@ public class LabelMgrPlugin extends Plugin {
|
|||
/**
|
||||
* AddLabelAction calls this method when an action occurs. At this point in
|
||||
* time, all we want to do is to display the Add Label Dialog.
|
||||
* @param context the action context
|
||||
*/
|
||||
protected void addLabelCallback(ListingActionContext context) {
|
||||
getAddEditDialog().addLabel(context.getAddress(), context.getProgram());
|
||||
|
@ -144,6 +138,7 @@ public class LabelMgrPlugin extends Plugin {
|
|||
/**
|
||||
* EditLabelAction calls this method when an action occurs. At this point in
|
||||
* time, all we want to do is to display the Add Label Dialog.
|
||||
* @param context the action context
|
||||
*/
|
||||
void editLabelCallback(ListingActionContext context) {
|
||||
|
||||
|
@ -275,8 +270,8 @@ public class LabelMgrPlugin extends Plugin {
|
|||
/**
|
||||
* Return true if the given context has label history.
|
||||
*
|
||||
* @param contextObj
|
||||
* @return
|
||||
* @param context the action context
|
||||
* @return true if the given context has label history
|
||||
*/
|
||||
boolean hasLabelHistory(ListingActionContext context) {
|
||||
ProgramLocation location = context.getLocation();
|
||||
|
@ -298,10 +293,10 @@ public class LabelMgrPlugin extends Plugin {
|
|||
if (!(context.getLocation() instanceof OperandFieldLocation)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OperandFieldLocation opLoc = (OperandFieldLocation) context.getLocation();
|
||||
Address address = opLoc.getAddress();
|
||||
int opIndex = opLoc.getOperandIndex();
|
||||
|
||||
Data dataComp = getDataComponent(context);
|
||||
if (dataComp != null) {
|
||||
if (isInUnion(dataComp)) {
|
||||
|
@ -311,8 +306,6 @@ public class LabelMgrPlugin extends Plugin {
|
|||
}
|
||||
|
||||
ReferenceManager refMgr = context.getProgram().getReferenceManager();
|
||||
//SymbolTable st = currentProgram.getSymbolTable();
|
||||
|
||||
return refMgr.getPrimaryReferenceFrom(address, opIndex);
|
||||
}
|
||||
|
||||
|
|
|
@ -4454,6 +4454,22 @@
|
|||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="ActionRenameLabel">
|
||||
<title>Rename Label</title>
|
||||
<para>
|
||||
Rename the label corresponding to the token under the cursor.
|
||||
</para>
|
||||
<para>
|
||||
A label can be renamed by triggering this action while the corresponding label token is
|
||||
under the cursor. This action brings up the
|
||||
<a href="help/topics/LabelMgrPlugin/Labels.htm#AddEditDialog">Edit Label Dialog</a>.
|
||||
</para>
|
||||
<para>
|
||||
The change will be immediately visible across all references to the label
|
||||
(including in any Decompiler, Listing, and Functions windows).
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="ActionRenameField">
|
||||
<title>Rename Field</title>
|
||||
<para>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
function in the Code Browser, then select the
|
||||
<span class="guiicon">
|
||||
<span class="inlinemediaobject"><img src="images/decompileFunction.gif" width="16" height="16"></span>
|
||||
</span> icon from the tool bar, or the
|
||||
</span> icon from the tool bar, or the
|
||||
<span class="bold"><strong>Decompile</strong></span> option from the
|
||||
<span class="bold"><strong>Window</strong></span> menu in the tool.
|
||||
</p>
|
||||
|
@ -91,7 +91,7 @@
|
|||
Initially pushing
|
||||
<span class="guiicon">
|
||||
<span class="inlinemediaobject"><img src="images/decompileFunction.gif" width="16" height="16"></span>
|
||||
</span> or selecting
|
||||
</span> or selecting
|
||||
<span class="bold"><strong>Decompile</strong></span> from the <span class="bold"><strong>Window</strong></span> menu in the tool
|
||||
brings up the <span class="emphasis"><em>main</em></span> window. The main window always displays the function
|
||||
at the <span class="emphasis"><em>current address</em></span> within the Code Browser and follows as the user navigates
|
||||
|
@ -153,7 +153,7 @@
|
|||
Pressing the
|
||||
<span class="guiicon">
|
||||
<span class="inlinemediaobject"><img src="images/camera-photo.png" width="16" height="16"></span>
|
||||
</span> icon
|
||||
</span> icon
|
||||
in another Decompiler window's toolbar causes a <span class="emphasis"><em>Snapshot</em></span> window
|
||||
to be created, which initially shows decompilation of the same function. Multiple
|
||||
Snapshot windows can be brought up to show decompilation of different functions
|
||||
|
@ -237,7 +237,7 @@
|
|||
<p>
|
||||
<span class="guiicon">
|
||||
<span class="inlinemediaobject"><img src="images/page_edit.png" width="16" height="16"></span>
|
||||
</span> - button
|
||||
</span> - button
|
||||
</p>
|
||||
<p>
|
||||
Exports the decompiled result of the current function to a file. A file chooser
|
||||
|
@ -262,7 +262,7 @@
|
|||
<p>
|
||||
<span class="guiicon">
|
||||
<span class="inlinemediaobject"><img src="images/camera-photo.png" width="16" height="16"></span>
|
||||
</span> - button
|
||||
</span> - button
|
||||
</p>
|
||||
<p>
|
||||
Creates a new <span class="emphasis"><em>Snapshot</em></span> window. The <span class="emphasis"><em>Snapshot</em></span> window
|
||||
|
@ -279,7 +279,7 @@
|
|||
<p>
|
||||
<span class="guiicon">
|
||||
<span class="inlinemediaobject"><img src="images/reload3.png" width="16" height="16"></span>
|
||||
</span> - button
|
||||
</span> - button
|
||||
</p>
|
||||
<p>
|
||||
Triggers a re-decompilation of the current function displayed in the window.
|
||||
|
@ -307,7 +307,7 @@
|
|||
<p>
|
||||
<span class="guiicon">
|
||||
<span class="inlinemediaobject"><img src="images/page_white_copy.png" width="16" height="16"></span>
|
||||
</span> - button
|
||||
</span> - button
|
||||
</p>
|
||||
<p>
|
||||
Copies the currently selected text in the decompiler window to the clipboard.
|
||||
|
@ -1049,6 +1049,26 @@
|
|||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="sect2">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="ActionRenameLabel"></a>Rename Label</h3></div></div></div>
|
||||
|
||||
<p>
|
||||
Rename the label corresponding to the token under the cursor.
|
||||
</p>
|
||||
<p>
|
||||
A label can be renamed by triggering this action while the corresponding label token is
|
||||
under the cursor. This action brings up the
|
||||
<a href="help/topics/LabelMgrPlugin/Labels.htm#AddEditDialog">Edit Label Dialog</a>.
|
||||
</p>
|
||||
<p>
|
||||
The change will be immediately visible across all references to the label
|
||||
(including in any Decompiler, Listing, and Functions windows).
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="sect2">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="ActionRenameField"></a>Rename Field</h3></div></div></div>
|
||||
|
|
|
@ -773,6 +773,10 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
|
|||
RenameFunctionAction renameFunctionAction = new RenameFunctionAction();
|
||||
setGroupInfo(renameFunctionAction, functionGroup, subGroupPosition++);
|
||||
|
||||
// not a function action, but it fits nicely in this group
|
||||
RenameLabelAction renameLabelAction = new RenameLabelAction();
|
||||
setGroupInfo(renameLabelAction, functionGroup, subGroupPosition++);
|
||||
|
||||
//
|
||||
// Variables
|
||||
//
|
||||
|
@ -981,6 +985,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
|
|||
addLocalAction(overrideSigAction);
|
||||
addLocalAction(deleteSigAction);
|
||||
addLocalAction(renameFunctionAction);
|
||||
addLocalAction(renameLabelAction);
|
||||
addLocalAction(debugFunctionAction);
|
||||
addLocalAction(convertAction);
|
||||
addLocalAction(findAction);
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.app.plugin.core.decompile.actions;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import docking.action.KeyBindingData;
|
||||
import docking.action.MenuData;
|
||||
import ghidra.app.decompiler.ClangLabelToken;
|
||||
import ghidra.app.decompiler.ClangToken;
|
||||
import ghidra.app.plugin.core.decompile.DecompilerActionContext;
|
||||
import ghidra.app.util.AddEditDialog;
|
||||
import ghidra.app.util.HelpTopics;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.model.symbol.Symbol;
|
||||
import ghidra.program.model.symbol.SymbolTable;
|
||||
import ghidra.util.HelpLocation;
|
||||
|
||||
public class RenameLabelAction extends AbstractDecompilerAction {
|
||||
|
||||
public RenameLabelAction() {
|
||||
super("Rename Label");
|
||||
|
||||
setHelpLocation(new HelpLocation(HelpTopics.DECOMPILER, "ActionRenameLabel"));
|
||||
|
||||
// same keybinding as the other rename actions
|
||||
setKeyBindingData(new KeyBindingData(KeyEvent.VK_L, 0));
|
||||
setPopupMenuData(new MenuData(new String[] { "Rename Label" }, "Decompile"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {
|
||||
ClangToken tokenAtCursor = context.getTokenAtCursor();
|
||||
return (tokenAtCursor instanceof ClangLabelToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decompilerActionPerformed(DecompilerActionContext context) {
|
||||
Program program = context.getProgram();
|
||||
SymbolTable symbolTable = program.getSymbolTable();
|
||||
Address address = context.getAddress();
|
||||
Symbol symbol = symbolTable.getPrimarySymbol(address);
|
||||
AddEditDialog dialog = new AddEditDialog("", context.getTool());
|
||||
dialog.editLabel(symbol, context.getProgram());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue