mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
Merge remote-tracking branch 'origin/gt-2758_dev747368_zipfilesystem_npe'
This commit is contained in:
commit
29e6df1c38
36 changed files with 290 additions and 343 deletions
|
@ -108,7 +108,7 @@ public class FileSystemIndexHelper<METADATATYPE> {
|
|||
* @return {@link GFile} instance or null if no file was added to the index at that path.
|
||||
*/
|
||||
public GFile lookup(String path) {
|
||||
String[] nameparts = path.split("/");
|
||||
String[] nameparts = (path != null ? path : "").split("/");
|
||||
GFile parent = lookupParent(nameparts);
|
||||
if (nameparts.length == 0) {
|
||||
return parent;
|
||||
|
|
|
@ -15,14 +15,14 @@
|
|||
*/
|
||||
package ghidra.formats.gfilesystem;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
import ghidra.formats.gfilesystem.annotations.FileSystemInfo;
|
||||
import ghidra.util.classfinder.ExtensionPoint;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface that represents a filesystem that contains files.
|
||||
* <p>
|
||||
|
@ -155,9 +155,10 @@ public interface GFileSystem extends Closeable, ExtensionPoint {
|
|||
* <p>
|
||||
* @param file {@link GFile} to get info message for.
|
||||
* @param monitor {@link TaskMonitor} to watch and update progress.
|
||||
* @return multi-line formatted string with info about the file.
|
||||
* @throws IOException if IO problem.
|
||||
* @return multi-line formatted string with info about the file, or null.
|
||||
*/
|
||||
public String getInfo(GFile file, TaskMonitor monitor) throws IOException;
|
||||
default public String getInfo(GFile file, TaskMonitor monitor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -129,9 +129,6 @@ public abstract class GFileSystemBase implements GFileSystem {
|
|||
@Override
|
||||
abstract public List<GFile> getListing(GFile directory) throws IOException;
|
||||
|
||||
@Override
|
||||
abstract public String getInfo(GFile file, TaskMonitor monitor) throws IOException;
|
||||
|
||||
/**
|
||||
* Legacy implementation of {@link #getInputStream(GFile, TaskMonitor)}.
|
||||
*
|
||||
|
|
|
@ -130,14 +130,19 @@ public class LocalFileSystemSub implements GFileSystem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getInfo(GFile file, TaskMonitor monitor) throws IOException {
|
||||
File localFile = getFileFromGFile(file);
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("Name: " + localFile.getName() + "\n");
|
||||
buffer.append("Size: " + localFile.length() + "\n");
|
||||
buffer.append("Date: " + new Date(localFile.lastModified()).toString() + "\n");
|
||||
return buffer.toString();
|
||||
public String getInfo(GFile file, TaskMonitor monitor) {
|
||||
try {
|
||||
File localFile = getFileFromGFile(file);
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("Name: " + localFile.getName() + "\n");
|
||||
buffer.append("Size: " + localFile.length() + "\n");
|
||||
buffer.append("Date: " + new Date(localFile.lastModified()).toString() + "\n");
|
||||
return buffer.toString();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// fail and return null
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -473,42 +473,50 @@ class FSBActionManager {
|
|||
* @param monitor {@link TaskMonitor} to monitor and update when accessing the filesystems.
|
||||
*/
|
||||
private void showInfoForFile(FSRL fsrl, TaskMonitor monitor) {
|
||||
String title = " no title ";
|
||||
String info = " no information available ";
|
||||
String fileSystemName = " unknown ";
|
||||
String title;
|
||||
String info;
|
||||
|
||||
if (fsrl != null) {
|
||||
info = "";
|
||||
title = "Info about " + fsrl.getName();
|
||||
if (fsrl instanceof FSRLRoot && ((FSRLRoot) fsrl).hasContainer()) {
|
||||
fsrl = ((FSRLRoot) fsrl).getContainer();
|
||||
}
|
||||
try (RefdFile refdFile = FileSystemService.getInstance().getRefdFile(fsrl, monitor)) {
|
||||
|
||||
title = fsrl.getName();
|
||||
|
||||
GFileSystem fs = refdFile.fsRef.getFilesystem();
|
||||
fileSystemName = fs.getDescription();
|
||||
info = "FSRL: " + fsrl + "\n";
|
||||
DomainFile associatedDomainFile =
|
||||
ProgramMappingService.getCachedDomainFileFor(fsrl);
|
||||
if (associatedDomainFile != null) {
|
||||
info = info + "Project file: " + associatedDomainFile.getPathname() + "\n";
|
||||
}
|
||||
String nodeInfo = fs.getInfo(refdFile.file, monitor);
|
||||
if (nodeInfo != null) {
|
||||
info += nodeInfo;
|
||||
}
|
||||
}
|
||||
catch (IOException | CancelledException e) {
|
||||
info = "Error retrieving information: " + e.getMessage();
|
||||
FSRL containerFSRL = ((FSRLRoot) fsrl).getContainer();
|
||||
title = containerFSRL.getName();
|
||||
info = getInfoStringFor(containerFSRL, monitor);
|
||||
info += "------------------------------------\n";
|
||||
}
|
||||
info += getInfoStringFor(fsrl, monitor);
|
||||
}
|
||||
else {
|
||||
title = "Missing File";
|
||||
info = "Unable to retrieve information";
|
||||
}
|
||||
|
||||
MultiLineMessageDialog.showMessageDialog(plugin.getTool().getActiveWindow(),
|
||||
"Info about " + title, null, "File system: " + fileSystemName + '\n' + info,
|
||||
MultiLineMessageDialog.INFORMATION_MESSAGE);
|
||||
MultiLineMessageDialog.showMessageDialog(plugin.getTool().getActiveWindow(), title, null,
|
||||
info, MultiLineMessageDialog.INFORMATION_MESSAGE);
|
||||
|
||||
}
|
||||
|
||||
private String getInfoStringFor(FSRL fsrl, TaskMonitor monitor) {
|
||||
try (RefdFile refdFile = FileSystemService.getInstance().getRefdFile(fsrl, monitor)) {
|
||||
GFileSystem fs = refdFile.fsRef.getFilesystem();
|
||||
String result = "File system: " + fs.getDescription() + "\n";
|
||||
result += "FSRL: " + fsrl + "\n";
|
||||
DomainFile associatedDomainFile = ProgramMappingService.getCachedDomainFileFor(fsrl);
|
||||
if (associatedDomainFile != null) {
|
||||
result += "Project file: " + associatedDomainFile.getPathname() + "\n";
|
||||
}
|
||||
String nodeInfo = fs.getInfo(refdFile.file, monitor);
|
||||
if (nodeInfo != null) {
|
||||
result += nodeInfo;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (IOException | CancelledException e) {
|
||||
return "Error retrieving information: " + e.getMessage() + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a list of supported file system types and loaders.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue