-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalStandaloneMerger.java
More file actions
98 lines (87 loc) · 3.99 KB
/
Copy pathFinalStandaloneMerger.java
File metadata and controls
98 lines (87 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.nio.file.*;
public class FinalStandaloneMerger {
public static void main(String[] args) throws Exception {
File baseApk = new File("D:/Ideas/Antigravity/Notes/apks_extracted/base.apk");
File outputApk = new File("D:/Ideas/Antigravity/Notes/MASTER_MASTER_FINAL.apk");
ZipInputStream zin = new ZipInputStream(new FileInputStream(baseApk));
ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(outputApk));
// We will keep the ORIGINAL manifest and original resources.arsc
// But we will MERGE all other resources and libs
Set<String> replaced = new HashSet<>(Arrays.asList("classes.dex", "classes2.dex"));
ZipEntry entry = zin.getNextEntry();
while (entry != null) {
if (!replaced.contains(entry.getName())) {
ZipEntry newEntry = new ZipEntry(entry.getName());
if (entry.getMethod() == ZipEntry.STORED) {
newEntry.setMethod(ZipEntry.STORED);
newEntry.setSize(entry.getSize());
newEntry.setCrc(entry.getCrc());
}
zout.putNextEntry(newEntry);
byte[] buf = new byte[1024];
int len;
while ((len = zin.read(buf)) > 0) zout.write(buf, 0, len);
zout.closeEntry();
}
entry = zin.getNextEntry();
}
zin.close();
// 1. Patched DEX (Nuclear bypassed)
addFile(zout, "D:/Ideas/Antigravity/Notes/new_dex/classes.dex", "classes.dex", false);
addFile(zout, "D:/Ideas/Antigravity/Notes/new_dex/classes2.dex", "classes2.dex", false);
// 2. Add Architecture Libs
injectSplit(zout, "D:/Ideas/Antigravity/Notes/apks_extracted/split_config.arm64_v8a.apk", "lib/", true);
// 3. Add Resources
injectSplit(zout, "D:/Ideas/Antigravity/Notes/apks_extracted/split_config.xxhdpi.apk", "res/", false);
zout.close();
System.out.println("Merge Complete.");
}
private static void addFile(ZipOutputStream zout, String srcPath, String entryName, boolean store) throws IOException {
byte[] buf = Files.readAllBytes(Paths.get(srcPath));
ZipEntry entry = new ZipEntry(entryName);
if (store) {
entry.setMethod(ZipEntry.STORED);
entry.setSize(buf.length);
CRC32 crc = new CRC32();
crc.update(buf);
entry.setCrc(crc.getValue());
}
zout.putNextEntry(entry);
zout.write(buf);
zout.closeEntry();
}
private static void injectSplit(ZipOutputStream zout, String splitPath, String prefix, boolean store) throws IOException {
try (ZipInputStream zin = new ZipInputStream(new FileInputStream(splitPath))) {
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null) {
if (entry.getName().startsWith(prefix)) {
byte[] buf = readAll(zin);
ZipEntry newEntry = new ZipEntry(entry.getName());
if (store) {
newEntry.setMethod(ZipEntry.STORED);
newEntry.setSize(buf.length);
CRC32 crc = new CRC32();
crc.update(buf);
newEntry.setCrc(crc.getValue());
}
try {
zout.putNextEntry(newEntry);
zout.write(buf);
zout.closeEntry();
} catch (ZipException e) {}
}
zin.closeEntry();
}
}
}
private static byte[] readAll(InputStream is) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) > 0) bos.write(buf, 0, len);
return bos.toByteArray();
}
}