Skip to content

Commit 7ecca67

Browse files
committed
aab support
1 parent 7db6665 commit 7ecca67

5 files changed

Lines changed: 286 additions & 7 deletions

File tree

pom.xml

Lines changed: 227 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<properties>
99
<!-- Project settings -->
10-
<java.version>1.8</java.version>
10+
<java.version>11</java.version>
1111
<maven.compiler.target>${java.version}</maven.compiler.target>
1212
<maven.compiler.source>${java.version}</maven.compiler.source>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -55,8 +55,130 @@
5555
<taskmanager.version>1.0.1</taskmanager.version>
5656
<google-java-format.version>1.7</google-java-format.version> <!-- Newer versions require Java 11+ -->
5757
<disk-lib.version>1.2.0</disk-lib.version>
58+
<aapt-version>8.12.0-13700139</aapt-version>
59+
<maven-dependency-plugin>3.6.1</maven-dependency-plugin>
5860
</properties>
5961

62+
<profiles>
63+
<profile>
64+
<id>unpack-aapt2-linux</id>
65+
<activation>
66+
<os>
67+
<family>unix</family>
68+
<name>linux</name>
69+
</os>
70+
</activation>
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.apache.maven.plugins</groupId>
75+
<artifactId>maven-dependency-plugin</artifactId>
76+
<version>${maven-dependency-plugin}</version>
77+
<executions>
78+
<execution>
79+
<id>unpack-linux-aapt2</id>
80+
<phase>generate-resources</phase>
81+
<goals>
82+
<goal>unpack</goal>
83+
</goals>
84+
<configuration>
85+
<artifactItems>
86+
<artifactItem>
87+
<groupId>com.android.tools.build</groupId>
88+
<artifactId>aapt2</artifactId>
89+
<version>${aapt-version}</version>
90+
<classifier>linux</classifier>
91+
<type>jar</type>
92+
<outputDirectory>${project.build.outputDirectory}/linux</outputDirectory>
93+
</artifactItem>
94+
</artifactItems>
95+
</configuration>
96+
</execution>
97+
</executions>
98+
</plugin>
99+
</plugins>
100+
</build>
101+
</profile>
102+
103+
<profile>
104+
<id>unpack-aapt2-windows</id>
105+
<activation>
106+
<os>
107+
<family>windows</family>
108+
</os>
109+
</activation>
110+
<build>
111+
<plugins>
112+
<plugin>
113+
<groupId>org.apache.maven.plugins</groupId>
114+
<artifactId>maven-dependency-plugin</artifactId>
115+
<version>${maven-dependency-plugin}</version>
116+
<executions>
117+
<execution>
118+
<id>unpack-windows-aapt2</id>
119+
<phase>generate-resources</phase>
120+
<goals>
121+
<goal>unpack</goal>
122+
</goals>
123+
<configuration>
124+
<artifactItems>
125+
<artifactItem>
126+
<groupId>com.android.tools.build</groupId>
127+
<artifactId>aapt2</artifactId>
128+
<version>${aapt-version}</version>
129+
<classifier>windows</classifier>
130+
<type>jar</type>
131+
<outputDirectory>${project.build.outputDirectory}/windows</outputDirectory>
132+
</artifactItem>
133+
</artifactItems>
134+
</configuration>
135+
</execution>
136+
</executions>
137+
</plugin>
138+
</plugins>
139+
</build>
140+
</profile>
141+
142+
<profile>
143+
<id>unpack-aapt2-macos</id>
144+
<activation>
145+
<os>
146+
<family>mac</family>
147+
</os>
148+
</activation>
149+
<build>
150+
<plugins>
151+
<plugin>
152+
<groupId>org.apache.maven.plugins</groupId>
153+
<artifactId>maven-dependency-plugin</artifactId>
154+
<version>${maven-dependency-plugin}</version>
155+
<executions>
156+
<execution>
157+
<id>unpack-macos-aapt2</id>
158+
<phase>generate-resources</phase>
159+
<goals>
160+
<goal>unpack</goal>
161+
</goals>
162+
<configuration>
163+
<artifactItems>
164+
<artifactItem>
165+
<groupId>com.android.tools.build</groupId>
166+
<artifactId>aapt2</artifactId>
167+
<version>${aapt-version}</version>
168+
<classifier>osx</classifier>
169+
<type>jar</type>
170+
<outputDirectory>${project.build.outputDirectory}/macos</outputDirectory>
171+
</artifactItem>
172+
</artifactItems>
173+
</configuration>
174+
</execution>
175+
</executions>
176+
</plugin>
177+
</plugins>
178+
</build>
179+
</profile>
180+
</profiles>
181+
60182
<repositories>
61183
<repository>
62184
<id>google</id>
@@ -402,6 +524,24 @@
402524
<version>${disk-lib.version}</version>
403525
</dependency>
404526

