forked from shirof1re/OpenDocPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_requirements.py
87 lines (70 loc) · 3.01 KB
/
setup_requirements.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
import os
import sys
import lzma
import subprocess
from zipfile import ZipFile
from contextlib import suppress
import requests
from ppadb.client import Client as AdbClient
ADB_PATH = "platform-tools\\adb.exe"
def get_device():
devices = client.devices()
if len(devices) == 0:
for port in default_ports:
with suppress(Exception):
client.remote_connect("127.0.0.1", port)
devices = client.devices()
if len(devices) == 1:
return devices[0]
print("No emulator found.\nEnter the adb connection url with port manually or type q to exit or press enter to wait for a device: ")
result = input()
if result.lower() == "q":
sys.exit(0)
if result:
result = result.split(":")
client.remote_connect(result[0], int(result[1]))
result = subprocess.getoutput(f'"{ADB_PATH}" wait-for-device')
devices = client.devices()
if len(devices) == 1:
return devices[0]
if not os.path.exists(ADB_PATH):
if not os.path.exists("adb.zip"):
print("No adb file found. Downloading the latest version.")
r = requests.get("https://dl.google.com/android/repository/platform-tools-latest-windows.zip", allow_redirects=True)
open('adb.zip', 'wb').write(r.content)
ZipFile('adb.zip').extractall(".")
os.system('cls')
subprocess.run(f"{ADB_PATH} kill-server")
subprocess.run(f"{ADB_PATH} start-server")
default_ports = [7555, 62001]
client = AdbClient(host="127.0.0.1", port=5037)
device = None
print("Trying to connect to currently opened emulator")
device = get_device()
print("Check the emulator and accept if it asks for root permission.")
with suppress(RuntimeError):
device.root()
device = get_device()
os.system(f'{ADB_PATH} wait-for-device')
frida_exists = device.shell('test -f /data/local/tmp/frida-server && echo True').strip()
if not frida_exists:
architecture = device.shell("getprop ro.product.cpu.abi").strip().replace("-v8a", "")
print(f"\nArchitecture: {architecture}")
if not os.path.exists(f"frida-server-{architecture}.xz"):
version = requests.get("https://api.github.com/repos/frida/frida/releases/latest").json()["tag_name"]
name = f"frida-server-{version}-android-{architecture}"
print(f"Downloading {name}...")
url = f"https://github.com/frida/frida/releases/download/{version}/{name}.xz"
r = requests.get(url, allow_redirects=True)
open(f"frida-server-{architecture}.xz", 'wb').write(r.content)
print("Extracting....")
with lzma.open(f"frida-server-{architecture}.xz") as f, open('frida-server', 'wb') as fout:
file_content = f.read()
fout.write(file_content)
print("Copying frida-server...")
device.push("frida-server", "/data/local/tmp/frida-server")
print("Modifying permissions")
device.shell("chmod 755 /data/local/tmp/frida-server")
os.remove("frida-server")
print("\nFrida-server is installed!")
input("Press enter to exit...")