diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index c62924d5..5e818e48 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -84,6 +84,7 @@ import static the.bytecode.club.bytecodeviewer.util.MiscUtils.guessLanguage; * + Krakatau Assembly compile - Needs to be fixed * * TODO IN-PROGRESS: + * + Resource Importer needs to be rewriten to handle resources better * + Finish dragging code * + Finish right-click tab menu detection * + Fix hook inject for EZ-Injection diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java b/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java index ea756219..a20c24c0 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Constants.java @@ -43,7 +43,7 @@ public class Constants public static final String libsDirectory = getBCVDirectory() + fs + "libs" + fs; public static String krakatauWorkingDirectory = getBCVDirectory() + fs + "krakatau_" + krakatauVersion; public static String enjarifyWorkingDirectory = getBCVDirectory() + fs + "enjarify_" + enjarifyVersion; - public static final String[] SUPPORTED_FILE_EXTENSIONS = new String[]{"jar", "zip", "class", "apk", "dex", "war", "jsp"}; + public static final String[] SUPPORTED_FILE_EXTENSIONS = new String[]{"jar", "zip", "class", "apk", "xapk", "dex", "war", "jsp"}; /** * Returns the BCV directory diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ImageRenderer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ImageRenderer.java index c9c18fc0..c0b74792 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ImageRenderer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcelist/ImageRenderer.java @@ -53,7 +53,7 @@ public class ImageRenderer extends DefaultTreeCellRenderer { setIcon(Resources.cplusplusIcon); } - else if (name.endsWith(".apk") || name.endsWith(".dex")) + else if (name.endsWith(".xapk") || name.endsWith(".apk") || name.endsWith(".dex")) { setIcon(Resources.androidIcon); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/Import.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/Import.java index 2e7f3995..e2d01271 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/Import.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/Import.java @@ -12,6 +12,7 @@ public enum Import FILE(new FileResourceImporter()), ZIP(new ZipResourceImporter()), CLASS(new ClassResourceImporter()), + XAPK(new XAPKResourceImporter()), APK(new APKResourceImporter()), DEX(new DEXResourceImporter()), ; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java index 6f441473..a31e5e01 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java @@ -68,6 +68,11 @@ public class ImportResource implements Runnable if(!Import.CLASS.getImporter().open(file)) update = false; } + else if (fn.endsWith(".xapk")) + { + Import.XAPK.getImporter().open(file); + return; + } else if (fn.endsWith(".apk")) { Import.APK.getImporter().open(file); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java new file mode 100644 index 00000000..715d923f --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java @@ -0,0 +1,86 @@ +package the.bytecode.club.bytecodeviewer.resources.importing.impl; + +import me.konloch.kontainer.io.DiskWriter; +import org.apache.commons.io.IOUtils; +import org.objectweb.asm.tree.ClassNode; +import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; +import the.bytecode.club.bytecodeviewer.resources.importing.Import; +import the.bytecode.club.bytecodeviewer.resources.importing.Importer; +import the.bytecode.club.bytecodeviewer.util.FileContainer; +import the.bytecode.club.bytecodeviewer.util.MiscUtils; + +import java.io.*; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.zip.ZipEntry; + +import static the.bytecode.club.bytecodeviewer.Constants.fs; +import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory; + +/** + * Compressed APKs (XAPK) + * + * @author Konloch + * @since 6/26/2021 + */ +public class XAPKResourceImporter implements Importer +{ + @Override + public boolean open(File file) throws Exception + { + FileContainer container = new FileContainer(file); + HashMap allDirectoryFiles = new HashMap<>(); + HashMap allDirectoryClasses = new HashMap<>(); + + Configuration.silenceExceptionGUI++; //turn exceptions off + try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(file)) + { + Enumeration entries = zipFile.entries(); + while (entries.hasMoreElements()) + { + final ZipEntry entry = entries.nextElement(); + final String fileName = entry.getName(); + + if(entry.isDirectory()) + continue; + + if (fileName.endsWith(".apk")) + { + File tempFile = new File(tempDirectory + fs + "temp" + MiscUtils.randomString(32) + fs + entry); + tempFile.getParentFile().mkdirs(); + + try (InputStream in = zipFile.getInputStream(entry); + OutputStream out = new FileOutputStream(tempFile)) + { + IOUtils.copy(in, out); + } + Import.APK.getImporter().open(tempFile); + } + else + { + //pack files into a single container + byte[] bytes; + try (InputStream in = zipFile.getInputStream(entry)) + { + bytes = IOUtils.toByteArray(in); + } + allDirectoryFiles.put(fileName, bytes); + } + } + } + Configuration.silenceExceptionGUI--; //turn exceptions back on + + container.classes.addAll(allDirectoryClasses.values()); + container.files = allDirectoryFiles; + BytecodeViewer.files.add(container); + return true; + } + + public File exportTo(File original, String extension, byte[] bytes) + { + File file = new File(original.getAbsolutePath() + extension); + DiskWriter.replaceFile(file.getAbsolutePath(), bytes, false); + return file; + } +} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/Dex2Jar.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/Dex2Jar.java index 58953362..ba6024aa 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/Dex2Jar.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/Dex2Jar.java @@ -3,6 +3,7 @@ package the.bytecode.club.bytecodeviewer.util; import com.googlecode.d2j.dex.Dex2jar; import java.io.File; +import java.io.IOException; import java.lang.reflect.Field; /***************************************************************************