Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
cde1f2b
chore(ENG-2785): stop sending advanced_analysis
brettwold Nov 10, 2026
74f570a
feat(ENG-4410): align plugin design with Ghidra themes and RevEng.AI …
robertmarsal Nov 10, 2026
9a7b420
fix(ENG-4233): open portal links via OS launcher; right-click to open…
robertmarsal Nov 10, 2026
f5c36a9
Merge pull request #217 from RevEngAI/chore-ENG-2785
brettwold Nov 10, 2026
129d27d
fix(ENG-4402): sort and colour BigDecimal similarity and confidence c…
robertmarsal Nov 10, 2026
d98da38
fix(ENG-4412): show only status in check status dialog (#222)
robertmarsal Nov 10, 2026
81f7b7a
test: assert theme colours in similarity cell colour test
robertmarsal Nov 10, 2026
66076e1
feat(ENG-4404): open matched binary in portal from function matching …
robertmarsal Nov 10, 2026
01c30a8
feat(ENG-4399): auto-run single function matching with 5 results (#224)
robertmarsal Nov 10, 2026
9ef7143
feat(ENG-4401): prompt users to update the plugin (#225)
robertmarsal Nov 11, 2026
a34938f
feat(ENG-4405): always show user submitted debug symbols option (#226)
robertmarsal Nov 11, 2026
d0f1c98
fix(ENG-4375): handle unsized data types in decoder (#227)
robertmarsal Nov 11, 2026
a0859be
feat(ENG-4421): bump ai.reveng:sdk to 4.75.1-rc.1
vgoat21 Nov 11, 2026
6567b3b
ci: run tests on PRs into staging
vgoat21 Nov 11, 2026
554a2d5
Merge pull request #228 from RevEngAI/joshuavillaltaesp/eng-4421-ghid…
vgoat21 Nov 11, 2026
839ad1f
fix(ENG-4400): keep Ghidra responsive when the network is down
vgoat21 Nov 11, 2026
3d6ffdd
Merge pull request #231 from RevEngAI/joshuavillaltaesp/eng-4400-ghid…
vgoat21 Nov 11, 2026
3e4ba55
feat(ENG-4403): add platform, architecture and user filters to functi…
vgoat21 Nov 11, 2026
a03b9a4
Merge pull request #232 from RevEngAI/joshuavillaltaesp/eng-4403-ghid…
vgoat21 Nov 11, 2026
e528615
feat(ENG-4406): redesign function matching dialog and fix its progres…
vgoat21 Nov 11, 2026
347caea
test(ENG-4406): wait for the automatic match before pressing Match Fu…
vgoat21 Nov 11, 2026
9ff2be7
fix: guard against null pointer exceptions and related crashes (#230)
robertmarsal Nov 11, 2026
5690732
test(ENG-4406): check the dialog is idle on the EDT before pressing M…
vgoat21 Nov 11, 2026
f58df8a
Merge pull request #233 from RevEngAI/joshuavillaltaesp/eng-4406-ghid…
vgoat21 Nov 11, 2026
eec4a86
feat(ENG-4411): transfer name, signature or both from function matching
vgoat21 Nov 11, 2026
4d8839c
Merge pull request #234 from RevEngAI/joshuavillaltaesp/eng-4411-ghid…
vgoat21 Nov 11, 2026
b8cb86c
fix(ENG-4453): don't overwrite real signatures with the server placeh…
vgoat21 Nov 11, 2026
3af051b
Merge pull request #235 from RevEngAI/joshuavillaltaesp/eng-4453-ghid…
vgoat21 Nov 11, 2026
82c139b
ci: don't fail the build when publishing the test report flakes
vgoat21 Nov 11, 2026
3fb6e55
Merge pull request #237 from RevEngAI/ci/test-report-continue-on-erro…
vgoat21 Nov 11, 2026
1ee24c4
Give each TypedApiImplementation its own ApiClient
vgoat21 Nov 12, 2026
03937b4
Retry idempotent requests on 5xx/429 and give uploads their own client
vgoat21 Nov 12, 2026
c8430cb
Merge pull request #239 from RevEngAI/joshuavillaltaesp/eng-4479-ghid…
vgoat21 Nov 12, 2026
772d97f
Merge pull request #238 from RevEngAI/joshuavillaltaesp/eng-4454-ghid…
vgoat21 Nov 12, 2026
897ba7f
Key debounced local-edit pushes by program as well as address/type path
vgoat21 Nov 12, 2026
60311fd
Merge pull request #240 from RevEngAI/joshuavillaltaesp/eng-4466-ghid…
vgoat21 Nov 12, 2026
754cbd3
Suppress pushback per program and only around the sync's own writes
vgoat21 Nov 12, 2026
4dfaa7d
Merge pull request #242 from RevEngAI/joshuavillaltaesp/eng-4456-ghid…
vgoat21 Nov 12, 2026
d71198c
Batch local renames per program, skip local-variable edits, re-tag re…
vgoat21 Nov 12, 2026
3432059
Wait for in-flight event delivery before ending a server write
vgoat21 Nov 12, 2026
190e487
Merge pull request #243 from RevEngAI/joshuavillaltaesp/eng-4482-ghid…
vgoat21 Nov 12, 2026
0be7d63
Report failed local-edit pushes and send them on the next sync
vgoat21 Nov 12, 2026
c2a9121
Report a failing portal once and retry unpushed edits automatically
vgoat21 Nov 12, 2026
c9776ad
Stop retrying edits the portal will never take, and isolate them
vgoat21 Nov 12, 2026
5508ae9
Report the edits that go up once a refused API key works again
vgoat21 Nov 12, 2026
ce7f6bd
Merge pull request #244 from RevEngAI/joshuavillaltaesp/eng-4455-ghid…
vgoat21 Nov 12, 2026
76fee77
fix(ENG-4464): bound the auto-unstrip poller, make it stoppable and s…
vgoat21 Nov 12, 2026
94c6a18
fix(ENG-4459): undo a half-finished attach and offer a retry
vgoat21 Nov 12, 2026
cbe9c8f
fix(ENG-4457): rename on the portal only the matches applied locally
vgoat21 Nov 12, 2026
da32b90
fix(ENG-4457): leave the transferred renames to the reactive push
vgoat21 Nov 12, 2026
33be697
fix(ENG-4464): let Detach cancel a running auto-unstrip sync and stop…
vgoat21 Nov 12, 2026
b95cf77
fix(ENG-4459): roll back a failed load in one transaction
vgoat21 Nov 12, 2026
db38bb5
fix(ENG-4460): retry transient errors while polling analysis status (…
robertmarsal Nov 12, 2026
1c81194
Merge pull request #247 from RevEngAI/joshuavillaltaesp/eng-4457-ghid…
vgoat21 Nov 12, 2026
1f90ec5
Merge pull request #245 from RevEngAI/joshuavillaltaesp/eng-4464-ghid…
vgoat21 Nov 12, 2026
d43ff66
fix(ENG-4461): bound and back off every status polling loop
vgoat21 Nov 12, 2026
b672cad
fix(ENG-4461): point unfinished-wait messages at a recovery that works
vgoat21 Nov 12, 2026
1dc31bb
test(ENG-4461): drive StatusPoller timing tests with a fake clock
vgoat21 Nov 12, 2026
11a2482
Merge pull request #249 from RevEngAI/joshuavillaltaesp/eng-4461-ghid…
vgoat21 Nov 12, 2026
e97dc67
fix(ENG-4476): normalise api and portal hostnames (#250)
robertmarsal Nov 13, 2026
0eb2321
fix(ENG-4465): report server-side analysis errors with the log tail a…
vgoat21 Nov 13, 2026
c3b54d9
test(ENG-4465): wait for the work behind the error dialog instead of …
vgoat21 Nov 13, 2026
ff1a930
test(ENG-4465): wait for every stage before looking for the error dialog
vgoat21 Nov 13, 2026
dab671d
test(ENG-4465): poll for the error dialog instead of counting task ro…
vgoat21 Nov 13, 2026
dcfc57f
Merge remote-tracking branch 'origin/staging' into joshuavillaltaesp/…
vgoat21 Nov 13, 2026
e8ba54c
Merge pull request #251 from RevEngAI/joshuavillaltaesp/eng-4465-ghid…
vgoat21 Nov 13, 2026
a011140
Merge remote-tracking branch 'origin/staging' into joshuavillaltaesp/…
vgoat21 Nov 13, 2026
296d643
Merge pull request #246 from RevEngAI/joshuavillaltaesp/eng-4459-ghid…
vgoat21 Nov 13, 2026
2076233
fix(ENG-4478): show the server's error message on API failures (#252)
robertmarsal Nov 13, 2026
99bf1dd
test(ENG-4485): cover every SDK method and model the plugin uses
vgoat21 Nov 13, 2026
b4f3374
feat(ENG-4563): migrate upload and analysis creation to v3 (#253)
robertmarsal Nov 13, 2026
d8f5783
Merge remote-tracking branch 'origin/staging' into joshuavillaltaesp/…
vgoat21 Nov 13, 2026
03ec824
Merge pull request #254 from RevEngAI/joshuavillaltaesp/eng-4485-ghid…
vgoat21 Nov 13, 2026
ca846ff
fix(ENG-4475): treat an empty mangled_name as absent
vgoat21 Nov 13, 2026
727e2ce
Merge pull request #255 from RevEngAI/joshuavillaltaesp/eng-4475-ghid…
vgoat21 Nov 13, 2026
f1a303c
fix(ENG-4484): load analysis details off the EDT before opening Funct…
vgoat21 Nov 13, 2026
0ae602f
Merge pull request #257 from RevEngAI/joshuavillaltaesp/eng-4484-ghid…
vgoat21 Nov 13, 2026
cbafc04
test(ENG-4483): pin how a transferred signature reaches the portal
vgoat21 Nov 13, 2026
b2ac9f7
Merge pull request #258 from RevEngAI/joshuavillaltaesp/eng-4483-ghid…
vgoat21 Nov 13, 2026
460a428
feat(ENG-4587): add cross-platform installation script (#259)
robertmarsal Nov 13, 2026
044073a
fix(ENG-4588): stop staging CI flakes in dialog and sync tests
vgoat21 Nov 13, 2026
7cec5c9
fix(ENG-4590): stop the analysis wait on Detach and close, ignore sta…
vgoat21 Nov 13, 2026
2f1cc6e
fix(ENG-4589): never push a null data type id
vgoat21 Nov 13, 2026
760305c
fix(ENG-4588): give the matching-status wait its own deadline
vgoat21 Nov 13, 2026
b562984
fix(ENG-4590): drop a results load the program was detached from mid-…
vgoat21 Nov 13, 2026
97e7ef1
fix(ENG-4589): explain closure-limit holds and quieten their logging
vgoat21 Nov 13, 2026
f1890b1
fix(ENG-4590): use the TaskMonitor names Ghidra 12.2 still has
vgoat21 Nov 13, 2026
ae51e0d
Merge pull request #260 from RevEngAI/joshuavillaltaesp/eng-4588-ghid…
vgoat21 Nov 13, 2026
c416221
Merge pull request #261 from RevEngAI/joshuavillaltaesp/eng-4590-ghid…
vgoat21 Nov 13, 2026
1feb649
Merge remote-tracking branch 'origin/staging' into joshuavillaltaesp/…
vgoat21 Nov 13, 2026
d5191b9
fix(ENG-4590): drop the duplicate awaitDialog that breaks the test build
vgoat21 Nov 13, 2026
eb17532
fix(ENG-4590): drop the duplicate awaitDialog that breaks the test build
vgoat21 Nov 13, 2026
a6867d1
test(ENG-4590): dump thread stacks when awaitDialog times out
vgoat21 Nov 13, 2026
ad40ca3
fix(ENG-4590): fire analysis status events after the current delivery
vgoat21 Nov 14, 2026
6602935
test(ENG-4590): dump thread stacks when awaitDialog times out
vgoat21 Nov 13, 2026
d8d10b1
fix(ENG-4590): fire analysis status events after the current delivery
vgoat21 Nov 14, 2026
cf8420c
Merge pull request #262 from RevEngAI/joshuavillaltaesp/eng-4589-ghid…
vgoat21 Nov 16, 2026
7538f6b
Merge pull request #263 from RevEngAI/joshuavillaltaesp/eng-4590-fix-…
vgoat21 Nov 16, 2026
2b80eee
fix(ENG-4588): don't let a late status from a cancelled wait resume it
vgoat21 Nov 16, 2026
4b08a45
ci(ENG-4588): complete a test report check the reporter left in progress
vgoat21 Nov 16, 2026
03da3b9
Merge pull request #265 from RevEngAI/joshuavillaltaesp/eng-4588-comp…
vgoat21 Nov 16, 2026
8fc86bf
Merge pull request #264 from RevEngAI/joshuavillaltaesp/eng-4588-stal…
vgoat21 Nov 16, 2026
102c346
chore: bump SDK to 4.77.1 (#266)
robertmarsal Nov 16, 2026
2631b89
Merge pull request #267 from RevEngAI/main
robertmarsal Nov 17, 2026
1edc3be
fix(ENG-4379): upload the binary stored in the program when its file …
robertmarsal Nov 17, 2026
5421cd4
test(ENG-4379): hash fixture bytes with the JDK, HashUtilities is mis…
robertmarsal Nov 17, 2026
e55f7c4
Merge pull request #268 from RevEngAI/rob/eng-4379-investigate-failed…
robertmarsal Nov 17, 2026
da36939
fix(ENG-4192): read data types without reflective record binding
robertmarsal Nov 17, 2026
45c9750
Merge pull request #269 from RevEngAI/rob/eng-4192-make-ghidra-plugin…
robertmarsal Nov 17, 2026
2e36633
feat(ENG-4705): download plugin updates in the background and install…
vgoat21 Nov 18, 2026
4534a05
Merge pull request #270 from RevEngAI/joshuavillaltaesp/eng-4705-plug…
vgoat21 Nov 18, 2026
9336b6b
feat(ENG-3917): link AI decompilation lines to disassembly
robertmarsal Nov 20, 2026
d2a8b5e
Merge pull request #272 from RevEngAI/rob/eng-3917-ghidra-source-code…
robertmarsal Nov 20, 2026
0bdd2b0
feat(ENG-3917): light disassembly on any caret move
robertmarsal Nov 23, 2026
f731f54
Merge pull request #273 from RevEngAI/rob/eng-3917-ghidra-attribution…
robertmarsal Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ Set `GHIDRA_INSTALL_DIR` to target a specific install, or `REVENG_PLUGIN_VERSION

The builds for latest stable version of the RevEng.AI Ghidra plugin for common Ghidra versions can be downloaded from the [Releases](https://github.com/revengai/plugin-ghidra/releases/latest) page.

### Updating

The plugin checks GitHub for a new release when Ghidra starts. If it finds one, it downloads the build for your Ghidra version in the background and checks it against the SHA-256 checksum GitHub publishes for the release. It then installs that build when you close Ghidra, so the new version runs the next time you start Ghidra.
The download is kept in `reai-plugin-update/` in your Ghidra user settings folder until it is installed.

This only works when the plugin is installed in your user `Extensions` folder, which is where the install script and `Install Extensions` put it.
You can turn off the check or the automatic install with `Check for updates` and `Install updates automatically` under `Edit` -> `Tool Options...` -> `RevEngAI Options` in the CodeBrowser. With the automatic install off, the plugin only tells you about new releases and links to the download.

### Supported Ghidra versions

We support all versions compatible with Ghidra 11.4+. Ghidra 11.4 through 12.1.x run on Java 21;
Expand Down
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,17 @@ tasks.register('pruneStaleJars', Delete) {
}
copyDependencies.dependsOn pruneStaleJars

// Ghidra < 12.1 loads its own Gson 2.9.0 ahead of the plugin's. Tests rerun the data-type reader
// against it to catch code that only works on newer Gson (e.g. reflective record binding).
configurations {
ghidraGson
}
dependencies {
ghidraGson 'com.google.code.gson:gson:2.9.0'
}

test {
systemProperty 'reveng.test.gson29', configurations.ghidraGson.singleFile.path
maxParallelForks = 3
useJUnitPlatform()
jvmArgs '--add-exports=java.desktop/sun.awt=ALL-UNNAMED'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@
import docking.action.DockingAction;
import docking.action.ToolBarData;
import docking.widgets.dialogs.InputDialog;
import docking.widgets.fieldpanel.FieldPanel;
import generic.theme.GColor;
import generic.theme.GIcon;
import ghidra.app.events.ProgramHighlightPluginEvent;
import ghidra.app.services.CodeViewerService;
import ghidra.app.util.viewer.listingpanel.ListingPanel;
import ghidra.framework.plugintool.ComponentProviderAdapter;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Program;
import ghidra.program.util.ProgramLocation;
import ghidra.program.util.ProgramSelection;
import ghidra.util.Msg;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.*;
Expand All @@ -35,6 +45,7 @@
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigInteger;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -70,6 +81,20 @@ public class AIDecompilationdWindow extends ComponentProviderAdapter {
/// completed decompilation is shown.
private RenderModel currentRenderModel;

private static final Color ATTRIBUTED_LINE = new GColor("color.bg.highlight");

/// Line attributions per function, fetched once its decompilation completes. Cleared with the
/// decompilation on refresh and regenerate.
private final Map<Function, LineAttributions> attributions = new java.util.concurrent.ConcurrentHashMap<>();
private final java.util.Set<Function> inFlightAttributions = java.util.concurrent.ConcurrentHashMap.newKeySet();

/// Last listing location, so attributions arriving later can light the line under the cursor.
private ProgramLocation lastLocation;
/// Program the listing highlight was set on, so only a highlight of ours is cleared.
private Program highlightedProgram;
private boolean settingCode;
private int caretLine = -1;

private static final Pattern IDENTIFIER = Pattern.compile("[A-Za-z_]\\w*");


Expand Down Expand Up @@ -231,6 +256,8 @@ private JComponent buildComponent() {
textArea = new RSyntaxTextArea(20, 60);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_C);
textArea.setEditable(false);
// The highlight colour marks attributed lines; a current-line tint would read as one.
textArea.setHighlightCurrentLine(false);
// The view stays read-only; edits are driven through double-click (rename) and the
// right-click context menu (comments) so they can be synced back to RevEng.AI.
textArea.setPopupMenu(null);
Expand Down Expand Up @@ -258,6 +285,20 @@ private void maybeShowPopup(MouseEvent e) {
}
}
});
textArea.addCaretListener(e -> {
if (settingCode) {
return;
}
try {
int line = textArea.getLineOfOffset(e.getDot());
if (line != caretLine) {
caretLine = line;
highlightFromDecompilation(line);
}
} catch (BadLocationException ignored) {
// The caret outran a re-render; the next move lights its line.
}
});
sp = new RTextScrollPane(textArea);

component.add(sp, BorderLayout.CENTER);
Expand Down Expand Up @@ -305,6 +346,8 @@ public void setDisplayedValuesBasedOnStatus(Function function, AIDecompilationSt
switch (status.status()) {
case COMPLETED -> {
setCode(renderWithMap(status.decompilation(), status.inlineComments()));
loadAttributions(function);
highlightFromListing(lastLocation);
descriptionArea.setText("<html>%s</html>".formatted(status.summary() == null ? "" : status.summary()));

String predictedName = status.predictedFunctionName();
Expand Down Expand Up @@ -441,12 +484,20 @@ private static String leadingWhitespace(String line) {

private void setCode(String code) {
String text = code;
textArea.setText(text);
textArea.removeAllLineHighlights();
settingCode = true;
try {
textArea.setText(text);
} finally {
settingCode = false;
}
caretLine = -1;
}

private void clear() {
this.function = null;
this.currentRenderModel = null;
clearListingHighlight();
setCode("");
descriptionArea.setText("");
predictedNamePanel.setVisible(false);
Expand Down Expand Up @@ -504,6 +555,10 @@ public void locationChanged(ProgramLocation loc) {
function = newFuncLocation;
var functionWithID = analyzedProgram.get().getIDForFunction(function);
functionWithID.ifPresent(this::refresh);

lastLocation = loc;
clearListingHighlight();
highlightFromListing(loc);
}

/**
Expand All @@ -517,6 +572,7 @@ private void refreshCurrentFunction() {
return;
}
cache.remove(target);
attributions.remove(target);
currentRenderModel = null;
var service = tool.getService(GhidraRevengService.class);
var analysed = service.getAnalysedProgram(target.getProgram());
Expand All @@ -540,6 +596,7 @@ private void regenerateCurrentFunction() {
return;
}
cache.remove(target);
attributions.remove(target);
currentRenderModel = null;
tool.getService(ReaiLoggingService.class).info("Regenerating the AI Decompilation for function %s".formatted(target.getName()));
setCode("");
Expand All @@ -549,6 +606,171 @@ private void regenerateCurrentFunction() {
contextChanged();
}

// --- Line attribution highlighting ---------------------------------------------------------

/// Fetch {@code target}'s line attributions in the background, once. A failure is cached as
/// empty, so a decompilation re-rendered on every poll does not refetch; Refresh retries.
private void loadAttributions(Function target) {
if (target == null || attributions.containsKey(target) || !inFlightAttributions.add(target)) {
return;
}
FunctionID functionID = resolveFunctionId(target);
if (functionID == null) {
inFlightAttributions.remove(target);
return;
}
var service = tool.getService(GhidraRevengService.class);
tool.execute(new Task("Fetch AI decompilation line attributions", false, false, false) {
@Override
public void run(TaskMonitor monitor) {
LineAttributions result = LineAttributions.EMPTY;
try {
var raw = service.getApi().getAIDecompilationLineAttributions(functionID);
if (!raw.isEmpty()) {
result = LineAttributions.of(raw, service.getApi().getAssembly(functionID));
}
} catch (Exception e) {
Msg.warn(AIDecompilationdWindow.this,
"Failed to fetch line attributions for %s: %s".formatted(target.getName(), e.getMessage()));
} finally {
attributions.put(target, result);
inFlightAttributions.remove(target);
}
SwingUtilities.invokeLater(() -> {
if (isCurrentFunction(target)) {
highlightFromListing(lastLocation);
}
});
}
}, 0);
}

/// Light the decompilation lines the instruction at {@code loc} fed, and bring the first into view.
private void highlightFromListing(ProgramLocation loc) {
textArea.removeAllLineHighlights();
caretLine = -1;
RenderModel model = currentRenderModel;
Function target = this.function;
if (loc == null || model == null || target == null || !target.getBody().contains(loc.getAddress())) {
return;
}
LineAttributions lines = attributions.get(target);
if (lines == null) {
return;
}
CodeUnit codeUnit = loc.getProgram().getListing().getCodeUnitContaining(loc.getAddress());
Address instruction = codeUnit == null ? loc.getAddress() : codeUnit.getMinAddress();
var decompilationLines = lines.decompilationLinesFor(instruction.getOffset());
int first = highlightDecompilationLines(model, decompilationLines);
if (first >= 0) {
try {
var view = textArea.modelToView2D(textArea.getLineStartOffset(first));
if (view != null) {
textArea.scrollRectToVisible(view.getBounds());
}
} catch (BadLocationException e) {
// The line went away with a re-render; nothing to scroll to.
}
}
}

/// Light the caret's decompilation line and the instructions that fed it, and scroll the listing
/// to them. The cursor stays put, so every attributed instruction shows the same colour.
/// A line the model attributed nothing to lights nothing.
private void highlightFromDecompilation(int displayLine) {
textArea.removeAllLineHighlights();
clearListingHighlight();
RenderModel model = currentRenderModel;
Function target = this.function;
LineAttributions lines = target == null ? null : attributions.get(target);
if (model == null || lines == null) {
return;
}
Integer sourceLine = model.sourceLine(displayLine);
if (sourceLine == null) {
return;
}
var addresses = lines.addressesFor(sourceLine - 1);
if (addresses.isEmpty()) {
return;
}
highlightDecompilationLines(model, List.of(sourceLine - 1));

Program program = target.getProgram();
var space = program.getAddressFactory().getDefaultAddressSpace();
var set = new AddressSet();
for (long offset : addresses) {
Address address = space.getAddress(offset);
CodeUnit codeUnit = program.getListing().getCodeUnitAt(address);
if (codeUnit == null) {
set.add(address);
} else {
set.add(codeUnit.getMinAddress(), codeUnit.getMaxAddress());
}
}
highlightedProgram = program;
tool.firePluginEvent(new ProgramHighlightPluginEvent(getName(), new ProgramSelection(set), program));

CodeViewerService codeViewer = tool.getService(CodeViewerService.class);
if (codeViewer != null) {
scrollListing(codeViewer.getListingPanel(), program, target.getEntryPoint(), set.getMinAddress());
}
}

/// Put the function's top at the top of the listing when {@code first} still fits on screen
/// below it; otherwise scroll to {@code first}, so the highlight is never off screen.
private static void scrollListing(ListingPanel listing, Program program, Address top, Address first) {
var indexes = listing.getAddressIndexMap();
BigInteger topIndex = indexes.getIndex(top);
BigInteger firstIndex = indexes.getIndex(first);
FieldPanel fieldPanel = listing.getFieldPanel();
if (topIndex != null && firstIndex != null && topIndex.compareTo(firstIndex) <= 0) {
int available = fieldPanel.getVisibleRect().height;
int needed = 0;
for (BigInteger i = topIndex; i != null && i.compareTo(firstIndex) <= 0 && needed <= available;
i = fieldPanel.getLayoutModel().getIndexAfter(i)) {
needed += fieldPanel.getHeight(i);
}
if (needed <= available) {
fieldPanel.setViewerPosition(topIndex, 0, 0);
return;
}
}
listing.scrollTo(new ProgramLocation(program, first));
}

/// Light every code line rendered from one of the 0-based {@code decompilationLines}.
/// @return the first display line lit, or -1
private int highlightDecompilationLines(RenderModel model, List<Integer> decompilationLines) {
int first = -1;
if (decompilationLines.isEmpty()) {
return first;
}
for (int displayLine = 0; displayLine < model.displaySource.size(); displayLine++) {
if (model.isCodeLine(displayLine) && decompilationLines.contains(model.displaySource.get(displayLine) - 1)) {
try {
textArea.addLineHighlight(displayLine, ATTRIBUTED_LINE);
} catch (BadLocationException e) {
continue;
}
if (first < 0) {
first = displayLine;
}
}
}
return first;
}

private void clearListingHighlight() {
if (highlightedProgram == null) {
return;
}
if (!highlightedProgram.isClosed()) {
tool.firePluginEvent(new ProgramHighlightPluginEvent(getName(), new ProgramSelection(), highlightedProgram));
}
highlightedProgram = null;
}

// --- Rename / comment editing -------------------------------------------------------------

private void handleDoubleClick(Point point) {
Expand Down
Loading
Loading