forked from shirof1re/ODPY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startfrida.py
70 lines (57 loc) · 2.25 KB
/
startfrida.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
import os
import sys
import subprocess
from contextlib import suppress
import json
from ppadb.client import Client as AdbClient
with open("config/config.json") as f:
config = json.load(f)
if os.path.isfile("C:\\ProgramData\\BlueStacks_nxt\\bluestacks.conf"):
with open("C:\\ProgramData\\BlueStacks_nxt\\bluestacks.conf", encoding="utf-8") as f:
s = f.read()
t = s
t = t.replace('bst.feature.rooting="0"', 'bst.feature.rooting="1"')
t = t.replace('.enable_root_access="0"', '.enable_root_access="1"')
if t != s:
with open("C:\\ProgramData\\BlueStacks_nxt\\bluestacks.conf", "w", encoding="utf-8") as f:
f.write(t)
server_port = config["server"]["port"]
default_ports = [16384, 7555, 5555]
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]))
devices = client.devices()
if len(devices) == 1:
return devices[0]
os.system('cls')
# subprocess.run(f'"{ADB_PATH}" kill-server')
subprocess.run(f'"{ADB_PATH}" start-server')
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')
print("\nRunning frida\nNow you can start fridahook\n")
os.system(f'"{ADB_PATH}" reverse tcp:{server_port} tcp:{server_port}')
if config["server"]["useSu"]:
os.system(f'"{ADB_PATH}"' + " shell su -c /data/local/tmp/frida-server")
else:
os.system(f'"{ADB_PATH}"' + " shell /data/local/tmp/frida-server")