diff --git a/pom.xml b/pom.xml index 1f6ece39b..4e8a2b81b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ - 1.8 + 11 ${java.version} ${java.version} UTF-8 @@ -55,8 +55,130 @@ 1.0.1 1.7 1.2.0 + 8.12.0-13700139 + 3.6.1 + + + unpack-aapt2-linux + + + unix + linux + + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${maven-dependency-plugin} + + + unpack-linux-aapt2 + generate-resources + + unpack + + + + + com.android.tools.build + aapt2 + ${aapt-version} + linux + jar + ${project.build.outputDirectory}/linux + + + + + + + + + + + + unpack-aapt2-windows + + + windows + + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${maven-dependency-plugin} + + + unpack-windows-aapt2 + generate-resources + + unpack + + + + + com.android.tools.build + aapt2 + ${aapt-version} + windows + jar + ${project.build.outputDirectory}/windows + + + + + + + + + + + + unpack-aapt2-macos + + + mac + + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${maven-dependency-plugin} + + + unpack-macos-aapt2 + generate-resources + + unpack + + + + + com.android.tools.build + aapt2 + ${aapt-version} + osx + jar + ${project.build.outputDirectory}/macos + + + + + + + + + + + google @@ -402,6 +524,24 @@ ${disk-lib.version} + + com.android.tools.build + bundletool + 1.18.1 + + + + com.android.tools.build + aapt2-proto + ${aapt-version} + + + + com.google.protobuf + protobuf-java + 4.31.1 + + + + + + + + diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java index a27e0d7a7..eaef87c17 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java @@ -119,7 +119,7 @@ public void promptForExport() Thread buildAPKThread = new Thread(() -> { - APKTool.buildAPK(new File(input), file, finalContainer); + APKTool.buildAPK(file, finalContainer); BytecodeViewer.updateBusyStatus(false); }, "Process APK"); 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 2de85240e..dddce2382 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 @@ -37,7 +37,8 @@ public enum Import CLASS(new ClassResourceImporter(), "class"), XAPK(new XAPKResourceImporter(), "xapk"), APK(new APKResourceImporter(), "apk"), - DEX(new DEXResourceImporter(), "dex"); + DEX(new DEXResourceImporter(), "dex"), + AAB(new AABResourceImporter(), "aab"); public static final HashMap extensionMap = new HashMap<>(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/AABResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/AABResourceImporter.java new file mode 100644 index 000000000..d42f3847d --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/AABResourceImporter.java @@ -0,0 +1,37 @@ +package the.bytecode.club.bytecodeviewer.resources.importing.impl; + +import com.android.tools.build.bundletool.commands.BuildApksCommand; +import the.bytecode.club.bytecodeviewer.resources.importing.Importer; +import the.bytecode.club.bytecodeviewer.util.MiscUtils; + +import java.io.File; +import java.nio.file.Path; + +import static the.bytecode.club.bytecodeviewer.Constants.FS; +import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY; + +public class AABResourceImporter implements Importer +{ + + @Override + public void open(File file) throws Exception + { + String randomStr = MiscUtils.randomString(32); + Path universalApksZipPath = Path.of(TEMP_DIRECTORY, randomStr + ".apks"); + + BuildApksCommand.builder() + .setApkBuildMode(BuildApksCommand.ApkBuildMode.UNIVERSAL) + .setGenerateOnlyForConnectedDevice(false) + .setBundlePath(file.toPath()) + .setOutputFile(universalApksZipPath) + .setOutputPrintStream(System.out) + .build() + .execute(); + + File universalApk = new File(TEMP_DIRECTORY + FS + randomStr + "_universal.apk"); + + MiscUtils.extractFileFromZip(universalApksZipPath, "universal.apk", universalApk.toPath()); + + APKResourceImporter.openImpl(universalApk, file.getName()); + } +} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/APKResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/APKResourceImporter.java index 05735e0be..64237439d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/APKResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/APKResourceImporter.java @@ -43,22 +43,25 @@ public void open(File file) throws Exception File tempCopy = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + ".apk"); FileUtils.copyFile(file, tempCopy); - ResourceContainer container = new ResourceContainer(tempCopy, file.getName()); + openImpl(tempCopy, file.getName()); + } + + static void openImpl(File apkFile, String importName) throws Exception { + ResourceContainer container = new ResourceContainer(apkFile, importName); // APK Resource Decoding Here if (BytecodeViewer.viewer.decodeAPKResources.isSelected()) { - APKTool.decodeResources(tempCopy, container); + APKTool.decodeResources(apkFile, container); container.resourceFiles = JarUtils.loadResourcesFromFolder(APKTool.DECODED_RESOURCES, container.APKToolContents); } - container.resourceFiles.putAll(JarUtils.loadResources(tempCopy)); // copy and rename + container.resourceFiles.putAll(JarUtils.loadResources(apkFile)); // copy and rename // to prevent unicode filenames // create a new resource importer and copy the contents from it - container.copy(Apk2Jar.obtainImpl().resourceContainerFromApk(tempCopy)); + container.copy(Apk2Jar.obtainImpl().resourceContainerFromApk(apkFile)); BytecodeViewer.addResourceContainer(container); } - } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/APKTool.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/APKTool.java index b46b32672..183a7448f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/APKTool.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/APKTool.java @@ -64,7 +64,7 @@ public static synchronized void decodeResources(File input, ResourceContainer co } } - public static synchronized void buildAPK(File input, File output, ResourceContainer container) + public static synchronized void buildAPK(File output, ResourceContainer container) { String temp = TEMP_DIRECTORY + FS; File tempDir = new File(temp + FS + MiscUtils.getRandomizedName() + FS); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java index 116003c66..3245dc8f2 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java @@ -30,6 +30,10 @@ import java.awt.image.BufferedImage; import java.io.*; import java.lang.reflect.Field; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; import static the.bytecode.club.bytecodeviewer.BytecodeViewer.gson; @@ -425,4 +429,12 @@ public static File deleteExistingFile(File file) return file; } + + public static void extractFileFromZip(Path zipFile, String fileName, Path outputFile) throws IOException + { + try (FileSystem fileSystem = FileSystems.newFileSystem(zipFile, (ClassLoader) null)) { + Path fileToExtract = fileSystem.getPath(fileName); + Files.copy(fileToExtract, outputFile); + } + } }