-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplitFixer.java
More file actions
54 lines (47 loc) · 2.14 KB
/
Copy pathSplitFixer.java
File metadata and controls
54 lines (47 loc) · 2.14 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
import java.io.*;
import java.util.zip.*;
import java.util.*;
public class SplitFixer {
public static void main(String[] args) throws Exception {
File dir = new File("D:/Ideas/Antigravity/Notes/apks_extracted");
File dest = new File("D:/Ideas/Antigravity/Notes/fixed_splits");
dest.mkdirs();
for (File f : dir.listFiles()) {
if (!f.getName().endsWith(".apk")) continue;
File output = new File(dest, f.getName());
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(f));
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(output))) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
byte[] data = readAll(zis);
ZipEntry newEntry = new ZipEntry(entry.getName());
// FORCE resources.arsc and native libs to be STORED (uncompressed)
if (entry.getName().equals("resources.arsc") || entry.getName().startsWith("lib/")) {
newEntry.setMethod(ZipEntry.STORED);
newEntry.setSize(data.length);
CRC32 crc = new CRC32();
crc.update(data);
newEntry.setCrc(crc.getValue());
} else {
newEntry.setMethod(ZipEntry.DEFLATED);
}
try {
zos.putNextEntry(newEntry);
zos.write(data);
zos.closeEntry();
} catch (ZipException e) {
// Skip duplicates
}
}
}
System.out.println("Fixed: " + f.getName());
}
}
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();
}
}