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;
|
package the.bytecode.club.bytecodeviewer.resources.importing;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||||
import the.bytecode.club.bytecodeviewer.Settings;
|
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.io.File;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
||||||
|
@ -65,7 +62,7 @@ public class ImportResource implements Runnable
|
||||||
Import.CLASS.getImporter().open(file);
|
Import.CLASS.getImporter().open(file);
|
||||||
|
|
||||||
//everything else import as a resource
|
//everything else import as a resource
|
||||||
else if(!importFile(file))
|
else if(!importKnownFile(file))
|
||||||
Import.FILE.getImporter().open(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
|
switch(extension)
|
||||||
if (fn.endsWith(".jar") || fn.endsWith(".zip") || fn.endsWith(".war") || fn.endsWith(".ear"))
|
{
|
||||||
Import.ZIP.getImporter().open(file);
|
//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
|
//check for XAPKs
|
||||||
else if (fn.endsWith(".xapk"))
|
case "xapk":
|
||||||
Import.XAPK.getImporter().open(file);
|
Import.XAPK.getImporter().open(file);
|
||||||
|
break;
|
||||||
|
|
||||||
//check for APKs
|
//check for APKs
|
||||||
else if (fn.endsWith(".apk"))
|
case "apk":
|
||||||
Import.APK.getImporter().open(file);
|
Import.APK.getImporter().open(file);
|
||||||
|
break;
|
||||||
|
|
||||||
//check for DEX
|
//check for DEX
|
||||||
else if (fn.endsWith(".dex"))
|
case "dex":
|
||||||
Import.DEX.getImporter().open(file);
|
Import.DEX.getImporter().open(file);
|
||||||
|
break;
|
||||||
//return false
|
|
||||||
else
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package the.bytecode.club.bytecodeviewer.resources.importing.impl;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
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.ImportResource;
|
||||||
import the.bytecode.club.bytecodeviewer.resources.importing.Importer;
|
import the.bytecode.club.bytecodeviewer.resources.importing.Importer;
|
||||||
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
|
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
|
||||||
|
@ -62,7 +61,7 @@ public class DirectoryResourceImporter implements Importer
|
||||||
final String fileName = child.getName();
|
final String fileName = child.getName();
|
||||||
|
|
||||||
//attempt to import archives automatically
|
//attempt to import archives automatically
|
||||||
if(ImportResource.importFile(file))
|
if(ImportResource.importKnownFile(file))
|
||||||
{
|
{
|
||||||
//let import resource handle it
|
//let import resource handle it
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue