This repository has been archived by the owner on Feb 22, 2019. It is now read-only.
forked from topjohnwu/magisk-module-installer
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_module.py
executable file
·116 lines (91 loc) · 3.52 KB
/
build_module.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: TheCjw<thecjw@live.com>
# Created on 2016.10.17
__author__ = "TheCjw"
import json
import lzma
import os
import requests
import shutil
import zipfile
def download_file(download_url, path):
if os.path.exists(path):
print("{0} is exists, skip...".format(os.path.basename(path)))
return
print("Downloading", download_url)
response = requests.get(download_url, stream=True)
with open(path, "wb") as out:
shutil.copyfileobj(response.raw, out)
del response
print("done.")
def extract_file(archive, file_name):
with lzma.open(archive) as f:
file_content = f.read()
path = os.path.dirname(file_name)
if not os.path.exists(path):
os.makedirs(path)
with open(file_name, "wb") as out:
out.write(file_content)
def main():
base_path = os.path.abspath(os.path.dirname(__file__))
frida_release_url = "https://api.github.com/repos/frida/frida/releases/latest"
response = requests.get(frida_release_url).text
config = json.loads(response)
version = config["tag_name"]
release_notes = config["body"]
print("Latest Frida version:", version)
print("Release notes:", release_notes)
module_prop = """id=FridaServer
name=Frida Server
version={version}
versionCode={version_code}
author=Frida
description={notes}
support=http://www.frida.re/
donate=
cacheModule=false
""".format(version=version,
version_code=version.replace(".", ""),
notes=release_notes)
with open("module.prop", "w") as f:
f.write(module_prop)
frida_server_32 = "frida-server-{0}-android-arm.xz".format(version)
frida_server_64 = "frida-server-{0}-android-arm64.xz".format(version)
download_url = "https://github.com/frida/frida/releases/download/{0}/".format(version)
cache_path = os.path.join(base_path, "cache")
frida_server_32_path = os.path.join(cache_path, frida_server_32)
frida_server_64_path = os.path.join(cache_path, frida_server_64)
download_file(download_url + frida_server_32, frida_server_32_path)
download_file(download_url + frida_server_64, frida_server_64_path)
# arm frida.
extract_file(frida_server_32_path, os.path.join(base_path,
"system/xbin/frida_server"))
extract_file(frida_server_64_path, os.path.join(base_path,
"system/xbin/frida_server64"))
file_list = ["common/service.sh",
"common/post-fs-data.sh",
"common/post-fs.sh",
"common/file_contexts_image",
"META-INF/com/google/android/update-binary",
"META-INF/com/google/android/updater-script",
"config.sh",
"changelog.txt",
"module.prop"]
for dp, dn, fn in os.walk("./system"):
for f in fn:
if f == "placeholder":
continue
file_list.append(os.path.join(dp, f))
print("Building Magisk module.")
with zipfile.ZipFile(os.path.join(cache_path,
"Magisk-Frida-Server-{0}.zip".format(version)), "w") as zf:
for file_name in file_list:
path = os.path.join(base_path, file_name)
if not os.path.exists(path):
print("{0} is not exists, skip...".format(path))
continue
zf.write(path, arcname=file_name)
print("Done.")
if __name__ == "__main__":
main()