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);
|
||||
projectIndex.removeIndexListener(this);
|
||||
|
||||
if (rootNode != null && rootNode.getFSRef() != null && !rootNode.getFSRef().isClosed()) {
|
||||
rootNode.getFSRef().getFilesystem().getRefManager().removeListener(this);
|
||||
if (rootNode != null) {
|
||||
FileSystemRef rootNodeFSRef = rootNode.getFSRef();
|
||||
if (rootNodeFSRef != null && !rootNodeFSRef.isClosed()) {
|
||||
rootNodeFSRef.getFilesystem().getRefManager().removeListener(this);
|
||||
}
|
||||
}
|
||||
fileHandlers.clear();
|
||||
if (gTree != null) {
|
||||
|
|
|
@ -107,11 +107,11 @@ public class FSBRootNode extends FSBNode {
|
|||
}
|
||||
|
||||
public FileSystemRef getFSRef() {
|
||||
return modelNode.rootDir.fsRef;
|
||||
return modelNode.rootDir != null ? modelNode.rootDir.fsRef : null;
|
||||
}
|
||||
|
||||
private void releaseFSRefIfModelNode() {
|
||||
if (this != modelNode) {
|
||||
if (this != modelNode || rootDir == null) {
|
||||
return;
|
||||
}
|
||||
FileSystemService.getInstance().releaseFileSystemImmediate(rootDir.fsRef);
|
||||
|
|
|
@ -168,6 +168,12 @@ public class FileSystemBrowserPlugin extends Plugin
|
|||
}
|
||||
|
||||
if (show) {
|
||||
showProvider(provider);
|
||||
}
|
||||
}
|
||||
|
||||
public void showProvider(FSBComponentProvider provider) {
|
||||
if (provider != null) {
|
||||
getTool().showComponentProvider(provider, true);
|
||||
getTool().toFront(provider);
|
||||
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.
|
||||
*/
|
||||
/* package */ FSBComponentProvider getProviderFor(FSRLRoot fsFSRL) {
|
||||
FSBComponentProvider provider = currentBrowsers.get(fsFSRL);
|
||||
public FSBComponentProvider getProviderFor(FSRL fsrl) {
|
||||
FSBComponentProvider provider = currentBrowsers.get(fsrl);
|
||||
if (provider == null) {
|
||||
Msg.info(this, "Could not find browser for " + fsFSRL);
|
||||
Msg.info(this, "Could not find browser for " + fsrl);
|
||||
return null;
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
public List<FSRL> getCurrentlyOpenBrowsers() {
|
||||
return List.copyOf(currentBrowsers.keySet());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
@Override
|
||||
public void processEvent(PluginEvent event) {
|
||||
|
|
|
@ -15,13 +15,14 @@
|
|||
*/
|
||||
package ghidra.plugins.fsbrowser.filehandlers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import docking.action.DockingAction;
|
||||
import docking.action.builder.ActionBuilder;
|
||||
import docking.widgets.SelectFromListDialog;
|
||||
import ghidra.formats.gfilesystem.FSRLRoot;
|
||||
import ghidra.formats.gfilesystem.FileSystemRef;
|
||||
import ghidra.formats.gfilesystem.*;
|
||||
import ghidra.plugins.fsbrowser.*;
|
||||
|
||||
public class ListMountedFSBFileHandler implements FSBFileHandler {
|
||||
|
@ -45,19 +46,52 @@ public class ListMountedFSBFileHandler implements FSBFileHandler {
|
|||
.popupMenuPath("List Mounted Filesystems")
|
||||
.popupMenuGroup("L")
|
||||
.onAction(ac -> {
|
||||
FSRLRoot fsFSRL = SelectFromListDialog.selectFromList(
|
||||
context.fsService().getMountedFilesystems(), "Select filesystem",
|
||||
"Choose filesystem to view", f -> f.toPrettyString());
|
||||
List<FSRL> sortedFSRLs = new ArrayList<>();
|
||||
sortedFSRLs.addAll(context.plugin().getCurrentlyOpenBrowsers());
|
||||
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());
|
||||
}
|
||||
|
||||
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