Skip to content

Commit 8eeb81d

Browse files
committed
Follow functions into both primary and secondary programs when double clicking
Fix #32
1 parent 76b897a commit 8eeb81d

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/main/java/bindiffhelper/BinDiffHelperProvider.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@
4949
import docking.wizard.WizardManager;
5050
import ghidra.app.decompiler.DecompInterface;
5151
import ghidra.app.decompiler.DecompileResults;
52+
import ghidra.app.events.ProgramLocationPluginEvent;
5253
import ghidra.app.services.CodeViewerService;
5354
import ghidra.framework.cmd.Command;
55+
import ghidra.framework.model.DomainFile;
5456
import ghidra.framework.model.Project;
5557
import ghidra.framework.plugintool.ComponentProviderAdapter;
58+
import ghidra.framework.plugintool.PluginEvent;
59+
import ghidra.framework.plugintool.PluginTool;
5660
import ghidra.program.model.address.Address;
5761
import ghidra.program.model.address.AddressSpace;
5862
import ghidra.program.model.listing.Function;
@@ -213,6 +217,7 @@ protected boolean isMetadataVersionOK(Connection c) throws Exception {
213217
}
214218

215219
public class DiffState {
220+
DomainFile df;
216221
BinExport2File beFile;
217222
Program prog;
218223
String addressCol, filename, exefilename, hash;
@@ -394,11 +399,21 @@ protected void doDiffWork() {
394399
public void mousePressed(MouseEvent e) {
395400
if (e.getClickCount() == 2 && table.getSelectedRow() != -1) {
396401
var entry = ctm.getEntry(table.getSelectedRow());
397-
cvs.goTo(new ProgramLocation(program, entry.primaryAddress), true);
398-
if (secondary.prog != null) {
402+
//cvs.goTo(new ProgramLocation(program, entry.primaryAddress), true);
403+
PluginEvent ev = new ProgramLocationPluginEvent(null, new ProgramLocation(program, entry.primaryAddress), program);
404+
tool.firePluginEvent(ev);
405+
406+
if (secondary.prog != null && secondary.df != null) {
399407
Address secAddress = secondary.prog.getAddressFactory().getDefaultAddressSpace()
400408
.getAddress(entry.secondaryAddress);
401-
secondary.cvs.goTo(new ProgramLocation(secondary.prog, secAddress), true);
409+
//secondary.cvs.goTo(new ProgramLocation(secondary.prog, secAddress), true);
410+
PluginEvent secev = new ProgramLocationPluginEvent(null, new ProgramLocation(secondary.prog, secAddress), secondary.prog);
411+
412+
for (var consumer : secondary.df.getConsumers()) {
413+
if (consumer instanceof PluginTool pt)
414+
pt.firePluginEvent(secev);
415+
}
416+
tool.firePluginEvent(secev);
402417
}
403418
}
404419
if (secondary.prog != null && e.getClickCount() == 3 && table.getSelectedRow() != -1) {

src/main/java/bindiffhelper/DiffWizard.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ public CodeViewerService getCvs() {
390390
public Program getProg() {
391391
return program;
392392
}
393+
394+
public DomainFile getDf() {
395+
return tp.getSelectedDomainFile();
396+
}
393397
}
394398

395399
class DiffPanelManager implements PanelManager {
@@ -516,18 +520,27 @@ public void finish() throws IllegalPanelStateException {
516520

517521
plugin.provider.secondary.cvs = program2Panel.getCvs();
518522
plugin.provider.secondary.prog = program2Panel.getProg();
523+
plugin.provider.secondary.df = program2Panel.getDf();
519524
plugin.provider.doDiffWork();
520525
wizardMgr.close();
521526
} else {
522527
// from project
523-
plugin.callBinDiff(fromProjectPanel.getDf(), files -> {
528+
DomainFile df = fromProjectPanel.getDf();
529+
plugin.callBinDiff(df, files -> {
524530
if (files != null) {
525531
try {
526532
plugin.provider.openExternalDBWithBinExports(files[2].getAbsolutePath(), files[0], files[1]);
527533
} catch (Exception e) {
528534
e.printStackTrace();
529535
}
530-
536+
plugin.provider.secondary.df = df;
537+
try {
538+
var dof = df.getReadOnlyDomainObject(plugin, DomainFile.DEFAULT_VERSION, TaskMonitor.DUMMY);
539+
if (dof instanceof Program p)
540+
plugin.provider.secondary.prog = p;
541+
} catch (Exception e) {
542+
543+
}
531544
plugin.provider.doDiffWork();
532545
wizardMgr.close();
533546
}

0 commit comments

Comments
 (0)