mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-02-16 15:40:14 +00:00
Merge remote-tracking branch 'origin/GP-3626_ghidraffe_CodeBrowserCopyGhidraURL_2'
This commit is contained in:
commit
c05dc21ead
@ -29,6 +29,8 @@
|
||||
<LI><A href="#ByteString">Byte String</A></LI>
|
||||
|
||||
<LI><A href="#ByteString_NoSpaces">Byte String (no spaces)</A></LI>
|
||||
|
||||
<LI><A href="#GhidraURL">GhidraURL</A></LI>
|
||||
</UL>
|
||||
|
||||
<P>The default copy operation in the Code Browser (achieved by executing the <A href=
|
||||
@ -179,6 +181,9 @@
|
||||
<LI><B>Address w/ Offset</B> - Copies the address at the cursor or each address in the
|
||||
current selection. The text is formatted to show the offset from the entry point of the
|
||||
function, for example: <CODE>main + 0x2</CODE></LI>
|
||||
|
||||
<LI><B>GhidraURL</B> <A name="GhidraURL"></A> - Creates a GhidraURL for the address under the
|
||||
cursor then copies that URL to the clipboard.</LI>
|
||||
</UL>
|
||||
|
||||
<P>The Code Browser <B>Listing</B> window can paste the following formats:</P>
|
||||
|
@ -18,6 +18,7 @@ package ghidra.app.plugin.core.clipboard;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
@ -41,6 +42,7 @@ import ghidra.app.services.ClipboardContentProviderService;
|
||||
import ghidra.app.util.*;
|
||||
import ghidra.app.util.viewer.listingpanel.ListingModel;
|
||||
import ghidra.framework.cmd.Command;
|
||||
import ghidra.framework.model.DomainFile;
|
||||
import ghidra.framework.plugintool.PluginTool;
|
||||
import ghidra.program.database.symbol.CodeSymbol;
|
||||
import ghidra.program.database.symbol.FunctionSymbol;
|
||||
@ -71,6 +73,10 @@ public class CodeBrowserClipboardProvider extends ByteCopier
|
||||
new ClipboardType(CodeUnitInfoTransferable.localDataTypeFlavor, "Labels");
|
||||
public static final ClipboardType COMMENTS_TYPE =
|
||||
new ClipboardType(CodeUnitInfoTransferable.localDataTypeFlavor, "Comments");
|
||||
public static final ClipboardType GHIDRA_LOCAL_URL_TYPE =
|
||||
new ClipboardType(DataFlavor.stringFlavor, "Local GhidraURL");
|
||||
public static final ClipboardType GHIDRA_SHARED_URL_TYPE =
|
||||
new ClipboardType(DataFlavor.stringFlavor, "Shared GhidraURL");
|
||||
|
||||
private static final List<ClipboardType> COPY_TYPES = createCopyTypesList();
|
||||
|
||||
@ -178,7 +184,32 @@ public class CodeBrowserClipboardProvider extends ByteCopier
|
||||
|
||||
@Override
|
||||
public List<ClipboardType> getCurrentCopyTypes() {
|
||||
return COPY_TYPES;
|
||||
ClipboardType urlType = getGhidraUrlClipboardType();
|
||||
if (urlType == null) {
|
||||
return COPY_TYPES;
|
||||
}
|
||||
|
||||
List<ClipboardType> currentCopyTypes = new ArrayList<>(COPY_TYPES);
|
||||
currentCopyTypes.add(urlType);
|
||||
return currentCopyTypes;
|
||||
}
|
||||
|
||||
private ClipboardType getGhidraUrlClipboardType() {
|
||||
if (currentProgram == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DomainFile domainFile = currentProgram.getDomainFile();
|
||||
if (domainFile == null) {
|
||||
return null;
|
||||
}
|
||||
if (domainFile.getLocalProjectURL(null) != null) {
|
||||
return GHIDRA_LOCAL_URL_TYPE;
|
||||
}
|
||||
if (domainFile.getSharedProjectURL(null) != null) {
|
||||
return GHIDRA_SHARED_URL_TYPE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -202,6 +233,12 @@ public class CodeBrowserClipboardProvider extends ByteCopier
|
||||
else if (copyType == COMMENTS_TYPE) {
|
||||
return copyLabelsComments(false, true, monitor);
|
||||
}
|
||||
else if (copyType == GHIDRA_LOCAL_URL_TYPE) {
|
||||
return copyLocalGhidraURL();
|
||||
}
|
||||
else if (copyType == GHIDRA_SHARED_URL_TYPE) {
|
||||
return copySharedGhidraURL();
|
||||
}
|
||||
|
||||
return copyBytes(copyType, monitor);
|
||||
}
|
||||
@ -390,6 +427,26 @@ public class CodeBrowserClipboardProvider extends ByteCopier
|
||||
return new CodeUnitInfoTransferable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Local GhidraURL to the currentLocation within the currentProgram.
|
||||
* @return string transferable GhidraURL type.
|
||||
*/
|
||||
private Transferable copyLocalGhidraURL() {
|
||||
String address = currentLocation.getAddress().toString();
|
||||
URL url = currentProgram.getDomainFile().getLocalProjectURL(address);
|
||||
return createStringTransferable(url.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Shared GhidraURL to the currentLocation within the currentProgram.
|
||||
* @return string transferable GhidraURL type.
|
||||
*/
|
||||
private Transferable copySharedGhidraURL() {
|
||||
String address = currentLocation.getAddress().toString();
|
||||
URL url = currentProgram.getDomainFile().getSharedProjectURL(address);
|
||||
return createStringTransferable(url.toString());
|
||||
}
|
||||
|
||||
private boolean pasteLabelsComments(Transferable pasteData, boolean pasteLabels,
|
||||
boolean pasteComments) {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user