Ghidra is a software reverse engineering (SRE) framework
add jarbundle, add toolbar actions, fix view versus row indexing
Jason P. Leasure5c28ab536c36
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleCompiler.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleCompiler.javadeleted file mode 100644index e4151b1e43..0000000000--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleCompiler.java+++ /dev/null@@ -1,294 +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.osgi;--import java.io.*;-import java.nio.charset.Charset;-import java.nio.file.*;-import java.util.*;-import java.util.jar.Attributes;-import java.util.jar.Manifest;-import java.util.stream.Collectors;-import java.util.stream.Stream;--import javax.tools.*;-import javax.tools.JavaFileObject.Kind;--import org.osgi.framework.Constants;-import org.osgi.framework.wiring.BundleRequirement;-import org.osgi.framework.wiring.BundleWiring;-import org.phidias.compile.BundleJavaManager;--import aQute.bnd.osgi.*;-import aQute.bnd.osgi.Clazz.QUERY;-import generic.jar.ResourceFile;-import ghidra.app.script.*;--public class BundleCompiler {- private BundleHost bh;-- static final String GENERATED_ACTIVATOR_CLASSNAME = "GeneratedActivator";-- BundleCompiler(BundleHost bh) {- this.bh = bh;- }-- private JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();-- /**- * compile a source directory to an exploded bundle- *- * @param sb the bundle info to build- * @param writer for updating the user during compilation- * @throws IOException for source/manifest file reading/generation and binary deletion/creation- * @throws OSGiException if generation of bundle metadata fails- */- void compileToExplodedBundle(GhidraSourceBundle sb, PrintWriter writer)- throws IOException, OSGiException {-- sb.compileAttempted();- ResourceFile srcdir = sb.getSourceDir();- Path bindir = sb.getBinDir();- Files.createDirectories(bindir);-- List<String> options = new ArrayList<>();- options.add("-g");- options.add("-d");- options.add(bindir.toString());- options.add("-sourcepath");- options.add(srcdir.toString());- options.add("-classpath");- options.add(System.getProperty("java.class.path") + File.pathSeparator + bindir.toString());- options.add("-proc:none");-- final JavaFileManager rfm =- new ResourceFileJavaFileManager(Collections.singletonList(sb.getSourceDir()));-- BundleJavaManager bjm = new BundleJavaManager(bh.getHostFramework(), rfm, options);- // The phidias BundleJavaManager is for compiling from within a bundle -- it makes the- // bundle dependencies available to the compiler classpath. Here, we are compiling in an as-yet- // non-existing bundle, so we forge the wiring based on @imports metadata.-- // XXX skip this if there's a source manifest, emit warnings about @imports- // get wires for currently active bundles to satisfy all requirements- List<BundleRequirement> reqs = sb.getAllReqs();- List<BundleWiring> bundleWirings = bh.resolve(reqs);-- if (!reqs.isEmpty()) {- writer.printf("%d import requirement%s remain%s unresolved:\n", reqs.size(),- reqs.size() > 1 ? "s" : "", reqs.size() > 1 ? "" : "s");- for (BundleRequirement req : reqs) {- writer.printf(" %s\n", req.toString());- }-- sb.setSummary(- String.format("%d missing @import%s:%s", reqs.size(), reqs.size() > 1 ? "s" : "",- reqs.stream().flatMap(- r -> OSGiUtils.extractPackages(r.toString()).stream()).distinct().collect(- Collectors.joining(","))));- }- else {- sb.setSummary("");- }- List<ResourceFile> newSources = sb.getNewSources();-- // send the capabilities to phidias- bundleWirings.forEach(bjm::addBundleWiring);-- final List<ResourceFileJavaFileObject> sourceFiles = newSources.stream().map(- sf -> new ResourceFileJavaFileObject(sf.getParentFile(), sf, Kind.SOURCE)).collect(- Collectors.toList());-- Path dmf = bindir.resolve("META-INF").resolve("MANIFEST.MF");- if (Files.exists(dmf)) {- Files.delete(dmf);- }-- // try to compile, if we fail, avoid offenders and try again- while (!sourceFiles.isEmpty()) {- DiagnosticCollector<JavaFileObject> diagnostics =- new DiagnosticCollector<JavaFileObject>();- JavaCompiler.CompilationTask task =- compiler.getTask(writer, bjm, diagnostics, options, null, sourceFiles);- // task.setProcessors // for annotation processing / code generation-- Boolean successfulCompilation = task.call();- if (successfulCompilation) {- break;- }- for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {- String err = d.toString() + "\n";- writer.write(err);- ResourceFileJavaFileObject sf = (ResourceFileJavaFileObject) d.getSource();- ResourceFile rf = sf.getFile();- sb.buildError(rf, err); // remember all errors for this file- if (sourceFiles.remove(sf)) {- writer.printf("skipping %s\n", sf.toString());- }- }- }- // mark the successful compilations- for (ResourceFileJavaFileObject sf : sourceFiles) {- ResourceFile rf = sf.getFile();- sb.buildSuccess(rf);- }- // buildErrors is now up to date, set status- if (sb.getFailingSourcesCount() > 0) {- sb.appendSummary(String.format("%d failing source files", sb.getFailingSourcesCount()));- }-- ResourceFile smf = new ResourceFile(srcdir, "META-INF" + File.separator + "MANIFEST.MF");- if (smf.exists()) {- System.err.printf("Found manifest, not generating one\n");- Files.createFile(dmf);- Files.copy(smf.getInputStream(), dmf, StandardCopyOption.REPLACE_EXISTING);- return;- }-- // no manifest, so create one with bndtools- Analyzer analyzer = new Analyzer();- analyzer.setJar(new Jar(bindir.toFile())); // give bnd the contents- Stream<Object> bjars = Files.list(GhidraScriptUtil.getCompiledBundlesDir()).filter(- f -> f.toString().endsWith(".jar")).map(f -> {- try {- return new Jar(f.toFile());- }- catch (IOException e1) {- e1.printStackTrace(writer);- return null;- }- });-- analyzer.addClasspath(bjars.collect(Collectors.toUnmodifiableList()));- analyzer.setProperty("Bundle-SymbolicName",- BundleHost.getSymbolicNameFromSourceDir(srcdir));- analyzer.setProperty("Bundle-Version", "1.0");- analyzer.setProperty("Import-Package", "*");- analyzer.setProperty("Export-Package", "!*.private.*,!*.internal.*,*");- // analyzer.setBundleActivator(s);-- try {- Manifest manifest;- try {- manifest = analyzer.calcManifest();- }- catch (Exception e) {- sb.appendSummary("bad manifest");- throw new OSGiException("failed to calculate manifest by analyzing code", e);- }- Attributes ma = manifest.getMainAttributes();-- String activator_classname = null;- try {- for (Clazz clazz : analyzer.getClassspace().values()) {- if (clazz.is(QUERY.IMPLEMENTS,- new Instruction("org.osgi.framework.BundleActivator"), analyzer)) {- System.err.printf("found BundleActivator class %s\n", clazz);- activator_classname = clazz.toString();- }- }- }- catch (Exception e) {- sb.appendSummary("failed bnd analysis");- throw new OSGiException("failed to query classes while searching for activator", e);- }- if (activator_classname == null) {- activator_classname = GENERATED_ACTIVATOR_CLASSNAME;- if (!buildDefaultActivator(bindir, activator_classname, writer)) {- sb.appendSummary("failed to build generated activator");- return;- }- // since we add the activator after bndtools built the imports, we should add its imports too- String imps = ma.getValue(Constants.IMPORT_PACKAGE);- if (imps == null) {- ma.putValue(Constants.IMPORT_PACKAGE,- GhidraBundleActivator.class.getPackageName());- }- else {- ma.putValue(Constants.IMPORT_PACKAGE,- imps + "," + GhidraBundleActivator.class.getPackageName());- }- }- ma.putValue(Constants.BUNDLE_ACTIVATOR, activator_classname);-- // write the manifest- Files.createDirectories(dmf.getParent());- try (OutputStream out = Files.newOutputStream(dmf)) {- manifest.write(out);- }- }- finally {- analyzer.close();- }- }-- /**- * create and compile a default bundle activator- *- * @param bindir destination for class file- * @param activator_classname the name to use for the genearted activator class- * @param writer for writing compile errors- * @return true if compilation succeeded- * @throws IOException for failed write of source/binary activator- */- private boolean buildDefaultActivator(Path bindir, String activator_classname, Writer writer)- throws IOException {- Path activator_dest = bindir.resolve(activator_classname + ".java");-- try (PrintWriter out =- new PrintWriter(Files.newBufferedWriter(activator_dest, Charset.forName("UTF-8")))) {- out.println("import " + GhidraBundleActivator.class.getName() + ";");- out.println("import org.osgi.framework.BundleActivator;");- out.println("import org.osgi.framework.BundleContext;");- out.println("public class " + GENERATED_ACTIVATOR_CLASSNAME +- " extends GhidraBundleActivator {");- out.println(" protected void start(BundleContext bc, Object api) {");- out.println(" // TODO: stuff to do on bundle start");- out.println(" }");- out.println(" protected void stop(BundleContext bc, Object api) {");- out.println(" // TODO: stuff to do on bundle stop");- out.println(" }");- out.println();- out.println("}");- }-- List<String> options = new ArrayList<>();- options.add("-g");- options.add("-d");- options.add(bindir.toString());- options.add("-sourcepath");- options.add(bindir.toString());- options.add("-classpath");- options.add(System.getProperty("java.class.path"));- options.add("-proc:none");-- StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);- BundleJavaManager bjm = new BundleJavaManager(bh.getHostFramework(), fm, options);- Iterable<? extends JavaFileObject> sourceFiles =- fm.getJavaFileObjectsFromPaths(List.of(activator_dest));- DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();- JavaCompiler.CompilationTask task =- compiler.getTask(writer, bjm, diagnostics, options, null, sourceFiles);- if (!task.call()) {- for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {- writer.write(d.getSource().toString() + ": " + d.getMessage(null) + "\n");- }- return false;- }- return true;- }--}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.javaindex 746873a6eb..1f054e0e3c 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java@@ -78,6 +78,7 @@ public class BundleHost {return new GhidraSourceBundle(this, path);case BndScript:case Jar:+ return new GhidraJarBundle(this, path);default:break;}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusModel.javaindex 83353d5deb..60aac28769 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusModel.java@@ -23,6 +23,7 @@ import java.util.stream.Collectors;import org.osgi.framework.Bundle;import docking.widgets.table.AbstractSortedTableModel;+import docking.widgets.table.TableSortingContext;import generic.jar.ResourceFile;import ghidra.app.script.GhidraScriptUtil;import ghidra.framework.options.SaveState;@@ -260,9 +261,9 @@ public class BundleStatusModel extends AbstractSortedTableModel<BundleStatus> {fireTableRowsInserted(index, files.size() - 1);}- void remove(int[] selectedRows) {+ void remove(int[] selectedModelRows) {List<BundleStatus> toRemove = new ArrayList<>();- for (int selectedRow : selectedRows) {+ for (int selectedRow : selectedModelRows) {toRemove.add(statuses.get(selectedRow));}for (BundleStatus status : toRemove) {@@ -311,8 +312,8 @@ public class BundleStatusModel extends AbstractSortedTableModel<BundleStatus> {public void setValueAt(Object aValue, int rowIndex, int columnIndex) {BundleStatus status = statuses.get(rowIndex);getColumn(columnIndex).setValue(status, aValue);- // XXX: avoid RowObjectSelectionManager.repairSelection by selecting the row we're editing- provider.selectRow(rowIndex);+ // XXX I don't know why it's unselected, but it's maddening+ provider.selectModelRow(rowIndex);}@Override@@ -499,11 +500,47 @@ public class BundleStatusModel extends AbstractSortedTableModel<BundleStatus> {ss.putBooleans("BundleStatus_READ", readonlyArr);}- public List<BundleStatus> getRowObjects(int[] rowIndices) {- List<BundleStatus> rows = new ArrayList<>(rowIndices.length);- for (int i : rowIndices) {- rows.add(statuses.get(i));+ public List<BundleStatus> getRowObjects(int[] modelRowIndices) {+ List<BundleStatus> rows = new ArrayList<>(modelRowIndices.length);+ for (int i : modelRowIndices) {+ rows.add(getRowObject(i));}return rows;}++ /**+ * avoid generating events when nothing changes+ */+ @Override+ protected void sort(List<BundleStatus> data, TableSortingContext<BundleStatus> sortingContext) {++ if (sortingContext.isUnsorted()) {+ // this is the 'no sort' state+ sortCompleted(sortingContext);+ notifyModelSorted(false);+ return;+ }++ hasEverSorted = true; // signal that we have sorted at least one time++ boolean[] change = { false };+ Comparator<BundleStatus> proxy = new Comparator<BundleStatus>() {+ Comparator<BundleStatus> p = sortingContext.getComparator();++ @Override+ public int compare(BundleStatus o1, BundleStatus o2) {+ int v = p.compare(o1, o2);+ if (v < 0) {+ change[0] = true;+ }+ return v;+ }+ };+ Collections.sort(data, proxy);+ sortCompleted(sortingContext);+ if (change[0]) {+ notifyModelSorted(false);+ }+ }+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusProvider.javaindex 701a1ea816..9470a855da 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusProvider.java@@ -19,6 +19,7 @@ import java.awt.*;import java.io.File;import java.util.Arrays;import java.util.List;+import java.util.stream.Collectors;import javax.swing.*;import javax.swing.event.TableModelEvent;@@ -26,6 +27,7 @@ import javax.swing.table.TableColumn;import docking.ActionContext;import docking.action.*;+import docking.util.AnimationUtils;import docking.widgets.filechooser.GhidraFileChooser;import docking.widgets.filechooser.GhidraFileChooserMode;import docking.widgets.table.*;@@ -39,7 +41,6 @@ import ghidra.util.exception.CancelledException;import ghidra.util.filechooser.GhidraFileChooserModel;import ghidra.util.filechooser.GhidraFileFilter;import ghidra.util.task.*;-import resources.Icons;import resources.ResourceManager;/**@@ -49,16 +50,16 @@ public class BundleStatusProvider extends ComponentProviderAdapter {static String preferenceForLastSelectedBundle = "LastGhidraScriptBundle";private JPanel panel;- private GTable bundleStatusTable;+ private LessFreneticGTable bundleStatusTable;private final BundleStatusModel bundleStatusModel;- private Color selectionColor;+ private GTableFilterPanel<BundleStatus> filterPanel;+private GhidraFileChooser fileChooser;private GhidraFileFilter filter;private final BundleHost bundleHost;- public void notifyTableChanged() {- bundleStatusTable.notifyTableChanged(new TableModelEvent(bundleStatusModel));- }+ static final String BUNDLE_GROUP = "0bundle group";+ static final String BUNDLE_LIST_GROUP = "1bundle list group";public BundleStatusProvider(PluginTool tool, String owner) {super(tool, "Bundle Status Manager", owner);@@ -97,21 +98,16 @@ public class BundleStatusProvider extends ComponentProviderAdapter {createActions();}- public BundleStatusModel getModel() {- return bundleStatusModel;- }-private void build() {panel = new JPanel(new BorderLayout(5, 5));- selectionColor = new Color(204, 204, 255);-- bundleStatusTable = new GTable(bundleStatusModel);+ bundleStatusTable = new LessFreneticGTable(bundleStatusModel);bundleStatusTable.setName("BUNDLESTATUS_TABLE");- bundleStatusTable.setSelectionBackground(selectionColor);+ bundleStatusTable.setSelectionBackground(new Color(204, 204, 255));bundleStatusTable.setSelectionForeground(Color.BLACK);bundleStatusTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);+ // give actions a chance to update status when selection changedbundleStatusTable.getSelectionModel().addListSelectionListener(e -> {if (e.getValueIsAdjusting()) {return;@@ -124,13 +120,17 @@ public class BundleStatusProvider extends ComponentProviderAdapter {int skinnyWidth = 50;- TableColumn column =+ TableColumn column;++ //+ column =bundleStatusTable.getColumnModel().getColumn(bundleStatusModel.enabledColumn.index);column.setPreferredWidth(skinnyWidth);column.setMinWidth(skinnyWidth);column.setMaxWidth(skinnyWidth);column.setWidth(skinnyWidth);+ //column = bundleStatusTable.getColumnModel().getColumn(bundleStatusModel.activeColumn.index);column.setPreferredWidth(skinnyWidth);column.setMinWidth(skinnyWidth);@@ -158,12 +158,11 @@ public class BundleStatusProvider extends ComponentProviderAdapter {});+ //column = bundleStatusTable.getColumnModel().getColumn(bundleStatusModel.typeColumn.index);-FontMetrics fontmetrics = panel.getFontMetrics(panel.getFont());column.setMaxWidth(10 +SwingUtilities.computeStringWidth(fontmetrics, GhidraBundle.Type.SourceDir.toString()));-column = bundleStatusTable.getColumnModel().getColumn(bundleStatusModel.pathColumn.index);column.setCellRenderer(new GTableCellRenderer() {@Override@@ -178,8 +177,7 @@ public class BundleStatusProvider extends ComponentProviderAdapter {}});- GTableFilterPanel<BundleStatus> filterPanel =- new GTableFilterPanel<>(bundleStatusTable, bundleStatusModel);+ filterPanel = new GTableFilterPanel<>(bundleStatusTable, bundleStatusModel);JScrollPane scrollPane = new JScrollPane(bundleStatusTable);scrollPane.getViewport().setBackground(bundleStatusTable.getBackground());@@ -191,28 +189,72 @@ public class BundleStatusProvider extends ComponentProviderAdapter {private void createActions() {DockingAction action;- //- action = new DockingAction("Clean", this.getName()) {+ //+ action = new DockingAction("ActivateBundle", this.getName()) {@Overridepublic void actionPerformed(ActionContext context) {- int[] selectedRows = bundleStatusTable.getSelectedRows();- for (BundleStatus o : bundleStatusModel.getRowObjects(selectedRows)) {- bundleHost.getGhidraBundle(o.getPath()).clean();- }+ startActivateSelectedTask();}@Overridepublic boolean isEnabledForContext(ActionContext context) {return bundleStatusTable.getSelectedRows().length > 0;}+ };+ action.setPopupMenuData(new MenuData(new String[] { "Activate bundles(s)" },+ ResourceManager.loadImage("images/media-playback-start.png"), BUNDLE_GROUP));+ action.setToolBarData(new ToolBarData(+ ResourceManager.loadImage("images/media-playback-start.png"), BUNDLE_GROUP));+ action.setDescription("Activate bundle(s)");+ action.setEnabled(false);+ getTool().addLocalAction(this, action);++ //+ action = new DockingAction("DeactivateBundle", this.getName()) {+ @Override+ public void actionPerformed(ActionContext context) {+ startDeactivateSelectedTask();+ }+ @Override+ public boolean isEnabledForContext(ActionContext context) {+ return bundleStatusTable.getSelectedRows().length > 0;+ }};- action.setPopupMenuData(- new MenuData(new String[] { "Clean bundle(s)" }, Icons.REFRESH_ICON, null));- action.setToolBarData(new ToolBarData(Icons.REFRESH_ICON, null));+ action.setPopupMenuData(new MenuData(new String[] { "Deactivate bundles(s)" },+ ResourceManager.loadImage("images/media-playback-stop.png"), BUNDLE_GROUP));+ action.setToolBarData(new ToolBarData(+ ResourceManager.loadImage("images/media-playback-stop.png"), BUNDLE_GROUP));+ action.setDescription("Deactivate bundle(s)");+ action.setEnabled(false);+ getTool().addLocalAction(this, action);++ //+ action = new DockingAction("CleanBundle", this.getName()) {+ @Override+ public void actionPerformed(ActionContext context) {+ int[] selectedModelRows = getSelectedModelRows();+ boolean anythingCleaned = false;+ for (BundleStatus o : bundleStatusModel.getRowObjects(selectedModelRows)) {+ anythingCleaned |= bundleHost.getGhidraBundle(o.getPath()).clean();+ }+ if (anythingCleaned) {+ AnimationUtils.shakeComponent(getComponent());+ }+ }- action.setDescription("Clean selected bundles");+ @Override+ public boolean isEnabledForContext(ActionContext context) {+ return bundleStatusTable.getSelectedRows().length > 0;+ }+ };+ // cache is a lightning bolt+ action.setPopupMenuData(new MenuData(new String[] { "Clean bundle(s)" },+ ResourceManager.loadImage("images/erase16.png"), BUNDLE_GROUP));+ action.setToolBarData(+ new ToolBarData(ResourceManager.loadImage("images/erase16.png"), BUNDLE_GROUP));+ action.setDescription("Clean build artifacts for bundle(s)");action.setEnabled(false);getTool().addLocalAction(this, action);@@ -230,8 +272,9 @@ public class BundleStatusProvider extends ComponentProviderAdapter {};action.setPopupMenuData(new MenuData(new String[] { "Add bundle" },- ResourceManager.loadImage("images/Plus.png"), null));- action.setToolBarData(new ToolBarData(ResourceManager.loadImage("images/Plus.png"), null));+ ResourceManager.loadImage("images/Plus.png"), BUNDLE_LIST_GROUP));+ action.setToolBarData(+ new ToolBarData(ResourceManager.loadImage("images/Plus.png"), BUNDLE_LIST_GROUP));action.setDescription("Display file chooser to add bundles to list");action.setEnabled(true);@@ -251,32 +294,36 @@ public class BundleStatusProvider extends ComponentProviderAdapter {};action.setPopupMenuData(new MenuData(new String[] { "Remove bundle(s)" },- ResourceManager.loadImage("images/edit-delete.png"), null));- action.setToolBarData(- new ToolBarData(ResourceManager.loadImage("images/edit-delete.png"), null));+ ResourceManager.loadImage("images/edit-delete.png"), BUNDLE_LIST_GROUP));+ action.setToolBarData(new ToolBarData(ResourceManager.loadImage("images/edit-delete.png"),+ BUNDLE_LIST_GROUP));action.setDescription("Remove selected bundles");action.setEnabled(true);getTool().addLocalAction(this, action);}- private void removeBundlesAction() {+ /**+ * get the currently selected rows and translate to model rows+ *+ * @return selected model rows+ */+ int[] getSelectedModelRows() {int[] selectedRows = bundleStatusTable.getSelectedRows();- if (selectedRows == null || selectedRows.length == 0) {- return;+ if (selectedRows == null) {+ return null;}- bundleStatusModel.remove(selectedRows);-- // select the next row based on what was selected- Arrays.sort(selectedRows);- int row = selectedRows[selectedRows.length - 1] + 1 - selectedRows.length;- int count = bundleStatusModel.getRowCount();- if (row >= count) {- row = count - 1;- }- if (row >= 0) {- bundleStatusTable.setRowSelectionInterval(row, row);+ return Arrays.stream(selectedRows).map(filterPanel::getModelRow).toArray();+ }++ private void removeBundlesAction() {+ int[] selectedModelRows = getSelectedModelRows();+ if (selectedModelRows == null || selectedModelRows.length == 0) {+ return;}++ bundleStatusModel.remove(selectedModelRows);+ bundleStatusTable.clearSelection();}private void addBundlesAction() {@@ -322,11 +369,6 @@ public class BundleStatusProvider extends ComponentProviderAdapter {}}- @Override- public JComponent getComponent() {- return panel;- }-/*@Overridepublic ActionContext getActionContext(MouseEvent event) {@@ -334,13 +376,97 @@ public class BundleStatusProvider extends ComponentProviderAdapter {}*/- public void dispose() {- bundleStatusTable.dispose();+ protected void startActivateSelectedTask() {+ ConsoleService console = getTool().getService(ConsoleService.class);+ int[] selectedModelRows = getSelectedModelRows();++ new TaskLauncher(new Task("activating", true, true, false) {+ @Override+ public void run(TaskMonitor monitor) throws CancelledException {+ long startTime = System.nanoTime();++ // suppress RowObjectSelectionManager repairs until after we're done+ bundleStatusTable.chill();++ List<GhidraBundle> gbs =+ bundleStatusModel.getRowObjects(selectedModelRows).stream().filter(+ bs -> !bs.isActive()).map(+ bs -> bundleHost.getGhidraBundle(bs.getPath())).collect(+ Collectors.toList());+ int total = gbs.size();+ int total_activated = 0;++ monitor.setMaximum(gbs.size());+ while (!gbs.isEmpty()) {+ List<GhidraBundle> l = gbs.stream().filter(+ gb -> bundleHost.canResolveAll(gb.getAllReqs())).collect(+ Collectors.toList());+ if (l.isEmpty()) {+ console.getStdErr().printf("%d unresolvable bundles remain\n", gbs.size());+ return;+ }+ gbs.removeAll(l);++ for (GhidraBundle gb : l) {+ try {+ gb.build(console.getStdErr());+ bundleHost.activateSynchronously(gb.getBundleLoc());+ ++total_activated;+ }+ catch (Exception e) {+ e.printStackTrace(console.getStdErr());+ }+ monitor.incrementProgress(1);+ }+ }+ long endTime = System.nanoTime();+ console.getStdOut().printf("%d/%d bundles activated in %3.2f seconds.\n",+ total_activated, total, (endTime - startTime) / 1e9);++ bundleStatusTable.thaw();+ }+ }, getComponent(), 1000);+ }++ protected void startDeactivateSelectedTask() {+ ConsoleService console = getTool().getService(ConsoleService.class);+ int[] selectedModelRows = getSelectedModelRows();++ new TaskLauncher(new Task("deactivating", true, true, false) {+ @Override+ public void run(TaskMonitor monitor) throws CancelledException {+ long startTime = System.nanoTime();++ List<GhidraBundle> gbs =+ bundleStatusModel.getRowObjects(selectedModelRows).stream().filter(+ bs -> bs.isActive()).map(+ bs -> bundleHost.getGhidraBundle(bs.getPath())).collect(+ Collectors.toList());++ int total = gbs.size();+ int total_deactivated = 0;+ monitor.setMaximum(gbs.size());+ for (GhidraBundle gb : gbs) {+ try {+ bundleHost.deactivateSynchronously(gb.getBundleLoc());+ ++total_deactivated;+ }+ catch (GhidraBundleException | InterruptedException e) {+ e.printStackTrace(console.getStdErr());+ }+ monitor.incrementProgress(1);+ }+ long endTime = System.nanoTime();+ console.getStdOut().printf("%d/%d bundles deactivated in %3.2f seconds.\n",+ total_deactivated, total, (endTime - startTime) / 1e9);++ }+ }, getComponent(), 1000);}- private void startActivateDeactiveTask(BundleStatus status, boolean activate) {+ protected void startActivateDeactiveTask(BundleStatus status, boolean activate) {status.setBusy(true);- notifyTableChanged();+ notifyTableRowChanged(bundleStatusModel.getRowIndex(status));ConsoleService console = getTool().getService(ConsoleService.class);new TaskLauncher(new Task((activate ? "Activating" : "Deactivating ") + " bundle...") {@@ -359,20 +485,50 @@ public class BundleStatusProvider extends ComponentProviderAdapter {catch (Exception e) {e.printStackTrace(console.getStdErr());status.setActive(!activate);-- Msg.showError(this, getComponent(), "bundle activation failed", e.getMessage());+ String message = e.getMessage();+ if (message == null) {+ message = "<exception has no message>";+ }+ Msg.showError(this, getComponent(), "bundle activation failed", message);}finally {status.setBusy(false);- notifyTableChanged();+ notifyTableRowChanged(bundleStatusModel.getRowIndex(status));}}}, null, 1000);}- // XXX workaround for RowObjectSelection.. repair- void selectRow(int rowIndex) {- bundleStatusTable.selectRow(rowIndex);+ public BundleStatusModel getModel() {+ return bundleStatusModel;+ }++ public void notifyTableChanged() {+ bundleStatusTable.notifyTableChanged(new TableModelEvent(bundleStatusModel));+ }++ public void notifyTableRowChanged(int rowIndex) {+ bundleStatusTable.notifyTableChanged(new TableModelEvent(bundleStatusModel, rowIndex));+ }++ @Override+ public JComponent getComponent() {+ return panel;+ }++ /*+ @Override+ public ActionContext getActionContext(MouseEvent event) {+ return new ActionContext(this, bundleStatusTable.getSelectedRows(), bundleStatusTable);+ }+ */++ public void dispose() {+ bundleStatusTable.dispose();+ }++ void selectModelRow(int modelRowIndex) {+ bundleStatusTable.selectRow(filterPanel.getViewRow(modelRowIndex));}}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundle.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundle.javaindex 063beecbe9..3441c1cbda 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundle.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundle.java@@ -2,8 +2,10 @@ package ghidra.app.plugin.core.osgi;import java.io.File;import java.io.PrintWriter;+import java.util.List;import org.osgi.framework.Bundle;+import org.osgi.framework.wiring.BundleRequirement;import generic.jar.ResourceFile;@@ -13,7 +15,12 @@ public interface GhidraBundle {BndScript, Jar, SourceDir, INVALID}- void clean();+ /**+ * clean build artifacts generated during build of this bundle+ *+ * @return true if anything was done+ */+ boolean clean();/*** attempt to build loadable bundle, if possible@@ -60,4 +67,6 @@ public interface GhidraBundle {return GhidraBundle.Type.INVALID;}+ List<BundleRequirement> getAllReqs();+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraJarBundle.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraJarBundle.javanew file mode 100644index 0000000000..17022e2e82--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraJarBundle.java@@ -0,0 +1,74 @@+package ghidra.app.plugin.core.osgi;++import java.io.PrintWriter;+import java.util.Collections;+import java.util.List;+import java.util.jar.Manifest;++import org.osgi.framework.Bundle;+import org.osgi.framework.wiring.BundleRequirement;++import aQute.bnd.osgi.Constants;+import aQute.bnd.osgi.Jar;+import generic.jar.ResourceFile;++public class GhidraJarBundle implements GhidraBundle {+ final private BundleHost bundleHost;++ final String bundleLoc;+ final ResourceFile path;++ public GhidraJarBundle(BundleHost bundleHost, ResourceFile path) {+ this.bundleHost = bundleHost;+ this.path = path;+ this.bundleLoc = "file://" + path.getAbsolutePath().toString();+ }++ @Override+ public boolean clean() {+ return false;+ }++ @Override+ public boolean build(PrintWriter writer) throws Exception {+ return true;+ }++ @Override+ public String getBundleLoc() {+ return bundleLoc;+ }++ @Override+ public Bundle getBundle() throws GhidraBundleException {+ return bundleHost.getBundle(getBundleLoc());+ }++ @Override+ public Bundle install() throws GhidraBundleException {+ return bundleHost.installFromLoc(getBundleLoc());+ }++ @Override+ public String getSummary() {+ return null;+ }++ @Override+ public List<BundleRequirement> getAllReqs() {+ Jar jar;+ try {+ jar = new Jar(path.getFile(true));+ Manifest m = jar.getManifest();+ String imps = m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);+ if (imps != null) {+ return BundleHost.parseImports(imps);+ }+ return Collections.emptyList();+ }+ catch (Exception e) {+ throw new RuntimeException(e);+ }+ }++}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.javaindex 42aac70ee7..9e2c6d3c80 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java@@ -18,23 +18,33 @@ package ghidra.app.plugin.core.osgi;import static java.util.stream.Collectors.*;import java.io.*;-import java.nio.file.Files;-import java.nio.file.Path;+import java.nio.charset.Charset;+import java.nio.file.*;import java.util.*;import java.util.Map.Entry;import java.util.function.Predicate;+import java.util.jar.Attributes;+import java.util.jar.Manifest;import java.util.regex.Pattern;import java.util.stream.Collectors;+import java.util.stream.Stream;++import javax.tools.*;+import javax.tools.JavaFileObject.Kind;import org.osgi.framework.Bundle;import org.osgi.framework.BundleException;+import org.osgi.framework.Constants;import org.osgi.framework.wiring.BundleRequirement;+import org.osgi.framework.wiring.BundleWiring;+import org.phidias.compile.BundleJavaManager;+import aQute.bnd.osgi.*;+import aQute.bnd.osgi.Clazz.QUERY;import generic.io.NullPrintWriter;import generic.jar.ResourceFile;import ghidra.app.plugin.core.osgi.BundleHost.BuildFailure;-import ghidra.app.script.GhidraScriptUtil;-import ghidra.app.script.ScriptInfo;+import ghidra.app.script.*;import ghidra.util.Msg;/**@@ -55,6 +65,9 @@ public class GhidraSourceBundle implements GhidraBundle {final List<ResourceFile> newSources = new ArrayList<>();final List<Path> oldBin = new ArrayList<>();+ static final String GENERATED_ACTIVATOR_CLASSNAME = "GeneratedActivator";+ private JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();+//// information indexed by source filefinal HashMap<ResourceFile, BuildFailure> buildErrors = new HashMap<>();@@ -162,7 +175,7 @@ public class GhidraSourceBundle implements GhidraBundle {}}- List<BundleRequirement> getAllReqs() {+ private List<BundleRequirement> getComputedReqs() {Map<String, BundleRequirement> dedupedReqs = new HashMap<>();buildReqs.values().stream().flatMap(List::stream).forEach(r -> dedupedReqs.putIfAbsent(r.toString(), r));@@ -170,6 +183,17 @@ public class GhidraSourceBundle implements GhidraBundle {return new ArrayList<>(dedupedReqs.values());}+ @Override+ public List<BundleRequirement> getAllReqs() {+ try {+ updateRequirementsFromMetadata();+ }+ catch (GhidraBundleException e) {+ throw new RuntimeException(e);+ }+ return getComputedReqs();+ }+/*** look for new sources, metadata, manifest file.*@@ -272,17 +296,20 @@ public class GhidraSourceBundle implements GhidraBundle {smf.lastModified() > Files.getLastModifiedTime(dmf).toMillis());}- static private void wipe(Path path) throws IOException {+ static protected boolean wipeContents(Path path) throws IOException {if (Files.exists(path)) {+ boolean anythingDeleted = false;for (Path p : (Iterable<Path>) Files.walk(path).sorted(Comparator.reverseOrder())::iterator) {- Files.deleteIfExists(p);+ anythingDeleted |= Files.deleteIfExists(p);}+ return anythingDeleted;}+ return false;}- private void wipeBinDir() throws IOException {- wipe(binDir);+ private boolean wipeBinDir() throws IOException {+ return wipeContents(binDir);}@Override@@ -354,8 +381,8 @@ public class GhidraSourceBundle implements GhidraBundle {}if (needsCompile) {- writer.printf("%d new files, %d skipped, %s\n", newSourcecount, failing,- newManifest ? ", new manifest" : "");+ // XXX update status?+ // writer.printf("%d new files, %d skipped, %s\n", newSourcecount, failing, newManifest ? ", new manifest" : "");// if there a bundle is currently active, uninstall itBundle b = getBundle();@@ -366,12 +393,7 @@ public class GhidraSourceBundle implements GhidraBundle {// once we've committed to recompile and regenerate generated classes, delete the old stuffdeleteOldBinaries();- BundleCompiler bundleCompiler = new BundleCompiler(bundleHost);-- long startTime = System.nanoTime();- bundleCompiler.compileToExplodedBundle(this, writer);- long endTime = System.nanoTime();- writer.printf("%3.2f seconds compile time.\n", (endTime - startTime) / 1e9);+ compileToExplodedBundle(writer);bundleHost.fireBundleBuilt(this);return true;}@@ -389,18 +411,19 @@ public class GhidraSourceBundle implements GhidraBundle {}@Override- public void clean() {+ public boolean clean() {try {Bundle b = getBundle();if (b != null) {bundleHost.deactivateSynchronously(b);}- wipeBinDir();+ return wipeBinDir();}catch (IOException | GhidraBundleException | InterruptedException e) {Msg.showError(this, null, "source bundle clean error","while attempting to delete the compiled directory, an exception was thrown", e);}+ return false;}private static Predicate<String> bintail =@@ -415,6 +438,9 @@ public class GhidraSourceBundle implements GhidraBundle {String n0 = source.getName();final String n = n0.substring(0, n0.length() - 5);// trim .javaResourceFile bp = new ResourceFile(binDir.resolve(relpath).toFile());+ if (!bp.exists() || !bp.isDirectory()) {+ return new ResourceFile[] {};+ }return bp.listFiles(f -> {String nn = f.getName();return nn.startsWith(n) && bintail.test(nn.substring(n.length()));@@ -498,4 +524,244 @@ public class GhidraSourceBundle implements GhidraBundle {t.printStackTrace();}}++ /**+ * compile a source directory to an exploded bundle+ *+ * @param writer for updating the user during compilation+ * @throws IOException for source/manifest file reading/generation and binary deletion/creation+ * @throws OSGiException if generation of bundle metadata fails+ */+ private void compileToExplodedBundle(PrintWriter writer) throws IOException, OSGiException {++ compileAttempted();+ ResourceFile srcdir = getSourceDir();+ Path bindir = getBinDir();+ Files.createDirectories(bindir);++ List<String> options = new ArrayList<>();+ options.add("-g");+ options.add("-d");+ options.add(bindir.toString());+ options.add("-sourcepath");+ options.add(srcdir.toString());+ options.add("-classpath");+ options.add(System.getProperty("java.class.path") + File.pathSeparator + bindir.toString());+ options.add("-proc:none");++ final JavaFileManager rfm =+ new ResourceFileJavaFileManager(Collections.singletonList(getSourceDir()));++ BundleJavaManager bjm = new BundleJavaManager(bundleHost.getHostFramework(), rfm, options);+ // The phidias BundleJavaManager is for compiling from within a bundle -- it makes the+ // bundle dependencies available to the compiler classpath. Here, we are compiling in an as-yet+ // non-existing bundle, so we forge the wiring based on @imports metadata.++ // XXX skip this if there's a source manifest, emit warnings about @imports+ // get wires for currently active bundles to satisfy all requirements+ List<BundleRequirement> reqs = getAllReqs();+ List<BundleWiring> bundleWirings = bundleHost.resolve(reqs);++ if (!reqs.isEmpty()) {+ writer.printf("%d import requirement%s remain%s unresolved:\n", reqs.size(),+ reqs.size() > 1 ? "s" : "", reqs.size() > 1 ? "" : "s");+ for (BundleRequirement req : reqs) {+ writer.printf(" %s\n", req.toString());+ }++ setSummary(+ String.format("%d missing @import%s:%s", reqs.size(), reqs.size() > 1 ? "s" : "",+ reqs.stream().flatMap(+ r -> OSGiUtils.extractPackages(r.toString()).stream()).distinct().collect(+ Collectors.joining(","))));+ }+ else {+ setSummary("");+ }+ // send the capabilities to phidias+ bundleWirings.forEach(bjm::addBundleWiring);++ final List<ResourceFileJavaFileObject> sourceFiles = newSources.stream().map(+ sf -> new ResourceFileJavaFileObject(sf.getParentFile(), sf, Kind.SOURCE)).collect(+ Collectors.toList());++ Path dmf = bindir.resolve("META-INF").resolve("MANIFEST.MF");+ if (Files.exists(dmf)) {+ Files.delete(dmf);+ }++ // try to compile, if we fail, avoid offenders and try again+ while (!sourceFiles.isEmpty()) {+ DiagnosticCollector<JavaFileObject> diagnostics =+ new DiagnosticCollector<JavaFileObject>();+ JavaCompiler.CompilationTask task =+ compiler.getTask(writer, bjm, diagnostics, options, null, sourceFiles);+ // task.setProcessors // for annotation processing / code generation++ Boolean successfulCompilation = task.call();+ if (successfulCompilation) {+ break;+ }+ for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {+ String err = d.toString() + "\n";+ writer.write(err);+ ResourceFileJavaFileObject sf = (ResourceFileJavaFileObject) d.getSource();+ ResourceFile rf = sf.getFile();+ buildError(rf, err); // remember all errors for this file+ if (sourceFiles.remove(sf)) {+ writer.printf("skipping %s\n", sf.toString());+ }+ }+ }+ // mark the successful compilations+ for (ResourceFileJavaFileObject sf : sourceFiles) {+ ResourceFile rf = sf.getFile();+ buildSuccess(rf);+ }+ // buildErrors is now up to date, set status+ if (getFailingSourcesCount() > 0) {+ appendSummary(String.format("%d failing source files", getFailingSourcesCount()));+ }++ ResourceFile smf = new ResourceFile(srcdir, "META-INF" + File.separator + "MANIFEST.MF");+ if (smf.exists()) {+ System.err.printf("Found manifest, not generating one\n");+ Files.createFile(dmf);+ Files.copy(smf.getInputStream(), dmf, StandardCopyOption.REPLACE_EXISTING);+ return;+ }++ // no manifest, so create one with bndtools+ Analyzer analyzer = new Analyzer();+ analyzer.setJar(new Jar(bindir.toFile())); // give bnd the contents+ Stream<Object> bjars = Files.list(GhidraScriptUtil.getCompiledBundlesDir()).filter(+ f -> f.toString().endsWith(".jar")).map(f -> {+ try {+ return new Jar(f.toFile());+ }+ catch (IOException e1) {+ e1.printStackTrace(writer);+ return null;+ }+ });++ analyzer.addClasspath(bjars.collect(Collectors.toUnmodifiableList()));+ analyzer.setProperty("Bundle-SymbolicName",+ BundleHost.getSymbolicNameFromSourceDir(srcdir));+ analyzer.setProperty("Bundle-Version", "1.0");+ analyzer.setProperty("Import-Package", "*");+ analyzer.setProperty("Export-Package", "!*.private.*,!*.internal.*,*");+ // analyzer.setBundleActivator(s);++ try {+ Manifest manifest;+ try {+ manifest = analyzer.calcManifest();+ }+ catch (Exception e) {+ appendSummary("bad manifest");+ throw new OSGiException("failed to calculate manifest by analyzing code", e);+ }+ Attributes ma = manifest.getMainAttributes();++ String activator_classname = null;+ try {+ for (Clazz clazz : analyzer.getClassspace().values()) {+ if (clazz.is(QUERY.IMPLEMENTS,+ new Instruction("org.osgi.framework.BundleActivator"), analyzer)) {+ System.err.printf("found BundleActivator class %s\n", clazz);+ activator_classname = clazz.toString();+ }+ }+ }+ catch (Exception e) {+ appendSummary("failed bnd analysis");+ throw new OSGiException("failed to query classes while searching for activator", e);+ }+ if (activator_classname == null) {+ activator_classname = GENERATED_ACTIVATOR_CLASSNAME;+ if (!buildDefaultActivator(bindir, activator_classname, writer)) {+ appendSummary("failed to build generated activator");+ return;+ }+ // since we add the activator after bndtools built the imports, we should add its imports too+ String imps = ma.getValue(Constants.IMPORT_PACKAGE);+ if (imps == null) {+ ma.putValue(Constants.IMPORT_PACKAGE,+ GhidraBundleActivator.class.getPackageName());+ }+ else {+ ma.putValue(Constants.IMPORT_PACKAGE,+ imps + "," + GhidraBundleActivator.class.getPackageName());+ }+ }+ ma.putValue(Constants.BUNDLE_ACTIVATOR, activator_classname);++ // write the manifest+ Files.createDirectories(dmf.getParent());+ try (OutputStream out = Files.newOutputStream(dmf)) {+ manifest.write(out);+ }+ }+ finally {+ analyzer.close();+ }+ }++ /**+ * create and compile a default bundle activator+ *+ * @param bindir destination for class file+ * @param activator_classname the name to use for the genearted activator class+ * @param writer for writing compile errors+ * @return true if compilation succeeded+ * @throws IOException for failed write of source/binary activator+ */+ private boolean buildDefaultActivator(Path bindir, String activator_classname, Writer writer)+ throws IOException {+ Path activator_dest = bindir.resolve(activator_classname + ".java");++ try (PrintWriter out =+ new PrintWriter(Files.newBufferedWriter(activator_dest, Charset.forName("UTF-8")))) {+ out.println("import " + GhidraBundleActivator.class.getName() + ";");+ out.println("import org.osgi.framework.BundleActivator;");+ out.println("import org.osgi.framework.BundleContext;");+ out.println("public class " + GENERATED_ACTIVATOR_CLASSNAME ++ " extends GhidraBundleActivator {");+ out.println(" protected void start(BundleContext bc, Object api) {");+ out.println(" // TODO: stuff to do on bundle start");+ out.println(" }");+ out.println(" protected void stop(BundleContext bc, Object api) {");+ out.println(" // TODO: stuff to do on bundle stop");+ out.println(" }");+ out.println();+ out.println("}");+ }++ List<String> options = new ArrayList<>();+ options.add("-g");+ options.add("-d");+ options.add(bindir.toString());+ options.add("-sourcepath");+ options.add(bindir.toString());+ options.add("-classpath");+ options.add(System.getProperty("java.class.path"));+ options.add("-proc:none");++ StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);+ BundleJavaManager bjm = new BundleJavaManager(bundleHost.getHostFramework(), fm, options);+ Iterable<? extends JavaFileObject> sourceFiles =+ fm.getJavaFileObjectsFromPaths(List.of(activator_dest));+ DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();+ JavaCompiler.CompilationTask task =+ compiler.getTask(writer, bjm, diagnostics, options, null, sourceFiles);+ if (!task.call()) {+ for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {+ writer.write(d.getSource().toString() + ": " + d.getMessage(null) + "\n");+ }+ return false;+ }+ return true;+ }+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/LessFreneticGTable.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/LessFreneticGTable.javanew file mode 100644index 0000000000..a95ab279a8--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/LessFreneticGTable.java@@ -0,0 +1,49 @@+package ghidra.app.plugin.core.osgi;++import javax.swing.JTable;+import javax.swing.event.TableModelEvent;+import javax.swing.table.TableModel;++import docking.widgets.table.*;++/**+ * RowObjectSelectionManager attempts to repair selections in a filtered table+ * before and after filter events. The additiona selection events, however, cause focus changes we don't want.+ */+class LessFreneticGTable extends GTable {+ boolean chilled = false;++ private class MySelectionManager<T> extends RowObjectSelectionManager<T> {++ MySelectionManager(JTable table, RowObjectTableModel<T> model) {+ super(table, model);+ }++ @Override+ public void tableChanged(TableModelEvent e) {+ if (!chilled) {+ super.tableChanged(e);+ }+ }++ }++ public void chill() {+ chilled = true;+ }++ public void thaw() {+ chilled = false;+ notifyTableChanged(new TableModelEvent(getModel()));+ }++ LessFreneticGTable(TableModel dm) {+ super(dm);+ }++ @SuppressWarnings("unchecked")+ @Override+ protected <T> SelectionManager createSelectionManager(TableModel model) {+ return new MySelectionManager<T>(this, (RowObjectTableModel<T>) model);+ }+}\ No newline at end of file