Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 227 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<properties>
<!-- Project settings -->
<java.version>1.8</java.version>
<java.version>11</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -55,8 +55,130 @@
<taskmanager.version>1.0.1</taskmanager.version>
<google-java-format.version>1.7</google-java-format.version> <!-- Newer versions require Java 11+ -->
<disk-lib.version>1.2.0</disk-lib.version>
<aapt-version>8.12.0-13700139</aapt-version>
<maven-dependency-plugin>3.6.1</maven-dependency-plugin>
</properties>

<profiles>
<profile>
<id>unpack-aapt2-linux</id>
<activation>
<os>
<family>unix</family>
<name>linux</name>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin}</version>
<executions>
<execution>
<id>unpack-linux-aapt2</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.android.tools.build</groupId>
<artifactId>aapt2</artifactId>
<version>${aapt-version}</version>
<classifier>linux</classifier>
<type>jar</type>
<outputDirectory>${project.build.outputDirectory}/linux</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>unpack-aapt2-windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin}</version>
<executions>
<execution>
<id>unpack-windows-aapt2</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.android.tools.build</groupId>
<artifactId>aapt2</artifactId>
<version>${aapt-version}</version>
<classifier>windows</classifier>
<type>jar</type>
<outputDirectory>${project.build.outputDirectory}/windows</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>unpack-aapt2-macos</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin}</version>
<executions>
<execution>
<id>unpack-macos-aapt2</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.android.tools.build</groupId>
<artifactId>aapt2</artifactId>
<version>${aapt-version}</version>
<classifier>osx</classifier>
<type>jar</type>
<outputDirectory>${project.build.outputDirectory}/macos</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<repositories>
<repository>
<id>google</id>
Expand Down Expand Up @@ -402,6 +524,24 @@
<version>${disk-lib.version}</version>
</dependency>

<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>bundletool</artifactId>
<version>1.18.1</version>
</dependency>

<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>aapt2-proto</artifactId>
<version>${aapt-version}</version>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>4.31.1</version>
</dependency>

<!-- TODO Re-add for Graal.JS support -->
<!--<dependency>
<groupId>org.graalvm.js</groupId>
Expand Down Expand Up @@ -506,6 +646,92 @@
</transformers>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin}</version>
<executions>
<execution>
<id>unpack-aapt2-windows</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.android.tools.build</groupId>
<artifactId>aapt2</artifactId>
<version>${aapt-version}</version>
<classifier>windows</classifier>
<type>jar</type>
<outputDirectory>${project.build.directory}/unpacked-aapt2/windows</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpack-aapt2-macos</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.android.tools.build</groupId>
<artifactId>aapt2</artifactId>
<version>${aapt-version}</version>
<classifier>osx</classifier>
<type>jar</type>
<outputDirectory>${project.build.directory}/unpacked-aapt2/macos</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpack-aapt2-linux</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.android.tools.build</groupId>
<artifactId>aapt2</artifactId>
<version>${aapt-version}</version>
<classifier>linux</classifier>
<type>jar</type>
<outputDirectory>${project.build.directory}/unpacked-aapt2/linux</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-unpacked-aapt2</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/unpacked-aapt2</directory>
<!-- This will create windows/, macos/, linux/ inside the classes dir -->
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Import> extensionMap = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Loading