527+
<dependency>
528+
<groupId>com.android.tools.build</groupId>
529+
<artifactId>bundletool</artifactId>
530+
<version>1.18.1</version>
531+
</dependency>
532+
533+
<dependency>
534+
<groupId>com.android.tools.build</groupId>
535+
<artifactId>aapt2-proto</artifactId>
536+
<version>${aapt-version}</version>
537+
</dependency>
538+
539+
<dependency>
540+
<groupId>com.google.protobuf</groupId>
541+
<artifactId>protobuf-java</artifactId>
542+
<version>4.31.1</version>
543+
</dependency>
544+
405545
<!-- TODO Re-add for Graal.JS support -->
406546
<!--<dependency>
407547
<groupId>org.graalvm.js</groupId>
@@ -506,6 +646,92 @@
506646
</transformers>
507647
</configuration>
508648
</plugin>
649+
<plugin>
650+
<groupId>org.apache.maven.plugins</groupId>
651+
<artifactId>maven-dependency-plugin</artifactId>
652+
<version>${maven-dependency-plugin}</version>
653+
<executions>
654+
<execution>
655+
<id>unpack-aapt2-windows</id>
656+
<phase>prepare-package</phase>
657+
<goals>
658+
<goal>unpack</goal>
659+
</goals>
660+
<configuration>
661+
<artifactItems>
662+
<artifactItem>
663+
<groupId>com.android.tools.build</groupId>
664+
<artifactId>aapt2</artifactId>
665+
<version>${aapt-version}</version>
666+
<classifier>windows</classifier>
667+
<type>jar</type>
668+
<outputDirectory>${project.build.directory}/unpacked-aapt2/windows</outputDirectory>
669+
</artifactItem>
670+
</artifactItems>
671+
</configuration>
672+
</execution>
673+
<execution>
674+
<id>unpack-aapt2-macos</id>
675+
<phase>prepare-package</phase>
676+
<goals>
677+
<goal>unpack</goal>
678+
</goals>
679+
<configuration>
680+
<artifactItems>
681+
<artifactItem>
682+
<groupId>com.android.tools.build</groupId>
683+
<artifactId>aapt2</artifactId>
684+
<version>${aapt-version}</version>
685+
<classifier>osx</classifier>
686+
<type>jar</type>
687+
<outputDirectory>${project.build.directory}/unpacked-aapt2/macos</outputDirectory>
688+
</artifactItem>
689+
</artifactItems>
690+
</configuration>
691+
</execution>
692+
<execution>
693+
<id>unpack-aapt2-linux</id>
694+
<phase>prepare-package</phase>
695+
<goals>
696+
<goal>unpack</goal>
697+
</goals>
698+
<configuration>
699+
<artifactItems>
700+
<artifactItem>
701+
<groupId>com.android.tools.build</groupId>
702+
<artifactId>aapt2</artifactId>
703+
<version>${aapt-version}</version>
704+
<classifier>linux</classifier>
705+
<type>jar</type>
706+
<outputDirectory>${project.build.directory}/unpacked-aapt2/linux</outputDirectory>
707+
</artifactItem>
708+
</artifactItems>
709+
</configuration>
710+
</execution>
711+
</executions>
712+
</plugin>
713+
<plugin>
714+
<artifactId>maven-resources-plugin</artifactId>
715+
<version>3.3.1</version>
716+
<executions>
717+
<execution>
718+
<id>copy-unpacked-aapt2</id>
719+
<phase>prepare-package</phase>
720+
<goals>
721+
<goal>copy-resources</goal>
722+
</goals>
723+
<configuration>
724+
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
725+
<resources>
726+
<resource>
727+
<directory>${project.build.directory}/unpacked-aapt2</directory>
728+
<!-- This will create windows/, macos/, linux/ inside the classes dir -->
729+
</resource>
730+
</resources>
731+
</configuration>
732+
</execution>
733+
</executions>
734+
</plugin>
509735
</plugins>
510736
</build>
511737

