-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantipktool.groovy
57 lines (51 loc) · 1.46 KB
/
antipktool.groovy
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
import java.io.InputStream
import java.io.OutputStream
import java.nio.file.*
println ''
if (args.length != 1) {
println "Usage: antipktool path-to-apk"
exit()
}
modifyManifest(args[0])
// https://github.com/iBotPeaches/Apktool/issues/1435
def modifyManifest(apkPath) {
Path apkFilePath = Paths.get(apkPath)
FileSystem fs = null
try {
fs = FileSystems.newFileSystem(apkFilePath, null)
Path manifestPath = fs.getPath("/AndroidManifest.xml")
Path manifestTempPath = fs.getPath("/___AndroidManifestTemp.xml")
Files.move(manifestPath, manifestTempPath)
streamCopy(manifestTempPath, manifestPath)
Files.delete(manifestTempPath)
println 'modified!'
} catch (IOException e) {
e.printStackTrace()
exit()
} finally {
fs.close()
}
}
private static void streamCopy(Path src, Path dst) throws IOException {
byte[] buf = new byte[8192]
InputStream isSrc = null
OutputStream osDst = null
try {
isSrc = Files.newInputStream(src)
osDst = Files.newOutputStream(dst)
int n = 0;
if ((n = isSrc.read(buf, 0, 4)) != -1) {
buf[0] = 0
osDst.write(buf, 0, n)
} else {
println "Couldn't read first four bytes"
exit()
}
while ((n = isSrc.read(buf)) != -1) {
osDst.write(buf, 0, n)
}
} finally {
osDst.close()
isSrc.close()
}
}