Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-3627 Copy GhidraURL action revisions

ghidra14b5022ecc1b5
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/FrontEndPlugin/Ghidra_Front_end.htm b/Ghidra/Features/Base/src/main/help/help/topics/FrontEndPlugin/Ghidra_Front_end.htm
index b4528bc66b..abb804637e 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/FrontEndPlugin/Ghidra_Front_end.htm
+++ b/Ghidra/Features/Base/src/main/help/help/topics/FrontEndPlugin/Ghidra_Front_end.htm
@@ -212,6 +212,27 @@
<P><IMG src="help/shared/note.png" border="0">External links will never show a broken
link state since they are not evaluated for such conditions.</P>
+ </BLOCKQUOTE>
+
+ <H4><A name="Copy_GhidraURL"></A>Copy Ghidra URL for File</H4>
+
+ <BLOCKQUOTE>
+ <P>The Ghidra URL of a selected project file, or file-link, may be copied in text form
+ into the Copy/Paste Clipboard for use in other places where a URL may be pasted
+ (e.g., Listing comment annotations, external applications, etc.).
+ This may be done for a file in the active project or a viewed project/repository.
+ A shared Ghidra project URL will be produced when possible, otherwise a local
+ project URL will be produced.</P>
+
+ <OL>
+ <LI>
+ Select a single file or file-link from the active project tree or viewed
+ project/repository tree.
+ </LI>
+
+ <LI>Right mouse click and choose the <I>Copy GhidraURL</I> option.
+ The URL text is now available in the clipboard for a subsequent text Paste operation.</LI>
+ </OL>
</BLOCKQUOTE>
<H4><A name="Cut"></A>Move Folders and Files</H4>
@@ -239,7 +260,7 @@
file that is in use or a folder that contains a file that is in use.</P>
</BLOCKQUOTE>
- <H4>Drag/Drop for Copy</H4>
+ <H4>Drag/Drop for File or Folder Copy</H4>
<BLOCKQUOTE>
<P>You can get the same effect of Copy/Paste using Drag and Drop.</P>
@@ -247,7 +268,7 @@
<OL>
<LI>Select a folder or file (or multiple folders and files).</LI>
- <LI>Hold the Ctrl key down and drag the object to another folder.</LI>
+ <LI><B>Hold the Ctrl key down and drag</B> the object to another folder.</LI>
<LI>Drop the object on a folder.</LI>
</OL>
@@ -261,7 +282,7 @@
regardless of whether you hold down the Ctrl key.</P>
</BLOCKQUOTE>
- <H4>Drag/Drop for Move</H4>
+ <H4>Drag/Drop for File or Folder Move</H4>
<BLOCKQUOTE>
<P>You can get the same effect of Cut/Paste using Drag and Drop.</P>
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 05c1a32bdf..7c2f7b0036 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
@@ -238,10 +238,12 @@ public class FrontEndPlugin extends Plugin
newFolderAction = new FrontEndProjectDataNewFolderAction(owner, groupName);
groupName = "Cut/copy/paste/new2";
+ copyGhidraURLAction = new ProjectDataCopyGhidraURLAction(owner, groupName);
+
+ groupName = "Cut/copy/paste/new3";
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);
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
index eea38b0522..ba9eee48e9 100644
--- 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
@@ -19,16 +19,13 @@ 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.framework.model.DomainFile;
+import ghidra.framework.model.LinkFileInfo;
import ghidra.util.HelpLocation;
import ghidra.util.Msg;
@@ -45,21 +42,25 @@ public class ProjectDataCopyGhidraURLAction extends ProjectDataCopyCutBaseAction
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);
+ DomainFile df = context.getSelectedFiles().getFirst();
+ LinkFileInfo linkInfo = df.getLinkInfo();
+ if (linkInfo != null && linkInfo.isFolderLink()) {
+ return; // folder-link not supported
}
- }
- else {
- url = context.getSelectedFolders().getFirst().getSharedProjectURL();
+ URL url = df.getSharedProjectURL(null);
if(url == null) {
- url = context.getSelectedFolders().getFirst().getLocalProjectURL();
+ url = df.getLocalProjectURL(null);
+ }
+ if (url != null) {
+ clipboard.setContents(new StringSelection(url.toString()), null);
+ }
+ else {
+ Msg.showError(ProjectDataCopyGhidraURLAction.class, null,
+ "Copy GhidraURL Failed",
+ "Failed to create file URL for: " + df.getPathname());
}
}
-
- clipboard.setContents(new StringSelection(url.toString()), null);
}
catch (IllegalStateException ise) {
// this can happen when other applications are accessing the system clipboard
@@ -71,12 +72,12 @@ public class ProjectDataCopyGhidraURLAction extends ProjectDataCopyCutBaseAction
@Override
protected boolean isEnabledForContext(FrontEndProjectTreeContext context) {
- if (!context.hasExactlyOneFileOrFolder()) {
+ if (context.hasExactlyOneFileOrFolder() && context.getFileCount() != 1) {
return false;
}
-
- Project activeProject = AppInfo.getActiveProject();
- if (activeProject == null) {
+ DomainFile df = context.getSelectedFiles().getFirst();
+ LinkFileInfo linkInfo = df.getLinkInfo();
+ if (linkInfo != null && linkInfo.isFolderLink()) {
return false;
}
return true;