XAPK Support
This commit is contained in:
parent
7dd66d675c
commit
fdf8e9baa5
7 changed files with 96 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<String, byte[]> allDirectoryFiles = new HashMap<>();
|
||||
HashMap<String, ClassNode> allDirectoryClasses = new HashMap<>();
|
||||
|
||||
Configuration.silenceExceptionGUI++; //turn exceptions off
|
||||
try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(file))
|
||||
{
|
||||
Enumeration<? extends ZipEntry> 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
/***************************************************************************
|
||||
|
|
Loading…
Reference in a new issue