src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/Import.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public enum Import
3737
CLASS(new ClassResourceImporter(), "class"),
3838
XAPK(new XAPKResourceImporter(), "xapk"),
3939
APK(new APKResourceImporter(), "apk"),
40-
DEX(new DEXResourceImporter(), "dex");
40+
DEX(new DEXResourceImporter(), "dex"),
41+
AAB(new AABResourceImporter(), "aab");
4142

4243
public static final HashMap<String, Import> extensionMap = new HashMap<>();
4344

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package the.bytecode.club.bytecodeviewer.resources.importing.impl;
2+
3+
import com.android.tools.build.bundletool.commands.BuildApksCommand;
4+
import the.bytecode.club.bytecodeviewer.resources.importing.Importer;
5+
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
6+
7+
import java.io.File;
8+
import java.nio.file.Path;
9+
10+
import static the.bytecode.club.bytecodeviewer.Constants.FS;
11+
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
12+
13+
public class AABResourceImporter implements Importer
14+
{
15+
16+
@Override
17+
public void open(File file) throws Exception
18+
{
19+
String randomStr = MiscUtils.randomString(32);
20+
Path universalApksZipPath = Path.of(TEMP_DIRECTORY, randomStr + ".apks");
21+
22+
BuildApksCommand.builder()
23+
.setApkBuildMode(BuildApksCommand.ApkBuildMode.UNIVERSAL)
24+
.setGenerateOnlyForConnectedDevice(false)
25+
.setBundlePath(file.toPath())
26+
.setOutputFile(universalApksZipPath)
27+
.setOutputPrintStream(System.out)
28+
.build()
29+
.execute();
30+
31+
File universalApk = new File(TEMP_DIRECTORY + FS + randomStr + "_universal.apk");
32+
33+
MiscUtils.extractFileFromZip(universalApksZipPath, "universal.apk", universalApk.toPath());
34+
35+
APKResourceImporter.openImpl(universalApk, file.getName());
36+
}
37+
}

src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/APKResourceImporter.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,25 @@ public void open(File file) throws Exception
4343
File tempCopy = new File(TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + ".apk");
4444
FileUtils.copyFile(file, tempCopy);
4545

46-
ResourceContainer container = new ResourceContainer(tempCopy, file.getName());
46+
openImpl(tempCopy, file.getName());
47+
}
48+
49+
static void openImpl(File apkFile, String importName) throws Exception {
50+
ResourceContainer container = new ResourceContainer(apkFile, importName);
4751

4852
// APK Resource Decoding Here
4953
if (BytecodeViewer.viewer.decodeAPKResources.isSelected())
5054
{
51-
APKTool.decodeResources(tempCopy, container);
55+
APKTool.decodeResources(apkFile, container);
5256
container.resourceFiles = JarUtils.loadResourcesFromFolder(APKTool.DECODED_RESOURCES, container.APKToolContents);
5357
}
5458

55-
container.resourceFiles.putAll(JarUtils.loadResources(tempCopy)); // copy and rename
59+
container.resourceFiles.putAll(JarUtils.loadResources(apkFile)); // copy and rename
5660
// to prevent unicode filenames
5761

5862
// create a new resource importer and copy the contents from it
59-
container.copy(Apk2Jar.obtainImpl().resourceContainerFromApk(tempCopy));
63+
container.copy(Apk2Jar.obtainImpl().resourceContainerFromApk(apkFile));
6064

6165
BytecodeViewer.addResourceContainer(container);
6266
}
63-
6467
}

src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
import java.awt.image.BufferedImage;
3131
import java.io.*;
3232
import java.lang.reflect.Field;
33+
import java.nio.file.FileSystem;
34+
import java.nio.file.FileSystems;
35+
import java.nio.file.Files;
36+
import java.nio.file.Path;
3337
import java.util.*;
3438

3539
import static the.bytecode.club.bytecodeviewer.BytecodeViewer.gson;
@@ -425,4 +429,12 @@ public static File deleteExistingFile(File file)
425429

426430
return file;
427431
}
432+
433+
public static void extractFileFromZip(Path zipFile, String fileName, Path outputFile) throws IOException
434+
{
435+
try (FileSystem fileSystem = FileSystems.newFileSystem(zipFile, (ClassLoader) null)) {
436+
Path fileToExtract = fileSystem.getPath(fileName);
437+
Files.copy(fileToExtract, outputFile);
438+
}
439+
}
428440
}

0 commit comments

Comments
 (0)