mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
rename variables, move bundlehost instance, clean dead fileinstaller code
This commit is contained in:
parent
2e05da019f
commit
ad897f263c
10 changed files with 80 additions and 122 deletions
|
@ -1,7 +1,6 @@
|
||||||
MODULE FILE LICENSE: lib/biz.aQute.bndlib-5.0.0.jar Apache License 2.0
|
MODULE FILE LICENSE: lib/biz.aQute.bndlib-5.0.0.jar Apache License 2.0
|
||||||
MODULE FILE LICENSE: lib/slf4j-api-1.7.25.jar MIT
|
MODULE FILE LICENSE: lib/slf4j-api-1.7.25.jar MIT
|
||||||
MODULE FILE LICENSE: lib/org.apache.felix.main-6.0.3.jar Apache License 2.0
|
MODULE FILE LICENSE: lib/org.apache.felix.main-6.0.3.jar Apache License 2.0
|
||||||
MODULE FILE LICENSE: lib/org.apache.felix.fileinstall-3.6.4.jar Apache License 2.0
|
|
||||||
MODULE FILE LICENSE: lib/org.apache.felix.framework-6.0.3.jar Apache License 2.0
|
MODULE FILE LICENSE: lib/org.apache.felix.framework-6.0.3.jar Apache License 2.0
|
||||||
MODULE FILE LICENSE: lib/animal-sniffer-annotations-1.9.jar MIT
|
MODULE FILE LICENSE: lib/animal-sniffer-annotations-1.9.jar MIT
|
||||||
MODULE FILE LICENSE: lib/org.osgi.core-5.0.0.jar Apache License 2.0
|
MODULE FILE LICENSE: lib/org.osgi.core-5.0.0.jar Apache License 2.0
|
||||||
|
|
|
@ -28,7 +28,6 @@ dependencies {
|
||||||
|
|
||||||
compile 'org.apache.felix:org.apache.felix.framework:6.0.3'
|
compile 'org.apache.felix:org.apache.felix.framework:6.0.3'
|
||||||
compile 'org.apache.felix:org.apache.felix.main:6.0.3'
|
compile 'org.apache.felix:org.apache.felix.main:6.0.3'
|
||||||
compile 'org.apache.felix:org.apache.felix.fileinstall:3.6.4'
|
|
||||||
compile 'com.github.rotty3000:phidias:0.3.7'
|
compile 'com.github.rotty3000:phidias:0.3.7'
|
||||||
compile 'biz.aQute.bnd:biz.aQute.bndlib:5.0.0'
|
compile 'biz.aQute.bnd:biz.aQute.bndlib:5.0.0'
|
||||||
compile 'org.slf4j:slf4j-api:1.7.25'
|
compile 'org.slf4j:slf4j-api:1.7.25'
|
||||||
|
|
|
@ -42,6 +42,7 @@ import generic.jar.ResourceFile;
|
||||||
import generic.util.Path;
|
import generic.util.Path;
|
||||||
import ghidra.app.plugin.core.script.osgi.*;
|
import ghidra.app.plugin.core.script.osgi.*;
|
||||||
import ghidra.app.script.*;
|
import ghidra.app.script.*;
|
||||||
|
import ghidra.app.script.osgi.BundleHost;
|
||||||
import ghidra.app.services.ConsoleService;
|
import ghidra.app.services.ConsoleService;
|
||||||
import ghidra.framework.options.SaveState;
|
import ghidra.framework.options.SaveState;
|
||||||
import ghidra.framework.plugintool.ComponentProviderAdapter;
|
import ghidra.framework.plugintool.ComponentProviderAdapter;
|
||||||
|
@ -71,7 +72,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
|
||||||
private GTree scriptCategoryTree;
|
private GTree scriptCategoryTree;
|
||||||
private DraggableScriptTable scriptTable;
|
private DraggableScriptTable scriptTable;
|
||||||
private GhidraScriptTableModel tableModel;
|
private GhidraScriptTableModel tableModel;
|
||||||
private BundleStatusProvider bundlePathManager;
|
private BundleStatusProvider bundleStatusProvider;
|
||||||
private TaskListener taskListener = new ScriptTaskListener();
|
private TaskListener taskListener = new ScriptTaskListener();
|
||||||
private GhidraScriptActionManager actionManager;
|
private GhidraScriptActionManager actionManager;
|
||||||
private GhidraTableFilterPanel<ResourceFile> tableFilterPanel;
|
private GhidraTableFilterPanel<ResourceFile> tableFilterPanel;
|
||||||
|
@ -119,7 +120,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
|
||||||
scriptTable.dispose();
|
scriptTable.dispose();
|
||||||
tableFilterPanel.dispose();
|
tableFilterPanel.dispose();
|
||||||
actionManager.dispose();
|
actionManager.dispose();
|
||||||
bundlePathManager.dispose();
|
bundleStatusProvider.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
GhidraScriptActionManager getActionManager() {
|
GhidraScriptActionManager getActionManager() {
|
||||||
|
@ -131,11 +132,11 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
void showBundleStatusDialog() {
|
void showBundleStatusDialog() {
|
||||||
bundlePathManager.setVisible(true);
|
bundleStatusProvider.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performRefresh() {
|
private void performRefresh() {
|
||||||
GhidraScriptUtil.setScriptDirectories(bundlePathManager.getPaths());
|
GhidraScriptUtil.setScriptDirectories(bundleStatusProvider.getPaths());
|
||||||
GhidraScriptUtil.clearMetadata();
|
GhidraScriptUtil.clearMetadata();
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
@ -340,12 +341,12 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BundlePath> getScriptDirectories() {
|
public List<BundlePath> getScriptDirectories() {
|
||||||
return bundlePathManager.getPaths().stream().filter(BundlePath::isDirectory).collect(
|
return bundleStatusProvider.getPaths().stream().filter(BundlePath::isDirectory).collect(
|
||||||
Collectors.toList());
|
Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableScriptDirectory(ResourceFile scriptDir) {
|
public void enableScriptDirectory(ResourceFile scriptDir) {
|
||||||
if (bundlePathManager.enablePath(scriptDir)) {
|
if (bundleStatusProvider.enablePath(scriptDir)) {
|
||||||
Msg.showInfo(this, getComponent(), "Script Path Added/Enabled",
|
Msg.showInfo(this, getComponent(), "Script Path Added/Enabled",
|
||||||
"The directory has been automatically enabled for use:\n" +
|
"The directory has been automatically enabled for use:\n" +
|
||||||
scriptDir.getAbsolutePath());
|
scriptDir.getAbsolutePath());
|
||||||
|
@ -396,7 +397,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
void runScript(String scriptName, TaskListener listener) {
|
void runScript(String scriptName, TaskListener listener) {
|
||||||
List<BundlePath> dirPaths = bundlePathManager.getPaths();
|
List<BundlePath> dirPaths = bundleStatusProvider.getPaths();
|
||||||
for (Path dir : dirPaths) {
|
for (Path dir : dirPaths) {
|
||||||
ResourceFile scriptSource = new ResourceFile(dir.getPath(), scriptName);
|
ResourceFile scriptSource = new ResourceFile(dir.getPath(), scriptName);
|
||||||
if (scriptSource.exists()) {
|
if (scriptSource.exists()) {
|
||||||
|
@ -536,7 +537,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
|
||||||
private void updateAvailableScriptFilesForAllPaths() {
|
private void updateAvailableScriptFilesForAllPaths() {
|
||||||
List<ResourceFile> scriptsToRemove = tableModel.getScripts();
|
List<ResourceFile> scriptsToRemove = tableModel.getScripts();
|
||||||
List<ResourceFile> scriptAccumulator = new ArrayList<>();
|
List<ResourceFile> scriptAccumulator = new ArrayList<>();
|
||||||
List<BundlePath> bundlePaths = bundlePathManager.getPaths();
|
List<BundlePath> bundlePaths = bundleStatusProvider.getPaths();
|
||||||
for (BundlePath bundlePath : bundlePaths) {
|
for (BundlePath bundlePath : bundlePaths) {
|
||||||
if (bundlePath.isDirectory()) {
|
if (bundlePath.isDirectory()) {
|
||||||
updateAvailableScriptFilesForDirectory(scriptsToRemove, scriptAccumulator,
|
updateAvailableScriptFilesForDirectory(scriptsToRemove, scriptAccumulator,
|
||||||
|
@ -732,12 +733,13 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void build() {
|
private void build() {
|
||||||
bundlePathManager =
|
|
||||||
new BundleStatusProvider(plugin.getTool(), plugin.getName());
|
bundleStatusProvider =
|
||||||
bundlePathManager.setFileChooserProperties("Select Script Bundle",
|
new BundleStatusProvider(plugin.getTool(), plugin.getName(), BundleHost.getInstance());
|
||||||
|
bundleStatusProvider.setFileChooserProperties("Select Script Bundle",
|
||||||
"LastGhidraScriptBundle");
|
"LastGhidraScriptBundle");
|
||||||
|
|
||||||
bundlePathManager.addListener(new BundlePathManagerListener() {
|
bundleStatusProvider.addListener(new BundlePathManagerListener() {
|
||||||
@Override
|
@Override
|
||||||
public void bundlesChanged() {
|
public void bundlesChanged() {
|
||||||
plugin.getTool().setConfigChanged(true);
|
plugin.getTool().setConfigChanged(true);
|
||||||
|
@ -1010,10 +1012,10 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readConfigState(SaveState saveState) {
|
public void readConfigState(SaveState saveState) {
|
||||||
bundlePathManager.restoreState(saveState);
|
bundleStatusProvider.restoreState(saveState);
|
||||||
|
|
||||||
// pull in the just-loaded paths
|
// pull in the just-loaded paths
|
||||||
List<BundlePath> paths = bundlePathManager.getPaths();
|
List<BundlePath> paths = bundleStatusProvider.getPaths();
|
||||||
GhidraScriptUtil.setScriptDirectories(paths);
|
GhidraScriptUtil.setScriptDirectories(paths);
|
||||||
actionManager.restoreUserDefinedKeybindings(saveState);
|
actionManager.restoreUserDefinedKeybindings(saveState);
|
||||||
actionManager.restoreScriptsThatAreInTool(saveState);
|
actionManager.restoreScriptsThatAreInTool(saveState);
|
||||||
|
@ -1037,7 +1039,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeConfigState(SaveState saveState) {
|
public void writeConfigState(SaveState saveState) {
|
||||||
bundlePathManager.saveState(saveState);
|
bundleStatusProvider.saveState(saveState);
|
||||||
actionManager.saveUserDefinedKeybindings(saveState);
|
actionManager.saveUserDefinedKeybindings(saveState);
|
||||||
actionManager.saveScriptsThatAreInTool(saveState);
|
actionManager.saveScriptsThatAreInTool(saveState);
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,6 @@ import ghidra.app.plugin.ProgramPlugin;
|
||||||
import ghidra.app.plugin.core.eclipse.EclipseConnection;
|
import ghidra.app.plugin.core.eclipse.EclipseConnection;
|
||||||
import ghidra.app.plugin.core.eclipse.EclipseIntegrationOptionsPlugin;
|
import ghidra.app.plugin.core.eclipse.EclipseIntegrationOptionsPlugin;
|
||||||
import ghidra.app.script.GhidraState;
|
import ghidra.app.script.GhidraState;
|
||||||
import ghidra.app.script.osgi.BundleHost;
|
|
||||||
import ghidra.app.script.osgi.OSGiException;
|
|
||||||
import ghidra.app.services.*;
|
import ghidra.app.services.*;
|
||||||
import ghidra.framework.options.SaveState;
|
import ghidra.framework.options.SaveState;
|
||||||
import ghidra.framework.options.ToolOptions;
|
import ghidra.framework.options.ToolOptions;
|
||||||
|
@ -50,22 +48,6 @@ import ghidra.util.task.TaskListener;
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
public class GhidraScriptMgrPlugin extends ProgramPlugin implements GhidraScriptService {
|
public class GhidraScriptMgrPlugin extends ProgramPlugin implements GhidraScriptService {
|
||||||
|
|
||||||
// XXX embedded OSGi should be a service, but ScriptProviders don't have any way to access services
|
|
||||||
static private BundleHost _bundle_host;
|
|
||||||
|
|
||||||
static public BundleHost getBundleHost() {
|
|
||||||
if (_bundle_host == null) {
|
|
||||||
_bundle_host = new BundleHost();
|
|
||||||
try {
|
|
||||||
_bundle_host.startFelix();
|
|
||||||
}
|
|
||||||
catch (OSGiException | IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _bundle_host;
|
|
||||||
}
|
|
||||||
|
|
||||||
private GhidraScriptComponentProvider provider;
|
private GhidraScriptComponentProvider provider;
|
||||||
|
|
||||||
public GhidraScriptMgrPlugin(PluginTool tool) {
|
public GhidraScriptMgrPlugin(PluginTool tool) {
|
||||||
|
|
|
@ -108,14 +108,13 @@ class BundleStatusModel extends AbstractSortedTableModel<BundlePath> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BundleStatusProvider mgr;
|
private BundleStatusProvider provider;
|
||||||
private List<BundlePath> paths = new ArrayList<>();
|
private List<BundlePath> paths = new ArrayList<>();
|
||||||
|
|
||||||
BundleStatusModel(BundleStatusProvider mgr) {
|
BundleStatusModel(BundleStatusProvider provider) {
|
||||||
super();
|
super();
|
||||||
this.mgr = mgr;
|
this.provider = provider;
|
||||||
List<BundlePath> paths=GhidraScriptUtil.getDefaultScriptBundles();
|
this.paths.addAll(dedupPaths(GhidraScriptUtil.getDefaultScriptBundles()));
|
||||||
this.paths.addAll(dedupPaths(paths));
|
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +175,7 @@ class BundleStatusModel extends AbstractSortedTableModel<BundlePath> {
|
||||||
paths.remove(path);
|
paths.remove(path);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
List<BundlePathManagerListener> listeners = mgr.getListeners();
|
List<BundlePathManagerListener> listeners = provider.getListeners();
|
||||||
for (BundlePathManagerListener listener : listeners) {
|
for (BundlePathManagerListener listener : listeners) {
|
||||||
listener.pathMessage("Unable to remove path.");
|
listener.pathMessage("Unable to remove path.");
|
||||||
}
|
}
|
||||||
|
@ -194,7 +193,7 @@ class BundleStatusModel extends AbstractSortedTableModel<BundlePath> {
|
||||||
paths.remove(path);
|
paths.remove(path);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
List<BundlePathManagerListener> listeners = mgr.getListeners();
|
List<BundlePathManagerListener> listeners = provider.getListeners();
|
||||||
for (BundlePathManagerListener listener : listeners) {
|
for (BundlePathManagerListener listener : listeners) {
|
||||||
listener.pathMessage("Unable to remove path.");
|
listener.pathMessage("Unable to remove path.");
|
||||||
}
|
}
|
||||||
|
@ -267,7 +266,7 @@ class BundleStatusModel extends AbstractSortedTableModel<BundlePath> {
|
||||||
BundlePath path = paths.get(rowIndex);
|
BundlePath path = paths.get(rowIndex);
|
||||||
COLUMN.val(columnIndex).setValue(path, aValue);
|
COLUMN.val(columnIndex).setValue(path, aValue);
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
mgr.fireBundlePathChanged(path);
|
provider.fireBundlePathChanged(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,6 +29,7 @@ import docking.widgets.filechooser.GhidraFileChooser;
|
||||||
import docking.widgets.filechooser.GhidraFileChooserMode;
|
import docking.widgets.filechooser.GhidraFileChooserMode;
|
||||||
import docking.widgets.table.*;
|
import docking.widgets.table.*;
|
||||||
import generic.jar.ResourceFile;
|
import generic.jar.ResourceFile;
|
||||||
|
import ghidra.app.script.osgi.BundleHost;
|
||||||
import ghidra.framework.options.SaveState;
|
import ghidra.framework.options.SaveState;
|
||||||
import ghidra.framework.plugintool.ComponentProviderAdapter;
|
import ghidra.framework.plugintool.ComponentProviderAdapter;
|
||||||
import ghidra.framework.plugintool.PluginTool;
|
import ghidra.framework.plugintool.PluginTool;
|
||||||
|
@ -43,7 +44,7 @@ import resources.ResourceManager;
|
||||||
public class BundleStatusProvider extends ComponentProviderAdapter {
|
public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
private JPanel panel;
|
private JPanel panel;
|
||||||
private GTable bundlePathTable;
|
private GTable bundlePathTable;
|
||||||
private BundleStatusModel bundlePathModel;
|
private BundleStatusModel bundleStatusModel;
|
||||||
private TableModelListener bundlePathModelListener;
|
private TableModelListener bundlePathModelListener;
|
||||||
private JButton addButton;
|
private JButton addButton;
|
||||||
private JButton removeButton;
|
private JButton removeButton;
|
||||||
|
@ -54,8 +55,11 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
private GhidraFileFilter filter;
|
private GhidraFileFilter filter;
|
||||||
private ArrayList<BundlePathManagerListener> listeners = new ArrayList<>();
|
private ArrayList<BundlePathManagerListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
public BundleStatusProvider(PluginTool tool, String owner) {
|
private BundleHost bundleHost;
|
||||||
|
|
||||||
|
public BundleStatusProvider(PluginTool tool, String owner, BundleHost bundleHost) {
|
||||||
super(tool, "Bundle Status Manager", "my owner");
|
super(tool, "Bundle Status Manager", "my owner");
|
||||||
|
this.bundleHost = bundleHost;
|
||||||
build();
|
build();
|
||||||
addToTool();
|
addToTool();
|
||||||
}
|
}
|
||||||
|
@ -89,7 +93,7 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
* @return enabled paths
|
* @return enabled paths
|
||||||
*/
|
*/
|
||||||
public List<BundlePath> getPaths() {
|
public List<BundlePath> getPaths() {
|
||||||
return bundlePathModel.getPaths();
|
return bundleStatusModel.getPaths();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,11 +103,11 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
*/
|
*/
|
||||||
public boolean enablePath(ResourceFile file) {
|
public boolean enablePath(ResourceFile file) {
|
||||||
ResourceFile dir = file.isDirectory() ? file : file.getParentFile();
|
ResourceFile dir = file.isDirectory() ? file : file.getParentFile();
|
||||||
for (BundlePath path : bundlePathModel.getAllPaths()) {
|
for (BundlePath path : bundleStatusModel.getAllPaths()) {
|
||||||
if (path.getPath().equals(dir)) {
|
if (path.getPath().equals(dir)) {
|
||||||
if (!path.isEnabled()) {
|
if (!path.isEnabled()) {
|
||||||
path.setEnabled(true);
|
path.setEnabled(true);
|
||||||
bundlePathModel.fireTableDataChanged();
|
bundleStatusModel.fireTableDataChanged();
|
||||||
fireBundlesChanged();
|
fireBundlesChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -112,21 +116,21 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
}
|
}
|
||||||
BundlePath p = new BundlePath(dir);
|
BundlePath p = new BundlePath(dir);
|
||||||
p.setEnabled(true);
|
p.setEnabled(true);
|
||||||
bundlePathModel.addPath(p);
|
bundleStatusModel.addPath(p);
|
||||||
Preferences.setProperty(preferenceForLastSelectedBundle, dir.getAbsolutePath());
|
Preferences.setProperty(preferenceForLastSelectedBundle, dir.getAbsolutePath());
|
||||||
fireBundlesChanged();
|
fireBundlesChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPaths(List<BundlePath> paths) {
|
public void setPaths(List<BundlePath> paths) {
|
||||||
bundlePathModel.setPaths(paths);
|
bundleStatusModel.setPaths(paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the paths in the table.
|
* Clear the paths in the table.
|
||||||
*/
|
*/
|
||||||
public void clear() {
|
public void clear() {
|
||||||
bundlePathModel.clear();
|
bundleStatusModel.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(BundlePathManagerListener listener) {
|
public void addListener(BundlePathManagerListener listener) {
|
||||||
|
@ -187,10 +191,10 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
fireBundlesChanged();
|
fireBundlesChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
bundlePathModel = new BundleStatusModel(this);
|
bundleStatusModel = new BundleStatusModel(this);
|
||||||
bundlePathModel.addTableModelListener(bundlePathModelListener);
|
bundleStatusModel.addTableModelListener(bundlePathModelListener);
|
||||||
|
|
||||||
bundlePathTable = new GTable(bundlePathModel);
|
bundlePathTable = new GTable(bundleStatusModel);
|
||||||
bundlePathTable.setName("BUNDLEPATH_TABLE");
|
bundlePathTable.setName("BUNDLEPATH_TABLE");
|
||||||
bundlePathTable.setSelectionBackground(selectionColor);
|
bundlePathTable.setSelectionBackground(selectionColor);
|
||||||
bundlePathTable.setSelectionForeground(Color.BLACK);
|
bundlePathTable.setSelectionForeground(Color.BLACK);
|
||||||
|
@ -205,22 +209,19 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
column.setMaxWidth(skinnyWidth);
|
column.setMaxWidth(skinnyWidth);
|
||||||
column.setWidth(skinnyWidth);
|
column.setWidth(skinnyWidth);
|
||||||
|
|
||||||
column =
|
column = bundlePathTable.getColumnModel().getColumn(BundleStatusModel.COLUMN.Active.index);
|
||||||
bundlePathTable.getColumnModel().getColumn(BundleStatusModel.COLUMN.Active.index);
|
|
||||||
column.setPreferredWidth(skinnyWidth);
|
column.setPreferredWidth(skinnyWidth);
|
||||||
column.setMinWidth(skinnyWidth);
|
column.setMinWidth(skinnyWidth);
|
||||||
column.setMaxWidth(skinnyWidth);
|
column.setMaxWidth(skinnyWidth);
|
||||||
column.setWidth(skinnyWidth);
|
column.setWidth(skinnyWidth);
|
||||||
|
|
||||||
column =
|
column = bundlePathTable.getColumnModel().getColumn(BundleStatusModel.COLUMN.Type.index);
|
||||||
bundlePathTable.getColumnModel().getColumn(BundleStatusModel.COLUMN.Type.index);
|
|
||||||
|
|
||||||
FontMetrics fontmetrics = panel.getFontMetrics(panel.getFont());
|
FontMetrics fontmetrics = panel.getFontMetrics(panel.getFont());
|
||||||
column.setMaxWidth(10 +
|
column.setMaxWidth(10 +
|
||||||
SwingUtilities.computeStringWidth(fontmetrics, BundlePath.Type.SourceDir.toString()));
|
SwingUtilities.computeStringWidth(fontmetrics, BundlePath.Type.SourceDir.toString()));
|
||||||
|
|
||||||
column =
|
column = bundlePathTable.getColumnModel().getColumn(BundleStatusModel.COLUMN.Path.index);
|
||||||
bundlePathTable.getColumnModel().getColumn(BundleStatusModel.COLUMN.Path.index);
|
|
||||||
column.setCellRenderer(new GTableCellRenderer() {
|
column.setCellRenderer(new GTableCellRenderer() {
|
||||||
@Override
|
@Override
|
||||||
public Component getTableCellRendererComponent(GTableCellRenderingData data) {
|
public Component getTableCellRendererComponent(GTableCellRenderingData data) {
|
||||||
|
@ -235,7 +236,7 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
});
|
});
|
||||||
|
|
||||||
GTableFilterPanel<BundlePath> filterPanel =
|
GTableFilterPanel<BundlePath> filterPanel =
|
||||||
new GTableFilterPanel<>(bundlePathTable, bundlePathModel);
|
new GTableFilterPanel<>(bundlePathTable, bundleStatusModel);
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane(bundlePathTable);
|
JScrollPane scrollPane = new JScrollPane(bundlePathTable);
|
||||||
scrollPane.getViewport().setBackground(bundlePathTable.getBackground());
|
scrollPane.getViewport().setBackground(bundlePathTable.getBackground());
|
||||||
|
@ -267,12 +268,12 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
if (selectedRows == null) {
|
if (selectedRows == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bundlePathModel.remove(selectedRows);
|
bundleStatusModel.remove(selectedRows);
|
||||||
|
|
||||||
// select the next row based on what was selected
|
// select the next row based on what was selected
|
||||||
Arrays.sort(selectedRows);
|
Arrays.sort(selectedRows);
|
||||||
int row = selectedRows[selectedRows.length - 1] + 1 - selectedRows.length;
|
int row = selectedRows[selectedRows.length - 1] + 1 - selectedRows.length;
|
||||||
int count = bundlePathModel.getRowCount();
|
int count = bundleStatusModel.getRowCount();
|
||||||
if (row >= count) {
|
if (row >= count) {
|
||||||
row = count - 1;
|
row = count - 1;
|
||||||
}
|
}
|
||||||
|
@ -323,7 +324,7 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
files.get(0).getAbsolutePath());
|
files.get(0).getAbsolutePath());
|
||||||
for (File element : files) {
|
for (File element : files) {
|
||||||
BundlePath p = new BundlePath(element);
|
BundlePath p = new BundlePath(element);
|
||||||
bundlePathModel.addPath(p);
|
bundleStatusModel.addPath(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,7 +343,7 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
* @param ss the SaveState object
|
* @param ss the SaveState object
|
||||||
*/
|
*/
|
||||||
public void saveState(SaveState ss) {
|
public void saveState(SaveState ss) {
|
||||||
List<BundlePath> paths = bundlePathModel.getAllPaths();
|
List<BundlePath> paths = bundleStatusModel.getAllPaths();
|
||||||
|
|
||||||
String[] pathArr = new String[paths.size()];
|
String[] pathArr = new String[paths.size()];
|
||||||
boolean[] enableArr = new boolean[paths.size()];
|
boolean[] enableArr = new boolean[paths.size()];
|
||||||
|
@ -379,15 +380,15 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
* Temporarily remove the listener to prevent too many
|
* Temporarily remove the listener to prevent too many
|
||||||
* notifications from being sent.
|
* notifications from being sent.
|
||||||
*/
|
*/
|
||||||
bundlePathModel.removeTableModelListener(bundlePathModelListener);
|
bundleStatusModel.removeTableModelListener(bundlePathModelListener);
|
||||||
|
|
||||||
boolean[] enableArr =
|
boolean[] enableArr =
|
||||||
ss.getBooleans("BundleManagerPanel_ENABLE", new boolean[pathArr.length]);
|
ss.getBooleans("BundleManagerPanel_ENABLE", new boolean[pathArr.length]);
|
||||||
boolean[] editArr = ss.getBooleans("BundleManagerPanel_EDIT", new boolean[pathArr.length]);
|
boolean[] editArr = ss.getBooleans("BundleManagerPanel_EDIT", new boolean[pathArr.length]);
|
||||||
boolean[] readArr = ss.getBooleans("BundleManagerPanel_READ", new boolean[pathArr.length]);
|
boolean[] readArr = ss.getBooleans("BundleManagerPanel_READ", new boolean[pathArr.length]);
|
||||||
|
|
||||||
List<BundlePath> oldPaths = bundlePathModel.getAllPaths();
|
List<BundlePath> oldPaths = bundleStatusModel.getAllPaths();
|
||||||
bundlePathModel.clear();
|
bundleStatusModel.clear();
|
||||||
|
|
||||||
for (int i = 0; i < pathArr.length; i++) {
|
for (int i = 0; i < pathArr.length; i++) {
|
||||||
BundlePath path = new BundlePath(pathArr[i], enableArr[i], editArr[i], readArr[i]);
|
BundlePath path = new BundlePath(pathArr[i], enableArr[i], editArr[i], readArr[i]);
|
||||||
|
@ -405,19 +406,19 @@ public class BundleStatusProvider extends ComponentProviderAdapter {
|
||||||
// This is needed to thin-out old default entries
|
// This is needed to thin-out old default entries
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
bundlePathModel.addPath(path);
|
bundleStatusModel.addPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (BundlePath path : oldPaths) {
|
for (BundlePath path : oldPaths) {
|
||||||
if (!path.isEditable()) {
|
if (!path.isEditable()) {
|
||||||
bundlePathModel.addPath(path);
|
bundleStatusModel.addPath(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reinstall the listener then fire the update.
|
* Reinstall the listener then fire the update.
|
||||||
*/
|
*/
|
||||||
bundlePathModel.addTableModelListener(bundlePathModelListener);
|
bundleStatusModel.addTableModelListener(bundlePathModelListener);
|
||||||
fireBundlesChanged();
|
fireBundlesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.osgi.framework.Bundle;
|
||||||
|
|
||||||
import generic.io.NullPrintWriter;
|
import generic.io.NullPrintWriter;
|
||||||
import generic.jar.ResourceFile;
|
import generic.jar.ResourceFile;
|
||||||
import ghidra.app.plugin.core.script.GhidraScriptMgrPlugin;
|
|
||||||
import ghidra.app.script.osgi.*;
|
import ghidra.app.script.osgi.*;
|
||||||
import ghidra.util.Msg;
|
import ghidra.util.Msg;
|
||||||
|
|
||||||
|
@ -32,7 +31,7 @@ public class JavaScriptProvider extends GhidraScriptProvider {
|
||||||
if (sourceDir == null) {
|
if (sourceDir == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return GhidraScriptMgrPlugin.getBundleHost().getSourceBundleInfo(sourceDir);
|
return BundleHost.getInstance().getSourceBundleInfo(sourceDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,7 +49,7 @@ public class JavaScriptProvider extends GhidraScriptProvider {
|
||||||
Bundle b = getBundleInfoForSource(sourceFile).getBundle();
|
Bundle b = getBundleInfoForSource(sourceFile).getBundle();
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
try {
|
try {
|
||||||
GhidraScriptMgrPlugin.getBundleHost().synchronousUninstall(b);
|
BundleHost.getInstance().synchronousUninstall(b);
|
||||||
}
|
}
|
||||||
catch (GhidraBundleException | InterruptedException e) {
|
catch (GhidraBundleException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -127,7 +126,7 @@ public class JavaScriptProvider extends GhidraScriptProvider {
|
||||||
|
|
||||||
needsBundleActivate |= needsCompile;
|
needsBundleActivate |= needsCompile;
|
||||||
|
|
||||||
BundleHost bundle_host = GhidraScriptMgrPlugin.getBundleHost();
|
BundleHost bundle_host = BundleHost.getInstance();
|
||||||
if (needsBundleActivate) {
|
if (needsBundleActivate) {
|
||||||
writer.printf("%s has %d new/updated %d failed in previous build(s)%s\n",
|
writer.printf("%s has %d new/updated %d failed in previous build(s)%s\n",
|
||||||
bi.getSourceDir().toString(), newSourcecount, failing,
|
bi.getSourceDir().toString(), newSourcecount, failing,
|
||||||
|
|
|
@ -42,6 +42,22 @@ import ghidra.util.task.*;
|
||||||
|
|
||||||
// XXX this class should be part of a service/plugin
|
// XXX this class should be part of a service/plugin
|
||||||
public class BundleHost {
|
public class BundleHost {
|
||||||
|
// XXX embedded OSGi should be a service, but ScriptProviders don't have any way to access services
|
||||||
|
static private BundleHost _instance;
|
||||||
|
|
||||||
|
static public BundleHost getInstance() {
|
||||||
|
if (_instance == null) {
|
||||||
|
_instance = new BundleHost();
|
||||||
|
try {
|
||||||
|
_instance.startFelix();
|
||||||
|
}
|
||||||
|
catch (OSGiException | IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
static public String getSymbolicNameFromSourceDir(ResourceFile sourceDir) {
|
static public String getSymbolicNameFromSourceDir(ResourceFile sourceDir) {
|
||||||
return Integer.toHexString(sourceDir.getAbsolutePath().hashCode());
|
return Integer.toHexString(sourceDir.getAbsolutePath().hashCode());
|
||||||
}
|
}
|
||||||
|
@ -214,10 +230,6 @@ public class BundleHost {
|
||||||
config.setProperty("ds.showtrace", "true");
|
config.setProperty("ds.showtrace", "true");
|
||||||
config.setProperty("ds.showerrors", "true");
|
config.setProperty("ds.showerrors", "true");
|
||||||
|
|
||||||
config.setProperty("felix.fileinstall.dir", getWatchedBundleDirs());
|
|
||||||
// config.setProperty("felix.fileinstall.log.level", "999");
|
|
||||||
// config.setProperty("felix.fileinstall.log.default", "jul"); // stdout
|
|
||||||
config.setProperty("felix.fileinstall.bundles.new.start", "true"); // autostart bundles
|
|
||||||
config.put(FelixConstants.LOG_LEVEL_PROP, "999");// was 4
|
config.put(FelixConstants.LOG_LEVEL_PROP, "999");// was 4
|
||||||
config.put(FelixConstants.LOG_LOGGER_PROP, new FelixLogger());
|
config.put(FelixConstants.LOG_LOGGER_PROP, new FelixLogger());
|
||||||
|
|
||||||
|
@ -301,9 +313,6 @@ public class BundleHost {
|
||||||
catch (BundleException e) {
|
catch (BundleException e) {
|
||||||
throw new OSGiException("starting felix OSGi framework", e);
|
throw new OSGiException("starting felix OSGi framework", e);
|
||||||
}
|
}
|
||||||
// fileinstall_bundle = installFromPath(findJarForClass(FileInstall.class));
|
|
||||||
// fileinstall_bundle.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String makeCacheDir() throws IOException {
|
private String makeCacheDir() throws IOException {
|
||||||
|
@ -312,11 +321,6 @@ public class BundleHost {
|
||||||
return cache_dir.toAbsolutePath().toString();
|
return cache_dir.toAbsolutePath().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** comma separated list of directories watched for bundles by fileinstaller */
|
|
||||||
private String getWatchedBundleDirs() {
|
|
||||||
return GhidraScriptUtil.getCompiledBundlesDir().toAbsolutePath().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bundle getBundle(String bundleLoc) {
|
public Bundle getBundle(String bundleLoc) {
|
||||||
return bc.getBundle(bundleLoc);
|
return bc.getBundle(bundleLoc);
|
||||||
}
|
}
|
||||||
|
@ -399,39 +403,12 @@ public class BundleHost {
|
||||||
return felix;
|
return felix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean stopBundleWatcher() {
|
public interface DiscrepencyCallback {
|
||||||
if (fileinstall_bundle != null) {
|
|
||||||
try {
|
|
||||||
fileinstall_bundle.stop();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (BundleException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean startBundleWatcher() {
|
|
||||||
if (fileinstall_bundle != null) {
|
|
||||||
try {
|
|
||||||
fileinstall_bundle.start();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (BundleException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public interface NewSourceCallback {
|
|
||||||
void found(ResourceFile source_file, Collection<Path> class_files) throws Throwable;
|
void found(ResourceFile source_file, Collection<Path> class_files) throws Throwable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void visitDiscrepencies(ResourceFile srcdir, Path bindir,
|
public static void visitDiscrepencies(ResourceFile srcdir, Path bindir,
|
||||||
NewSourceCallback new_source_cb) {
|
DiscrepencyCallback new_source_cb) {
|
||||||
try {
|
try {
|
||||||
// delete class files for which java is either newer, or no longer exists
|
// delete class files for which java is either newer, or no longer exists
|
||||||
Deque<ResourceFile> stack = new ArrayDeque<>();
|
Deque<ResourceFile> stack = new ArrayDeque<>();
|
||||||
|
|
|
@ -978,9 +978,9 @@ public abstract class AbstractGhidraScriptMgrPluginTest
|
||||||
String myTestName = super.testName.getMethodName();
|
String myTestName = super.testName.getMethodName();
|
||||||
|
|
||||||
// destroy any NewScriptxxx files...and Temp ones too
|
// destroy any NewScriptxxx files...and Temp ones too
|
||||||
BundleStatusProvider pathManager =
|
BundleStatusProvider bundleStatusProvider =
|
||||||
(BundleStatusProvider) TestUtils.getInstanceField("bundlePathManager", provider);
|
(BundleStatusProvider) TestUtils.getInstanceField("bundlePathManager", provider);
|
||||||
List<BundlePath> paths = pathManager.getPaths();
|
List<BundlePath> paths = bundleStatusProvider.getPaths();
|
||||||
for (BundlePath path : paths) {
|
for (BundlePath path : paths) {
|
||||||
File file = path.getPath().getFile(false);
|
File file = path.getPath().getFile(false);
|
||||||
File[] listFiles = file.listFiles();
|
File[] listFiles = file.listFiles();
|
||||||
|
|
|
@ -116,11 +116,11 @@ public class GhidraScriptMgrPluginScreenShots extends GhidraScreenShotGenerator
|
||||||
paths.add(new BundlePath("$GHIDRA_HOME/Features/Base/ghidra_scripts"));
|
paths.add(new BundlePath("$GHIDRA_HOME/Features/Base/ghidra_scripts"));
|
||||||
paths.add(new BundlePath("/User/defined/invalid/directory"));
|
paths.add(new BundlePath("/User/defined/invalid/directory"));
|
||||||
|
|
||||||
BundleStatusProvider bundleStatus = showProvider(BundleStatusProvider.class);
|
BundleStatusProvider bundleStatusProvider = showProvider(BundleStatusProvider.class);
|
||||||
bundleStatus.setPaths(paths);
|
bundleStatusProvider.setPaths(paths);
|
||||||
|
|
||||||
waitForComponentProvider(BundleStatusProvider.class);
|
waitForComponentProvider(BundleStatusProvider.class);
|
||||||
captureComponent(bundleStatus.getComponent());
|
captureComponent(bundleStatusProvider.getComponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue