Skip to content

Commit 3535227

Browse files
authored
Add Markdown deep links (#1)
1 parent b2a9906 commit 3535227

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ When you (or somebody else) clicks on the link the referenced binary will open i
2929

3030
> ⚠️ Currently the link handler does not distinguish between projects, and (on non-linux platforms) it cannot open Ghidra by itself. Therefore you will need to have Ghidra open and the project containing the binary referenced in the link open.
3131
32+
You can use the "Copy Markdown Deep Link" content menu item to copy a fully formatted link, where the symbol name or address is the title of the link and the `disas://` is the target.
33+
3234
# ⚙️ Installation
3335
### Linux
3436
1. Download and install the latest release of the ghidra-deep-links extension from https://github.com/foundryzero/ghidra-deep-links/releases

extension/src/main/java/deeplinks/DeepLinksToolPlugin.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public DeepLinksToolPlugin(PluginTool tool) {
4848
}
4949

5050
private void registerActions() {
51+
// Copy link only action
5152
DockingAction copyLinkToAddressAction = new DockingAction("Copy Deep Link", getName()) {
5253
@Override
5354
public boolean isAddToPopup(ActionContext context) {
@@ -77,6 +78,42 @@ public void actionPerformed(ActionContext context) {
7778
copyLinkToAddressAction.setPopupMenuData(new MenuData(new String[] { "Copy Deep Link" }));
7879
copyLinkToAddressAction.setEnabled(true);
7980
tool.addAction(copyLinkToAddressAction);
81+
82+
DockingAction copyMarkdownLinkToAddressAction = new DockingAction("Copy Markdown Deep Link", getName()) {
83+
@Override
84+
public boolean isAddToPopup(ActionContext context) {
85+
// This context menu only makes sense inside a Listing or Decompiler window.
86+
return (context instanceof ListingActionContext || context instanceof DecompilerActionContext);
87+
}
88+
89+
@Override
90+
public void actionPerformed(ActionContext context) {
91+
if (!(context instanceof ListingActionContext || context instanceof DecompilerActionContext)) {
92+
return;
93+
}
94+
95+
NavigatableActionContext naviContext = (NavigatableActionContext) context;
96+
Program prog = naviContext.getProgram();
97+
ProgramLocation loc = naviContext.getLocation();
98+
99+
SymbolTable symbols = prog.getSymbolTable();
100+
Symbol symbol = symbols.getPrimarySymbol(loc.getAddress());
101+
102+
String addressText = "0x" + loc.getAddress().toString();
103+
String url = buildURL(addressText, prog, symbol);
104+
String linkTitle = addressText;
105+
if (symbol != null) {
106+
linkTitle = symbol.getName();
107+
}
108+
String markdown = String.format("[`%s`](%s)", linkTitle, url);
109+
copyToSystemClipboard(markdown);
110+
}
111+
};
112+
113+
// Adds the action to the right-click menu, and enables it.
114+
copyMarkdownLinkToAddressAction.setPopupMenuData(new MenuData(new String[] { "Copy Markdown Deep Link" }));
115+
copyMarkdownLinkToAddressAction.setEnabled(true);
116+
tool.addAction(copyMarkdownLinkToAddressAction);
80117
}
81118

82119
private String buildURL(String loc, Program program, Symbol symbol) {

0 commit comments

Comments
 (0)