Slightly Better Resource Importing
This commit is contained in:
parent
ad660815f3
commit
c38bc180d9
2 changed files with 34 additions and 25 deletions
|
@ -1,13 +1,10 @@
|
|||
package the.bytecode.club.bytecodeviewer.resources.importing;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||
import the.bytecode.club.bytecodeviewer.Settings;
|
||||
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
|
||||
import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListPane;
|
||||
import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
/***************************************************************************
|
||||
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
||||
|
@ -65,7 +62,7 @@ public class ImportResource implements Runnable
|
|||
Import.CLASS.getImporter().open(file);
|
||||
|
||||
//everything else import as a resource
|
||||
else if(!importFile(file))
|
||||
else if(!importKnownFile(file))
|
||||
Import.FILE.getImporter().open(file);
|
||||
}
|
||||
}
|
||||
|
@ -82,29 +79,42 @@ public class ImportResource implements Runnable
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean importFile(File file) throws Exception
|
||||
/**
|
||||
* Imports a file using File-Specific importers/decoders
|
||||
*/
|
||||
public static boolean importKnownFile(File file) throws Exception
|
||||
{
|
||||
final String fn = file.getName();
|
||||
final String fn = FilenameUtils.getName(file.getName()).toLowerCase();
|
||||
final String extension = fn.contains(":") ? null : FilenameUtils.getExtension(fn);
|
||||
|
||||
//check for zip archives
|
||||
if (fn.endsWith(".jar") || fn.endsWith(".zip") || fn.endsWith(".war") || fn.endsWith(".ear"))
|
||||
Import.ZIP.getImporter().open(file);
|
||||
switch(extension)
|
||||
{
|
||||
//check for zip archives
|
||||
case "jar":
|
||||
case "zip":
|
||||
case "war":
|
||||
case "ear": //TODO ear needs to work the same as XAPK
|
||||
Import.ZIP.getImporter().open(file);
|
||||
break;
|
||||
|
||||
//check for XAPKs
|
||||
else if (fn.endsWith(".xapk"))
|
||||
Import.XAPK.getImporter().open(file);
|
||||
//check for XAPKs
|
||||
case "xapk":
|
||||
Import.XAPK.getImporter().open(file);
|
||||
break;
|
||||
|
||||
//check for APKs
|
||||
else if (fn.endsWith(".apk"))
|
||||
Import.APK.getImporter().open(file);
|
||||
//check for APKs
|
||||
case "apk":
|
||||
Import.APK.getImporter().open(file);
|
||||
break;
|
||||
|
||||
//check for DEX
|
||||
else if (fn.endsWith(".dex"))
|
||||
Import.DEX.getImporter().open(file);
|
||||
|
||||
//return false
|
||||
else
|
||||
return false;
|
||||
//check for DEX
|
||||
case "dex":
|
||||
Import.DEX.getImporter().open(file);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package the.bytecode.club.bytecodeviewer.resources.importing.impl;
|
|||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||
import the.bytecode.club.bytecodeviewer.resources.importing.Import;
|
||||
import the.bytecode.club.bytecodeviewer.resources.importing.ImportResource;
|
||||
import the.bytecode.club.bytecodeviewer.resources.importing.Importer;
|
||||
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
|
||||
|
@ -62,7 +61,7 @@ public class DirectoryResourceImporter implements Importer
|
|||
final String fileName = child.getName();
|
||||
|
||||
//attempt to import archives automatically
|
||||
if(ImportResource.importFile(file))
|
||||
if(ImportResource.importKnownFile(file))
|
||||
{
|
||||
//let import resource handle it
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue