Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7212: post-review GP-7212: oops GP-7212: oops GP=7212: more from review GP=7212: listing->goto GP=7212: radix GP=7212: working? GP-7212: nix vertical GP-7212: post-review, first round GP-7212: rename script GP-7212: slight refactoring GP-7212: help GP-7212: refactor to Base GP-7212: google recs GP-7212: bug fixes GP-7212: selectable axes GP-7212: more than 2 bounds GP-7212: html GP-7212: details GP-7212: filter fix GP-7212: working panel GP-7212: axial data GP-7212: bounded objects GP-7212: more X,Y GP-7212: first pass X,Y Gp-7212: reorganizing

d-millar357d60e05993
diff --git a/Ghidra/Debug/Debugger/certification.manifest b/Ghidra/Debug/Debugger/certification.manifest
index c8363f723c..1103faf45a 100644
--- a/Ghidra/Debug/Debugger/certification.manifest
+++ b/Ghidra/Debug/Debugger/certification.manifest
@@ -9,6 +9,7 @@ README.md||GHIDRA||||END|
data/ExtensionPoint.manifest||GHIDRA||||END|
data/debugger.theme.properties||GHIDRA||||END|
src/main/help/help/TOC_Source.xml||GHIDRA||||END|
+src/main/help/help/topics/BentoServicePlugin/BentoServicePlugin.html||GHIDRA||||END|
src/main/help/help/topics/BreakpointTimelinePlugin/BreakpointTimelinePlugin.html||GHIDRA||||END|
src/main/help/help/topics/BreakpointTimelinePlugin/images/BreakpointTimelinePlugin.png||GHIDRA||||END|
src/main/help/help/topics/BreakpointTimelinePlugin/images/BreakpointTimelinePluginNoGrid.png||GHIDRA||||END|
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/DebuggerMemviewPlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/DebuggerMemviewPlugin.java
index 1e4466ba89..60452130a9 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/DebuggerMemviewPlugin.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/DebuggerMemviewPlugin.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,16 +15,14 @@
*/
package ghidra.app.plugin.core.debug.gui.memview;
-import java.util.List;
-
import ghidra.app.plugin.PluginCategoryNames;
-import ghidra.app.plugin.core.debug.AbstractDebuggerPlugin;
+import ghidra.app.plugin.core.bento.BentoServicePlugin;
import ghidra.app.plugin.core.debug.DebuggerPluginPackage;
import ghidra.app.plugin.core.debug.event.TraceActivatedPluginEvent;
+import ghidra.app.services.DebuggerListingService;
import ghidra.app.services.DebuggerTraceManagerService;
import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.util.PluginStatus;
-import ghidra.program.model.listing.Program;
@PluginInfo(
shortDescription = "Displays memory vs time",
@@ -36,31 +34,25 @@ import ghidra.program.model.listing.Program;
TraceActivatedPluginEvent.class
},
servicesRequired = {
+ DebuggerListingService.class,
DebuggerTraceManagerService.class
},
servicesProvided = {
MemviewService.class
})
-public class DebuggerMemviewPlugin extends AbstractDebuggerPlugin implements MemviewService {
+public class DebuggerMemviewPlugin extends BentoServicePlugin implements MemviewService {
- protected MemviewProvider provider;
private DebuggerMemviewTraceListener listener;
public DebuggerMemviewPlugin(PluginTool tool) {
- super(tool);
+ super(tool, "Memview");
}
@Override
protected void init() {
- provider = new MemviewProvider(getTool(), this);
- listener = new DebuggerMemviewTraceListener(provider);
- super.init();
- }
-
- @Override
- protected void dispose() {
- tool.removeComponentProvider(provider);
- super.dispose();
+ codeViewerService = tool.getService(DebuggerListingService.class);
+ defaultProvider = new MemviewProvider(getTool(), this);
+ listener = new DebuggerMemviewTraceListener((MemviewProvider) defaultProvider);
}
@Override
@@ -72,26 +64,8 @@ public class DebuggerMemviewPlugin extends AbstractDebuggerPlugin implements Mem
}
@Override
- public MemviewProvider getProvider() {
- return provider;
- }
-
- public void toggleTrackTrace() {
+ public void toggleTracking() {
listener.toggleTrackTrace();
}
- @Override
- public void setBoxes(List<MemoryBox> boxList) {
- provider.setBoxes(boxList);
- }
-
- @Override
- public void initViews() {
- provider.initViews();
- }
-
- @Override
- public void setProgram(Program program) {
- provider.setProgram(program);
- }
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/DebuggerMemviewTraceListener.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/DebuggerMemviewTraceListener.java
index 1a890c9060..97df53479b 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/DebuggerMemviewTraceListener.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/DebuggerMemviewTraceListener.java
@@ -17,6 +17,7 @@ package ghidra.app.plugin.core.debug.gui.memview;
import java.util.*;
+import ghidra.app.plugin.core.bento.*;
import ghidra.async.AsyncDebouncer;
import ghidra.async.AsyncTimer;
import ghidra.debug.api.tracemgr.DebuggerCoordinates;
@@ -52,14 +53,14 @@ public class DebuggerMemviewTraceListener extends TraceDomainObjectListener {
private boolean trackBreakpoints = true;
private boolean trackBytes = true;
- List<MemoryBox> updateList = new ArrayList<>();
+ List<BentoBox> updateList = new ArrayList<>();
private final AsyncDebouncer<Void> updateLabelDebouncer =
new AsyncDebouncer<>(AsyncTimer.DEFAULT_TIMER, 100);
public DebuggerMemviewTraceListener(MemviewProvider provider) {
this.provider = provider;
- updateLabelDebouncer.addListener(__ -> Swing.runIfSwingOrRunLater(() -> doUpdate()));
+ updateLabelDebouncer.addListener(_ -> Swing.runIfSwingOrRunLater(() -> doUpdate()));
listenFor(TraceEvents.THREAD_ADDED, this::threadChanged);
listenFor(TraceEvents.THREAD_CHANGED, this::threadChanged);
@@ -93,7 +94,7 @@ public class DebuggerMemviewTraceListener extends TraceDomainObjectListener {
listenForUntyped(DomainObjectEvent.RESTORED, this::objectRestored);
}
- public MemviewProvider getProvider() {
+ public BentoProvider getProvider() {
return provider;
}
@@ -193,12 +194,16 @@ public class DebuggerMemviewTraceListener extends TraceDomainObjectListener {
private void valueCreated(TraceObjectValue value) {
if (value.getCanonicalPath().equals(KeyPath.of(TraceTimeManager.KEY_TIME_RADIX))) {
+ provider.setRadix(0,
+ BentoRadix.fromStr(currentTrace.getTimeManager().getTimeRadix().name()));
provider.fireTableDataChanged();
}
}
private void valueDeleted(TraceObjectValue value) {
if (value.getCanonicalPath().equals(KeyPath.of(TraceTimeManager.KEY_TIME_RADIX))) {
+ provider.setRadix(0,
+ BentoRadix.fromStr(currentTrace.getTimeManager().getTimeRadix().name()));
provider.fireTableDataChanged();
}
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/LifespanBoundedObject.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/LifespanBoundedObject.java
new file mode 100644
index 0000000000..61deff1c82
--- /dev/null
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/LifespanBoundedObject.java
@@ -0,0 +1,28 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.debug.gui.memview;
+
+import ghidra.app.plugin.core.bento.BoundedObject;
+import ghidra.trace.model.Lifespan;
+
+public class LifespanBoundedObject extends BoundedObject {
+
+ public LifespanBoundedObject(Lifespan span) {
+ super(span.lmin(), span.lmax());
+ this.obj = span;
+ }
+
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemoryBox.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemoryBox.java
index 9461b471e7..dca28da3fd 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemoryBox.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemoryBox.java
@@ -16,47 +16,23 @@
package ghidra.app.plugin.core.debug.gui.memview;
import java.awt.Color;
-import java.awt.Graphics;
-import java.util.HashMap;
-import java.util.Map;
-import generic.theme.GThemeDefaults.Colors;
+import ghidra.app.plugin.core.bento.*;
import ghidra.program.model.address.AddressRange;
import ghidra.trace.model.Lifespan;
import ghidra.trace.model.Trace;
-import ghidra.trace.model.time.schedule.TraceSchedule.TimeRadix;
-public class MemoryBox {
+public class MemoryBox extends BentoBox {
protected final Trace trace;
- protected String id;
protected MemviewBoxType type;
- protected AddressRange range;
- protected long start;
- protected long stop = Long.MAX_VALUE;
- protected long startAddr;
- protected long stopAddr = -1;
- protected long startTime;
- protected long stopTime = -1;
-
- protected int pixAstart;
- protected int pixAend;
- protected int boundA;
- protected int pixTstart;
- protected int pixTend;
- protected int boundT;
- protected Color color;
-
- protected boolean current;
public MemoryBox(Trace trace, String id, MemviewBoxType type, AddressRange range, long tick,
Color color) {
+ super(id, new BoundedObject(tick, Long.MAX_VALUE), new AddressRangeBoundedObject(range),
+ color);
this.trace = trace;
- this.id = id;
this.type = type;
- this.range = range;
- this.start = tick;
- this.color = color;
}
public MemoryBox(Trace trace, String id, MemviewBoxType type, AddressRange range, long tick) {
@@ -64,201 +40,15 @@ public class MemoryBox {
}
public MemoryBox(Trace trace, String id, MemviewBoxType type, AddressRange range,
- Lifespan trange) {
- this(trace, id, type, range, trange.lmin());
- setEnd(trange.lmax());
- }
-
- public String getId() {
- return id;
+ Lifespan span) {
+ super(id, new LifespanBoundedObject(span), new AddressRangeBoundedObject(range),
+ type.getColor());
+ this.trace = trace;
+ this.type = type;
}
public MemviewBoxType getType() {
return type;
}
- public AddressRange getRange() {
- return range;
- }
-
- public Lifespan getSpan() {
- return Lifespan.span(start, stop);
- }
-
- public long getStart() {
- return start;
- }
-
- public long getEnd() {
- return stop;
- }
-
- public void setEnd(long tick) {
- this.stop = stop < tick ? stop : tick;
- }
-
- public Color getColor() {
- return color;
- }
-
- public void setColor(Color color) {
- this.color = color;
- }
-
- public int getAddressPixelStart() {
- return pixAstart;
- }
-
- public int getAddressPixelWidth() {
- if (pixAend - pixAstart <= 0) {
- return 1;
- }
- return pixAend - pixAstart;
- }
-
- public int getTimePixelStart() {
- return pixTstart;
- }
-
- public int getTimePixelWidth() {
- if (pixTend < pixTstart) {
- pixTend = boundT;
- }
- if (pixTend - pixTstart == 0) {
- return 1;
- }
- return pixTend - pixTstart;
- }
-
- public int getX(boolean vertical) {
- return vertical ? pixTstart : pixAstart;
- }
-
- public int getY(boolean vertical) {
- return vertical ? pixAstart : pixTstart;
- }
-
- public void setCurrent(boolean current) {
- this.current = current;
- }
-
- public boolean isCurrent() {
- return current;
- }
-
- public void render(Graphics g, boolean vertical) {
- int x = vertical ? getTimePixelStart() : getAddressPixelStart();
- int w = vertical ? getTimePixelWidth() : getAddressPixelWidth();
- int y = vertical ? getAddressPixelStart() : getTimePixelStart();
- int h = vertical ? getAddressPixelWidth() : getTimePixelWidth();
- g.setColor(Colors.BORDER);
- g.fillRect(x - 1, y - 1, w + 2, h + 2);
- g.setColor(color);
- g.fillRect(x, y, w, h);
- }
-
- public void renderBA(Graphics g, boolean vertical, int sz) {
- int x = vertical ? 0 : getAddressPixelStart();
- int w = vertical ? sz : getAddressPixelWidth();
- int y = vertical ? getAddressPixelStart() : 0;
- int h = vertical ? getAddressPixelWidth() : sz;
- g.setColor(Colors.BORDER);
- g.fillRect(x - 1, y - 1, w + 2, h + 2);
- g.setColor(color);
- g.fillRect(x, y, w, h);
- }
-
- public void renderBT(Graphics g, boolean vertical, int sz, int bound) {
- int x = vertical ? getTimePixelStart() : 0;
- int w = vertical ? 1 : sz;
- int y = vertical ? 0 : getTimePixelStart();
- int h = vertical ? sz : 1;
- g.setColor(Colors.BORDER);
- g.fillRect(x - 1, y - 1, w + 2, h + 2);
- g.setColor(color);
- g.fillRect(x, y, w, h);
- }
-
- public void setAddressBounds(MemviewMap map, int bound) {
- if (stopAddr < 0) {
- stopAddr = startAddr;
- }
- pixAstart = getPixel(map, startAddr, bound);
- pixAend = getPixel(map, stopAddr, bound);
- boundA = bound;
- }
-
- public void setTimeBounds(MemviewMap map, int bound) {
- pixTstart = getPixel(map, startTime, bound);
- pixTend = getPixel(map, stopTime, bound);
- boundT = bound;
- }
-
- protected int getPixel(MemviewMap map, long offset, int bound) {
- return map.getPixel(offset);
- }
-
- public long getStartAddress() {
- return startAddr;
- }
-
- public void setStartAddress(long val) {
- startAddr = val;
- }
-
- public long getStopAddress() {
- return stopAddr;
- }
-
- public void setStopAddress(long val) {
- stopAddr = val;
- }
-
- public long getStartTime() {
- return startTime;
- }
-
- public void setStartTime(long val) {
- startTime = val;
- }
-
- public long getStopTime() {
- return stopTime;
- }
-
- public void setStopTime(long val) {
- stopTime = val;
- }
-
- private TimeRadix getTimeRadix() {
- return trace.getTimeManager().getTimeRadix();
- }
-
- public String formatStart() {
- return getTimeRadix().format(start);
- }
-
- public String formatEnd() {
- return getTimeRadix().format(stop);
- }
-
- public boolean inPixelRange(long pos) {
- if (pos < pixTstart) {
- return false;
- }
- if (pixTend <= 0) {
- return true;
- }
- return pos <= pixTend;
- }
-
- public Map<String, Object> getAttributeMap() {
- Map<String, Object> map = new HashMap<>();
- map.put("Id", getId());
- map.put("StartAddr", getStartAddress());
- map.put("StopAddr", getStopAddress());
- map.put("StartTime", getStartTime());
- map.put("StopTIme", getStopTime());
- return map;
- }
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewMapModel.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewMapModel.java
deleted file mode 100644
index 903ab0317e..0000000000
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewMapModel.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ghidra.app.plugin.core.debug.gui.memview;
-
-import java.util.*;
-
-import docking.widgets.table.AbstractSortedTableModel;
-import ghidra.program.model.address.Address;
-
-class MemviewMapModel extends AbstractSortedTableModel<MemoryBox> {
-
- final static byte NAME = 0;
- final static byte ASTART = 1;
- final static byte ASTOP = 2;
- final static byte TSTART = 3;
- final static byte TSTOP = 4;
-
- final static String NAME_COL = "Name";
- final static String ASTART_COL = "Start Address";
- final static String ASTOP_COL = "End Address";
- final static String TSTART_COL = "Start Time";
- final static String TSTOP_COL = "End Time";
-
- private List<MemoryBox> memList = new ArrayList<>();
- private Map<String, MemoryBox> memMap = new HashMap<>();
- private MemviewProvider provider;
-
- private final static String COLUMN_NAMES[] =
- { NAME_COL, ASTART_COL, ASTOP_COL, TSTART_COL, TSTOP_COL };
-
- public MemviewMapModel(MemviewProvider provider) {
- super(ASTART);
- this.provider = provider;
- }
-
- public List<MemoryBox> getBoxes() {
- return memList;
- }
-
- public void addBoxes(Collection<MemoryBox> boxes) {
- if (memList == null) {
- memList = new ArrayList<>();
- }
- for (MemoryBox b : boxes) {
- if (memMap.containsKey(b.getId())) {
- MemoryBox mb = memMap.get(b.getId());
- memList.remove(mb);
- }
- memList.add(b);
- memMap.put(b.getId(), b);
- }
- fireTableDataChanged();
- }
-
- public void setBoxes(Collection<MemoryBox> boxes) {
- memList = new ArrayList<>();
- for (MemoryBox b : boxes) {
- memList.add(b);
- memMap.put(b.getId(), b);
- }
- fireTableDataChanged();
- }
-
- public void reset() {
- memList = new ArrayList<>();
- memMap.clear();
- fireTableDataChanged();
- }
-
- void update() {
- }
-
- @Override
- public boolean isSortable(int columnIndex) {
- return true;
- }
-
- @Override
- public String getName() {
- return "Memory vs Time Map";
- }
-
- @Override
- public int getColumnCount() {
- return COLUMN_NAMES.length;
- }
-
- @Override
- public String getColumnName(int column) {
-
- if (column < 0 || column >= COLUMN_NAMES.length) {
- return "UNKNOWN";
- }
-
- return COLUMN_NAMES[column];
- }
-
- /**
- * Convenience method for locating columns by name. Implementation is naive so this should be
- * overridden if this method is to be called often. This method is not in the TableModel
- * interface and is not used by the JTable.
- */
- @Override
- public int findColumn(String columnName) {
- for (int i = 0; i < COLUMN_NAMES.length; i++) {
- if (COLUMN_NAMES[i].equals(columnName)) {
- return i;
- }
- }
- return 0;
- }
-
- /**
- * Returns Object.class by default
- */
- @Override
- public Class<?> getColumnClass(int columnIndex) {
- if (columnIndex == ASTART || columnIndex == ASTOP) {
- return Address.class;
- }
- return String.class;
- }
-
- /**
- * Return whether this column is editable.
- */
- @Override
- public boolean isCellEditable(int rowIndex, int columnIndex) {
- return false;
- }
-
- /**
- * Returns the number of records managed by the data source object. A <B>JTable</B> uses this
- * method to determine how many rows it should create and display. This method should be quick,
- * as it is call by <B>JTable</B> quite frequently.
- *
- * @return the number or rows in the model
- * @see #getColumnCount
- */
- @Override
- public int getRowCount() {
- return memList.size();
- }
-
- public MemoryBox getBoxAt(int rowIndex) {
- if (memList == null) {
- return null;
- }
- if (rowIndex < 0 || rowIndex >= memList.size()) {
- return null;
- }
- MemoryBox box = memList.get(rowIndex);
- try {
- box.getStart();
- }
- catch (ConcurrentModificationException e) {
- update();
- }
- return memList.get(rowIndex);
- }
-
- public int getIndexForBox(MemoryBox box) {
- return memList.indexOf(box);
- }
-
- @Override
- public Object getColumnValueForRow(MemoryBox box, int columnIndex) {
- try {
- switch (columnIndex) {
- case NAME:
- return box.getId();
- case ASTART:
- return box.getRange().getMinAddress();
- case ASTOP:
- return box.getRange().getMaxAddress();
- case TSTART:
- return box.formatStart();
- case TSTOP:
- long end = box.getEnd();
- if (end == Long.MAX_VALUE) {
- return "+" + '\u221e' + '\u2025';
- }
- return box.formatEnd();
- default:
- return "UNKNOWN";
- }
- }
- catch (ConcurrentModificationException e) {
- update();
- }
- return null;
- }
-
- @Override
- public List<MemoryBox> getModelData() {
- return memList;
- }
-
- @Override
- protected Comparator<MemoryBox> createSortComparator(int columnIndex) {
- return new MemoryMapComparator(columnIndex);
- }
-
- private class MemoryMapComparator implements Comparator<MemoryBox> {
- private final int sortColumn;
-
- public MemoryMapComparator(int sortColumn) {
- this.sortColumn = sortColumn;
- }
-
- @Override
- public int compare(MemoryBox b1, MemoryBox b2) {
-
- switch (sortColumn) {
- case NAME:
- return b1.getId().compareToIgnoreCase(b2.getId());
- case ASTART:
- return (int) (b1.getStartAddress() - b2.getStartAddress());
- case ASTOP:
- return (int) (b1.getStopAddress() - b2.getStopAddress());
- case TSTART:
- return (int) (b1.getStartTime() - b2.getStartTime());
- case TSTOP:
- return (int) (b1.getStopTime() - b2.getStopTime());
- default:
- return 0;
- }
- }
- }
-}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewPanel.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewPanel.java
deleted file mode 100644
index 1b30609d49..0000000000
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewPanel.java
+++ /dev/null
@@ -1,509 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ghidra.app.plugin.core.debug.gui.memview;
-
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-import java.util.List;
-
-import javax.swing.*;
-
-import generic.theme.GColor;
-import generic.theme.GThemeDefaults.Colors;
-import ghidra.program.model.address.Address;
-import ghidra.program.model.address.AddressRange;
-import ghidra.trace.model.time.schedule.TraceSchedule.TimeRadix;
-
-public class MemviewPanel extends JPanel implements MouseListener, MouseMotionListener {
- private static final long serialVersionUID = 1L;
-
- private static final Color ARROW_COLOR =
- new GColor("color.debugger.plugin.plugin.memview.arrow");
-
- private MemviewProvider provider;
- private MemviewMap amap;
- private MemviewMap tmap;
- private List<MemoryBox> boxList = new ArrayList<>();
-
- private int pressedX;
- private int pressedY;
- private boolean enableDrag = false;
- private boolean ctrlPressed = false;
- private int barWidth = 1000;
- private int barHeight = 500;
- private boolean vertical = false;
-
- private int currentPixelAddr = -1;
- private int currentPixelTime = -1;
- private Rectangle currentRectangle = null;
-
- private List<MemoryBox> blist = null;
- private Map<String, MemoryBox> bmap = new HashMap<>();
-
- private TreeSet<Address> addresses = new TreeSet<>();
- private TreeSet<Long> times = new TreeSet<>();
- private Address[] addressArray;
- private Long[] timesArray;
- private Map<Long, Set<MemoryBox>> addr2box = new HashMap<>();
- private Map<Long, Set<MemoryBox>> time2box = new HashMap<>();
-
- public MemviewPanel(MemviewProvider provider) {
- this.provider = provider;
- setPreferredSize(new Dimension(barWidth, barHeight));
- setSize(getPreferredSize());
- setBorder(BorderFactory.createLineBorder(Colors.BORDER, 1));
- setFocusable(true);
-
- addMouseListener(this);
- addMouseMotionListener(this);
- ToolTipManager.sharedInstance().registerComponent(this);
-
- // This panel takes focus since it is a custom widget. Focusable components need to
- // have their accessible name set.
- String viewName = "Memory View";
- setName(viewName);
- getAccessibleContext().setAccessibleName(viewName);
- }
-
- @Override
- public Dimension getPreferredSize() {
- int asz = amap != null ? (int) (amap.getSize()) : 500;
- int tsz = tmap != null ? (int) (tmap.getSize()) : 500;
- int w = vertical ? tsz : asz;
- int h = vertical ? asz : tsz;
- return new Dimension(w, h);
- }
-
- @Override
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.setColor(getBackground());
- Rectangle clip = g.getClipBounds();
- g.fillRect(clip.x, clip.y, clip.width, clip.height);
-
- //If the width has changed, force a refresh
- int height = getHeight();
- int width = getWidth();
- if (vertical && clip.height > height || !vertical && clip.width > width) {
- refresh();
- return;
- }
-
- g.fillRect(0, 0, width, height);
-
- for (MemoryBox box : boxList) {
- box.render(g, vertical);
- }
-
- //Draw the current location arrow
- if (currentPixelAddr >= 0) {
- drawArrow(g);
- }
- if (currentRectangle != null) {
- drawFrame(g);
- }
- }
-
- private static final int LOCATION_BASE_WIDTH = 1;
- private static final int LOCATION_BASE_HEIGHT = 6;
- private static final int LOCATION_ARROW_WIDTH = 3;
- private static final int LOCATION_ARROW_HEIGHT = 9;
- private static final int[] locXs = { 0, -LOCATION_BASE_WIDTH, -LOCATION_BASE_WIDTH,
- -LOCATION_ARROW_WIDTH, 0, LOCATION_ARROW_WIDTH, LOCATION_BASE_WIDTH, LOCATION_BASE_WIDTH };
- private static final int[] locYs = { 0, 0, LOCATION_BASE_HEIGHT, LOCATION_BASE_HEIGHT,
- LOCATION_ARROW_HEIGHT, LOCATION_BASE_HEIGHT, LOCATION_BASE_HEIGHT, 0 };
-
- private void drawArrow(Graphics g) {
- Graphics2D g2 = (Graphics2D) g;
- if (vertical) {
- g2.rotate(90.0f / 180.0f * Math.PI);
- g2.translate(0, LOCATION_ARROW_HEIGHT);
- g.translate(currentPixelAddr, -currentPixelTime);
- g2.rotate(Math.PI);
- }
- else {
- g2.translate(0, -LOCATION_ARROW_HEIGHT);
- g.translate(currentPixelAddr, currentPixelTime);
- }
-
- g.setColor(ARROW_COLOR);
- g.fillPolygon(locXs, locYs, locXs.length);
-
- if (vertical) {
- g2.rotate(Math.PI);
- g.translate(-currentPixelAddr, currentPixelTime);
- g2.translate(0, -LOCATION_ARROW_HEIGHT);
- g2.rotate(-90.0f / 180.0f * Math.PI);
- }
- else {
- g.translate(-currentPixelAddr, -currentPixelTime);
- g2.translate(0, LOCATION_ARROW_HEIGHT);
- }
- }
-
- private void drawFrame(Graphics g) {
- int x = currentRectangle.x;
- int y = currentRectangle.y;
- int w = currentRectangle.width;
- int h = currentRectangle.height;
- g.setColor(ARROW_COLOR);
- g.fillRect(x - 1, y - 1, 1, h + 2);
- g.fillRect(x - 1, y - 1, w + 2, 1);
- g.fillRect(x + w + 1, y - 1, 1, h + 2);
- g.fillRect(x - 1, y + h + 1, w + 2, 1);
- }
-
- void initViews() {
- setSize(new Dimension(vertical ? times.size() : addresses.size(),
- vertical ? addresses.size() : times.size()));
- this.amap = new MemviewMap(addresses.size(), addresses.size());
- this.tmap = new MemviewMap(times.size(), times.size());
- }
-
- public void refresh() {
- if (amap == null || tmap == null) {
- return;
- }
- if (vertical) {
- amap.createMapping(provider.getZoomAmountA());
- tmap.createMapping(provider.getZoomAmountT());
- }
- else {
- amap.createMapping(provider.getZoomAmountA());
- tmap.createMapping(provider.getZoomAmountT());
- }
-
- updateBoxes();
- }
-
- void updateBoxes() {
- if (!this.isShowing()) {
- return;
- }
-
- boxList = new ArrayList<>();
- Collection<MemoryBox> boxes = getBoxes();
- if (boxes == null) {
- return;
- }
- for (MemoryBox box : boxes) {
- if (box == null) {
- continue;
- }
-
- int bound = vertical ? getHeight() - 1 : getWidth() - 1;
- box.setAddressBounds(amap, bound);
- bound = vertical ? getWidth() - 1 : getHeight() - 1;
- box.setTimeBounds(tmap, bound);
-
- boxList.add(box);
- }
-
- repaint(0, 0, getWidth(), getHeight());
- }
-
- @Override
- public void mousePressed(MouseEvent e) {
- requestFocus(); // COMPONENT
-
- ctrlPressed = false;
- currentRectangle = null;
-
- if (e.getButton() == MouseEvent.BUTTON1) {
- enableDrag = true;
- pressedX = e.getX();
- pressedY = e.getY();
- currentPixelAddr = vertical ? pressedY : pressedX;
- currentPixelTime = vertical ? pressedX : pressedY;
- provider.selectTableEntry(getBoxesAt(pressedX, pressedY));
- provider.refresh();
- }
-
- if (e.getButton() == MouseEvent.BUTTON3) {
- ctrlPressed = true;
- enableDrag = true;
- pressedX = e.getX();
- pressedY = e.getY();
- }
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- enableDrag = false;
- }
-
- @Override
- public void mouseClicked(MouseEvent e) {
- enableDrag = false;
- }
-
- @Override
- public void mouseEntered(MouseEvent e) {
- // Nothing to do
- }
-
- @Override
- public void mouseExited(MouseEvent e) {
- // Nothing to do
- }
-
- @Override
- public void mouseDragged(MouseEvent e) {
- if (enableDrag) {
- if (!ctrlPressed) {
- provider.goTo(pressedX - e.getX(), pressedY - e.getY());
- }
- else {
- currentRectangle =
- new Rectangle(pressedX, pressedY, e.getX() - pressedX, e.getY() - pressedY);
- provider.selectTableEntry(getBoxesIn(currentRectangle));
- provider.refresh();
- }
- }
- }
-
- @Override
- public void mouseMoved(MouseEvent e) {
- // Nothing to do
- }
-
- public void setSelection(Set<MemoryBox> boxes) {
- for (MemoryBox memoryBox : boxes) {
- currentPixelAddr = memoryBox.pixAstart;
- currentPixelTime = memoryBox.pixTstart;
- refresh();
- }
- }
-
- public String getTitleAnnotation() {
- if (currentPixelAddr < 0 || addressArray == null) {
- return "";
- }
- String aval = getTagForAddr(currentPixelAddr);
- String tval = getTagForTick(currentPixelTime);
- String vals = vertical ? tval + ":" + aval : aval + ":" + tval;
- return "curpos=[" + vals + "]";
- }
-
- public Set<MemoryBox> getBoxesAt(int x, int y) {
- long addr = getAddr(x, y);
- long tick = getTick(x, y);
- long pos = vertical ? x : y;
- Set<MemoryBox> matches = new HashSet<>();
- Set<MemoryBox> mboxes = addr2box.get(addr);
- if (mboxes != null && tick < timesArray.length) {
- for (MemoryBox memoryBox : mboxes) {
- if (memoryBox.inPixelRange(pos)) {
- matches.add(memoryBox);
- }
- }
- }
- return matches;
- }
-
- public Set<MemoryBox> getBoxesIn(Rectangle r) {
- long startAddr = getAddr(r.x, r.y);
- long startTick = getTick(r.x, r.y);
- long stopAddr = getAddr(r.x + r.width, r.y + r.height);
- long stopTick = getTick(r.x + r.width, r.y + r.height);
- Set<MemoryBox> matches = new HashSet<>();
- for (long addr = startAddr; addr < stopAddr; addr++) {
- Set<MemoryBox> mboxes = addr2box.get(addr);
- for (MemoryBox memoryBox : mboxes) {
- if (memoryBox.getStartTime() >= startTick || memoryBox.getStopTime() <= stopTick) {
- matches.add(memoryBox);
- }
- }
- }
- return matches;
- }
-
- @Override
- public String getToolTipText(MouseEvent e) {
- if (amap == null || tmap == null) {
- return e.getX() + ":" + e.getY();
- }
- long addr = getAddr(e.getX(), e.getY());
- long tick = getTick(e.getX(), e.getY());
- String aval = getTagForAddr(addr);
- String tval = getTagForTick(tick);
- Set<MemoryBox> boxes = getBoxesAt(e.getX(), e.getY());
- for (MemoryBox memoryBox : boxes) {
- aval = memoryBox.getId();
- }
- return vertical ? tval + " : " + aval : aval + " : " + tval;
- }
-
- private void parseBoxes(Collection<MemoryBox> boxes) {
- addresses.clear();
- times.clear();
- addr2box.clear();
- time2box.clear();
-
- for (MemoryBox box : boxes) {
- AddressRange range = box.getRange();
- if (range != null) {
- addresses.add(range.getMinAddress());
- addresses.add(range.getMaxAddress());
- }
- long start = box.getStart();
- long end = box.getEnd();
- times.add(start);
- times.add(end);
- }
-
- initViews();
- addressArray = new Address[addresses.size()];
- timesArray = new Long[times.size()];
- addresses.toArray(addressArray);
- times.toArray(timesArray);
-
- for (MemoryBox box : boxes) {
- AddressRange range = box.getRange();
- if (range != null) {
- box.setStartAddress(addresses.headSet(range.getMinAddress()).size());
- box.setStopAddress(addresses.headSet(range.getMaxAddress()).size());
- }
- box.setStartTime(times.headSet(box.getStart()).size());
- box.setStopTime(times.headSet(box.getEnd()).size());
-
- Set<MemoryBox> mboxes = addr2box.get(box.getStartAddress());
- if (mboxes == null) {
- mboxes = new HashSet<>();
- }
- mboxes.add(box);
- addr2box.put(box.getStartAddress(), mboxes);
- mboxes = addr2box.get(box.getStopAddress());
- if (mboxes == null) {
- mboxes = new HashSet<>();
- }
- mboxes.add(box);
- addr2box.put(box.getStopAddress(), mboxes);
-
- mboxes = time2box.get(box.getStartTime());
- if (mboxes == null) {
- mboxes = new HashSet<>();
- }
- mboxes.add(box);
- time2box.put(box.getStartTime(), mboxes);
- mboxes = time2box.get(box.getStopTime());
- if (mboxes == null) {
- mboxes = new HashSet<>();
- }
- mboxes.add(box);
- time2box.put(box.getStopTime(), mboxes);
- }
- refresh();
- }
-
- public List<MemoryBox> getBoxes() {
- return blist;
- }
-
- public void setBoxes(List<MemoryBox> boxes) {
- this.blist = boxes;
- for (MemoryBox b : boxes) {
- bmap.put(b.getId(), b);
- }
- parseBoxes(blist);
- }
-
- public void addBoxes(List<MemoryBox> boxes) {
- if (blist == null) {
- blist = new ArrayList<>();
- }
- for (MemoryBox b : boxes) {
- if (bmap.containsKey(b.getId())) {
- MemoryBox box = bmap.get(b.getId());
- blist.remove(box);
- }
- blist.add(b);
- bmap.put(b.getId(), b);
- }
- parseBoxes(blist);
- }
-
- public void reset() {
- blist = new ArrayList<>();
- bmap.clear();
- parseBoxes(blist);
- }
-
- void setAddressPixelMap(MemviewMap map) {
- this.amap = map;
- }
-
- void setTimePixelMap(MemviewMap tmap) {
- this.tmap = tmap;
- }
-
- public boolean getVerticalMode() {
- return vertical;
- }
-
- public void setVerticalMode(boolean vertical) {
- this.vertical = vertical;
- }
-
- public long getAddr(int x, int y) {
- if (amap == null) {
- return 0;
- }
- return vertical ? amap.getOffset(y) : amap.getOffset(x);
- }
-
- public long getTick(int x, int y) {
- if (tmap == null) {
- return 0;
- }
- return vertical ? tmap.getOffset(x) : tmap.getOffset(y);
- }
-
- public String getTagForAddr(long addr) {
- String aval = "";
- if (0 <= addr && addr < addressArray.length) {
- aval = addressArray[(int) addr].toString();
- }
- return aval;
- }
-
- private TimeRadix getTimeRadix() {
- if (boxList == null || boxList.isEmpty()) {
- return TimeRadix.DEFAULT;
- }
- return boxList.get(0).trace.getTimeManager().getTimeRadix();
- }
-
- public String getTagForTick(long tick) {
- TimeRadix radix = getTimeRadix();
- String tval = "";
- if (0 <= tick && tick < timesArray.length) {
- Long time = timesArray[(int) tick];
- tval = radix.format(time);
- }
- return tval;
- }
-
- public void scaleCurrentPixelAddr(double changeAmount) {
- this.currentPixelAddr = (int) (currentPixelAddr * Math.pow(2.0, changeAmount));
- }
-
- public void scaleCurrentPixelTime(double changeAmount) {
- this.currentPixelTime = (int) (currentPixelTime * Math.pow(2.0, changeAmount));
- }
-
-}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewProvider.java
index a580a6153a..5ced84e336 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewProvider.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewProvider.java
@@ -15,301 +15,36 @@
*/
package ghidra.app.plugin.core.debug.gui.memview;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-import java.util.List;
+import javax.swing.Icon;
-import javax.swing.*;
-
-import docking.ActionContext;
-import docking.DefaultActionContext;
-import docking.action.DockingAction;
import docking.action.builder.ToggleActionBuilder;
-import ghidra.app.plugin.core.debug.DebuggerPluginPackage;
-import ghidra.app.plugin.core.debug.gui.DebuggerResources;
-import ghidra.app.plugin.core.debug.gui.DebuggerResources.AbstractRefreshAction;
-import ghidra.app.plugin.core.debug.gui.memview.actions.*;
-import ghidra.app.services.DebuggerListingService;
-import ghidra.framework.plugintool.*;
-import ghidra.framework.plugintool.AutoService.Wiring;
-import ghidra.framework.plugintool.annotation.AutoServiceConsumed;
-import ghidra.program.model.listing.Program;
+import generic.theme.GIcon;
+import ghidra.app.plugin.core.bento.BentoProvider;
+import ghidra.app.plugin.core.bento.BentoServicePlugin;
+import ghidra.framework.plugintool.PluginTool;
import ghidra.util.HelpLocation;
-import ghidra.util.Swing;
-
-public class MemviewProvider extends ComponentProviderAdapter {
-
- private static final String TITLE = "Memview";
-
- private Wiring autoServiceWiring;
- @AutoServiceConsumed
- private DebuggerListingService listingService;
-
- private DebuggerMemviewPlugin plugin;
- private JComponent mainPanel;
- private MemviewPanel memviewPanel;
- private MemviewTable memviewTable;
- private JScrollPane scrollPane;
-
- //private Address location;
- private boolean vertical = true;
- private boolean applyFilter = true;
+import resources.ResourceManager;
- private double zoomAmountA = 1.0;
- private double zoomAmountT = 1.0;
- long halfPage = 512L;
+public class MemviewProvider extends BentoProvider {
- public MemviewProvider(PluginTool tool, DebuggerMemviewPlugin plugin) {
- super(tool, TITLE, plugin.getName());
- this.plugin = plugin;
+ private static final Icon ICON_SYNC =
+ ResourceManager.getScaledIcon(new GIcon("icon.widget.imagepanel.reset"), 12, 12);
- this.autoServiceWiring = AutoService.wireServicesConsumed(plugin, this);
-
- //setIcon(DebuggerResources.ICON_PROVIDER_REGIONS);
- //setHelpLocation(DebuggerResources.HELP_PROVIDER_REGIONS);
- setWindowMenuGroup(DebuggerPluginPackage.NAME);
-
- mainPanel = new JPanel(new BorderLayout());
- mainPanel.addComponentListener(new ComponentAdapter() {
- @Override
- public void componentResized(ComponentEvent e) {
- resized();
- }
- });
- tool.addComponentProvider(this, false);
- createActions();
- buildPanel();
+ public MemviewProvider(PluginTool tool, BentoServicePlugin plugin) {
+ super(tool, plugin, false);
}
- private void createActions() {
-
- DockingAction zoomInAAction = new ZoomInAAction(this);
- tool.addLocalAction(this, zoomInAAction);
-
- DockingAction zoomOutAAction = new ZoomOutAAction(this);
- tool.addLocalAction(this, zoomOutAAction);
-
- DockingAction zoomInTAction = new ZoomInTAction(this);
- tool.addLocalAction(this, zoomInTAction);
-
- DockingAction zoomOutTAction = new ZoomOutTAction(this);
- tool.addLocalAction(this, zoomOutTAction);
-
- new ToggleActionBuilder("Toggle Layout", plugin.getName()) //
- //.menuPath("&Toggle layout") //
- .toolBarIcon(AbstractRefreshAction.ICON)
- .helpLocation(new HelpLocation(plugin.getName(), "toggle_layout")) //
- .onAction(ctx -> performToggleLayout(ctx))
- .buildAndInstallLocal(this);
+ @Override
+ protected void createActions() {
+ super.createActions();
- new ToggleActionBuilder("Toggle Process Trace", plugin.getName()) //
+ new ToggleActionBuilder("Toggle Tracking", getOwner()) //
//.menuPath("&Toggle layout") //
- .toolBarIcon(DebuggerResources.ICON_SYNC)
- .helpLocation(new HelpLocation(plugin.getName(), "toggle_process_trace")) //
- .onAction(ctx -> performToggleTrace(ctx))
+ .toolBarIcon(ICON_SYNC)
+ .helpLocation(new HelpLocation(getOwner(), "toggle_tracking")) //
+ .onAction(ctx -> performToggleTracking(ctx))
.selected(false)
.buildAndInstallLocal(this);
- new ToggleActionBuilder("Apply Filter To Panel", plugin.getName()) //
- //.menuPath("&Toggle layout") //
- .toolBarIcon(DebuggerResources.ICON_FILTER)
- .helpLocation(new HelpLocation(plugin.getName(), "apply_to_panel")) //
- .onAction(ctx -> performApplyFilterToPanel(ctx))
- .selected(true)
- .buildAndInstallLocal(this);
-
- }
-
- void buildPanel() {
- mainPanel.removeAll();
- memviewPanel = new MemviewPanel(this);
- memviewTable = new MemviewTable(this);
-
- scrollPane = new JScrollPane(memviewPanel);
- scrollPane.setPreferredSize(memviewPanel.getSize());
-
- JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
- splitPane.setRightComponent(scrollPane);
- splitPane.setLeftComponent(memviewTable.getComponent());
- splitPane.setDividerLocation(0.5);
- mainPanel.add(splitPane, BorderLayout.CENTER);
- //mainPanel.add(memviewTable.getComponent(), BorderLayout.WEST);
-
- setDirection();
-
- mainPanel.validate();
- }
-
- private void performToggleLayout(ActionContext ctx) {
- vertical = !vertical;
- setDirection();
- refresh();
- }
-
- private void performToggleTrace(ActionContext ctx) {
- plugin.toggleTrackTrace();
- }
-
- private void performApplyFilterToPanel(ActionContext ctx) {
- applyFilter = !isApplyFilter();
- applyFilter();
- }
-
- public void applyFilter() {
- if (applyFilter) {
- memviewTable.applyFilter();
- }
- else {
- memviewPanel.setBoxes(memviewTable.getBoxes());
- }
- refresh();
- }
-
- private void setDirection() {
- memviewPanel.setVerticalMode(vertical);
- }
-
- void dispose() {
- tool.removeComponentProvider(this);
- }
-
- @Override
- public ActionContext getActionContext(MouseEvent event) {
- if (event != null && event.getSource() == mainPanel) {
- return new DefaultActionContext(this, mainPanel);
- }
- if (event != null && event.getSource() == memviewPanel) {
- return new DefaultActionContext(this, memviewPanel);
- }
- return null;
- }
-
- @Override
- public JComponent getComponent() {
- return mainPanel;
- }
-
- @Override
- public HelpLocation getHelpLocation() {
- return new HelpLocation(plugin.getName(), plugin.getName());
- }
-
- public void setProgram(Program program) {
- memviewTable.setProgram(program);
- }
-
- public void initViews() {
- memviewPanel.initViews();
- memviewPanel.setPreferredSize(new Dimension(300, 100));
- memviewTable.setListingService(listingService);
- mainPanel.doLayout();
- mainPanel.repaint();
- }
-
- public void refresh() {
- String subTitle = " (" + zoomAmountA + "x:" + zoomAmountT + ") ";
- subTitle += memviewPanel.getTitleAnnotation();
- setSubTitle(subTitle);
- memviewPanel.refresh();
- scrollPane.getViewport().doLayout();
- }
-
- public void goTo(int x, int y) {
- Rectangle bounds = scrollPane.getBounds();
- scrollPane.getViewport()
- .scrollRectToVisible(new Rectangle(x, y, bounds.width, bounds.height));
- scrollPane.getViewport().doLayout();
- }
-
- public void goTo(MemoryBox box) {
- Point p = new Point(box.getX(vertical) - 10, box.getY(vertical) - 10);
- Point p0 = scrollPane.getViewport().getViewPosition();
- int w = scrollPane.getViewport().getWidth();
- int h = scrollPane.getViewport().getHeight();
- if (p.x > p0.x && p.x < p0.x + w && p.y > p0.y && p.y < p0.y + h) {
- return;
- }
- scrollPane.getViewport().setViewPosition(p);
- }
-
- public void selectTableEntry(Set<MemoryBox> boxes) {
- memviewTable.setSelection(boxes);
- }
-
- public void selectPanelPosition(Set<MemoryBox> boxes) {
- memviewPanel.setSelection(boxes);
- if (boxes.size() == 1) {
- Iterator<MemoryBox> iterator = boxes.iterator();
- goTo(iterator.next());
- }
- }
-
- public void changeZoomA(int changeAmount) {
- this.zoomAmountA = (float) (zoomAmountA * Math.pow(2.0, changeAmount));
- memviewPanel.scaleCurrentPixelAddr(changeAmount);
- }
-
- public double getZoomAmountA() {
- return zoomAmountA;
- }
-
- public void changeZoomT(int changeAmount) {
- this.zoomAmountT = (float) (zoomAmountT * Math.pow(2.0, changeAmount));
- memviewPanel.scaleCurrentPixelTime(changeAmount);
- }
-
- public double getZoomAmountT() {
- return zoomAmountT;
- }
-
- void resized() {
- memviewPanel.refresh();
- }
-
- public void setBoxes(List<MemoryBox> blist) {
- Swing.runIfSwingOrRunLater(() -> {
- memviewTable.setBoxes(blist);
- memviewTable.applyFilter();
- //memviewPanel.setBoxes(memviewTable.getBoxes());
- });
- }
-
- public void setBoxesInPanel(List<MemoryBox> blist) {
- Swing.runIfSwingOrRunLater(() -> {
- memviewPanel.setBoxes(blist);
- memviewPanel.refresh();
- });
- }
-
- public void addBox(MemoryBox box) {
- List<MemoryBox> blist = new ArrayList<>();
- blist.add(box);
- addBoxes(blist);
- }
-
- public void addBoxes(List<MemoryBox> blist) {
- Swing.runIfSwingOrRunLater(() -> {
- memviewTable.addBoxes(blist);
- memviewTable.applyFilter();
- //memviewPanel.addBoxes(memviewTable.getBoxes());
- });
- }
-
- public boolean isApplyFilter() {
- return applyFilter;
- }
-
- public void reset() {
- Swing.runIfSwingOrRunLater(() -> {
- memviewTable.reset();
- memviewPanel.reset();
- });
- }
-
- void fireTableDataChanged() {
- Swing.runIfSwingOrRunLater(() -> {
- memviewTable.fireTableDataChanged();
- });
}
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewService.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewService.java
index 921705a65a..b9212f4e65 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewService.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewService.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,24 +15,19 @@
*/
package ghidra.app.plugin.core.debug.gui.memview;
-import java.util.List;
-
+import ghidra.app.plugin.core.bento.BentoService;
import ghidra.framework.plugintool.ServiceInfo;
-import ghidra.program.model.listing.Program;
/**
* The MemviewService provides a general service for displaying objects
* on time vs. memory axes (a la Boxes)
*/
-@ServiceInfo(defaultProvider = DebuggerMemviewPlugin.class, description = "Display memory vs. time events")
-public interface MemviewService {
-
- public void setBoxes(List<MemoryBox> boxList);
-
- public void initViews();
-
- public void setProgram(Program currentProgram);
+@ServiceInfo(
+ defaultProvider = DebuggerMemviewPlugin.class,
+ description = "Display memory vs. time events"
+)
+public interface MemviewService extends BentoService {
- public MemviewProvider getProvider();
+ // No additonal members
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewTable.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewTable.java
deleted file mode 100644
index 065cd2b2bb..0000000000
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewTable.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ghidra.app.plugin.core.debug.gui.memview;
-
-import java.awt.BorderLayout;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.util.*;
-
-import javax.swing.*;
-
-import docking.widgets.filter.FilterListener;
-import generic.theme.GIcon;
-import ghidra.app.services.DebuggerListingService;
-import ghidra.program.model.address.Address;
-import ghidra.program.model.address.AddressRangeImpl;
-import ghidra.program.model.listing.Program;
-import ghidra.util.table.GhidraTable;
-import ghidra.util.table.GhidraTableFilterPanel;
-import ghidra.util.task.SwingUpdateManager;
-
-public class MemviewTable {
-
- public static final Icon ICON_TABLE = new GIcon("icon.table");
-
- private MemviewMapModel model;
- private GhidraTable table;
- private GhidraTableFilterPanel<?> filterPanel;
- private FilterListener filterListener;
- private SwingUpdateManager applyFilterManager = new SwingUpdateManager(this::applyFilter);
- private JPanel component;
-
- private MemviewProvider provider;
- private Program program;
- private DebuggerListingService listingService;
-
- public MemviewTable(MemviewProvider provider) {
- this.provider = provider;
- this.model = new MemviewMapModel(provider);
- this.table = new GhidraTable(model);
- table.setHTMLRenderingEnabled(true);
- this.component = new JPanel(new BorderLayout());
- JScrollPane scrollPane = new JScrollPane(table);
- filterPanel = new GhidraTableFilterPanel<>(table, model);
- component.add(scrollPane, BorderLayout.CENTER);
- component.add(filterPanel, BorderLayout.SOUTH);
- table.setAutoscrolls(true);
-
- String namePrefix = "Memory View";
- table.setAccessibleNamePrefix(namePrefix);
- filterPanel.setAccessibleNamePrefix(namePrefix);
-
- table.getSelectionModel().addListSelectionListener(e -> {
- if (e.getValueIsAdjusting()) {
- return;
- }
- int modelRow = filterPanel.getModelRow(table.getSelectedRow());
- MemoryBox box = model.getBoxAt(modelRow);
- if (box != null) {
- Set<MemoryBox> boxes = new HashSet<>();
- boxes.add(box);
- provider.selectPanelPosition(boxes);
- }
- });
- table.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- if (e.getClickCount() == 2) {
- navigateToSelectedObject();
- }
- }
- });
-
- filterListener = new FilterActionFilterListener();
- filterPanel.addFilterChagnedListener(filterListener);
- }
-
- public JComponent getComponent() {
- return component;
- }
-
- public JComponent getPrincipalComponent() {
- return table;
- }
-
- public void setProgram(Program program) {
- this.program = program;
- }
-
- public void setListingService(DebuggerListingService listingService) {
- this.listingService = listingService;
- }
-
- public void setBoxes(Collection<MemoryBox> blist) {
- model.setBoxes(blist);
- }
-
- public void addBoxes(Collection<MemoryBox> blist) {
- model.addBoxes(blist);
- }
-
- public void reset() {
- model.reset();
- }
-
- public List<MemoryBox> getBoxes() {
- return model.getBoxes();
- }
-
- public void setSelection(Set<MemoryBox> set) {
- table.clearSelection();
- for (MemoryBox box : set) {
- int index = model.getIndexForBox(box);
- int viewRow = filterPanel.getViewRow(index);
- if (viewRow >= 0) {
- table.addRowSelectionInterval(viewRow, viewRow);
- table.scrollToSelectedRow();
- }
- }
- }
-
- protected void navigateToSelectedObject() {
- int selectedRow = table.getSelectedRow();
- int selectedColumn = table.getSelectedColumn();
- Object value = table.getValueAt(selectedRow, selectedColumn);
- Address addr = null;
- if (value instanceof Address) {
- addr = (Address) value;
- }
- if (value instanceof AddressRangeImpl) {
- AddressRangeImpl range = (AddressRangeImpl) value;
- addr = range.getMinAddress();
- }
- if (value instanceof Long) {
- Long lval = (Long) value;
- if (program != null) {
- addr = program.getAddressFactory().getAddressSpace("ram").getAddress(lval);
- }
- }
- if (listingService != null) {
- listingService.goTo(addr, true);
- }
- }
-
- public void applyFilter() {
- List<MemoryBox> blist = new ArrayList<>();
- for (int i = 0; i < filterPanel.getRowCount(); i++) {
- int row = filterPanel.getModelRow(i);
- if (row >= 0) {
- blist.add(model.getBoxAt(row));
- }
- }
- provider.setBoxesInPanel(blist);
- }
-
- private class FilterActionFilterListener implements FilterListener {
- @Override
- public void filterChanged(String text) {
- if (provider.isApplyFilter()) {
- applyFilterManager.updateLater();
- }
- }
- }
-
- void fireTableDataChanged() {
- model.fireTableDataChanged();
- }
-
- /*
- private List<MemviewRow> generateRows(Collection<MemoryBox> changed) {
- List<MemviewRow> list = new ArrayList<>();
- for (MemoryBox box : changed) {
- list.add(new MemviewRow(box));
- }
- if (model instanceof EnumeratedColumnTableModel) {
- @SuppressWarnings("unchecked")
- EnumeratedColumnTableModel<MemviewRow> m =
- (EnumeratedColumnTableModel<MemviewRow>) model;
- m.clear();
- m.addAll(list);
- }
- setColumns();
- model.fireTableStructureChanged();
- return list;
- }
- */
-
- /*
- private MemviewRow findMatch(MemoryBox changed) {
- MemviewRow match = null;
- for (int i = 0; i < model.getRowCount(); i++) {
- MemviewRow row = model.getRowObject(i);
- if (row.getBox().equals(changed)) {
- row.setAttributes(changed.getAttributeMap());
- match = row;
- break;
- }
- }
- return match;
- }
- */
-
- /*
- private List<MemviewRow> updateMatch(MemviewRow match) {
- MemviewEnumeratedColumnTableModel m = (MemviewEnumeratedColumnTableModel) model;
- m.updateColumns(match);
- m.fireTableDataChanged();
- List<MemviewRow> list = new ArrayList<>();
- if (match != null) {
- list.add(match);
- model.setLastSelectedObjects(list);
- model.fireTableStructureChanged();
- }
- return list;
- }
- */
-
- /*
- public void setColumns() {
- MemviewEnumeratedColumnTableModel m = (MemviewEnumeratedColumnTableModel) model;
- for (int i = 0; i < model.getRowCount(); i++) {
- MemviewRow r = model.getRowObject(i);
- m.updateColumns(r);
- }
- m.fireTableStructureChanged();
- }
- */
-
- /*
- public TargetObject getSelectedObject() {
- int selectedColumn = table.getSelectedColumn();
- R r = model.getRowObject(table.getSelectedRow());
- if (r instanceof ObjectAttributeRow) {
- ObjectAttributeRow row = (ObjectAttributeRow) r;
- return row.getTargetObject();
- }
- if (r instanceof MemviewRow) {
- MemviewRow row = (MemviewRow) r;
- TargetObject targetObject = row.getTargetObject();
- if (selectedColumn > 0) {
- List<String> keys = row.getKeys();
- if (selectedColumn >= keys.size()) {
- selectedColumn = 0;
- }
- String key = keys.get(selectedColumn);
- Map<String, ?> attributes = targetObject.getCachedAttributes();
- Object object = attributes.get(key);
- if (object instanceof TargetObject) {
- return (TargetObject) object;
- }
- }
- return targetObject;
- }
- return null;
- }
- */
-
- /*
- public void setSelectedObject(MemoryBox selection) {
- for (int i = 0; i < model.getRowCount(); i++) {
- MemviewRow row = model.getRowObject(i);
- if (row.getBox().equals(selection)) {
- table.selectRow(i);
- break;
- }
- }
- }
- */
-
- /*
- public void setFocus(MemoryBox focused) {
- Swing.runIfSwingOrRunLater(() -> {
- setSelectedObject(focused);
- });
- }
- */
-
-}
diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifest
index c4a2a78013..7706f188ff 100644
--- a/Ghidra/Features/Base/certification.manifest
+++ b/Ghidra/Features/Base/certification.manifest
@@ -263,6 +263,8 @@ src/main/help/help/topics/AutoAnalysisPlugin/images/AutoAnalysis.png||GHIDRA||||
src/main/help/help/topics/AutoAnalysisPlugin/images/AutoAnalysisOptions.png||GHIDRA||||END|
src/main/help/help/topics/AutoAnalysisPlugin/images/BackgroundAnalysisTasks.png||GHIDRA||||END|
src/main/help/help/topics/AutoAnalysisPlugin/images/ProgramOptions.png||GHIDRA||||END|
+src/main/help/help/topics/BentoServicePlugin/BentoServicePlugin.html||GHIDRA||||END|
+src/main/help/help/topics/BentoServicePlugin/images/BentoServicePlugin.png||GHIDRA||||END|
src/main/help/help/topics/BlockModel/Block_Model.htm||GHIDRA||||END|
src/main/help/help/topics/BlockModel/images/BasicBlockCode.png||GHIDRA||||END|
src/main/help/help/topics/BookmarkPlugin/Bookmarks.htm||GHIDRA||||END|
diff --git a/Ghidra/Features/Base/data/base.icons.theme.properties b/Ghidra/Features/Base/data/base.icons.theme.properties
index 729e6b709b..5cb285e819 100644
--- a/Ghidra/Features/Base/data/base.icons.theme.properties
+++ b/Ghidra/Features/Base/data/base.icons.theme.properties
@@ -38,6 +38,8 @@ icon.plugin.datatypes.structure = cstruct.png
icon.plugin.assembler.question = question_zero.png
+icon.plugin.bento.refresh = icon.refresh
+
icon.plugin.bookmark.add = icon.check
icon.plugin.bookmark.delete = icon.base.delete
icon.plugin.bookmark.select = text_align_justify.png
diff --git a/Ghidra/Features/Base/src/main/help/help/TOC_Source.xml b/Ghidra/Features/Base/src/main/help/help/TOC_Source.xml
index a9f086ddac..bc0171c5d2 100644
--- a/Ghidra/Features/Base/src/main/help/help/TOC_Source.xml
+++ b/Ghidra/Features/Base/src/main/help/help/TOC_Source.xml
@@ -334,6 +334,7 @@
<tocdef id="Scalars" sortgroup="e" text="Scalars" target="help/topics/ScalarSearchPlugin/The_Scalar_Table.htm" />
<tocdef id="Instruction Patterns" sortgroup="f" text="Instruction Patterns" target="help/topics/Search/Search_Instruction_Patterns.htm" />
<tocdef id="Address Tables" sortgroup="g" text="Address Tables" target="help/topics/Search/Search_for_AddressTables.htm" />
+ <tocdef id="Bento View" text="Bento View" target="help/topics/BentoServicePlugin/BentoServicePlugin.html" />
<tocdef id="Direct References" sortgroup="h" text="Direct References" target="help/topics/Search/Search_for_DirectReferences.htm" />
<tocdef id="Search Results Window" sortgroup="i" text="Query Results Window" target="help/topics/Search/Query_Results_Dialog.htm" />
</tocdef>
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/BentoServicePlugin/BentoServicePlugin.html b/Ghidra/Features/Base/src/main/help/help/topics/BentoServicePlugin/BentoServicePlugin.html
new file mode 100644
index 0000000000..5ccd415d06
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/help/help/topics/BentoServicePlugin/BentoServicePlugin.html
@@ -0,0 +1,76 @@
+<!DOCTYPE doctype PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN">
+
+<HTML>
+ <HEAD>
+ <META name="generator" content=
+ "HTML Tidy for Java (vers. 2009-12-01), see jtidy.sourceforge.net">
+
+ <TITLE>Bento View</TITLE>
+ <META http-equiv="Content-Type" content="text/html; charset=windows-1252">
+ <LINK rel="stylesheet" type="text/css" href="help/shared/DefaultStyle.css">
+ </HEAD>
+
+ <BODY lang="EN-US">
+ <H1><A name="plugin"></A>Bento View</H1>
+
+ <DIV class="image">
+ <IMG alt="" src="images/BentoServicePlugin.png">
+ </DIV>
+
+ <P>The bento view window provides a generic x vs. y (or y vs. x) plot of
+ objects marked as of interest. The plot may be populated from either a script, typically
+ processing row objects, or updated on-the-fly as with the MemviewPlugin (shown above), which extends it.
+ The objects are listed in the viewer's table on the left for the purpose of quick
+ identification and sorting, and displayed in a scrolled plotting panel on the right.</P>
+
+ <P>The panel does NOT preserve distances. Rather, the objects are plotted based on the order of
+ their lower/upper x/y bounds. In other words, if two address vs. time objects are plotted with address
+ ranges [0x100-0x102] and [0x10000000-0x20000000], positions 1-4 on the address axis will
+ correspond to the addresses 0x100, 0x102, 0x10000000, and 0x20000000. Mousing over the object
+ should display it's true bounds, but, in some cases, you will need to locate on the top left
+ corner to get an accurate tool tip. Points past the maximum x- or y-value will not display
+ values for that coordinate.</P>
+
+ <H2>Table</H2>
+
+ <P>The table on the right provides the standard Ghidra table-style interface listing each
+ object, its starting and ending x-values and starting and ending y-values, if available. Clicking
+ on start/end values will navigate in the listing if they represent addresses. All columns are
+ sortable, and the tables filterable, as usual. A single selected row will cause a red arrow to
+ be drawn at the top left corner of the corresponding object in the panel. Applying the filter
+ will redisplay only the selected objects in the panel, if that option is enabled.</P>
+
+ <H2>Plot Panel</H2>
+
+ <P>The panel displays all of the objects in the table or the table's selection, depending on the
+ options enabled. Clicking on the panel will set the red arrow at that position and display the
+ current position in the title. The size of the panel can be expanded or contracted on either axis
+ with the Zoom buttons. The top left corner of the panel (which may or may not be visible depending on
+ scrolling) always corresponds to the first y-value and the first x-value. Scroll bars are enabled
+ if any object lies outside the viewable portion of the panel. Drag&amp;drop can also be used to
+ position the panel view. Ctrl-drag&amp;drop draws a box around a region of the display, and the
+ enclosed objects are selected in the table.</P>
+
+ <H2>Navigation</H2>
+
+ <H3><A name="zoom"></A><IMG alt="" src="icon.widget.imagepanel.zoom.in">Zoom</H3>
+
+ <P>The four zoom buttons either contract or expand the view along the x- or y-axes.</P>
+
+ <H3><A name="toggle_layout"></A><IMG alt="" src="icon.plugin.bento.refresh">Toggle Layout</H3>
+
+ <P>The default panel view is x vs. y. The toggle button serves as both the way to
+ switch views and to refresh the display.</P>
+
+ <H3><A name="toggle_tracking"></A><IMG alt="" src="icon.widget.imagepanel.reset">Toggle Tracking</H3>
+
+ <P>By default, as new objects are added, they appear in the table and panel. The behavior
+ can be toggled on or off at the user's discretion.</P>
+
+ <H3><A name="apply_to_panel"></A><IMG alt="" src="icon.widget.filterpanel.filter.off">Toggle Apply
+ Filter</H3>
+
+ <P>This button determines whether the table filter affects the plot panel. When toggled on,
+ only objects listed in the table are displayed in the plot.</P>
+ </BODY>
+</HTML>
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/BentoServicePlugin/images/BentoServicePlugin.png b/Ghidra/Features/Base/src/main/help/help/topics/BentoServicePlugin/images/BentoServicePlugin.png
new file mode 100644
index 0000000000..5e7231ba9c
Binary files /dev/null and b/Ghidra/Features/Base/src/main/help/help/topics/BentoServicePlugin/images/BentoServicePlugin.png differ
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/AddressRangeBoundedObject.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/AddressRangeBoundedObject.java
new file mode 100644
index 0000000000..5ae9a059dd
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/AddressRangeBoundedObject.java
@@ -0,0 +1,43 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+import ghidra.program.model.address.AddressRange;
+
+public class AddressRangeBoundedObject extends BoundedObject {
+
+ public AddressRangeBoundedObject(AddressRange range) {
+ super(range.getMinAddress().getOffset(), range.getMaxAddress().getOffset());
+ this.loRep = range.getMinAddress();
+ this.hiRep = range.getMaxAddress();
+ this.obj = range;
+ }
+
+ @Override
+ public BentoRadix getDefaultRadix() {
+ return BentoRadix.HEX_LOWER;
+ }
+
+ @Override
+ public Object getLowRep() {
+ return loRep;
+ }
+
+ @Override
+ public Object getHiRep() {
+ return hiRep;
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoAxialData.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoAxialData.java
new file mode 100644
index 0000000000..2292bd8bf4
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoAxialData.java
@@ -0,0 +1,185 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+import java.util.*;
+
+public class BentoAxialData {
+
+ private BentoProvider provider;
+ private int index;
+
+ // map - pixels to positions
+ private BentoPixelMap pix2pos;
+ // map - position to box
+ private Map<Long, Set<BentoBox>> pos2box = new HashMap<>();
+ // sorted values
+ private TreeSet<Long> values = new TreeSet<>();
+ // values indexed by position
+ private Long[] valueArray = new Long[0];
+
+ private int currentPixel = -1;
+ private double zoomAmount = 1.0;
+
+
+ public BentoAxialData(BentoProvider provider, int index) {
+ this.provider = provider;
+ this.index = index;
+ }
+
+ int initViews() {
+ this.setMap(new BentoPixelMap(values.size(), values.size()));
+ return values.size();
+ }
+
+ public void refresh() {
+ if (pix2pos == null) {
+ return;
+ }
+ pix2pos.createMapping(zoomAmount);
+ }
+
+
+ public void parseBoxes(Collection<BentoBox> boxes) {
+ values.clear();
+ pos2box.clear();
+
+ if (boxes == null || boxes.isEmpty()) {
+ valueArray = new Long[0];
+ initViews();
+ return;
+ }
+
+ for (BentoBox box : boxes) {
+ BoundedObject obj = box.getObj(getIndex());
+ if (obj != null) {
+ values.add(obj.loBound);
+ values.add(obj.hiBound);
+ }
+ }
+
+ initViews();
+ valueArray = values.toArray(new Long[0]);
+
+ Map<Long, Integer> valueToIndexMap = new HashMap<>(valueArray.length);
+ for (int i = 0; i < valueArray.length; i++) {
+ valueToIndexMap.put(valueArray[i], i);
+ }
+
+ for (BentoBox box : boxes) {
+ BoundedObject obj = box.getObj(getIndex());
+ if (obj == null) {
+ continue;
+ }
+
+ int startPos = valueToIndexMap.getOrDefault(obj.loBound, 0);
+ int stopPos = valueToIndexMap.getOrDefault(obj.hiBound, 0);
+
+ obj.setStart(startPos);
+ obj.setStop(stopPos);
+
+ pos2box.computeIfAbsent(obj.getStart(), _ -> new HashSet<>()).add(box);
+ pos2box.computeIfAbsent(obj.getStop(), _ -> new HashSet<>()).add(box);
+ }
+ }
+
+ public long getPos(int pixel) {
+ if (pix2pos == null) {
+ return 0;
+ }
+ return pix2pos.getOffset(pixel);
+ }
+
+ public String getTagForPos(Long position) {
+ if (valueArray == null) {
+ return "";
+ }
+
+ int pos = position == null ? (int) getPos(currentPixel) : position.intValue();
+
+ if (pos >= 0 && pos < valueArray.length) {
+ Long val = valueArray[pos];
+ return provider.getRadix(index).format(val);
+ }
+ return "";
+ }
+
+ public double getZoom() {
+ return zoomAmount;
+ }
+
+ public void scaleCurrentPixel(double changeAmount) {
+ this.zoomAmount = (float) (zoomAmount * Math.pow(2.0, changeAmount));
+ this.currentPixel = (int) (currentPixel * Math.pow(2.0, changeAmount));
+ }
+
+ public int getSizeValues() {
+ return values.size();
+ }
+
+ public BentoPixelMap getMap() {
+ return pix2pos;
+ }
+
+ public void setMap(BentoPixelMap map) {
+ this.pix2pos = map;
+ }
+
+ public TreeSet<Long> getValues() {
+ return values;
+ }
+
+ public void setValues(TreeSet<Long> values) {
+ this.values = values;
+ if (values != null) {
+ this.valueArray = values.toArray(new Long[0]);
+ }
+ }
+
+ public Long[] getArray() {
+ return valueArray;
+ }
+
+ public Long[] setArray(Long[] array) {
+ this.valueArray = array;
+ return this.valueArray;
+ }
+
+ public Map<Long, Set<BentoBox>> getPosMap() {
+ return pos2box;
+ }
+
+ public void setPosMap(Map<Long, Set<BentoBox>> pos2box) {
+ this.pos2box = pos2box;
+ }
+
+ public int getCurrentPixel() {
+ return currentPixel;
+ }
+
+ public void setCurrentPixel(int pixel) {
+ this.currentPixel = pixel;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoBox.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoBox.java
new file mode 100644
index 0000000000..44d42d5432
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoBox.java
@@ -0,0 +1,107 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+import java.awt.*;
+import java.util.List;
+
+import generic.theme.GThemeDefaults.Colors;
+
+public class BentoBox {
+
+ protected final String id;
+ protected final List<BoundedObject> obj;
+
+ protected Color color;
+
+ public BentoBox(String id, BoundedObject objX, BoundedObject objY, Color color) {
+ this.id = id;
+ this.obj = List.of(objX, objY);
+ this.color = color;
+ }
+
+ public BentoBox(String id, List<BoundedObject> objects, Color color) {
+ this.id = id;
+ this.color = color;
+ this.obj = List.copyOf(objects);
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public int getNumIndices() {
+ return obj.size();
+ }
+
+ public long getLowBound(int index) {
+ return obj.get(index).loBound;
+ }
+
+ public long getHighBound(int index) {
+ return obj.get(index).hiBound;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ public BoundedObject getObj(int index) {
+ return obj.get(index);
+ }
+
+ public MappedObject getMappedObj(int index) {
+ return obj.get(index).getMappedObject();
+ }
+
+ public int getPixelStart(int index) {
+ return getMappedObj(index).getPixelStart();
+ }
+
+ public int getPixelWidth(int index) {
+ return getMappedObj(index).getPixelWidth();
+ }
+
+ public void render(Graphics g, int xIndex, int yIndex) {
+ int x = getPixelStart(xIndex);
+ int w = getPixelWidth(xIndex);
+ int y = getPixelStart(yIndex);
+ int h = getPixelWidth(yIndex);
+ g.setColor(Colors.BORDER);
+ g.fillRect(x - 1, y - 1, w + 2, h + 2);
+ g.setColor(color);
+ g.fillRect(x, y, w, h);
+ }
+
+ public Rectangle getRectangle(int xIndex, int yIndex) {
+ BoundedObject objX = obj.get(xIndex);
+ BoundedObject objY = obj.get(yIndex);
+ return new Rectangle(
+ (int) objX.getStart(), (int) objY.getStart(),
+ (int) (objX.getStop() - objX.getStart() + 1),
+ (int) (objY.getStop() - objY.getStart() + 1));
+ }
+
+ @Override
+ public String toString() {
+ return id != null ? id : "BentoBox (unnamed)";
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoMapModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoMapModel.java
new file mode 100644
index 0000000000..379596cfb7
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoMapModel.java
@@ -0,0 +1,289 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+import java.util.*;
+
+import docking.widgets.table.AbstractSortedTableModel;
+
+class BentoMapModel extends AbstractSortedTableModel<BentoBox> {
+
+ final static byte NAME = 0;
+ final static byte XSTART = 1;
+ final static byte XSTOP = 2;
+ final static byte YSTART = 3;
+ final static byte YSTOP = 4;
+
+ final static String NAME_COL = "Name";
+ final static String XSTART_COL = "Start X";
+ final static String XSTOP_COL = "End X";
+ final static String YSTART_COL = "Start Y";
+ final static String YSTOP_COL = "End Y";
+
+ private BentoProvider provider;
+ private List<BentoBox> boxList = new ArrayList<>();
+ private Map<String, BentoBox> boxMap = new HashMap<>();
+
+ private List<Integer> columnIndices = new ArrayList<>(
+ List.of(-1, 0, 0, 1, 1));
+ private List<Boolean> columnBounds = new ArrayList<>(
+ List.of(true, true, false, true, false));
+ private List<String> columnNames = new ArrayList<>(
+ List.of(NAME_COL, XSTART_COL, XSTOP_COL, YSTART_COL, YSTOP_COL));
+
+ private List<String> names;
+ private int xIndex = 0;
+ private int yIndex = 1;
+
+ public BentoMapModel(BentoProvider provider) {
+ super(YSTART);
+ this.provider = provider;
+ }
+
+ public List<BentoBox> getBoxes() {
+ return Collections.unmodifiableList(boxList);
+ }
+
+ public void addBoxes(Collection<BentoBox> boxes) {
+ boolean altered = false;
+ for (BentoBox b : boxes) {
+ if (b == null || b.getId() == null)
+ continue;
+
+ BentoBox oldBox = boxMap.put(b.getId(), b);
+ if (oldBox != null) {
+ boxList.remove(oldBox);
+ }
+ boxList.add(b);
+ altered = true;
+ }
+
+ if (altered) {
+ fireTableDataChanged();
+ }
+ }
+
+ public void setBoxes(Collection<BentoBox> boxes) {
+ boxList.clear();
+ boxMap.clear();
+ for (BentoBox b : boxes) {
+ if (b == null || b.getId() == null) {
+ continue;
+ }
+ boxList.add(b);
+ boxMap.put(b.getId(), b);
+ }
+ fireTableDataChanged();
+ }
+
+ public void reset() {
+ boxList.clear();
+ boxMap.clear();
+ fireTableDataChanged();
+ }
+
+ @Override
+ public boolean isSortable(int columnIndex) {
+ return true;
+ }
+
+ @Override
+ public String getName() {
+ return "X vs Y Map";
+ }
+
+ @Override
+ public int getColumnCount() {
+ return columnNames.size();
+ }
+
+ @Override
+ public String getColumnName(int column) {
+
+ if (column < 0 || column >= columnNames.size()) {
+ return "UNKNOWN";
+ }
+
+ return columnNames.get(column);
+ }
+
+ /**
+ * Convenience method for locating columns by name. Implementation is naive so this should be
+ * overridden if this method is to be called often. This method is not in the TableModel
+ * interface and is not used by the JTable.
+ */
+ @Override
+ public int findColumn(String columnName) {
+ for (int i = 0; i < columnNames.size(); i++) {
+ if (columnNames.get(i).equals(columnName)) {
+ return i;
+ }
+ }
+ return 0;
+ }
+
+ /**
+ * Returns Object.class by default
+ */
+ @Override
+ public Class<?> getColumnClass(int columnIndex) {
+ return String.class;
+ }
+
+ /**
+ * Return whether this column is editable.
+ */
+ @Override
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ return false;
+ }
+
+ /**
+ * Returns the number of records managed by the data source object. A <B>JTable</B> uses this
+ * method to determine how many rows it should create and display. This method should be quick,
+ * as it is call by <B>JTable</B> quite frequently.
+ *
+ * @return the number or rows in the model
+ * @see #getColumnCount
+ */
+ @Override
+ public int getRowCount() {
+ return boxList.size();
+ }
+
+ public BentoBox getBoxAt(int rowIndex) {
+ if (rowIndex < 0 || rowIndex >= boxList.size()) {
+ return null;
+ }
+ return boxList.get(rowIndex);
+ }
+
+ public int getIndexForBox(BentoBox box) {
+ return boxList.indexOf(box);
+ }
+
+ @Override
+ public Object getColumnValueForRow(BentoBox box, int columnIndex) {
+ if (columnIndex == NAME) {
+ return box.getId();
+ }
+ try {
+ int objIndex = columnIndices.get(columnIndex);
+ BoundedObject obj = box.getObj(objIndex);
+ if (obj == null) {
+ return "UNKNOWN";
+ }
+
+ Object rep = columnBounds.get(columnIndex) ? obj.getLowRep() : obj.getHiRep();
+ if (rep instanceof Long lrep) {
+ BentoRadix radix = provider.getRadix(columnIndices.get(columnIndex));
+ rep = radix.format(lrep);
+ }
+ return rep;
+ }
+ catch (IndexOutOfBoundsException e) {
+ return "UNKNOWN";
+ }
+ }
+
+ @Override
+ public List<BentoBox> getModelData() {
+ return boxList;
+ }
+
+ @Override
+ protected Comparator<BentoBox> createSortComparator(int columnIndex) {
+ return new BentoComparator(columnIndex);
+ }
+
+ public List<String> getColumnNames() {
+ return columnNames;
+ }
+
+ public void setColumnNames(List<String> names) {
+ this.names = names;
+ columnIndices.clear();
+ columnBounds.clear();
+ columnNames.clear();
+
+ columnIndices.add(-1);
+ columnBounds.add(true);
+ columnNames.add(NAME_COL);
+
+ int index = 0;
+ for (String n : names) {
+ columnIndices.add(index);
+ columnIndices.add(index);
+ columnBounds.add(true);
+ columnBounds.add(false);
+ columnNames.add("Start" + n);
+ columnNames.add("Stop" + n);
+ index++;
+ }
+ fireTableStructureChanged();
+ }
+
+ private class BentoComparator implements Comparator<BentoBox> {
+ private final int sortColumn;
+
+ public BentoComparator(int sortColumn) {
+ this.sortColumn = sortColumn;
+ }
+
+ @Override
+ public int compare(BentoBox b1, BentoBox b2) {
+ if (b1 == b2) {
+ return 0;
+ }
+ if (sortColumn == 0) {
+ return b1.getId().compareToIgnoreCase(b2.getId());
+ }
+ if (sortColumn == xIndex * 2 + 1) {
+ return (int) (b1.getObj(xIndex).getStart() - b2.getObj(xIndex).getStart());
+ }
+ if (sortColumn == xIndex * 2 + 2) {
+ return (int) (b1.getObj(xIndex).getStop() - b2.getObj(xIndex).getStop());
+ }
+ if (sortColumn == yIndex * 2 + 1) {
+ return (int) (b1.getObj(yIndex).getStart() - b2.getObj(yIndex).getStart());
+ }
+ if (sortColumn == yIndex * 2 + 2) {
+ return (int) (b1.getObj(yIndex).getStop() - b2.getObj(yIndex).getStop());
+ }
+ return 0;
+ }
+ }
+
+ public int getColumnIndex(int i) {
+ return columnIndices.get(i);
+ }
+
+ protected void setIndex(boolean x, int index) {
+ if (x) {
+ this.xIndex = index;
+ }
+ else {
+ this.yIndex = index;
+ }
+ }
+
+ public String getTitle() {
+ if (names.isEmpty()) {
+ return "X \u00d7 Y";
+ }
+ return names.get(xIndex) + " \u00d7 " + names.get(yIndex);
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoPanel.java
new file mode 100644
index 0000000000..af9bc75421
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoPanel.java
@@ -0,0 +1,435 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import java.util.List;
+
+import javax.swing.*;
+
+import generic.theme.GColor;
+import generic.theme.GThemeDefaults.Colors;
+
+public class BentoPanel extends JPanel implements MouseListener, MouseMotionListener {
+ private static final long serialVersionUID = 1L;
+
+ private static final Color ARROW_COLOR =
+ new GColor("color.debugger.plugin.plugin.memview.arrow");
+
+ private BentoProvider provider;
+ private List<BentoBox> boxList = new ArrayList<>();
+
+ private int pressedX;
+ private int pressedY;
+ private int pressedHZ;
+ private int pressedVT;
+ private boolean enableDrag = false;
+ private boolean ctrlPressed = false;
+ private int barWidth = 1000;
+ private int barHeight = 500;
+
+ private Rectangle currentRectangle = null;
+
+ private List<BentoBox> blist = Collections.emptyList();
+ private Map<String, BentoBox> bmap = new HashMap<>();
+
+ private BentoAxialData dataX;
+ private BentoAxialData dataY;
+
+ public BentoPanel(BentoProvider provider) {
+ this.provider = provider;
+ dataX = new BentoAxialData(provider, 0);
+ dataY = new BentoAxialData(provider, 1);
+ setPreferredSize(new Dimension(barWidth, barHeight));
+ setSize(getPreferredSize());
+ setBorder(BorderFactory.createLineBorder(Colors.BORDER, 1));
+ setFocusable(true);
+
+ addMouseListener(this);
+ addMouseMotionListener(this);
+ ToolTipManager.sharedInstance().registerComponent(this);
+
+ // This panel takes focus since it is a custom widget. Focusable components need to
+ // have their accessible name set.
+ String viewName = "Box View";
+ setName(viewName);
+ getAccessibleContext().setAccessibleName(viewName);
+ }
+
+ @Override
+ public Dimension getPreferredSize() {
+ BentoPixelMap xMap = dataX.getMap();
+ BentoPixelMap yMap = dataY.getMap();
+ int h = yMap != null ? (int) (yMap.getSize()) : 500;
+ int w = xMap != null ? (int) (xMap.getSize()) : 500;
+ return new Dimension(w, h);
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ g.setColor(getBackground());
+ Rectangle clip = g.getClipBounds();
+ g.fillRect(clip.x, clip.y, clip.width, clip.height);
+
+ //If the width has changed, force a refresh
+ int height = getHeight();
+ int width = getWidth();
+ if (clip.height > height) {
+ refresh();
+ return;
+ }
+
+ g.fillRect(0, 0, width, height);
+
+ for (BentoBox box : boxList) {
+ box.render(g, dataX.getIndex(), dataY.getIndex());
+ }
+
+ //Draw the current location arrow
+ if (dataY.getCurrentPixel() >= 0) {
+ drawArrow(g);
+ }
+ if (currentRectangle != null) {
+ drawFrame(g);
+ }
+ }
+
+ private static final int LOCATION_BASE_WIDTH = 1;
+ private static final int LOCATION_BASE_HEIGHT = 6;
+ private static final int LOCATION_ARROW_WIDTH = 3;
+ private static final int LOCATION_ARROW_HEIGHT = 9;
+ private static final int[] locXs = { 0, -LOCATION_BASE_WIDTH, -LOCATION_BASE_WIDTH,
+ -LOCATION_ARROW_WIDTH, 0, LOCATION_ARROW_WIDTH, LOCATION_BASE_WIDTH, LOCATION_BASE_WIDTH };
+ private static final int[] locYs = { 0, 0, LOCATION_BASE_HEIGHT, LOCATION_BASE_HEIGHT,
+ LOCATION_ARROW_HEIGHT, LOCATION_BASE_HEIGHT, LOCATION_BASE_HEIGHT, 0 };
+
+ private void drawArrow(Graphics g) {
+ Graphics2D g2 = (Graphics2D) g.create();
+ try {
+ int curY = dataY.getCurrentPixel();
+ int curX = dataX.getCurrentPixel();
+ g2.translate(0, -LOCATION_ARROW_HEIGHT);
+ g.translate(curX, curY);
+
+ g.setColor(ARROW_COLOR);
+ g.fillPolygon(locXs, locYs, locXs.length);
+
+ g.translate(-curX, -curY);
+ g2.translate(0, LOCATION_ARROW_HEIGHT);
+ }
+ finally {
+ g2.dispose();
+ }
+ }
+
+ private void drawFrame(Graphics g) {
+ int x = currentRectangle.x;
+ int y = currentRectangle.y;
+ int w = currentRectangle.width;
+ int h = currentRectangle.height;
+ g.setColor(ARROW_COLOR);
+ g.fillRect(x - 1, y - 1, 1, h + 2);
+ g.fillRect(x - 1, y - 1, w + 2, 1);
+ g.fillRect(x + w + 1, y - 1, 1, h + 2);
+ g.fillRect(x - 1, y + h + 1, w + 2, 1);
+ }
+
+ void initViews() {
+ int szX = dataX.initViews();
+ int szY = dataY.initViews();
+ setSize(new Dimension(szX, szY));
+ }
+
+ public void refresh() {
+ dataX.refresh();
+ dataY.refresh();
+ updateBoxes();
+ }
+
+ void updateBoxes() {
+ if (!this.isShowing()) {
+ return;
+ }
+
+ Collection<BentoBox> boxes = getBoxes();
+ if (boxes == null) {
+ return;
+ }
+ List<BentoBox> updatedList = new ArrayList<>();
+ BentoPixelMap xMap = dataX.getMap();
+ BentoPixelMap yMap = dataY.getMap();
+
+ int boundX = getWidth() - 1;
+ int boundY = getHeight() - 1;
+
+ for (BentoBox box : boxes) {
+ if (box == null) {
+ continue;
+ }
+
+ box.getObj(dataX.getIndex()).getMappedObject().setBounds(xMap, boundX);
+ box.getObj(dataY.getIndex()).getMappedObject().setBounds(yMap, boundY);
+
+ updatedList.add(box);
+ }
+
+ this.boxList = updatedList;
+ repaint();
+ //repaint(0, 0, getWidth(), getHeight());
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ requestFocus(); // COMPONENT
+
+ ctrlPressed = false;
+ currentRectangle = null;
+
+ if (e.getButton() == MouseEvent.BUTTON1) {
+ enableDrag = true;
+ pressedHZ = e.getX();
+ pressedVT = e.getY();
+ pressedX = pressedHZ;
+ pressedY = pressedVT;
+ dataX.setCurrentPixel(pressedX);
+ dataY.setCurrentPixel(pressedY);
+ provider.selectTableEntry(getBoxesAt(pressedX, pressedY));
+ provider.refresh();
+ }
+
+ if (e.getButton() == MouseEvent.BUTTON3) {
+ ctrlPressed = true;
+ enableDrag = true;
+ pressedHZ = e.getX();
+ pressedVT = e.getY();
+ }
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ enableDrag = false;
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ provider.navigateToSelectedObject();
+ }
+ enableDrag = false;
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ // Nothing to do
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ // Nothing to do
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ if (enableDrag) {
+ if (!ctrlPressed) {
+ provider.goTo(pressedHZ - e.getX(), pressedVT - e.getY());
+ }
+ else {
+ int x = Math.min(pressedHZ, e.getX());
+ int y = Math.min(pressedVT, e.getY());
+ int w = Math.abs(e.getX() - pressedHZ);
+ int h = Math.abs(e.getY() - pressedVT);
+
+ currentRectangle = new Rectangle(x, y, w, h);
+ provider.selectTableEntry(getBoxesIn(currentRectangle));
+ provider.refresh();
+ }
+ }
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ // Nothing to do
+ }
+
+ public void setSelection(Set<BentoBox> boxes) {
+ for (BentoBox box : boxes) {
+ dataX.setCurrentPixel(box.getObj(0).getMappedObject().getPixelStart());
+ dataY.setCurrentPixel(box.getObj(1).getMappedObject().getPixelStart());
+ refresh();
+ }
+ }
+
+ public String getTitleAnnotation() {
+ String xval = dataX.getTagForPos(null);
+ String yval = dataY.getTagForPos(null);
+ String vals = xval + ":" + yval;
+ return "curpos=[" + vals + "]";
+ }
+
+ public Set<BentoBox> getBoxesAt(int atX, int atY) {
+ Rectangle posRect = new Rectangle(atX, atY, 1, 1);
+ return getBoxesIn(posRect);
+ }
+
+ public Set<BentoBox> getBoxesIn(Rectangle r) {
+ int startX = (int) dataX.getPos(r.x);
+ int startY = (int) dataY.getPos(r.y);
+ int stopX = (int) dataX.getPos(r.x + r.width);
+ int stopY = (int) dataY.getPos(r.y + r.height);
+
+ Rectangle posRect = new Rectangle(startX, startY,
+ stopX - startX + 1, stopY - startY + 1);
+
+ Set<BentoBox> matches = new HashSet<>();
+ for (BentoBox box : boxList) {
+ Rectangle boxRect = box.getRectangle(dataX.getIndex(), dataY.getIndex());
+ if (posRect.intersects(boxRect)) {
+ matches.add(box);
+ }
+ }
+ return matches;
+ }
+
+ @Override
+ public String getToolTipText(MouseEvent e) {
+ BentoPixelMap xMap = dataX.getMap();
+ BentoPixelMap yMap = dataY.getMap();
+ if (yMap == null || xMap == null) {
+ return e.getX() + ":" + e.getY();
+ }
+
+ int pixX = e.getX();
+ long x = dataX.getPos(pixX);
+ int pixY = e.getY();
+ long y = dataY.getPos(pixY);
+ String xval = dataX.getTagForPos(x);
+ String yval = dataY.getTagForPos(y);
+ Set<BentoBox> boxes = getBoxesAt(pixX, pixY);
+
+ StringBuilder sb = new StringBuilder(yval);
+ sb.append(" [");
+ boolean first = true;
+ for (BentoBox box : boxes) {
+ if (box.getId() == null) {
+ continue;
+ }
+ if (!first) {
+ sb.append(",");
+ }
+ sb.append(box.getId());
+ first = false;
+ }
+ sb.append("]");
+ yval = sb.toString();
+
+ String colon = xval.equals("") && yval.equals("") ? "" : " : ";
+ return xval + colon + yval;
+ }
+
+ private void parseBoxes(Collection<BentoBox> boxes) {
+ if (!boxes.isEmpty()) {
+ double d = Math.log(getWidth() / boxes.size()) / Math.log(2.0);
+ int escapeCounter = 0;
+ while (dataX.getZoom() < d && escapeCounter < 50) {
+ provider.changeZoom(0, 1);
+ provider.changeZoom(1, 1);
+ escapeCounter++;
+ }
+ }
+ dataX.parseBoxes(boxes);
+ dataY.parseBoxes(boxes);
+ refresh();
+ }
+
+ public List<BentoBox> getBoxes() {
+ return blist;
+ }
+
+ public void setBoxes(List<BentoBox> boxes) {
+ this.blist = boxes;
+ for (BentoBox b : boxes) {
+ if (b.getId() != null) {
+ bmap.put(b.getId(), b);
+ }
+ }
+ parseBoxes(blist);
+ }
+
+ public void addBoxes(List<BentoBox> boxes) {
+ if (blist == null) {
+ blist = new ArrayList<>();
+ }
+ for (BentoBox b : boxes) {
+ if (bmap.containsKey(b.getId())) {
+ BentoBox box = bmap.get(b.getId());
+ blist.remove(box);
+ }
+ blist.add(b);
+ bmap.put(b.getId(), b);
+ }
+ parseBoxes(blist);
+ }
+
+ public void reset() {
+ blist = new ArrayList<>();
+ bmap.clear();
+ parseBoxes(blist);
+ }
+
+ protected BentoRadix getRadix(int index) {
+ if (boxList == null || boxList.isEmpty()) {
+ return BentoRadix.DEFAULT;
+ }
+ return provider.getRadix(index);
+ }
+
+ public void scaleCurrentPixel(int index, double changeAmount) {
+ switch (index) {
+ case 0 -> {
+ dataX.scaleCurrentPixel(changeAmount);
+ }
+ case 1 -> {
+ dataY.scaleCurrentPixel(changeAmount);
+ }
+ }
+ }
+
+ public double getZoom(int index) {
+ return switch (index) {
+ case 0 -> dataX.getZoom();
+ case 1 -> dataY.getZoom();
+ default -> throw new IllegalArgumentException("Unexpected zoom index");
+ };
+ }
+
+ public void setIndex(boolean x, int colIndex) {
+ if (x) {
+ dataX.setIndex(colIndex);
+ }
+ else {
+ dataY.setIndex(colIndex);
+ }
+ }
+
+ public int getIndex(boolean x) {
+ return x ? dataX.getIndex() : dataY.getIndex();
+ }
+
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewMap.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoPixelMap.java
similarity index 83%
rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewMap.java
rename to Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoPixelMap.java
index df02e5bdc7..7dd202a87a 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/MemviewMap.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoPixelMap.java
@@ -4,27 +4,26 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ghidra.app.plugin.core.debug.gui.memview;
+package ghidra.app.plugin.core.bento;
-public class MemviewMap {
+public class BentoPixelMap {
private long max;
- private long sz;
private double elementsPerPixel;
private double multiplier;
- public MemviewMap(long elems, long pixels) {
- max = sz = elems;
- elementsPerPixel = pixels == 0 ? 0 : elems / pixels;
+ public BentoPixelMap(long elems, long pixels) {
+ max = elems;
+ elementsPerPixel = pixels <= 0 ? 0.0 : (double) elems / pixels;
multiplier = 1.0;
}
@@ -33,6 +32,9 @@ public class MemviewMap {
}
public long getOffset(int pixel) {
+ if (multiplier == 0.0) {
+ return 0;
+ }
return Math.round(pixel * elementsPerPixel / multiplier);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoProvider.java
new file mode 100644
index 0000000000..20f3b92a56
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoProvider.java
@@ -0,0 +1,344 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import java.util.List;
+
+import javax.swing.*;
+
+import docking.ActionContext;
+import docking.DefaultActionContext;
+import docking.action.DockingAction;
+import docking.action.builder.ToggleActionBuilder;
+import generic.theme.GIcon;
+import ghidra.app.plugin.core.bento.actions.*;
+import ghidra.framework.plugintool.ComponentProviderAdapter;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.listing.Program;
+import ghidra.util.HelpLocation;
+import ghidra.util.Swing;
+import resources.ResourceManager;
+
+public class BentoProvider extends ComponentProviderAdapter {
+
+ private BentoServicePlugin plugin;
+
+ private JComponent mainPanel;
+ private BentoPanel bentoPanel;
+ private BentoTable bentoTable;
+ private JScrollPane scrollPane;
+
+ private boolean applyFilter = true;
+
+ private static final Icon ICON_REFRESH =
+ ResourceManager.getScaledIcon(new GIcon("icon.debugger.refresh"), 12, 12);
+ private static final Icon ICON_FILTER =
+ ResourceManager.getScaledIcon(new GIcon("icon.widget.filterpanel.filter.off"), 12, 12);
+ long halfPage = 512L;
+
+ private Map<Integer, BentoRadix> radixMap = new HashMap<>();
+
+ public BentoProvider(PluginTool tool, BentoServicePlugin plugin, boolean isTransient) {
+ super(tool, plugin.title, plugin.getName());
+ this.plugin = plugin;
+ if (isTransient) {
+ setTransient();
+ }
+
+ mainPanel = new JPanel(new BorderLayout());
+ tool.addComponentProvider(this, false);
+ createActions();
+ buildPanel();
+ mainPanel.addComponentListener(new ComponentAdapter() {
+ private int lastWidth = -1;
+ private int lastHeight = -1;
+
+ @Override
+ public void componentResized(ComponentEvent e) {
+ int currentWidth = mainPanel.getWidth();
+ int currentHeight = mainPanel.getHeight();
+ if (currentWidth != lastWidth || currentHeight != lastHeight) {
+ lastWidth = currentWidth;
+ lastHeight = currentHeight;
+ resized();
+ }
+ }
+ });
+ }
+
+ protected void createActions() {
+
+ DockingAction zoomInYAction = new ZoomInYAction(this);
+ tool.addLocalAction(this, zoomInYAction);
+
+ DockingAction zoomOutYAction = new ZoomOutYAction(this);
+ tool.addLocalAction(this, zoomOutYAction);
+
+ DockingAction zoomInXAction = new ZoomInXAction(this);
+ tool.addLocalAction(this, zoomInXAction);
+
+ DockingAction zoomOutXAction = new ZoomOutXAction(this);
+ tool.addLocalAction(this, zoomOutXAction);
+
+ new ToggleActionBuilder("Toggle Layout", getOwner())
+ .toolBarIcon(ICON_REFRESH)
+ .helpLocation(new HelpLocation(getOwner(), "toggle_layout"))
+ .onAction(ctx -> performToggleLayout(ctx))
+ .buildAndInstallLocal(this);
+
+ new ToggleActionBuilder("Apply Filter To Panel", getOwner())
+ .toolBarIcon(ICON_FILTER)
+ .helpLocation(new HelpLocation(getOwner(), "apply_to_panel"))
+ .onAction(ctx -> performApplyFilterToPanel(ctx))
+ .selected(true)
+ .buildAndInstallLocal(this);
+
+ }
+
+ void buildPanel() {
+ mainPanel.removeAll();
+ bentoPanel = new BentoPanel(this);
+ bentoTable = new BentoTable(this);
+
+ scrollPane = new JScrollPane(bentoPanel);
+ scrollPane.setPreferredSize(bentoPanel.getSize());
+
+ JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
+ splitPane.setRightComponent(scrollPane);
+ splitPane.setLeftComponent(bentoTable.getComponent());
+
+ splitPane.setResizeWeight(0.5);
+ mainPanel.add(splitPane, BorderLayout.CENTER);
+
+ initViews();
+ mainPanel.validate();
+ }
+
+ private void performToggleLayout(ActionContext ctx) {
+ toggleDirection();
+ refresh();
+ }
+
+ protected void performToggleTracking(ActionContext ctx) {
+ if (plugin != null) {
+ plugin.toggleTracking();
+ }
+ }
+
+ private void performApplyFilterToPanel(ActionContext ctx) {
+ applyFilter = !isApplyFilter();
+ applyFilter();
+ }
+
+ public void applyFilter() {
+ if (applyFilter) {
+ bentoTable.applyFilter();
+ }
+ else {
+ bentoPanel.setBoxes(bentoTable.getBoxes());
+ }
+ refresh();
+ }
+
+ public void setIndex(boolean x, int index) {
+ bentoTable.getModel().setIndex(x, index);
+ bentoPanel.setIndex(x, index);
+ refresh();
+ }
+
+ private void toggleDirection() {
+ int xIndex = bentoPanel.getIndex(true);
+ int yIndex = bentoPanel.getIndex(false);
+ setIndex(true, yIndex);
+ setIndex(false, xIndex);
+ bentoPanel.setBoxes(bentoPanel.getBoxes());
+ }
+
+ void dispose() {
+ tool.removeComponentProvider(this);
+ }
+
+ @Override
+ public ActionContext getActionContext(MouseEvent event) {
+ if (event != null && event.getSource() == mainPanel) {
+ return new DefaultActionContext(this, mainPanel);
+ }
+ if (event != null && event.getSource() == bentoPanel) {
+ return new DefaultActionContext(this, bentoPanel);
+ }
+ return null;
+ }
+
+ @Override
+ public JComponent getComponent() {
+ return mainPanel;
+ }
+
+ @Override
+ public HelpLocation getHelpLocation() {
+ return new HelpLocation(getOwner(), getOwner());
+ }
+
+ public void setProgram(Program program) {
+ bentoTable.setProgram(program);
+ }
+
+ public void initViews() {
+ bentoPanel.initViews();
+ bentoPanel.setPreferredSize(new Dimension(300, 100));
+ bentoTable.setCodeViewerService(plugin.getCodeViewerService());
+ mainPanel.doLayout();
+ mainPanel.repaint();
+ }
+
+ public void refresh() {
+ StringBuilder titleBuilder = new StringBuilder(bentoTable.getTitle());
+ titleBuilder.append(" (")
+ .append(bentoPanel.getZoom(0))
+ .append(" \u00d7 ")
+ .append(bentoPanel.getZoom(1))
+ .append(") ")
+ .append(bentoPanel.getTitleAnnotation());
+
+ setSubTitle(titleBuilder.toString());
+ bentoPanel.refresh();
+ scrollPane.getViewport().doLayout();
+ }
+
+ public void goTo(int x, int y) {
+ Rectangle bounds = scrollPane.getBounds();
+ scrollPane.getViewport()
+ .scrollRectToVisible(new Rectangle(x, y, bounds.width, bounds.height));
+ scrollPane.getViewport().doLayout();
+ }
+
+ public void goTo(BentoBox box) {
+ try {
+ Point p = new Point(box.getPixelStart(bentoPanel.getIndex(true)) - 10,
+ box.getPixelStart(bentoPanel.getIndex(false)) - 10);
+ Point p0 = scrollPane.getViewport().getViewPosition();
+ int w = scrollPane.getViewport().getWidth();
+ int h = scrollPane.getViewport().getHeight();
+ if (p.x > p0.x && p.x < p0.x + w && p.y > p0.y && p.y < p0.y + h) {
+ return;
+ }
+ scrollPane.getViewport().setViewPosition(p);
+ }
+ catch (IndexOutOfBoundsException e) {
+ // IGNORE
+ }
+ }
+
+ public void selectTableEntry(Set<BentoBox> boxes) {
+ bentoTable.setSelection(boxes);
+ }
+
+ public void selectPanelPosition(Set<BentoBox> boxes) {
+ bentoPanel.setSelection(boxes);
+ if (boxes.size() == 1) {
+ Iterator<BentoBox> iterator = boxes.iterator();
+ goTo(iterator.next());
+ }
+ }
+
+ public double getZoomAmount(int index) {
+ return bentoPanel.getZoom(index);
+ }
+
+ public void changeZoom(int index, int changeAmount) {
+ bentoPanel.scaleCurrentPixel(index, changeAmount);
+ }
+
+ void resized() {
+ bentoPanel.refresh();
+ }
+
+ public void setBoxes(List<BentoBox> blist) {
+ if (!blist.isEmpty()) {
+ BentoBox sample = blist.get(0);
+ for (int i = 0; i < sample.getNumIndices(); i++) {
+ BoundedObject bo = sample.getObj(i);
+ radixMap.put(i, bo.getDefaultRadix());
+ }
+ }
+ Swing.runIfSwingOrRunLater(() -> {
+ bentoTable.setBoxes(blist);
+ bentoTable.applyFilter();
+ });
+ }
+
+ public void setBoxesInPanel(List<BentoBox> blist) {
+ Swing.runIfSwingOrRunLater(() -> {
+ bentoPanel.setBoxes(blist);
+ bentoPanel.refresh();
+ });
+ }
+
+ public void addBox(BentoBox box) {
+ List<BentoBox> blist = new ArrayList<>();
+ blist.add(box);
+ addBoxes(blist);
+ }
+
+ public void addBoxes(List<BentoBox> blist) {
+ Swing.runIfSwingOrRunLater(() -> {
+ bentoTable.addBoxes(blist);
+ bentoTable.applyFilter();
+ });
+ }
+
+ public boolean isApplyFilter() {
+ return applyFilter;
+ }
+
+ public void reset() {
+ Swing.runIfSwingOrRunLater(() -> {
+ bentoTable.reset();
+ bentoPanel.reset();
+ });
+ }
+
+ public void fireTableDataChanged() {
+ Swing.runIfSwingOrRunLater(() -> {
+ bentoTable.fireTableDataChanged();
+ });
+ }
+
+ public void navigateToSelectedObject() {
+ bentoTable.navigateToSelectedObject();
+ }
+
+ public void setColumns(List<String> cols) {
+ bentoTable.setColumns(cols, bentoPanel);
+ }
+
+ protected BentoPanel getPanel() {
+ return bentoPanel;
+ }
+
+ public void setRadix(int index, BentoRadix radix) {
+ radixMap.put(index, radix);
+ }
+
+ public BentoRadix getRadix(int index) {
+ BentoRadix radix = radixMap.get(index);
+ return radix == null ? BentoRadix.DEFAULT : radix;
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoRadix.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoRadix.java
new file mode 100644
index 0000000000..9fb4f5d248
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoRadix.java
@@ -0,0 +1,70 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+public enum BentoRadix {
+ /** Use decimal (default) */
+ DEC("dec", 10, "%d"),
+ /** Use upper-case hexadecimal */
+ HEX_UPPER("HEX", 16, "%X"),
+ /** Use lower-case hexadecimal */
+ HEX_LOWER("hex", 16, "%x");
+
+ /** The default radix (decimal) */
+ public static final BentoRadix DEFAULT = DEC;
+
+ /**
+ * Get the radix specified by the given string
+ *
+ * @param s the name of the specified radix
+ * @return the radix
+ */
+ public static BentoRadix fromStr(String s) {
+ return switch (s) {
+ case "dec" -> DEC;
+ case "HEX" -> HEX_UPPER;
+ case "hex" -> HEX_LOWER;
+ default -> DEFAULT;
+ };
+ }
+
+ public final String name;
+ public final int n;
+ public final String fmt;
+
+ private BentoRadix(String name, int n, String fmt) {
+ this.name = name;
+ this.n = n;
+ this.fmt = fmt;
+ }
+
+ public String format(long time) {
+ return fmt.formatted(time);
+ }
+
+ public long decode(String nm) {
+ if (nm.startsWith("0x") || nm.startsWith("0X") ||
+ nm.startsWith("-0x") || nm.startsWith("-0X")) {
+ return Long.parseLong(nm, 16);
+ }
+ if (nm.startsWith("0n") || nm.startsWith("0N") ||
+ nm.startsWith("-0n") || nm.startsWith("-0N")) {
+ return Long.parseLong(nm, 10);
+ }
+ return Long.parseLong(nm, n);
+ }
+}
+
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoService.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoService.java
new file mode 100644
index 0000000000..22f069f688
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoService.java
@@ -0,0 +1,30 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+import ghidra.framework.plugintool.ServiceInfo;
+
+/**
+ * The BentoService provides a general service for displaying objects (a la Boxes)
+ */
+@ServiceInfo(defaultProvider = BentoServicePlugin.class, description = "Display X vs. Y data")
+public interface BentoService {
+
+ public BentoProvider getDefaultProvider();
+
+ public BentoProvider createProvider();
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoServicePlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoServicePlugin.java
new file mode 100644
index 0000000000..6e18b2fdf8
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoServicePlugin.java
@@ -0,0 +1,97 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import ghidra.app.CorePluginPackage;
+import ghidra.app.plugin.PluginCategoryNames;
+import ghidra.app.services.CodeViewerService;
+import ghidra.framework.plugintool.*;
+import ghidra.framework.plugintool.util.PluginStatus;
+import ghidra.util.Swing;
+
+@PluginInfo(
+ shortDescription = "Displays X/Y data",
+ description = "Provides visualization/navigation across multiple axes",
+ category = PluginCategoryNames.GRAPH,
+ packageName = CorePluginPackage.NAME,
+ status = PluginStatus.RELEASED,
+ servicesRequired = {
+ CodeViewerService.class,
+ },
+ servicesProvided = {
+ BentoService.class
+ })
+public class BentoServicePlugin extends Plugin implements BentoService {
+
+ protected CodeViewerService codeViewerService;
+
+ final String title;
+ protected BentoProvider defaultProvider;
+ protected List<BentoProvider> transientProviders = new ArrayList<>();
+
+ public BentoServicePlugin(PluginTool tool) {
+ this(tool, "Bento View");
+ }
+
+ protected BentoServicePlugin(PluginTool tool, String title) {
+ this.title = title;
+ super(tool);
+ }
+
+ @Override
+ protected void init() {
+ codeViewerService = tool.getService(CodeViewerService.class);
+ defaultProvider = new BentoProvider(getTool(), this, false);
+ super.init();
+ }
+
+ @Override
+ protected void dispose() {
+ tool.removeComponentProvider(defaultProvider);
+ for (BentoProvider provider : transientProviders) {
+ tool.removeComponentProvider(provider);
+ }
+ super.dispose();
+ }
+
+ @Override
+ public BentoProvider getDefaultProvider() {
+ return defaultProvider;
+ }
+
+ @Override
+ public BentoProvider createProvider() {
+ return Swing.runNow(() -> {
+ BentoProvider p = new BentoProvider(getTool(), this, true);
+ transientProviders.add(p);
+ p.initViews();
+ tool.showComponentProvider(p, true);
+ return p;
+ });
+ }
+
+ public void toggleTracking() {
+ // IGNORE
+ }
+
+ public CodeViewerService getCodeViewerService() {
+ return codeViewerService;
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoTable.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoTable.java
new file mode 100644
index 0000000000..522cffc23a
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BentoTable.java
@@ -0,0 +1,264 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import java.util.List;
+
+import javax.swing.*;
+import javax.swing.event.*;
+
+import generic.theme.GIcon;
+import ghidra.app.services.CodeViewerService;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.address.AddressRange;
+import ghidra.program.model.listing.Program;
+import ghidra.program.util.ProgramLocation;
+import ghidra.util.table.GhidraTable;
+import ghidra.util.table.GhidraTableFilterPanel;
+import ghidra.util.task.SwingUpdateManager;
+
+public class BentoTable {
+
+ public static final Icon ICON_TABLE = new GIcon("icon.table");
+
+ private BentoMapModel model;
+ private GhidraTable table;
+ private GhidraTableFilterPanel<?> filterPanel;
+ private FilterActionFilterListener filterListener;
+ private SwingUpdateManager applyFilterManager =
+ new SwingUpdateManager(this::applyFilter);
+ private JPanel component;
+ private static int clickedColumnIndex = -1;
+
+ private BentoProvider provider;
+ private Program program;
+ private CodeViewerService codeViewerService;
+
+ public BentoTable(BentoProvider provider) {
+ this.provider = provider;
+ this.model = new BentoMapModel(provider);
+ this.table = new GhidraTable(model);
+ table.setHTMLRenderingEnabled(true);
+ this.component = new JPanel(new BorderLayout());
+ JScrollPane scrollPane = new JScrollPane(table);
+ filterPanel = new GhidraTableFilterPanel<>(table, model);
+ component.add(scrollPane, BorderLayout.CENTER);
+ component.add(filterPanel, BorderLayout.SOUTH);
+ table.setAutoscrolls(true);
+
+ String namePrefix = "Memory View";
+ table.setAccessibleNamePrefix(namePrefix);
+ filterPanel.setAccessibleNamePrefix(namePrefix);
+
+ table.getSelectionModel().addListSelectionListener(e -> {
+ if (e.getValueIsAdjusting()) {
+ return;
+ }
+ int modelRow = filterPanel.getModelRow(table.getSelectedRow());
+ if (modelRow >= 0) {
+ BentoBox box = model.getBoxAt(modelRow);
+ if (box != null) {
+ Set<BentoBox> boxes = new HashSet<>();
+ boxes.add(box);
+ provider.selectPanelPosition(boxes);
+ }
+ }
+ });
+ table.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ navigateToSelectedObject();
+ }
+ }
+ });
+
+ filterListener = new FilterActionFilterListener();
+ filterPanel.getTableFilterModel().addTableModelListener(filterListener);
+
+ JPopupMenu popupMenu = table.getTableColumnPopupMenu(0);
+ JMenuItem menuItemX = new JMenuItem("Set x-axis");
+ popupMenu.add(menuItemX);
+
+ menuItemX.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (clickedColumnIndex > 0) {
+ int xIndex = (clickedColumnIndex - 1) / 2;
+ provider.setIndex(true, xIndex);
+ }
+ }
+ });
+
+ JMenuItem menuItemY = new JMenuItem("Set y-axis");
+ popupMenu.add(menuItemY);
+
+ menuItemY.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (clickedColumnIndex > 0) {
+ int yIndex = (clickedColumnIndex - 1) / 2;
+ provider.setIndex(false, yIndex);
+ }
+ }
+ });
+
+ popupMenu.addPopupMenuListener(new PopupMenuListener() {
+ @Override
+ public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
+ Component invoker = popupMenu.getInvoker();
+ Point mousePos = invoker.getMousePosition();
+
+ if (mousePos != null) {
+ if (invoker instanceof JTable) {
+ clickedColumnIndex = table.columnAtPoint(mousePos);
+ }
+ else if (invoker instanceof javax.swing.table.JTableHeader) {
+ clickedColumnIndex = table.getTableHeader().columnAtPoint(mousePos);
+ }
+ }
+ }
+
+ @Override
+ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
+ // IGNORE
+ }
+
+ @Override
+ public void popupMenuCanceled(PopupMenuEvent e) {
+ // IGNORE
+ }
+ });
+ }
+
+ public JComponent getComponent() {
+ return component;
+ }
+
+ public JComponent getPrincipalComponent() {
+ return table;
+ }
+
+ public void setProgram(Program program) {
+ this.program = program;
+ }
+
+ public void setCodeViewerService(CodeViewerService codeViewerService) {
+ this.codeViewerService = codeViewerService;
+ }
+
+ public void setBoxes(Collection<BentoBox> blist) {
+ model.setBoxes(blist);
+ }
+
+ public void addBoxes(Collection<BentoBox> blist) {
+ model.addBoxes(blist);
+ }
+
+ public void reset() {
+ model.reset();
+ }
+
+ public List<BentoBox> getBoxes() {
+ return model.getBoxes();
+ }
+
+ public void setSelection(Set<BentoBox> set) {
+ table.clearSelection();
+ for (BentoBox box : set) {
+ int index = model.getIndexForBox(box);
+ int viewRow = filterPanel.getViewRow(index);
+ if (viewRow >= 0) {
+ table.addRowSelectionInterval(viewRow, viewRow);
+ table.scrollToSelectedRow();
+ }
+ }
+ }
+
+ protected void navigateToSelectedObject() {
+ int selectedRow = table.getSelectedRow();
+ int selectedColumn = table.getSelectedColumn();
+ if (selectedRow < 0 || selectedColumn < 0) {
+ return;
+ }
+
+ Object value = table.getValueAt(selectedRow, selectedColumn);
+ Address addr = null;
+ if (selectedColumn < 0) {
+ for (int i = 0; i < table.getColumnCount(); i++) {
+ value = table.getValueAt(selectedRow, i);
+ if (value instanceof Address) {
+ addr = (Address) value;
+ break;
+ }
+ }
+ }
+ if (value instanceof Address a) {
+ addr = a;
+ }
+ if (value instanceof AddressRange range) {
+ addr = range.getMinAddress();
+ }
+ if (value instanceof Long lval && program != null) {
+ addr = program.getAddressFactory().getAddressSpace("ram").getAddress(lval);
+ }
+ if (codeViewerService != null && program != null && addr != null) {
+ ProgramLocation loc = new ProgramLocation(program, addr);
+ codeViewerService.goTo(loc, true);
+ }
+ }
+
+ public void applyFilter() {
+ List<BentoBox> blist = new ArrayList<>();
+ for (int i = 0; i < filterPanel.getRowCount(); i++) {
+ int row = filterPanel.getModelRow(i);
+ if (row >= 0) {
+ blist.add(model.getBoxAt(row));
+ }
+ }
+ provider.setBoxesInPanel(blist);
+ }
+
+ private class FilterActionFilterListener implements TableModelListener {
+
+ @Override
+ public void tableChanged(TableModelEvent e) {
+ if (provider.isApplyFilter()) {
+ applyFilterManager.updateLater();
+ }
+ }
+ }
+
+ void fireTableDataChanged() {
+ model.fireTableDataChanged();
+ }
+
+ public void setColumns(List<String> cols, BentoPanel panel) {
+ model.setColumnNames(cols);
+ }
+
+ public String getTitle() {
+ return model.getTitle();
+ }
+
+ public BentoMapModel getModel() {
+ return model;
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BoundedObject.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BoundedObject.java
new file mode 100644
index 0000000000..6f9f5b8fb8
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/BoundedObject.java
@@ -0,0 +1,82 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+public class BoundedObject {
+
+ protected Object obj;
+ public Object loRep;
+ public Object hiRep;
+ public long loBound;
+ public long hiBound;
+ protected long startPos;
+ protected long endPos;
+
+ protected MappedObject mobj;
+
+ public BoundedObject(long min) {
+ this(min, Long.MAX_VALUE);
+ }
+
+ public BoundedObject(long min, long max) {
+ this.obj = min;
+ this.loBound = min;
+ this.hiBound = max;
+ this.loRep = this.loBound;
+ this.hiRep = this.hiBound;
+ mobj = new MappedObject(this);
+ }
+
+ public long getStart() {
+ return startPos;
+ }
+
+ public void setStart(long val) {
+ startPos = val;
+ }
+
+ public long getStop() {
+ return endPos;
+ }
+
+ public void setStop(long val) {
+ endPos = val;
+ }
+
+ public MappedObject getMappedObject() {
+ return mobj;
+ }
+
+ /* The following two methods feed directly to cells in a table and, while typically
+ * rendered as String's, may be given special treatment based on their type */
+
+ public Object getLowRep() {
+ return loBound;
+ }
+
+ public Object getHiRep() {
+ long end = hiBound;
+ if (end == Long.MAX_VALUE) {
+ return "+\u221e";
+ }
+ return hiBound;
+ }
+
+ public BentoRadix getDefaultRadix() {
+ return BentoRadix.DEFAULT;
+ }
+
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/FunctionBoundedObject.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/FunctionBoundedObject.java
new file mode 100644
index 0000000000..18045b2aa9
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/FunctionBoundedObject.java
@@ -0,0 +1,43 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+import ghidra.program.model.listing.Function;
+
+public class FunctionBoundedObject extends BoundedObject {
+
+ public FunctionBoundedObject(Function f) {
+ super(f.getBody().getMinAddress().getOffset(), f.getBody().getMaxAddress().getOffset());
+ this.loRep = f.getBody().getMinAddress();
+ this.hiRep = f.getBody().getMaxAddress();
+ this.obj = f;
+ }
+
+ @Override
+ public BentoRadix getDefaultRadix() {
+ return BentoRadix.HEX_LOWER;
+ }
+
+ @Override
+ public Object getLowRep() {
+ return loRep;
+ }
+
+ @Override
+ public Object getHiRep() {
+ return hiRep;
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/MappedObject.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/MappedObject.java
new file mode 100644
index 0000000000..cc7cec03af
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/MappedObject.java
@@ -0,0 +1,65 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.bento;
+
+public class MappedObject {
+
+ private final BoundedObject obj;
+
+ protected int pixStart;
+ protected int pixEnd;
+ protected int pixBound;
+
+ public MappedObject(BoundedObject obj) {
+ this.obj = obj;
+ }
+
+ public int getAddressPixelWidth() {
+ int width = pixEnd - pixStart;
+ return (width <= 0) ? 1 : width;
+ }
+
+ public int getPixelStart() {
+ return pixStart;
+ }
+
+ public int getPixelWidth() {
+ int currentEnd = pixEnd;
+ if (currentEnd < pixStart) {
+ currentEnd = pixBound;
+ }
+
+ int width = currentEnd - pixStart;
+ return (width <= 0) ? 1 : width;
+ }
+
+ public boolean inPixelRange(long pos) {
+ if (pos < pixStart) {
+ return false;
+ }
+ if (pixEnd <= 0) {
+ return true;
+ }
+ return pos <= pixEnd;
+ }
+
+ public void setBounds(BentoPixelMap map, int bound) {
+ pixStart = map.getPixel(obj.getStart());
+ pixEnd = map.getPixel(obj.getStop());
+ pixBound = bound;
+ }
+
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomInTAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomInXAction.java
similarity index 68%
rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomInTAction.java
rename to Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomInXAction.java
index 25c9930524..16999746d8 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomInTAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomInXAction.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ghidra.app.plugin.core.debug.gui.memview.actions;
+package ghidra.app.plugin.core.bento.actions;
import javax.swing.Icon;
@@ -21,24 +21,24 @@ import docking.ActionContext;
import docking.action.DockingAction;
import docking.action.ToolBarData;
import generic.theme.GIcon;
-import ghidra.app.plugin.core.debug.gui.memview.MemviewProvider;
+import ghidra.app.plugin.core.bento.BentoProvider;
import ghidra.util.HelpLocation;
-public class ZoomInTAction extends DockingAction {
+public class ZoomInXAction extends DockingAction {
private static final Icon ICON = new GIcon("icon.widget.imagepanel.zoom.in");
- private MemviewProvider provider;
+ private BentoProvider provider;
- public ZoomInTAction(MemviewProvider provider) {
- super("Zoom In (Time)", provider.getOwner());
+ public ZoomInXAction(BentoProvider provider) {
+ super("Zoom In (X)", provider.getOwner());
this.provider = provider;
setEnabled(true);
- this.setToolBarData(new ToolBarData(ICON, "aoverview"));
+ this.setToolBarData(new ToolBarData(ICON, "xoverview"));
- setDescription("Zoom In (T)");
- setHelpLocation(new HelpLocation("DebuggerMemviewPlugin", "zoom"));
+ setDescription("Zoom In (X)");
+ setHelpLocation(new HelpLocation("BentoServicePlugin", "zoom"));
}
@Override
@@ -48,7 +48,7 @@ public class ZoomInTAction extends DockingAction {
@Override
public void actionPerformed(ActionContext context) {
- provider.changeZoomT(1);
+ provider.changeZoom(0, 1);
provider.refresh();
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomInAAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomInYAction.java
similarity index 68%
rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomInAAction.java
rename to Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomInYAction.java
index dc9f989b41..0b23d66830 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomInAAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomInYAction.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ghidra.app.plugin.core.debug.gui.memview.actions;
+package ghidra.app.plugin.core.bento.actions;
import javax.swing.Icon;
@@ -21,24 +21,24 @@ import docking.ActionContext;
import docking.action.DockingAction;
import docking.action.ToolBarData;
import generic.theme.GIcon;
-import ghidra.app.plugin.core.debug.gui.memview.MemviewProvider;
+import ghidra.app.plugin.core.bento.BentoProvider;
import ghidra.util.HelpLocation;
-public class ZoomInAAction extends DockingAction {
+public class ZoomInYAction extends DockingAction {
private static final Icon ICON = new GIcon("icon.widget.imagepanel.zoom.in");
- private MemviewProvider provider;
+ private BentoProvider provider;
- public ZoomInAAction(MemviewProvider provider) {
- super("Zoom In (Addrs)", provider.getOwner());
+ public ZoomInYAction(BentoProvider provider) {
+ super("Zoom In (Y)", provider.getOwner());
this.provider = provider;
setEnabled(true);
- this.setToolBarData(new ToolBarData(ICON, "aoverview"));
+ this.setToolBarData(new ToolBarData(ICON, "yoverview"));
- setDescription("Zoom In (A)");
- setHelpLocation(new HelpLocation("DebuggerMemviewPlugin", "zoom"));
+ setDescription("Zoom In (Y)");
+ setHelpLocation(new HelpLocation("BentoServicePlugin", "zoom"));
}
@Override
@@ -48,7 +48,7 @@ public class ZoomInAAction extends DockingAction {
@Override
public void actionPerformed(ActionContext context) {
- provider.changeZoomA(1);
+ provider.changeZoom(1, 1);
provider.refresh();
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomOutTAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomOutXAction.java
similarity index 68%
rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomOutTAction.java
rename to Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomOutXAction.java
index 0db04407fa..c855965eb0 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomOutTAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomOutXAction.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ghidra.app.plugin.core.debug.gui.memview.actions;
+package ghidra.app.plugin.core.bento.actions;
import javax.swing.Icon;
@@ -21,24 +21,24 @@ import docking.ActionContext;
import docking.action.DockingAction;
import docking.action.ToolBarData;
import generic.theme.GIcon;
-import ghidra.app.plugin.core.debug.gui.memview.MemviewProvider;
+import ghidra.app.plugin.core.bento.BentoProvider;
import ghidra.util.HelpLocation;
-public class ZoomOutTAction extends DockingAction {
+public class ZoomOutXAction extends DockingAction {
private static final Icon ICON = new GIcon("icon.widget.imagepanel.zoom.out");
- private MemviewProvider provider;
+ private BentoProvider provider;
- public ZoomOutTAction(MemviewProvider provider) {
- super("Zoom Out (Time)", provider.getOwner());
+ public ZoomOutXAction(BentoProvider provider) {
+ super("Zoom Out (X)", provider.getOwner());
this.provider = provider;
setEnabled(true);
- this.setToolBarData(new ToolBarData(ICON, "aoverview"));
+ this.setToolBarData(new ToolBarData(ICON, "xoverview"));
- setDescription("Zoom Out (T)");
- setHelpLocation(new HelpLocation("DebuggerMemviewPlugin", "zoom"));
+ setDescription("Zoom Out (X)");
+ setHelpLocation(new HelpLocation("BentoServicePlugin", "zoom"));
}
@Override
@@ -48,7 +48,7 @@ public class ZoomOutTAction extends DockingAction {
@Override
public void actionPerformed(ActionContext context) {
- provider.changeZoomT(-1);
+ provider.changeZoom(0, -1);
provider.refresh();
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomOutAAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomOutYAction.java
similarity index 68%
rename from Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomOutAAction.java
rename to Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomOutYAction.java
index 9a0b639d3b..9efc49f147 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memview/actions/ZoomOutAAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bento/actions/ZoomOutYAction.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ghidra.app.plugin.core.debug.gui.memview.actions;
+package ghidra.app.plugin.core.bento.actions;
import javax.swing.Icon;
@@ -21,24 +21,24 @@ import docking.ActionContext;
import docking.action.DockingAction;
import docking.action.ToolBarData;
import generic.theme.GIcon;
-import ghidra.app.plugin.core.debug.gui.memview.MemviewProvider;
+import ghidra.app.plugin.core.bento.BentoProvider;
import ghidra.util.HelpLocation;
-public class ZoomOutAAction extends DockingAction {
+public class ZoomOutYAction extends DockingAction {
private static final Icon ICON = new GIcon("icon.widget.imagepanel.zoom.out");
- private MemviewProvider provider;
+ private BentoProvider provider;
- public ZoomOutAAction(MemviewProvider provider) {
- super("Zoom Out (Addrs)", provider.getOwner());
+ public ZoomOutYAction(BentoProvider provider) {
+ super("Zoom Out (Y)", provider.getOwner());
this.provider = provider;
setEnabled(true);
- this.setToolBarData(new ToolBarData(ICON, "aoverview"));
+ this.setToolBarData(new ToolBarData(ICON, "yoverview"));
- setDescription("Zoom Out (A)");
- setHelpLocation(new HelpLocation("DebuggerMemviewPlugin", "zoom"));
+ setDescription("Zoom Out (Y)");
+ setHelpLocation(new HelpLocation("BentoServicePlugin", "zoom"));
}
@Override
@@ -48,7 +48,7 @@ public class ZoomOutAAction extends DockingAction {
@Override
public void actionPerformed(ActionContext context) {
- provider.changeZoomA(-1);
+ provider.changeZoom(1, -1);
provider.refresh();
}
diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/ExampleBentoScript.java b/Ghidra/Features/Decompiler/ghidra_scripts/ExampleBentoScript.java
new file mode 100644
index 0000000000..544c662e78
--- /dev/null
+++ b/Ghidra/Features/Decompiler/ghidra_scripts/ExampleBentoScript.java
@@ -0,0 +1,306 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+// Displays a table comparing the sizes of functions to the sizes of their decompilations.
+
+// Use this script to help identify functions that are being decompiled incorrectly. If you find
+// a function with many instructions whose decompilation is quite short, there might be something fishy going on
+// with the return value.
+//
+// Note: a value of -1.0 in the "Ratio" column indicates a failure during decompilation.
+
+// @category Analysis
+
+import java.awt.Color;
+import java.util.*;
+import java.util.function.Consumer;
+
+import org.apache.commons.collections4.IteratorUtils;
+
+import ghidra.app.decompiler.*;
+import ghidra.app.decompiler.parallel.*;
+import ghidra.app.plugin.core.bento.*;
+import ghidra.app.script.GhidraScript;
+import ghidra.app.tablechooser.*;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.*;
+import ghidra.program.model.pcode.HighFunction;
+import ghidra.program.model.pcode.PcodeOpAST;
+import ghidra.util.task.TaskMonitor;
+
+public class ExampleBentoScript extends GhidraScript {
+
+ // This script is essentially identical to the CompareFunctionSizesScript, but adds the
+ // option of plotting some subset of the table entries as a "Bento" display.
+
+ static class ExampleBentoExecutor implements TableChooserExecutor {
+
+ private BentoService service;
+ private Program program;
+
+ public ExampleBentoExecutor(PluginTool tool, Program program) {
+ service = tool.getService(BentoService.class);
+ this.program = program;
+ }
+
+ @Override
+ public String getButtonName() {
+ return "Plot";
+ }
+
+ @Override
+ public boolean execute(AddressableRowObject rowObject) {
+ return false;
+ }
+
+ @SuppressWarnings("hiding")
+ @Override
+ public boolean executeInBulk(List<AddressableRowObject> rowObjects,
+ List<AddressableRowObject> deleted, TaskMonitor monitor) {
+ List<BentoBox> boxes = new ArrayList<>();
+ for (AddressableRowObject row : rowObjects) {
+ if (row instanceof ExampleRow src) {
+ BoundedObject x = new BoundedObject(src.getNumInstructions(),
+ src.getNumInstructions() + 100);
+ BoundedObject y = new FunctionBoundedObject(src.getFunction());
+ BoundedObject z = new BoundedObject(src.getNumHighOps(),
+ src.getNumHighOps() + 40);
+ List<BoundedObject> objects = new ArrayList<>();
+ objects.add(x);
+ objects.add(y);
+ objects.add(z);
+ BentoBox box = new BentoBox(src.getFunction().getName(), objects, Color.RED);
+ boxes.add(box);
+ }
+ }
+ BentoProvider provider = service.createProvider();
+ provider.setBoxes(boxes);
+ provider.setProgram(program);
+ provider.setColumns(List.of("Inst", "Addr", "Op"));
+ provider.setRadix(0, BentoRadix.HEX_UPPER);
+ return false;
+ }
+ }
+
+ static class ExampleRow implements AddressableRowObject {
+ private int numInstructions;
+ private int numHighOps;
+ private double ratio;
+ private Function func;
+
+ public ExampleRow(Function f, int numInst, int numHigh) {
+ func = f;
+ numInstructions = numInst;
+ numHighOps = numHigh;
+ if (numHighOps == 0) {
+ ratio = -1.0;
+ }
+ else {
+ ratio = (numHighOps * 1.0) / numInstructions;
+ }
+ }
+
+ public int getNumInstructions() {
+ return numInstructions;
+ }
+
+ public int getNumHighOps() {
+ return numHighOps;
+ }
+
+ public Function getFunction() {
+ return func;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(func.getName());
+ sb.append(" instructions: ");
+ sb.append(Integer.toString(numInstructions));
+ sb.append(", high ops: ");
+ sb.append(Integer.toString(numHighOps));
+ return sb.toString();
+ }
+
+ @Override
+ public Address getAddress() {
+ return func.getEntryPoint();
+ }
+
+ public double getRatio() {
+ return ratio;
+ }
+ }
+
+ @Override
+ protected void run() throws Exception {
+
+ if (isRunningHeadless()) {
+ println("This script cannot be run headlessly");
+ return;
+ }
+
+ ExampleBentoExecutor executor = new ExampleBentoExecutor(this.getState().getTool(), currentProgram);
+ TableChooserDialog bentoDialog =
+ createTableChooserDialog(currentProgram.getName() + " function sizes", executor);
+ configureTableColumns(bentoDialog);
+ bentoDialog.show();
+
+ DecompilerCallback<ExampleRow> callback = new DecompilerCallback<>(
+ currentProgram, new CompareFunctionSizesScriptConfigurer(currentProgram)) {
+
+ @Override
+ public ExampleRow process(DecompileResults results, TaskMonitor tMonitor)
+ throws Exception {
+
+ Listing listing = currentProgram.getListing();
+ Function function = results.getFunction();
+ InstructionIterator it = listing.getInstructions(function.getBody(), true);
+ int numInstructions = IteratorUtils.size(it);
+
+ // indicate failure of decompilation by having 0 high pcode ops
+ int numHighOps = 0;
+ HighFunction highFunction = results.getHighFunction();
+ if (highFunction != null) {
+ Iterator<PcodeOpAST> ops = highFunction.getPcodeOps();
+ if (ops != null) {
+ numHighOps = IteratorUtils.size(ops);
+ }
+ }
+ return new ExampleRow(function, numInstructions, numHighOps);
+ }
+ };
+
+ Consumer<ExampleRow> consumer = data -> bentoDialog.add(data);
+ FunctionIterator it = currentProgram.getFunctionManager().getFunctionsNoStubs(true);
+ ParallelDecompiler.decompileFunctions(callback, currentProgram, it, consumer, monitor);
+ callback.dispose();
+ }
+
+ class CompareFunctionSizesScriptConfigurer implements DecompileConfigurer {
+ private Program p;
+
+ public CompareFunctionSizesScriptConfigurer(Program prog) {
+ p = prog;
+ }
+
+ @Override
+ public void configure(DecompInterface decompiler) {
+ decompiler.toggleCCode(false);
+ decompiler.toggleSyntaxTree(true);
+ decompiler.setSimplificationStyle("decompile");
+ DecompileOptions opts = new DecompileOptions();
+ opts.grabFromProgram(p);
+ decompiler.setOptions(opts);
+ }
+ }
+
+
+ interface RowEntries {
+ void add(ExampleRow row);
+
+ void setMessage(String message);
+
+ void clear();
+ }
+
+ class TableEntryList implements RowEntries {
+
+ private TableChooserDialog tDialog;
+
+ public TableEntryList(TableChooserDialog dialog) {
+ tDialog = dialog;
+ }
+
+ @Override
+ public void add(ExampleRow row) {
+ tDialog.add(row);
+
+ }
+
+ @Override
+ public void setMessage(String message) {
+ tDialog.setMessage(message);
+
+ }
+
+ @Override
+ public void clear() {
+ return;
+ }
+
+ }
+
+ private void configureTableColumns(TableChooserDialog dialog) {
+
+ StringColumnDisplay functionNameColumn = new StringColumnDisplay() {
+ @Override
+ public String getColumnName() {
+ return "Function Name";
+ }
+
+ @Override
+ public String getColumnValue(AddressableRowObject rowObject) {
+ return ((ExampleRow) rowObject).getFunction().getName();
+ }
+ };
+
+ ColumnDisplay<Integer> highOpsColumn = new AbstractComparableColumnDisplay<>() {
+
+ @Override
+ public Integer getColumnValue(AddressableRowObject rowObject) {
+ return ((ExampleRow) rowObject).getNumHighOps();
+ }
+
+ @Override
+ public String getColumnName() {
+ return "Num High Ops";
+ }
+ };
+
+ ColumnDisplay<Integer> instructionColumn = new AbstractComparableColumnDisplay<>() {
+
+ @Override
+ public Integer getColumnValue(AddressableRowObject rowObject) {
+ return ((ExampleRow) rowObject).getNumInstructions();
+ }
+
+ @Override
+ public String getColumnName() {
+ return "Num Instructions";
+ }
+ };
+
+ ColumnDisplay<Double> ratioColumn = new AbstractComparableColumnDisplay<>() {
+
+ @Override
+ public Double getColumnValue(AddressableRowObject rowObject) {
+ return ((ExampleRow) rowObject).getRatio();
+ }
+
+ @Override
+ public String getColumnName() {
+ return "Ratio";
+ }
+ };
+ dialog.addCustomColumn(functionNameColumn);
+ dialog.addCustomColumn(highOpsColumn);
+ dialog.addCustomColumn(instructionColumn);
+ dialog.addCustomColumn(ratioColumn);
+ }
+
+}