Skip to content

Commit

Permalink
reports: add get_logs
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Feb 19, 2022
1 parent 22d4136 commit 4a39e11
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/rpcclient/rpcclient/darwin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ def uname(self):
def is_idevice(self):
return self.uname.machine.startswith('i')

@property
def roots(self) -> typing.List[str]:
""" get a list of all accessible darwin roots when used for lookup of files/preferences/... """
result = ['/']
for username in self.fs.scandir('/Users'):
if not username.is_dir() or not self.fs.accessible(username.path):
continue
result.append(username.path)
return result

def set_airplane_mode(self, mode: bool):
""" set whether the device should enter airplane mode (turns off baseband, bt, etc...) """
preferences = self.symbols.objc_getClass('RadiosPreferences').objc_call('new')
Expand Down
2 changes: 1 addition & 1 deletion src/rpcclient/rpcclient/darwin/crash_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, client, crash_reports_dir):

def list(self, prefixed='') -> List[CrashReport]:
result = []
for root in ['/'] + self._client.fs.listdir('/Users'):
for root in self._client.roots:
root = Path(root) / self._crash_reports_dir

if not self._client.fs.accessible(root):
Expand Down
21 changes: 21 additions & 0 deletions src/rpcclient/rpcclient/darwin/reports.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pathlib import Path
from typing import List

from rpcclient.darwin.crash_reports import CrashReports


Expand All @@ -8,6 +11,24 @@ def __init__(self, client, crash_reports_dir):
self._client = client
self.crash_reports = CrashReports(client, crash_reports_dir)

def get_logs(self, prefix='') -> List[Path]:
result = []
sub_paths = ['var/log', 'Library/Logs']
for sub_path in sub_paths:
for path in self._client.roots:
path = Path(path) / sub_path
if not self._client.fs.accessible(path):
continue

for root, dirs, files in self._client.fs.walk(path, onerror=lambda x: None):
for name in files:
if not self._client.fs.accessible(path):
continue

if name.endswith('.log') and name.startswith(prefix):
result.append(Path(root) / name)
return result

@property
def system_log(self) -> str:
with self._client.fs.open('/var/log/system.log', 'r') as f:
Expand Down
22 changes: 16 additions & 6 deletions src/rpcclient/rpcclient/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,25 @@ def accessible(self, path: str):
return False

@path_to_str('top')
def walk(self, top: str):
def walk(self, top: str, onerror=None):
""" provides the same results as os.walk(top) """
dirs = []
files = []
for entry in self.scandir(top):
if entry.is_dir():
dirs.append(entry.name)
else:
files.append(entry.name)
try:
for entry in self.scandir(top):
try:
if entry.is_dir():
dirs.append(entry.name)
else:
files.append(entry.name)
except Exception as e:
if not onerror:
raise e
onerror(e)
except Exception as e:
if not onerror:
raise e
onerror(e)

yield top, dirs, files

Expand Down

0 comments on commit 4a39e11

Please sign in to comment.