mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-29 23:52:00 +00:00
Merge remote-tracking branch
'origin/GP-4318_ryanmkurtz_PR-6195_austenadler_copy-special' (Closes #6195)
This commit is contained in:
commit
4f95fdd111
@ -182,6 +182,10 @@
|
||||
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>Byte Source Offset</B> - Copies the byte source offset from the start of the file for
|
||||
each address in the current selection. If the address is not backed by a file,
|
||||
<CODE><NO_OFFSET></CODE> is copied.</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>
|
||||
|
@ -44,10 +44,12 @@ 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.mem.AddressSourceInfo;
|
||||
import ghidra.program.database.symbol.CodeSymbol;
|
||||
import ghidra.program.database.symbol.FunctionSymbol;
|
||||
import ghidra.program.model.address.*;
|
||||
import ghidra.program.model.listing.*;
|
||||
import ghidra.program.model.mem.Memory;
|
||||
import ghidra.program.model.symbol.*;
|
||||
import ghidra.program.util.*;
|
||||
import ghidra.util.Msg;
|
||||
@ -65,6 +67,8 @@ public class CodeBrowserClipboardProvider extends ByteCopier
|
||||
new ClipboardType(DataFlavor.stringFlavor, "Address");
|
||||
public static final ClipboardType ADDRESS_TEXT_WITH_OFFSET_TYPE =
|
||||
new ClipboardType(DataFlavor.stringFlavor, "Address w/ Offset");
|
||||
public static final ClipboardType BYTE_SOURCE_OFFSET_TYPE =
|
||||
new ClipboardType(DataFlavor.stringFlavor, "Byte Source Offset");
|
||||
public static final ClipboardType CODE_TEXT_TYPE =
|
||||
new ClipboardType(DataFlavor.stringFlavor, "Formatted Code");
|
||||
public static final ClipboardType LABELS_COMMENTS_TYPE =
|
||||
@ -94,6 +98,7 @@ public class CodeBrowserClipboardProvider extends ByteCopier
|
||||
list.add(CPP_BYTE_ARRAY_TYPE);
|
||||
list.add(ADDRESS_TEXT_TYPE);
|
||||
list.add(ADDRESS_TEXT_WITH_OFFSET_TYPE);
|
||||
list.add(BYTE_SOURCE_OFFSET_TYPE);
|
||||
|
||||
return list;
|
||||
}
|
||||
@ -221,6 +226,9 @@ public class CodeBrowserClipboardProvider extends ByteCopier
|
||||
else if (copyType == ADDRESS_TEXT_WITH_OFFSET_TYPE) {
|
||||
return copySymbolString(monitor);
|
||||
}
|
||||
else if (copyType == BYTE_SOURCE_OFFSET_TYPE) {
|
||||
return copyByteSourceOffset(monitor);
|
||||
}
|
||||
else if (copyType == CODE_TEXT_TYPE) {
|
||||
return copyCode(monitor);
|
||||
}
|
||||
@ -382,6 +390,24 @@ public class CodeBrowserClipboardProvider extends ByteCopier
|
||||
return createStringTransferable(StringUtils.join(strings, "\n"));
|
||||
}
|
||||
|
||||
private Transferable copyByteSourceOffset(TaskMonitor monitor) {
|
||||
AddressSetView addrs = getSelectedAddresses();
|
||||
Memory currentMemory = currentProgram.getMemory();
|
||||
List<String> strings = new ArrayList<>();
|
||||
AddressIterator addresses = addrs.getAddresses(true);
|
||||
while (addresses.hasNext() && !monitor.isCancelled()) {
|
||||
AddressSourceInfo addressSourceInfo =
|
||||
currentMemory.getAddressSourceInfo(addresses.next());
|
||||
if (addressSourceInfo != null) {
|
||||
long fileOffset = addressSourceInfo.getFileOffset();
|
||||
String fileOffsetString =
|
||||
fileOffset != -1 ? "%x".formatted(fileOffset) : "<NO_OFFSET>";
|
||||
strings.add(fileOffsetString);
|
||||
}
|
||||
}
|
||||
return createStringTransferable(String.join("\n", strings));
|
||||
}
|
||||
|
||||
protected Transferable copyCode(TaskMonitor monitor) {
|
||||
|
||||
AddressSetView addressSet = getSelectedAddresses();
|
||||
|
Loading…
Reference in New Issue
Block a user