Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-3627 add ability to copy a GhidraURL in the Project Window View.

ghidraffed2c87fed8106
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndPlugin.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndPlugin.java
index 11d2f9d466..05c1a32bdf 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndPlugin.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndPlugin.java
@@ -135,6 +135,7 @@ public class FrontEndPlugin extends Plugin
private ProjectDataCutAction cutAction;
private ClearCutAction clearCutAction;
private ProjectDataCopyAction copyAction;
+ private ProjectDataCopyGhidraURLAction copyGhidraURLAction;
private ProjectDataPasteAction pasteAction;
private ProjectDataPasteLinkAction pasteLinkAction;
private ProjectDataPasteLinkAction pasteRelativeLinkAction;
@@ -240,6 +241,7 @@ public class FrontEndPlugin extends Plugin
cutAction = new ProjectDataCutAction(owner, groupName);
clearCutAction = new ClearCutAction(owner);
copyAction = new ProjectDataCopyAction(owner, groupName);
+ copyGhidraURLAction = new ProjectDataCopyGhidraURLAction(owner, groupName);
pasteAction = new ProjectDataPasteAction(owner, groupName);
pasteLinkAction = new ProjectDataPasteLinkAction(owner, groupName, false);
pasteRelativeLinkAction = new ProjectDataPasteLinkAction(owner, groupName, true);
@@ -264,6 +266,7 @@ public class FrontEndPlugin extends Plugin
tool.addAction(cutAction);
tool.addAction(clearCutAction);
tool.addAction(copyAction);
+ tool.addAction(copyGhidraURLAction);
tool.addAction(pasteAction);
tool.addAction(pasteLinkAction);
tool.addAction(pasteRelativeLinkAction);
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/projectdata/actions/ProjectDataCopyGhidraURLAction.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/projectdata/actions/ProjectDataCopyGhidraURLAction.java
new file mode 100644
index 0000000000..eea38b0522
--- /dev/null
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/projectdata/actions/ProjectDataCopyGhidraURLAction.java
@@ -0,0 +1,84 @@
+/* ###
+ * 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.framework.main.projectdata.actions;
+
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.StringSelection;
+import java.net.URL;
+
+import javax.swing.Icon;
+
+import org.apache.commons.collections4.CollectionUtils;
+
+import docking.action.MenuData;
+import docking.dnd.GClipboard;
+import generic.theme.GIcon;
+import ghidra.framework.main.AppInfo;
+import ghidra.framework.main.datatree.FrontEndProjectTreeContext;
+import ghidra.framework.model.Project;
+import ghidra.util.HelpLocation;
+import ghidra.util.Msg;
+
+public class ProjectDataCopyGhidraURLAction extends ProjectDataCopyCutBaseAction {
+
+ public ProjectDataCopyGhidraURLAction(String owner, String group) {
+ super("Copy GhidraURL", owner);
+ setPopupMenuData(new MenuData(new String[] { "Copy GhidraURL" }, null, group));
+ setHelpLocation(new HelpLocation("FrontEndPlugin", "Copy GhidraURL"));
+ }
+
+ @Override
+ protected void actionPerformed(FrontEndProjectTreeContext context) {
+ Clipboard clipboard = GClipboard.getSystemClipboard();
+
+ try {
+ URL url = null;
+ if(CollectionUtils.isNotEmpty(context.getSelectedFiles())) {
+ url = context.getSelectedFiles().getFirst().getSharedProjectURL(null);
+ if(url == null) {
+ url = context.getSelectedFiles().getFirst().getLocalProjectURL(null);
+ }
+ }
+ else {
+ url = context.getSelectedFolders().getFirst().getSharedProjectURL();
+ if(url == null) {
+ url = context.getSelectedFolders().getFirst().getLocalProjectURL();
+ }
+ }
+
+ clipboard.setContents(new StringSelection(url.toString()), null);
+ }
+ catch (IllegalStateException ise) {
+ // this can happen when other applications are accessing the system clipboard
+ Msg.showError(ProjectDataCopyGhidraURLAction.class, null, "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.");
+ }
+ }
+
+ @Override
+ protected boolean isEnabledForContext(FrontEndProjectTreeContext context) {
+ if (!context.hasExactlyOneFileOrFolder()) {
+ return false;
+ }
+
+ Project activeProject = AppInfo.getActiveProject();
+ if (activeProject == null) {
+ return false;
+ }
+ return true;
+ }
+}