mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
activate new bundles when added, deactivate bundles before removing
This commit is contained in:
parent
2d7b0d33b8
commit
6fe16f73ee
3 changed files with 57 additions and 26 deletions
|
@ -182,8 +182,10 @@ public class BundleHost {
|
|||
* @param bundleFiles a list of bundle files
|
||||
* @param enabled if the new bundle should be enabled
|
||||
* @param systemBundle if the new bundle is a system bundle
|
||||
* @return the new bundle objects
|
||||
*/
|
||||
public void add(List<ResourceFile> bundleFiles, boolean enabled, boolean systemBundle) {
|
||||
public Collection<GhidraBundle> add(List<ResourceFile> bundleFiles, boolean enabled,
|
||||
boolean systemBundle) {
|
||||
Map<ResourceFile, GhidraBundle> newBundleMap = bundleFiles.stream()
|
||||
.collect(Collectors.toUnmodifiableMap(Function.identity(),
|
||||
bundleFile -> createGhidraBundle(BundleHost.this, bundleFile, enabled,
|
||||
|
@ -193,7 +195,9 @@ public class BundleHost {
|
|||
.stream()
|
||||
.collect(Collectors.toUnmodifiableMap(GhidraBundle::getLocationIdentifier,
|
||||
Function.identity())));
|
||||
fireBundlesAdded(newBundleMap.values());
|
||||
Collection<GhidraBundle> newBundles = newBundleMap.values();
|
||||
fireBundlesAdded(newBundles);
|
||||
return newBundles;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -263,27 +263,8 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {
|
|||
if (selectedModelRows == null || selectedModelRows.length == 0) {
|
||||
return;
|
||||
}
|
||||
doDeactivateBundles();
|
||||
|
||||
// partition bundles into system (bundles.get(true)) and non-system (bundles.get(false)).
|
||||
Map<Boolean, List<GhidraBundle>> bundles =
|
||||
bundleStatusTableModel.getRowObjects(selectedModelRows)
|
||||
.stream()
|
||||
.map(bs -> bundleHost.getExistingGhidraBundle(bs.getFile()))
|
||||
.collect(Collectors.partitioningBy(GhidraBundle::isSystemBundle));
|
||||
|
||||
List<GhidraBundle> systemBundles = bundles.get(true);
|
||||
if (!systemBundles.isEmpty()) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (GhidraBundle bundle : systemBundles) {
|
||||
bundleHost.disable(bundle);
|
||||
stringBuilder.append(bundle.getFile() + "\n");
|
||||
}
|
||||
Msg.showWarn(this, this.getComponent(), "Unabled to remove",
|
||||
"System bundles cannot be removed:\n" + stringBuilder.toString());
|
||||
}
|
||||
|
||||
bundleHost.remove(bundles.get(false));
|
||||
new TaskLauncher(new RemoveBundlesTask("removing bundles", getSelectedStatuses()),
|
||||
getComponent(), 1000);
|
||||
}
|
||||
|
||||
private void showAddBundlesFileChooser() {
|
||||
|
@ -324,10 +305,17 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {
|
|||
List<File> files = fileChooser.getSelectedFiles();
|
||||
if (!files.isEmpty()) {
|
||||
Preferences.setProperty(PREFENCE_LAST_SELECTED_BUNDLE, files.get(0).getAbsolutePath());
|
||||
List<ResourceFile> resourceFiles =
|
||||
files.stream().map(ResourceFile::new).collect(Collectors.toUnmodifiableList());
|
||||
Collection<GhidraBundle> bundles = bundleHost.add(resourceFiles, true, false);
|
||||
|
||||
bundleHost.add(
|
||||
files.stream().map(ResourceFile::new).collect(Collectors.toUnmodifiableList()),
|
||||
true, false);
|
||||
new TaskLauncher(new Task("activating new bundles") {
|
||||
@Override
|
||||
public void run(TaskMonitor monitor) throws CancelledException {
|
||||
bundleHost.activateAll(bundles, monitor,
|
||||
getTool().getService(ConsoleService.class).getStdErr());
|
||||
}
|
||||
}, getComponent(), 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -396,6 +384,42 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {
|
|||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
private final class RemoveBundlesTask extends Task {
|
||||
private final DeactivateBundlesTask deactivateBundlesTask;
|
||||
private final List<BundleStatus> statuses;
|
||||
|
||||
private RemoveBundlesTask(String title, List<BundleStatus> statuses) {
|
||||
super(title);
|
||||
this.deactivateBundlesTask =
|
||||
new DeactivateBundlesTask("deactivating", true, true, false, statuses);
|
||||
this.statuses = statuses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(TaskMonitor monitor) throws CancelledException {
|
||||
deactivateBundlesTask.run(monitor);
|
||||
if (!monitor.isCancelled()) {
|
||||
// partition bundles into system (bundles.get(true)) and non-system (bundles.get(false)).
|
||||
Map<Boolean, List<GhidraBundle>> bundles = statuses.stream()
|
||||
.map(bs -> bundleHost.getExistingGhidraBundle(bs.getFile()))
|
||||
.collect(Collectors.partitioningBy(GhidraBundle::isSystemBundle));
|
||||
|
||||
List<GhidraBundle> systemBundles = bundles.get(true);
|
||||
if (!systemBundles.isEmpty()) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (GhidraBundle bundle : systemBundles) {
|
||||
bundleHost.disable(bundle);
|
||||
stringBuilder.append(bundle.getFile() + "\n");
|
||||
}
|
||||
Msg.showWarn(this, BundleStatusComponentProvider.this.getComponent(),
|
||||
"Unabled to remove",
|
||||
"System bundles cannot be removed:\n" + stringBuilder.toString());
|
||||
}
|
||||
bundleHost.remove(bundles.get(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ActivateBundlesTask extends Task {
|
||||
private final List<BundleStatus> statuses;
|
||||
|
||||
|
|
|
@ -120,6 +120,9 @@ public class GhidraScriptInfoManager {
|
|||
* @return info or null if the assumption was wrong. If null is returned, an error dialog is shown
|
||||
*/
|
||||
public ScriptInfo getExistingScriptInfo(ResourceFile script) {
|
||||
if (script == null) {
|
||||
return null;
|
||||
}
|
||||
ScriptInfo info = scriptFileToInfoMap.get(script);
|
||||
if (info == null) {
|
||||
String error = (script.exists() ? "" : "non") + "existing script" + script.toString() +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue