-
Notifications
You must be signed in to change notification settings - Fork 1
/
Logcat.py
38 lines (31 loc) · 959 Bytes
/
Logcat.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
# !/usr/bin/python3
# -*- coding: utf8 -*-
# author: moyichen
# date: 2021/3/23
import re
import threading
import subprocess
from AndroidDevice import AndroidDevice
from utils import bytes_to_str
class Logcat(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.exit = False
self.filter = 'hook'
def run(self) -> None:
adb = AndroidDevice.get_device()
adb.AdbCmd(['logcat', '-c'])
ps = subprocess.Popen('adb logcat -v time', stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
for line in ps.stdout:
if self.exit:
break
try:
line = bytes_to_str(line).strip()
if re.search(self.filter, line):
print(line)
except:
print(line)
adb.AdbCmd(['logcat', '-c'])
def quit(self):
self.exit = True
self.join(timeout=10)