Better Resource Importing
This commit is contained in:
parent
c38bc180d9
commit
07bbfaf299
2 changed files with 29 additions and 35 deletions
|
@ -2,6 +2,8 @@ package the.bytecode.club.bytecodeviewer.resources.importing;
|
||||||
|
|
||||||
import the.bytecode.club.bytecodeviewer.resources.importing.impl.*;
|
import the.bytecode.club.bytecodeviewer.resources.importing.impl.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
||||||
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
|
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
|
||||||
|
@ -28,16 +30,29 @@ public enum Import
|
||||||
{
|
{
|
||||||
DIRECTORY(new DirectoryResourceImporter()),
|
DIRECTORY(new DirectoryResourceImporter()),
|
||||||
FILE(new FileResourceImporter()),
|
FILE(new FileResourceImporter()),
|
||||||
ZIP(new ZipResourceImporter()),
|
//TODO ear needs to work the same as XAPK
|
||||||
CLASS(new ClassResourceImporter()),
|
ZIP(new ZipResourceImporter(), "zip", "jar", "war", "ear"),
|
||||||
XAPK(new XAPKResourceImporter()),
|
CLASS(new ClassResourceImporter(), "class"),
|
||||||
APK(new APKResourceImporter()),
|
XAPK(new XAPKResourceImporter(), "xapk"),
|
||||||
DEX(new DEXResourceImporter()),
|
APK(new APKResourceImporter(), "apk"),
|
||||||
|
DEX(new DEXResourceImporter(), "dex"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Importer importer;
|
public static final HashMap<String, Import> extensionMap = new HashMap<>();
|
||||||
|
|
||||||
Import(Importer importer) {this.importer = importer;}
|
private final Importer importer;
|
||||||
|
private final String[] extensions;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
for(Import i : values())
|
||||||
|
for(String s : i.extensions)
|
||||||
|
extensionMap.put(s, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
Import(Importer importer, String... extensions) {this.importer = importer;
|
||||||
|
this.extensions = extensions;
|
||||||
|
}
|
||||||
|
|
||||||
public Importer getImporter()
|
public Importer getImporter()
|
||||||
{
|
{
|
||||||
|
|
|
@ -87,34 +87,13 @@ public class ImportResource implements Runnable
|
||||||
final String fn = FilenameUtils.getName(file.getName()).toLowerCase();
|
final String fn = FilenameUtils.getName(file.getName()).toLowerCase();
|
||||||
final String extension = fn.contains(":") ? null : FilenameUtils.getExtension(fn);
|
final String extension = fn.contains(":") ? null : FilenameUtils.getExtension(fn);
|
||||||
|
|
||||||
switch(extension)
|
Import imp = Import.extensionMap.get(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
|
if(imp == null)
|
||||||
case "xapk":
|
|
||||||
Import.XAPK.getImporter().open(file);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//check for APKs
|
|
||||||
case "apk":
|
|
||||||
Import.APK.getImporter().open(file);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//check for DEX
|
|
||||||
case "dex":
|
|
||||||
Import.DEX.getImporter().open(file);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
//import/decode the file using the file specific importer
|
||||||
|
imp.getImporter().open(file);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue