-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathfrida-skeleton.py
executable file
·86 lines (65 loc) · 2.34 KB
/
frida-skeleton.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import os
import signal
import sys
import time
import coloredlogs
import urllib3
from lib.core.options import options
from lib.core.settings import LOG_DIR, LOG_FILENAME
from lib.core.watch_thread import WatchThread
from lib.utils.adb import Adb
# disable ssl warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class MainExit(Exception):
pass
class FridaSkeleton:
def __init__(self):
self.log = logging.getLogger(self.__class__.__name__)
def start(self):
try:
if options.list:
for device in Adb.devices().out.split('\n')[1:]:
print(device)
sys.exit(0)
level = logging.DEBUG if options.verbose else logging.INFO
coloredlogs.install(level=level)
# set log
os.makedirs(LOG_DIR, mode=0o700, exist_ok=True)
log_file = open(os.path.join(LOG_DIR, LOG_FILENAME), 'a', encoding='utf-8')
coloredlogs.install(level=level, stream=log_file)
# set handling interrupt exceptions
signal.signal(signal.SIGTERM, self.shutdown)
signal.signal(signal.SIGINT, self.shutdown)
Adb.start_server()
watch_thread = WatchThread()
try:
watch_thread.start()
while True:
time.sleep(1)
except MainExit:
while True:
try:
self.log.info('shutdown command received, wait for clean up please...')
watch_thread.terminate()
while watch_thread.is_alive():
time.sleep(1)
break
except MainExit:
pass
except (KeyboardInterrupt, InterruptedError):
pass
self.log.info('thank you for using, bye!')
def shutdown(self, signum, frame):
if signum == signal.SIGINT:
self.log.debug('keyboard interrupt event detected')
elif signum == signal.SIGTERM:
self.log.debug('termination event detected')
else:
self.log.warning('unknown event detected')
raise MainExit
if __name__ == '__main__':
skeleton = FridaSkeleton()
skeleton.start()