-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApkPatcher.java
More file actions
70 lines (62 loc) · 3.03 KB
/
Copy pathApkPatcher.java
File metadata and controls
70 lines (62 loc) · 3.03 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
import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.nio.file.*;
public class ApkPatcher {
public static void main(String[] args) throws Exception {
File apkFile = new File("D:/Ideas/Antigravity/Notes/temp_patch.apk");
File tempFile = new File("D:/Ideas/Antigravity/Notes/rebuilt_mrdarkside_base_temp.apk");
ZipInputStream zin = new ZipInputStream(new FileInputStream(apkFile));
ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(tempFile));
ZipEntry entry = zin.getNextEntry();
while (entry != null) {
String name = entry.getName();
if (!name.startsWith("classes") && !name.startsWith("lib/")) {
ZipEntry newEntry = new ZipEntry(name);
// If it was stored (uncompressed), we must keep it stored
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();
// Add patched files (classes are usually deflated, libs can be stored but we'll deflate for size unless required)
addFile(zout, "D:/Ideas/Antigravity/Notes_Replica/prebuilt/dex/classes.dex", "classes.dex", false);
addFile(zout, "D:/Ideas/Antigravity/Notes_Replica/prebuilt/dex/classes2.dex", "classes2.dex", false);
String libBase = "D:/Ideas/Antigravity/Notes_Replica/prebuilt/lib/arm64-v8a/";
String[] libs = {"libapp.so", "libclib.so", "libflutter.so", "libobjectbox-jni.so", "libpbkdf2_native.so", "libpolarssl.so", "libsecurity.so", "libtmlib.so"};
for (String lib : libs) {
// Native libs in Flutter should ideally be STORED for faster loading on Android 6+,
// but let's stick to default DEFLATED first as it's safer for compatibility
// unless we encounter more errors.
addFile(zout, libBase + lib, "lib/arm64-v8a/" + lib, false);
}
zout.close();
if (apkFile.exists()) apkFile.delete();
tempFile.renameTo(apkFile);
}
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, 0, buf.length);
zout.closeEntry();
}
}