diff --git a/Ghidra/Features/Base/data/file_extension_icons.xml b/Ghidra/Features/Base/data/file_extension_icons.xml index 9db71c2daf..52a3bdd107 100644 --- a/Ghidra/Features/Base/data/file_extension_icons.xml +++ b/Ghidra/Features/Base/data/file_extension_icons.xml @@ -14,7 +14,7 @@ - + diff --git a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/FileSystemIndexHelper.java b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/FileSystemIndexHelper.java index 14c5b66386..55cef99a75 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/FileSystemIndexHelper.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/FileSystemIndexHelper.java @@ -108,7 +108,7 @@ public class FileSystemIndexHelper { * @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; diff --git a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/GFileSystem.java b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/GFileSystem.java index dd5e9870b6..f37ca6072c 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/GFileSystem.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/GFileSystem.java @@ -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. *

@@ -155,9 +155,10 @@ public interface GFileSystem extends Closeable, ExtensionPoint { *

* @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; + } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/GFileSystemBase.java b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/GFileSystemBase.java index 1abcee1882..21ab576ccb 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/GFileSystemBase.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/GFileSystemBase.java @@ -129,9 +129,6 @@ public abstract class GFileSystemBase implements GFileSystem { @Override abstract public List getListing(GFile directory) throws IOException; - @Override - abstract public String getInfo(GFile file, TaskMonitor monitor) throws IOException; - /** * Legacy implementation of {@link #getInputStream(GFile, TaskMonitor)}. * diff --git a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/LocalFileSystemSub.java b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/LocalFileSystemSub.java index ec0dee76ad..94701c4a91 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/LocalFileSystemSub.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/LocalFileSystemSub.java @@ -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 diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBActionManager.java b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBActionManager.java index 2265eccf84..c42dd099aa 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBActionManager.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBActionManager.java @@ -472,42 +472,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. */ diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/apk/ApkFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/apk/ApkFileSystem.java index 0d1ab34bd3..cfc97ae8ff 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/apk/ApkFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/apk/ApkFileSystem.java @@ -55,11 +55,6 @@ public class ApkFileSystem extends GFileSystemBase { return new ArrayList<>(); } - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } - @Override protected InputStream getData(GFile file, TaskMonitor monitor) throws IOException, CancelledException, CryptoException { diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageFileSystem.java index c40a25213e..c774026204 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/bootimg/BootImageFileSystem.java @@ -86,7 +86,7 @@ public class BootImageFileSystem extends GFileSystemBase { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { if (file == kernelFile) { return "This is the actual KERNEL for the android device. You can analyze this file."; } diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexToJarFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexToJarFileSystem.java index b1ebdefd34..9e6f5b98b5 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexToJarFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexToJarFileSystem.java @@ -175,9 +175,4 @@ public class DexToJarFileSystem extends GFileSystemBase { public void close() throws IOException { super.close(); } - - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } } diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexToSmaliFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexToSmaliFileSystem.java index dec244401b..4d6a2dcd23 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexToSmaliFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/DexToSmaliFileSystem.java @@ -146,7 +146,6 @@ public class DexToSmaliFileSystem extends GFileSystemBase { } } - private void storeFile(GFile file, File entry) { if (file == null) { return; @@ -166,11 +165,6 @@ public class DexToSmaliFileSystem extends GFileSystemBase { map.clear(); super.close(); } - - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } } /* DexHeader header = new DexHeader(provider); diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/kernel/KernelFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/kernel/KernelFileSystem.java index 37a29c45ae..2d13f46efe 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/kernel/KernelFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/kernel/KernelFileSystem.java @@ -95,11 +95,6 @@ public class KernelFileSystem extends GFileSystemBase { : Collections.emptyList(); } - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } - @Override protected InputStream getData(GFile file, TaskMonitor monitor) throws IOException, CancelledException, CryptoException { diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/odex/OdexFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/odex/OdexFileSystem.java index 5888c0e256..fc9d27b99c 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/odex/OdexFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/odex/OdexFileSystem.java @@ -64,7 +64,7 @@ public class OdexFileSystem extends GFileSystemBase { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { StringBuilder builder = new StringBuilder(); builder.append("Magic: " + odexHeader.getMagic()).append("\n"); builder.append("Dex Offset: " + Integer.toHexString(odexHeader.getDexOffset())).append( diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/xml/AndroidXmlFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/xml/AndroidXmlFileSystem.java index e538287911..70b7cf3dbe 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/xml/AndroidXmlFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/xml/AndroidXmlFileSystem.java @@ -96,11 +96,6 @@ public class AndroidXmlFileSystem extends GFileSystemBase { return new ByteArrayInputStream(payloadBytes); } - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } - @Override public List getListing(GFile directory) throws IOException { List tmp = new ArrayList<>(); diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/coff/CoffArchiveFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/coff/CoffArchiveFileSystem.java index 2c07b0db0f..41ba600f87 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/coff/CoffArchiveFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/coff/CoffArchiveFileSystem.java @@ -104,7 +104,7 @@ public class CoffArchiveFileSystem implements GFileSystem { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { CoffArchiveMemberHeader entry = fsih.getMetadata(file); return (entry == null) ? null : FSUtilities.infoMapToString(getInfoMap(entry)); } diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/complzss/CompLzssFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/complzss/CompLzssFileSystem.java index 18d993cfeb..efe61a99ef 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/complzss/CompLzssFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/complzss/CompLzssFileSystem.java @@ -55,11 +55,6 @@ public class CompLzssFileSystem extends GFileSystemBase { return null; } - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } - @Override public List getListing(GFile directory) throws IOException { return (directory == null || directory.equals(root)) ? Arrays.asList(decompressedFile) diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/cpio/CpioFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/cpio/CpioFileSystem.java index df26490144..8d305041c3 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/cpio/CpioFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/cpio/CpioFileSystem.java @@ -107,9 +107,9 @@ public class CpioFileSystem extends GFileSystemBase { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { CpioArchiveEntry entry = map.get(file); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); try { buffer.append("Name: " + entry.getName() + "\n"); buffer.append("Checksum: " + Long.toHexString(entry.getChksum()) + "\n"); @@ -126,6 +126,7 @@ public class CpioFileSystem extends GFileSystemBase { buffer.append("Device ID: " + Long.toHexString(entry.getDevice()) + "\n"); } catch (Exception e) { + // ignore } return buffer.toString(); } diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4FileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4FileSystem.java index cab86cb4c1..538e9fa1d7 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4FileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4FileSystem.java @@ -43,221 +43,219 @@ public class Ext4FileSystem implements GFileSystem { this.provider = provider; } - public void mountFS( TaskMonitor monitor ) throws IOException, CancelledException { - BinaryReader reader = new BinaryReader( provider, true ); - reader.setPointerIndex( 0x400 ); + public void mountFS(TaskMonitor monitor) throws IOException, CancelledException { + BinaryReader reader = new BinaryReader(provider, true); + reader.setPointerIndex(0x400); - Ext4SuperBlock superBlock = new Ext4SuperBlock( reader ); + Ext4SuperBlock superBlock = new Ext4SuperBlock(reader); - this.volumeName = superBlock.getVolumeName( ); + this.volumeName = superBlock.getVolumeName(); - this.uuid = NumericUtilities.convertBytesToString( superBlock.getS_uuid( ) ); + this.uuid = NumericUtilities.convertBytesToString(superBlock.getS_uuid()); - int s_log_block_size = superBlock.getS_log_block_size( ); - blockSize = ( int ) Math.pow( 2, ( 10 + s_log_block_size ) ); + int s_log_block_size = superBlock.getS_log_block_size(); + blockSize = (int) Math.pow(2, (10 + s_log_block_size)); - int groupSize = blockSize * superBlock.getS_blocks_per_group( ); - int numGroups = ( int ) ( provider.length( ) / groupSize ); - if ( provider.length( ) % groupSize != 0 ) { + int groupSize = blockSize * superBlock.getS_blocks_per_group(); + int numGroups = (int) (provider.length() / groupSize); + if (provider.length() % groupSize != 0) { numGroups++; } - boolean is64Bit = ( superBlock.getS_desc_size( ) > 32 ) && ( ( superBlock.getS_feature_incompat( ) & 0x80 ) > 0 ); + boolean is64Bit = + (superBlock.getS_desc_size() > 32) && ((superBlock.getS_feature_incompat() & 0x80) > 0); int groupDescriptorOffset = blockSize; - reader.setPointerIndex( groupDescriptorOffset ); - Ext4GroupDescriptor [] groupDescriptors = new Ext4GroupDescriptor [ numGroups ]; - for ( int i = 0; i < numGroups; i++ ) { - monitor.checkCanceled( ); - groupDescriptors[ i ] = new Ext4GroupDescriptor( reader, is64Bit ); - monitor.incrementProgress( 1 ); + reader.setPointerIndex(groupDescriptorOffset); + Ext4GroupDescriptor[] groupDescriptors = new Ext4GroupDescriptor[numGroups]; + for (int i = 0; i < numGroups; i++) { + monitor.checkCanceled(); + groupDescriptors[i] = new Ext4GroupDescriptor(reader, is64Bit); + monitor.incrementProgress(1); } - Ext4Inode [] inodes = getInodes( reader, superBlock, groupDescriptors, is64Bit, monitor ); + Ext4Inode[] inodes = getInodes(reader, superBlock, groupDescriptors, is64Bit, monitor); - int s_inodes_count = superBlock.getS_inodes_count( ); - for ( int i = 0; i < s_inodes_count; i++ ) { - Ext4Inode inode = inodes[ i ]; - if ( inode == null ) { + int s_inodes_count = superBlock.getS_inodes_count(); + for (int i = 0; i < s_inodes_count; i++) { + Ext4Inode inode = inodes[i]; + if (inode == null) { continue; } - if ( ( inode.getI_mode( ) & Ext4Constants.I_MODE_MASK ) == Ext4Constants.S_IFDIR ) { - processDirectory( reader, superBlock, inodes, i, null, null, monitor ); + if ((inode.getI_mode() & Ext4Constants.I_MODE_MASK) == Ext4Constants.S_IFDIR) { + processDirectory(reader, superBlock, inodes, i, null, null, monitor); } - else if ( ( inode.getI_mode( ) & Ext4Constants.I_MODE_MASK ) == Ext4Constants.S_IFREG ) { - processFile( reader, superBlock, inode, monitor ); + else if ((inode.getI_mode() & Ext4Constants.I_MODE_MASK) == Ext4Constants.S_IFREG) { + processFile(reader, superBlock, inode, monitor); } } } - private void processDirectory( BinaryReader reader, - Ext4SuperBlock superBlock, - Ext4Inode[] inodes, - int index, - String name, - GFile parent, - TaskMonitor monitor ) throws IOException, CancelledException { + private void processDirectory(BinaryReader reader, Ext4SuperBlock superBlock, + Ext4Inode[] inodes, int index, String name, GFile parent, TaskMonitor monitor) + throws IOException, CancelledException { - if ( name != null && ( name.equals( "." ) || name.equals( ".." ) ) ) { + if (name != null && (name.equals(".") || name.equals(".."))) { return; } - Ext4Inode inode = inodes[ index ]; - if ( name == null && parent == null ) { - parent = fsih.getRootDir( ); + Ext4Inode inode = inodes[index]; + if (name == null && parent == null) { + parent = fsih.getRootDir(); } else { - if ( parent == null ) { - parent = fsih.getRootDir( ); + if (parent == null) { + parent = fsih.getRootDir(); } - parent = fsih.storeFileWithParent( name, parent, -1, true, ( inode.getI_size_high( ) << 32 ) | inode.getI_size_lo( ), new Ext4File( name, inode ) ); + parent = fsih.storeFileWithParent(name, parent, -1, true, + (inode.getI_size_high() << 32) | inode.getI_size_lo(), new Ext4File(name, inode)); } - if ( ( inode.getI_flags( ) & Ext4Constants.EXT4_EXTENTS_FL ) == 0 ) { + if ((inode.getI_flags() & Ext4Constants.EXT4_EXTENTS_FL) == 0) { return; } - boolean isDirEntry2 = ( superBlock.getS_feature_incompat( ) & Ext4Constants.INCOMPAT_FILETYPE ) != 0; + boolean isDirEntry2 = + (superBlock.getS_feature_incompat() & Ext4Constants.INCOMPAT_FILETYPE) != 0; // if uses extents - if ( ( inode.getI_flags( ) & Ext4Constants.EXT4_EXTENTS_FL ) != 0 ) { - Ext4IBlock i_block = inode.getI_block( ); - processIBlock( reader, superBlock, inodes, parent, isDirEntry2, i_block, monitor ); + if ((inode.getI_flags() & Ext4Constants.EXT4_EXTENTS_FL) != 0) { + Ext4IBlock i_block = inode.getI_block(); + processIBlock(reader, superBlock, inodes, parent, isDirEntry2, i_block, monitor); } else { - throw new IOException( "File system fails to use extents." ); + throw new IOException("File system fails to use extents."); } - inodes[ index ] = null; + inodes[index] = null; } - private void processIBlock( BinaryReader reader, - Ext4SuperBlock superBlock, - Ext4Inode[] inodes, - GFile parent, - boolean isDirEntry2, - Ext4IBlock i_block, - TaskMonitor monitor ) throws CancelledException, IOException { - Ext4ExtentHeader header = i_block.getHeader( ); - if ( header.getEh_depth( ) == 0 ) { - short numEntries = header.getEh_entries( ); - List< Ext4Extent > entries = i_block.getExtentEntries( ); - for ( int i = 0; i < numEntries; i++ ) { - monitor.checkCanceled( ); - Ext4Extent extent = entries.get( i ); - long low = extent.getEe_start_lo( ) & 0xffffffffL; - long high = extent.getEe_start_hi( ) & 0xffffffffL; - long blockNumber = ( high << 16 ) | low; + private void processIBlock(BinaryReader reader, Ext4SuperBlock superBlock, Ext4Inode[] inodes, + GFile parent, boolean isDirEntry2, Ext4IBlock i_block, TaskMonitor monitor) + throws CancelledException, IOException { + Ext4ExtentHeader header = i_block.getHeader(); + if (header.getEh_depth() == 0) { + short numEntries = header.getEh_entries(); + List entries = i_block.getExtentEntries(); + for (int i = 0; i < numEntries; i++) { + monitor.checkCanceled(); + Ext4Extent extent = entries.get(i); + long low = extent.getEe_start_lo() & 0xffffffffL; + long high = extent.getEe_start_hi() & 0xffffffffL; + long blockNumber = (high << 16) | low; long offset = blockNumber * blockSize; - reader.setPointerIndex( offset ); - if ( isDirEntry2 ) { - processDirEntry2( reader, superBlock, inodes, parent, monitor, extent, offset ); + reader.setPointerIndex(offset); + if (isDirEntry2) { + processDirEntry2(reader, superBlock, inodes, parent, monitor, extent, offset); } else { - processDirEntry( reader, superBlock, inodes, parent, monitor, extent, offset ); + processDirEntry(reader, superBlock, inodes, parent, monitor, extent, offset); } } } else { //throw new IOException( "Unhandled extent tree depth > 0 for inode " + index ); - short numEntries = header.getEh_entries( ); + short numEntries = header.getEh_entries(); List entries = i_block.getIndexEntries(); - for ( int i = 0; i < numEntries; i++ ) { - monitor.checkCanceled( ); + for (int i = 0; i < numEntries; i++) { + monitor.checkCanceled(); - Ext4ExtentIdx extentIndex = entries.get( i ); + Ext4ExtentIdx extentIndex = entries.get(i); long lo = extentIndex.getEi_leaf_lo(); long hi = extentIndex.getEi_leaf_hi(); - long physicalBlockOfNextLevel = ( hi << 16 ) | lo; + long physicalBlockOfNextLevel = (hi << 16) | lo; long offset = physicalBlockOfNextLevel * blockSize; // System.out.println( ""+physicalBlockOfNextLevel ); // System.out.println( "" ); - reader.setPointerIndex( offset ); - Ext4IBlock intermediateBlock = new Ext4IBlock( reader, true ); - processIBlock( reader, superBlock, inodes, parent, isDirEntry2, intermediateBlock, monitor ); + reader.setPointerIndex(offset); + Ext4IBlock intermediateBlock = new Ext4IBlock(reader, true); + processIBlock(reader, superBlock, inodes, parent, isDirEntry2, intermediateBlock, + monitor); } } } - private void processDirEntry( BinaryReader reader, - Ext4SuperBlock superBlock, - Ext4Inode [] inodes, - GFile parent, - TaskMonitor monitor, - Ext4Extent extent, - long offset ) throws CancelledException, IOException { + private void processDirEntry(BinaryReader reader, Ext4SuperBlock superBlock, Ext4Inode[] inodes, + GFile parent, TaskMonitor monitor, Ext4Extent extent, long offset) + throws CancelledException, IOException { - while ( ( reader.getPointerIndex( ) - offset ) < ( ( long ) extent.getEe_len( ) * blockSize ) ) { - monitor.checkCanceled( ); - if ( reader.peekNextInt( ) == 0 ) { + while ((reader.getPointerIndex() - offset) < ((long) extent.getEe_len() * blockSize)) { + monitor.checkCanceled(); + if (reader.peekNextInt() == 0) { return; } - Ext4DirEntry dirEnt = new Ext4DirEntry( reader ); - int childIndex = dirEnt.getInode( ); - Ext4Inode child = inodes[ childIndex ]; - if ( ( child.getI_mode( ) & Ext4Constants.I_MODE_MASK ) == Ext4Constants.S_IFDIR ) { - String childName = dirEnt.getName( ); - long readerOffset = reader.getPointerIndex( ); - processDirectory( reader, superBlock, inodes, childIndex, childName, parent, monitor ); - reader.setPointerIndex( readerOffset ); + Ext4DirEntry dirEnt = new Ext4DirEntry(reader); + int childIndex = dirEnt.getInode(); + Ext4Inode child = inodes[childIndex]; + if ((child.getI_mode() & Ext4Constants.I_MODE_MASK) == Ext4Constants.S_IFDIR) { + String childName = dirEnt.getName(); + long readerOffset = reader.getPointerIndex(); + processDirectory(reader, superBlock, inodes, childIndex, childName, parent, + monitor); + reader.setPointerIndex(readerOffset); } - else if ( ( child.getI_mode( ) & Ext4Constants.I_MODE_MASK ) == Ext4Constants.S_IFREG || ( child.getI_mode( ) & Ext4Constants.I_MODE_MASK ) == Ext4Constants.S_IFLNK ) { - storeFile( inodes, dirEnt, parent ); + else if ((child.getI_mode() & Ext4Constants.I_MODE_MASK) == Ext4Constants.S_IFREG || + (child.getI_mode() & Ext4Constants.I_MODE_MASK) == Ext4Constants.S_IFLNK) { + storeFile(inodes, dirEnt, parent); } else { - throw new IOException( "Inode " + dirEnt.getInode( ) + " has unhandled file type: " + ( child.getI_mode( ) & 0xF000 ) ); + throw new IOException("Inode " + dirEnt.getInode() + " has unhandled file type: " + + (child.getI_mode() & 0xF000)); } } } - private void processDirEntry2( BinaryReader reader, - Ext4SuperBlock superBlock, - Ext4Inode [] inodes, - GFile parent, - TaskMonitor monitor, - Ext4Extent extent, - long offset ) throws CancelledException, IOException { + private void processDirEntry2(BinaryReader reader, Ext4SuperBlock superBlock, + Ext4Inode[] inodes, GFile parent, TaskMonitor monitor, Ext4Extent extent, long offset) + throws CancelledException, IOException { - while ( ( reader.getPointerIndex( ) - offset ) < ( ( long ) extent.getEe_len( ) * blockSize ) ) { - monitor.checkCanceled( ); - if ( reader.peekNextInt( ) == 0 ) { + while ((reader.getPointerIndex() - offset) < ((long) extent.getEe_len() * blockSize)) { + monitor.checkCanceled(); + if (reader.peekNextInt() == 0) { return; } - Ext4DirEntry2 dirEnt2 = new Ext4DirEntry2( reader ); - if ( dirEnt2.getFile_type( ) == Ext4Constants.FILE_TYPE_DIRECTORY ) { - int childInode = dirEnt2.getInode( ); - String childName = dirEnt2.getName( ); - long readerOffset = reader.getPointerIndex( ); - processDirectory( reader, superBlock, inodes, childInode, childName, parent, monitor ); - reader.setPointerIndex( readerOffset ); + Ext4DirEntry2 dirEnt2 = new Ext4DirEntry2(reader); + if (dirEnt2.getFile_type() == Ext4Constants.FILE_TYPE_DIRECTORY) { + int childInode = dirEnt2.getInode(); + String childName = dirEnt2.getName(); + long readerOffset = reader.getPointerIndex(); + processDirectory(reader, superBlock, inodes, childInode, childName, parent, + monitor); + reader.setPointerIndex(readerOffset); } - else if ( dirEnt2.getFile_type( ) == Ext4Constants.FILE_TYPE_REGULAR_FILE || dirEnt2.getFile_type( ) == Ext4Constants.FILE_TYPE_SYMBOLIC_LINK ) { - storeFile( inodes, dirEnt2, parent ); + else if (dirEnt2.getFile_type() == Ext4Constants.FILE_TYPE_REGULAR_FILE || + dirEnt2.getFile_type() == Ext4Constants.FILE_TYPE_SYMBOLIC_LINK) { + storeFile(inodes, dirEnt2, parent); } else { - throw new IOException( "Inode " + dirEnt2.getInode( ) + " has unhandled file type: " + dirEnt2.getFile_type( ) ); + throw new IOException("Inode " + dirEnt2.getInode() + " has unhandled file type: " + + dirEnt2.getFile_type()); } } } - private void storeFile( Ext4Inode [] inodes, Ext4DirEntry dirEnt, GFile parent ) { - int fileInodeNum = dirEnt.getInode( ); - Ext4Inode fileInode = inodes[ fileInodeNum ]; - long fileSize = ( fileInode.getI_size_high( ) << 32 ) | fileInode.getI_size_lo( ); - fsih.storeFileWithParent( dirEnt.getName( ), parent, -1, ( fileInode.getI_mode( ) & Ext4Constants.I_MODE_MASK ) == Ext4Constants.S_IFDIR, fileSize, - new Ext4File( dirEnt.getName( ), fileInode ) ); - inodes[ fileInodeNum ] = null; + private void storeFile(Ext4Inode[] inodes, Ext4DirEntry dirEnt, GFile parent) { + int fileInodeNum = dirEnt.getInode(); + Ext4Inode fileInode = inodes[fileInodeNum]; + long fileSize = (fileInode.getI_size_high() << 32) | fileInode.getI_size_lo(); + fsih.storeFileWithParent(dirEnt.getName(), parent, -1, + (fileInode.getI_mode() & Ext4Constants.I_MODE_MASK) == Ext4Constants.S_IFDIR, fileSize, + new Ext4File(dirEnt.getName(), fileInode)); + inodes[fileInodeNum] = null; } - private void storeFile( Ext4Inode [] inodes, Ext4DirEntry2 dirEnt2, GFile parent ) { - int fileInodeNum = dirEnt2.getInode( ); - Ext4Inode fileInode = inodes[ fileInodeNum ]; - if ( fileInode == null ) { + private void storeFile(Ext4Inode[] inodes, Ext4DirEntry2 dirEnt2, GFile parent) { + int fileInodeNum = dirEnt2.getInode(); + Ext4Inode fileInode = inodes[fileInodeNum]; + if (fileInode == null) { return;//TODO } - long fileSize = ( fileInode.getI_size_high( ) << 32 ) | fileInode.getI_size_lo( ); - fsih.storeFileWithParent( dirEnt2.getName( ), parent, -1, dirEnt2.getFile_type( ) == Ext4Constants.FILE_TYPE_DIRECTORY, fileSize, new Ext4File( dirEnt2.getName( ), fileInode ) ); - inodes[ fileInodeNum ] = null; + long fileSize = (fileInode.getI_size_high() << 32) | fileInode.getI_size_lo(); + fsih.storeFileWithParent(dirEnt2.getName(), parent, -1, + dirEnt2.getFile_type() == Ext4Constants.FILE_TYPE_DIRECTORY, fileSize, + new Ext4File(dirEnt2.getName(), fileInode)); + inodes[fileInodeNum] = null; } - private void processFile( BinaryReader reader, Ext4SuperBlock superBlock, Ext4Inode inode, TaskMonitor monitor ) { + private void processFile(BinaryReader reader, Ext4SuperBlock superBlock, Ext4Inode inode, + TaskMonitor monitor) { } @@ -272,7 +270,7 @@ public class Ext4FileSystem implements GFileSystem { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { Ext4File ext4File = fsih.getMetadata(file); if (ext4File == null) { return null; @@ -337,7 +335,7 @@ public class Ext4FileSystem implements GFileSystem { throw new IOException("Not parent file for " + file); } symlinkDestPath = - FSUtilities.appendPath(file.getParentFile().getPath(), symlinkDestPath); + FSUtilities.appendPath(file.getParentFile().getPath(), symlinkDestPath); } file = lookup(symlinkDestPath); @@ -347,17 +345,17 @@ public class Ext4FileSystem implements GFileSystem { } private InputStream getInputStream(Ext4Inode inode) throws IOException { - int i_size_lo = inode.getI_size_lo( ); - int i_size_high = inode.getI_size_high( ); - long size = ( i_size_high << 32 ) | i_size_lo; + int i_size_lo = inode.getI_size_lo(); + int i_size_high = inode.getI_size_high(); + long size = (i_size_high << 32) | i_size_lo; - boolean usesExtents = ( inode.getI_flags( ) & Ext4Constants.EXT4_EXTENTS_FL ) != 0; - if ( usesExtents ) { - Ext4IBlock i_block = inode.getI_block( ); - Ext4ExtentHeader header = i_block.getHeader( ); - if ( header.getEh_depth( ) == 0 ) { - List< Ext4Extent > entries = i_block.getExtentEntries( ); - return concatenateExtents( entries, size ); + boolean usesExtents = (inode.getI_flags() & Ext4Constants.EXT4_EXTENTS_FL) != 0; + if (usesExtents) { + Ext4IBlock i_block = inode.getI_block(); + Ext4ExtentHeader header = i_block.getHeader(); + if (header.getEh_depth() == 0) { + List entries = i_block.getExtentEntries(); + return concatenateExtents(entries, size); } } return null; @@ -369,65 +367,67 @@ public class Ext4FileSystem implements GFileSystem { * * TODO better memory management? currently loads entire file into memory. */ - private InputStream concatenateExtents( List< Ext4Extent > entries, long actualSize ) throws IOException { - if ( actualSize > Integer.MAX_VALUE ) { - throw new IOException( "File is >2GB, too large to extract. Please report to Ghidra team." ); + private InputStream concatenateExtents(List entries, long actualSize) + throws IOException { + if (actualSize > Integer.MAX_VALUE) { + throw new IOException( + "File is >2GB, too large to extract. Please report to Ghidra team."); } - ByteArrayOutputStream baos = new ByteArrayOutputStream( ); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); - for ( int i = 0 ; i < entries.size( ) ; ++i ) { - Ext4Extent extent = entries.get( i ); + for (int i = 0; i < entries.size(); ++i) { + Ext4Extent extent = entries.get(i); - long low = extent.getEe_start_lo( ) & 0xffffffffL; - long high = extent.getEe_start_hi( ) & 0xffffffffL; - long blockNumber = ( high << 16 ) | low; + long low = extent.getEe_start_lo() & 0xffffffffL; + long high = extent.getEe_start_hi() & 0xffffffffL; + long blockNumber = (high << 16) | low; long extentOffset = blockNumber * blockSize; - long extentSize = ( extent.getEe_len( ) & 0xffffL ) * blockSize; + long extentSize = (extent.getEe_len() & 0xffffL) * blockSize; try { - byte [] extentBytes = provider.readBytes( extentOffset, extentSize ); - baos.write( extentBytes ); + byte[] extentBytes = provider.readBytes(extentOffset, extentSize); + baos.write(extentBytes); } - catch ( IOException e ) { + catch (IOException e) { // ignore } } - return new ByteArrayInputStream( baos.toByteArray( ), 0, (int) actualSize ); + return new ByteArrayInputStream(baos.toByteArray(), 0, (int) actualSize); } - private Ext4Inode [] getInodes( BinaryReader reader, - Ext4SuperBlock superBlock, - Ext4GroupDescriptor [] groupDescriptors, - boolean is64Bit, - TaskMonitor monitor ) throws IOException, CancelledException { + private Ext4Inode[] getInodes(BinaryReader reader, Ext4SuperBlock superBlock, + Ext4GroupDescriptor[] groupDescriptors, boolean is64Bit, TaskMonitor monitor) + throws IOException, CancelledException { - int inodeCount = superBlock.getS_inodes_count( ); - Ext4Inode [] inodes = new Ext4Inode [ inodeCount + 1 ]; + int inodeCount = superBlock.getS_inodes_count(); + Ext4Inode[] inodes = new Ext4Inode[inodeCount + 1]; int inodeIndex = 1; - for ( int i = 0; i < groupDescriptors.length; i++ ) { - monitor.checkCanceled( ); - long inodeTableBlockOffset = groupDescriptors[ i ].getBg_inode_table_lo( ) & 0xffffffffL; - if ( is64Bit ) { - inodeTableBlockOffset = ( groupDescriptors[ i ].getBg_inode_table_hi( ) << 32 ) | inodeTableBlockOffset; + for (int i = 0; i < groupDescriptors.length; i++) { + monitor.checkCanceled(); + long inodeTableBlockOffset = groupDescriptors[i].getBg_inode_table_lo() & 0xffffffffL; + if (is64Bit) { + inodeTableBlockOffset = + (groupDescriptors[i].getBg_inode_table_hi() << 32) | inodeTableBlockOffset; } long offset = inodeTableBlockOffset * blockSize; - reader.setPointerIndex( offset ); - int inodesPerGroup = superBlock.getS_inodes_per_group( ); - monitor.setMessage( "Reading inode table " + i + " of " + ( groupDescriptors.length - 1 ) + "..." ); - monitor.setMaximum( inodesPerGroup ); - monitor.setProgress( 0 ); - for ( int j = 0; j < inodesPerGroup; j++ ) { - monitor.checkCanceled( ); - monitor.incrementProgress( 1 ); + reader.setPointerIndex(offset); + int inodesPerGroup = superBlock.getS_inodes_per_group(); + monitor.setMessage( + "Reading inode table " + i + " of " + (groupDescriptors.length - 1) + "..."); + monitor.setMaximum(inodesPerGroup); + monitor.setProgress(0); + for (int j = 0; j < inodesPerGroup; j++) { + monitor.checkCanceled(); + monitor.incrementProgress(1); - Ext4Inode inode = new Ext4Inode( reader ); - offset = offset + superBlock.getS_inode_size( ); - reader.setPointerIndex( offset ); + Ext4Inode inode = new Ext4Inode(reader); + offset = offset + superBlock.getS_inode_size(); + reader.setPointerIndex(offset); - inodes[ inodeIndex++ ] = inode; //inodes[ inodesPerGroup * i + j ] = inode; + inodes[inodeIndex++] = inode; //inodes[ inodesPerGroup * i + j ] = inode; } } return inodes; diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/gzip/GZipFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/gzip/GZipFileSystem.java index 68b90c5a6b..80957271c3 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/gzip/GZipFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/gzip/GZipFileSystem.java @@ -147,12 +147,11 @@ public class GZipFileSystem implements GFileSystem { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { if (payload.equals(file)) { return FSUtilities.infoMapToString(getInfoMap()); } return null; - } public Map getInfoMap() { diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/apple8900/Apple8900FileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/apple8900/Apple8900FileSystem.java index 382c15abc8..bf220987a7 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/apple8900/Apple8900FileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/apple8900/Apple8900FileSystem.java @@ -81,9 +81,4 @@ public class Apple8900FileSystem extends GFileSystemBase { dataFile = GFileImpl.fromFilename(this, root, "DATA", false, header.getSizeOfData(), null); } - - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } } diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dmg/DmgClientFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dmg/DmgClientFileSystem.java index e511c89673..8f37de003e 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dmg/DmgClientFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dmg/DmgClientFileSystem.java @@ -15,16 +15,16 @@ */ package ghidra.file.formats.ios.dmg; +import java.io.*; +import java.util.ArrayList; +import java.util.List; + import ghidra.formats.gfilesystem.*; import ghidra.formats.gfilesystem.annotations.FileSystemInfo; import ghidra.util.Msg; import ghidra.util.exception.CancelledException; import ghidra.util.task.*; -import java.io.*; -import java.util.ArrayList; -import java.util.List; - /** * A {@link GFileSystem} that uses an external DMG server process to parse DMG files * and presents the contents as a filesystem. @@ -200,7 +200,7 @@ public class DmgClientFileSystem implements GFileSystem { } @Override - public String getInfo(GFile gFile, TaskMonitor monitor) throws IOException { + public String getInfo(GFile gFile, TaskMonitor monitor) { monitor.addCancelledListener(listener); StringBuffer buffer = new StringBuffer(); diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dyldcache/DyldCacheFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dyldcache/DyldCacheFileSystem.java index f6ac1f863e..2d23778815 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dyldcache/DyldCacheFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/dyldcache/DyldCacheFileSystem.java @@ -111,11 +111,6 @@ public class DyldCacheFileSystem extends GFileSystemBase { } */ - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } - @Override public List getListing(GFile directory) throws IOException { if (directory == null || directory.equals(root)) { diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ibootim/iBootImFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ibootim/iBootImFileSystem.java index 4748880fb6..7a5580cb44 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ibootim/iBootImFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ibootim/iBootImFileSystem.java @@ -32,8 +32,8 @@ import ghidra.util.exception.CancelledException; import ghidra.util.exception.CryptoException; import ghidra.util.task.TaskMonitor; -@FileSystemInfo(type = "ibootim", description = "iOS " - + iBootImConstants.SIGNATURE, factory = GFileSystemBaseFactory.class) +@FileSystemInfo(type = "ibootim", description = "iOS " + + iBootImConstants.SIGNATURE, factory = GFileSystemBaseFactory.class) public class iBootImFileSystem extends GFileSystemBase implements GIconProvider { private iBootImHeader header; @@ -59,19 +59,15 @@ public class iBootImFileSystem extends GFileSystemBase implements GIconProvider public Icon getIcon(GFile file, TaskMonitor monitor) throws IOException, CancelledException { File cacheFile = fsService.getFile(file.getFSRL(), monitor); try (InputStream cacheInputStream = new FileInputStream(cacheFile)) { - GImageFormat format = (header.getFormat() == iBootImConstants.FORMAT_ARGB) ? GImageFormat.RGB_ALPHA_4BYTE - : GImageFormat.GRAY_ALPHA_2BYTE; - GImage image = new GImage(header.getWidth(), header.getHeight(), format, cacheInputStream, - cacheFile.length()); + GImageFormat format = + (header.getFormat() == iBootImConstants.FORMAT_ARGB) ? GImageFormat.RGB_ALPHA_4BYTE + : GImageFormat.GRAY_ALPHA_2BYTE; + GImage image = new GImage(header.getWidth(), header.getHeight(), format, + cacheInputStream, cacheFile.length()); return image.toPNG(); } } - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } - @Override public List getListing(GFile directory) throws IOException { if (directory == null || directory.equals(root)) { diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/img2/Img2FileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/img2/Img2FileSystem.java index 63d452ba2a..7fd85ff48b 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/img2/Img2FileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/img2/Img2FileSystem.java @@ -55,11 +55,6 @@ public class Img2FileSystem extends GFileSystemBase { return null; } - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } - @Override public List getListing(GFile directory) throws IOException { return (directory == null || directory.equals(root)) ? Arrays.asList(imageTypeFile) diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ipsw/IpswFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ipsw/IpswFileSystem.java index f4f027b8cd..861d99e3d4 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ipsw/IpswFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/ipsw/IpswFileSystem.java @@ -57,11 +57,6 @@ public class IpswFileSystem extends GFileSystemBase { return new ArrayList<>(); } - @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { - return null; - } - @Override protected InputStream getData(GFile file, TaskMonitor monitor) throws IOException, CancelledException, CryptoException { diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGFileSystem.java index b2fe46da02..33a58be34f 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGFileSystem.java @@ -92,7 +92,7 @@ public class CrushedPNGFileSystem extends GFileSystemBase { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { return png.toString(); } diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/prelink/PrelinkFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/prelink/PrelinkFileSystem.java index 3f55a04a15..e4cc35001c 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/prelink/PrelinkFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/prelink/PrelinkFileSystem.java @@ -118,12 +118,9 @@ public class PrelinkFileSystem extends GFileSystemBase implements GFileSystemPro } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { PrelinkMap info = fileToPrelinkInfoMap.get(file); - if (info != null) { - return info.toString(); - } - return null; + return (info != null) ? info.toString() : null; } @Override diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/iso9660/ISO9660FileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/iso9660/ISO9660FileSystem.java index ec6ad4fa59..1aa69a27a8 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/iso9660/ISO9660FileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/iso9660/ISO9660FileSystem.java @@ -160,7 +160,7 @@ public class ISO9660FileSystem extends GFileSystemBase { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { ISO9660Directory dir = fileToDirectoryMap.get(file); if (dir != null) { return dir.toString(); diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/java/JavaClassDecompilerFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/java/JavaClassDecompilerFileSystem.java index c7511e2727..c727f5fd9e 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/java/JavaClassDecompilerFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/java/JavaClassDecompilerFileSystem.java @@ -139,7 +139,7 @@ public class JavaClassDecompilerFileSystem implements GFileSystem { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { if (fsIndexHelper.getPayloadFile().equals(file)) { Map info = new HashMap<>(); info.put("Class name", className); diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/omf/OmfArchiveFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/omf/OmfArchiveFileSystem.java index 0d4ea5a166..365b13fc1f 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/omf/OmfArchiveFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/omf/OmfArchiveFileSystem.java @@ -110,7 +110,7 @@ public class OmfArchiveFileSystem implements GFileSystem { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { OmfLibraryRecord.MemberHeader entry = fsih.getMetadata(file); return (entry == null) ? null : FSUtilities.infoMapToString(getInfoMap(entry)); } diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/sevenzip/SevenZipFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/sevenzip/SevenZipFileSystem.java index b7ccd0e523..4fd784b11e 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/sevenzip/SevenZipFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/sevenzip/SevenZipFileSystem.java @@ -180,7 +180,7 @@ public class SevenZipFileSystem extends GFileSystemBase { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { ISimpleInArchiveItem entry = map.get(file); StringBuffer buffer = new StringBuffer(); try { diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/sparseimage/SparseImageFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/sparseimage/SparseImageFileSystem.java index a6f7e3f650..4ed6ca4fb1 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/sparseimage/SparseImageFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/sparseimage/SparseImageFileSystem.java @@ -15,15 +15,15 @@ */ package ghidra.file.formats.sparseimage; +import java.io.*; +import java.util.*; + import ghidra.app.util.bin.ByteProvider; import ghidra.formats.gfilesystem.*; import ghidra.formats.gfilesystem.annotations.FileSystemInfo; import ghidra.util.exception.CancelledException; import ghidra.util.task.TaskMonitor; -import java.io.*; -import java.util.*; - /** * A pseudo filesystem that contains a single file that is the decompressed contents * of the sparse container file. @@ -101,7 +101,7 @@ public class SparseImageFileSystem implements GFileSystem { SparseImageDecompressor sid = new SparseImageDecompressor(provider, os); sid.decompress(monitor); } - } , monitor); + }, monitor); } @Override @@ -123,7 +123,7 @@ public class SparseImageFileSystem implements GFileSystem { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { if (payload.equals(file)) { return FSUtilities.infoMapToString(getInfoMap()); } diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/tar/TarFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/tar/TarFileSystem.java index af1eaae4ca..bb5d3e7826 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/tar/TarFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/tar/TarFileSystem.java @@ -15,17 +15,17 @@ */ package ghidra.file.formats.tar; -import ghidra.formats.gfilesystem.*; -import ghidra.formats.gfilesystem.annotations.FileSystemInfo; -import ghidra.util.exception.CancelledException; -import ghidra.util.task.TaskMonitor; - import java.io.*; import java.util.*; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import ghidra.formats.gfilesystem.*; +import ghidra.formats.gfilesystem.annotations.FileSystemInfo; +import ghidra.util.exception.CancelledException; +import ghidra.util.task.TaskMonitor; + /** * TAR file system implementation. *

@@ -169,12 +169,9 @@ public class TarFileSystem implements GFileSystem { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { TarMetadata tmd = fsih.getMetadata(file); - if (tmd == null) { - throw new IOException("Unknown file " + file); - } - return FSUtilities.infoMapToString(getInfoMap(tmd.tarArchiveEntry)); + return (tmd != null) ? FSUtilities.infoMapToString(getInfoMap(tmd.tarArchiveEntry)) : null; } @Override diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ubi/UniversalBinaryFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ubi/UniversalBinaryFileSystem.java index fd9d0bb5ba..c1f377bdba 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ubi/UniversalBinaryFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ubi/UniversalBinaryFileSystem.java @@ -45,12 +45,9 @@ public class UniversalBinaryFileSystem extends GFileSystemBase { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { int index = list.indexOf(file); - if (index == -1) { - return null; - } - return header.getArchitectures().get(index).toString(); + return (index != -1) ? header.getArchitectures().get(index).toString() : null; } @Override @@ -79,7 +76,8 @@ public class UniversalBinaryFileSystem extends GFileSystemBase { Processor processor = CpuTypes.getProcessor(architecture.getCpuType(), architecture.getCpuSubType()); int bitSize = CpuTypes.getProcessorBitSize(architecture.getCpuType()); - String name = processor + "-" + bitSize + "-cpu0x" + Integer.toHexString(architecture.getCpuSubType()); + String name = processor + "-" + bitSize + "-cpu0x" + + Integer.toHexString(architecture.getCpuSubType()); GFileImpl file = GFileImpl.fromFilename(this, root, name, false, architecture.getSize(), null); list.add(file); @@ -100,7 +98,8 @@ public class UniversalBinaryFileSystem extends GFileSystemBase { FatArch architecture = architectures.get(index); - return new BoundedInputStream(provider.getInputStream(architecture.getOffset()), architecture.getSize()); + return new BoundedInputStream(provider.getInputStream(architecture.getOffset()), + architecture.getSize()); } @Override diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/yaffs2/YAFFS2FileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/yaffs2/YAFFS2FileSystem.java index 3b5d341868..bd186cd028 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/yaffs2/YAFFS2FileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/yaffs2/YAFFS2FileSystem.java @@ -98,7 +98,7 @@ public class YAFFS2FileSystem extends GFileSystemBase { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { return "YAFFS2, Yet Another Flash File System V2, commonly used for Android System and UserData images."; } diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/zip/ZipFileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/zip/ZipFileSystem.java index d86d396bb8..dc2b135adf 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/zip/ZipFileSystem.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/zip/ZipFileSystem.java @@ -117,9 +117,9 @@ public class ZipFileSystem implements GFileSystem { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { ZipEntry zipEntry = fsIndexHelper.getMetadata(file); - return FSUtilities.infoMapToString(getInfoMap(zipEntry)); + return (zipEntry != null) ? FSUtilities.infoMapToString(getInfoMap(zipEntry)) : null; } @Override diff --git a/GhidraBuild/Skeleton/src/main/java/skeleton/SkeletonFileSystem.java b/GhidraBuild/Skeleton/src/main/java/skeleton/SkeletonFileSystem.java index 3d88ead2d1..d6119ea9b8 100644 --- a/GhidraBuild/Skeleton/src/main/java/skeleton/SkeletonFileSystem.java +++ b/GhidraBuild/Skeleton/src/main/java/skeleton/SkeletonFileSystem.java @@ -30,10 +30,8 @@ import ghidra.util.task.TaskMonitor; /** * TODO: Provide class-level documentation that describes what this file system does. */ -@FileSystemInfo( - type = "fstypegoeshere", // ([a-z0-9]+ only) - description = "File system description goes here", - factory = SkeletonFileSystem.MyFileSystemFactory.class) +@FileSystemInfo(type = "fstypegoeshere", // ([a-z0-9]+ only) + description = "File system description goes here", factory = SkeletonFileSystem.MyFileSystemFactory.class) public class SkeletonFileSystem implements GFileSystem { private final FSRLRoot fsFSRL; @@ -130,7 +128,7 @@ public class SkeletonFileSystem implements GFileSystem { } @Override - public String getInfo(GFile file, TaskMonitor monitor) throws IOException { + public String getInfo(GFile file, TaskMonitor monitor) { MyMetadata metadata = fsih.getMetadata(file); return (metadata == null) ? null : FSUtilities.infoMapToString(getInfoMap(metadata)); }