-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsword.py
More file actions
64 lines (54 loc) · 2.02 KB
/
sword.py
File metadata and controls
64 lines (54 loc) · 2.02 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
55
56
57
58
59
60
61
62
63
64
import subprocess
import sys
from rich.console import Console
from lib import control
from lib import logger
class Sword:
def __init__(self):
self.adb_path = "./tools/adb"
self.console = Console()
self.log = logger.Log()
self.control = control.AdbRunner()
def run_command(self, command):
try:
result = subprocess.run(
command, # command
shell=True, # getoutput pake shell=True by default
capture_output=True, # biar bisa ambil output
text=True, # decode ke string
timeout=15 # timeout 15 detik
)
return result.stdout
except Exception as e:
self.log.error(f"Error running command: {e}")
return False
def adb(self,status):
if status == "start":
self.run_command(f"{self.adb_path} start-server")
self.log.info("ADB Started")
if status == "stop":
self.run_command(f"{self.adb_path} kill-server")
self.log.info("ADB stopped")
def connect(self,ip,port=5555):
self.log.info(f"Connecting to {ip}:{port}")
conn = self.run_command(f"{self.adb_path} connect {ip}:{port}")
if "connected" in str(conn).lower():
self.log.info(f"Connected to {ip}:{port}")
self.spawn_control()
else:
self.log.error(f"Unable to connect to {ip}:{port}")
def spawn_control(self):
self.log.info("Checking device connection...")
devices = subprocess.getoutput("adb devices").splitlines()
if len(devices) < 2 or "device" not in devices[1]:
self.log.error("No connected device found!")
else:
self.log.info("Device connected!")
self.control.get_device_info()
self.control.show_menu()
def run(self,ip):
self.connect(ip)
self.adb("stop")
if __name__ == "__main__":
app = Sword()
app.run(sys.argv[1])