mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
Merge remote-tracking branch 'origin/GP-0_dev747368_fix_fsb_tests'
This commit is contained in:
commit
8537164d80
4 changed files with 67 additions and 20 deletions
|
@ -230,8 +230,11 @@ public class FSBComponentProvider extends ComponentProviderAdapter
|
||||||
plugin.getTool().removePopupActionProvider(this);
|
plugin.getTool().removePopupActionProvider(this);
|
||||||
projectIndex.removeIndexListener(this);
|
projectIndex.removeIndexListener(this);
|
||||||
|
|
||||||
if (rootNode != null && rootNode.getFSRef() != null && !rootNode.getFSRef().isClosed()) {
|
if (rootNode != null) {
|
||||||
rootNode.getFSRef().getFilesystem().getRefManager().removeListener(this);
|
FileSystemRef rootNodeFSRef = rootNode.getFSRef();
|
||||||
|
if (rootNodeFSRef != null && !rootNodeFSRef.isClosed()) {
|
||||||
|
rootNodeFSRef.getFilesystem().getRefManager().removeListener(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fileHandlers.clear();
|
fileHandlers.clear();
|
||||||
if (gTree != null) {
|
if (gTree != null) {
|
||||||
|
|
|
@ -107,11 +107,11 @@ public class FSBRootNode extends FSBNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileSystemRef getFSRef() {
|
public FileSystemRef getFSRef() {
|
||||||
return modelNode.rootDir.fsRef;
|
return modelNode.rootDir != null ? modelNode.rootDir.fsRef : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void releaseFSRefIfModelNode() {
|
private void releaseFSRefIfModelNode() {
|
||||||
if (this != modelNode) {
|
if (this != modelNode || rootDir == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FileSystemService.getInstance().releaseFileSystemImmediate(rootDir.fsRef);
|
FileSystemService.getInstance().releaseFileSystemImmediate(rootDir.fsRef);
|
||||||
|
|
|
@ -168,6 +168,12 @@ public class FileSystemBrowserPlugin extends Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show) {
|
if (show) {
|
||||||
|
showProvider(provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showProvider(FSBComponentProvider provider) {
|
||||||
|
if (provider != null) {
|
||||||
getTool().showComponentProvider(provider, true);
|
getTool().showComponentProvider(provider, true);
|
||||||
getTool().toFront(provider);
|
getTool().toFront(provider);
|
||||||
provider.contextChanged();
|
provider.contextChanged();
|
||||||
|
@ -283,20 +289,24 @@ public class FileSystemBrowserPlugin extends Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For testing access only.
|
* Returns an already opened provider for the specified FSRL.
|
||||||
*
|
*
|
||||||
* @param fsFSRL {@link FSRLRoot} of browser component to fetch.
|
* @param fsrl {@link FSRL} of root dir of browser component to fetch.
|
||||||
* @return provider or null if not found.
|
* @return provider or null if not found.
|
||||||
*/
|
*/
|
||||||
/* package */ FSBComponentProvider getProviderFor(FSRLRoot fsFSRL) {
|
public FSBComponentProvider getProviderFor(FSRL fsrl) {
|
||||||
FSBComponentProvider provider = currentBrowsers.get(fsFSRL);
|
FSBComponentProvider provider = currentBrowsers.get(fsrl);
|
||||||
if (provider == null) {
|
if (provider == null) {
|
||||||
Msg.info(this, "Could not find browser for " + fsFSRL);
|
Msg.info(this, "Could not find browser for " + fsrl);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FSRL> getCurrentlyOpenBrowsers() {
|
||||||
|
return List.copyOf(currentBrowsers.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------
|
||||||
@Override
|
@Override
|
||||||
public void processEvent(PluginEvent event) {
|
public void processEvent(PluginEvent event) {
|
||||||
|
|
|
@ -15,13 +15,14 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.plugins.fsbrowser.filehandlers;
|
package ghidra.plugins.fsbrowser.filehandlers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import docking.action.DockingAction;
|
import docking.action.DockingAction;
|
||||||
import docking.action.builder.ActionBuilder;
|
import docking.action.builder.ActionBuilder;
|
||||||
import docking.widgets.SelectFromListDialog;
|
import docking.widgets.SelectFromListDialog;
|
||||||
import ghidra.formats.gfilesystem.FSRLRoot;
|
import ghidra.formats.gfilesystem.*;
|
||||||
import ghidra.formats.gfilesystem.FileSystemRef;
|
|
||||||
import ghidra.plugins.fsbrowser.*;
|
import ghidra.plugins.fsbrowser.*;
|
||||||
|
|
||||||
public class ListMountedFSBFileHandler implements FSBFileHandler {
|
public class ListMountedFSBFileHandler implements FSBFileHandler {
|
||||||
|
@ -45,19 +46,52 @@ public class ListMountedFSBFileHandler implements FSBFileHandler {
|
||||||
.popupMenuPath("List Mounted Filesystems")
|
.popupMenuPath("List Mounted Filesystems")
|
||||||
.popupMenuGroup("L")
|
.popupMenuGroup("L")
|
||||||
.onAction(ac -> {
|
.onAction(ac -> {
|
||||||
FSRLRoot fsFSRL = SelectFromListDialog.selectFromList(
|
List<FSRL> sortedFSRLs = new ArrayList<>();
|
||||||
context.fsService().getMountedFilesystems(), "Select filesystem",
|
sortedFSRLs.addAll(context.plugin().getCurrentlyOpenBrowsers());
|
||||||
"Choose filesystem to view", f -> f.toPrettyString());
|
sortedFSRLs.sort((f1, f2) -> f1.toString().compareTo(f2.toString()));
|
||||||
|
FSRL fsrl = SelectFromListDialog.selectFromList(sortedFSRLs,
|
||||||
|
"Select filesystem", "Choose filesystem to view",
|
||||||
|
f -> getPrettyFSRLString(f));
|
||||||
|
|
||||||
|
if (fsrl != null) {
|
||||||
|
context.plugin().showProvider(context.plugin().getProviderFor(fsrl));
|
||||||
|
|
||||||
FileSystemRef fsRef;
|
|
||||||
if (fsFSRL != null &&
|
|
||||||
(fsRef = context.fsService().getMountedFilesystem(fsFSRL)) != null) {
|
|
||||||
context.fsbComponent()
|
|
||||||
.getPlugin()
|
|
||||||
.createNewFileSystemBrowser(fsRef, null, true);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getPrettyFSRLString(FSRL fsrl) {
|
||||||
|
FileSystemService fsService = context.fsService();
|
||||||
|
LocalFileSystem localFS = fsService.getLocalFS();
|
||||||
|
if (localFS.getRootDir().getFSRL().equals(fsrl)) {
|
||||||
|
return "My Computer";
|
||||||
|
}
|
||||||
|
else if (fsrl.getNestingDepth() == 1) {
|
||||||
|
return new File(fsrl.getPath()).getPath();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (fsrl.getPath().equals("/")) {
|
||||||
|
fsrl = fsrl.getFS();
|
||||||
|
}
|
||||||
|
String result = "";
|
||||||
|
List<FSRL> fsrlParts = fsrl.split();
|
||||||
|
for (int i = 0; i < fsrlParts.size(); i++) {
|
||||||
|
FSRL part = fsrlParts.get(i);
|
||||||
|
if (i == 0) {
|
||||||
|
result = new File(part.getPath()).getPath();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (part instanceof FSRLRoot) {
|
||||||
|
// skip, will be last element
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result += "|" + part.getPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue