Skip to content

Commit

Permalink
reports: add system_log
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Feb 19, 2022
1 parent 1ea9d29 commit 1b830fc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/rpcclient/rpcclient/darwin/crash_reports.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from typing import List

from pycrashreport.crash_report import CrashReport
Expand All @@ -10,13 +11,18 @@ def __init__(self, client, crash_reports_dir):

def list(self, prefixed='') -> List[CrashReport]:
result = []
for entry in self._client.fs.scandir(self._crash_reports_dir):
if entry.is_file() and entry.name.endswith('.ips') and entry.name.startswith(prefixed):
with self._client.fs.open(entry.path, 'r') as f:
result.append(CrashReport(f.readall().decode(), filename=entry.path))
for root in ['/'] + self._client.fs.listdir('/Users'):
root = Path(root) / self._crash_reports_dir

if not self._client.fs.accessible(root):
continue

for entry in self._client.fs.scandir(root):
if entry.is_file() and entry.name.endswith('.ips') and entry.name.startswith(prefixed):
with self._client.fs.open(entry.path, 'r') as f:
result.append(CrashReport(f.readall().decode(), filename=entry.path))
return result

def clear(self, prefixed=''):
for entry in self._client.fs.scandir(self._crash_reports_dir):
if entry.is_file() and entry.name.endswith('.ips') and entry.name.startswith(prefixed):
self._client.fs.remove(entry.path)
for entry in self.list(prefixed=prefixed):
self._client.fs.remove(entry.filename)
8 changes: 8 additions & 0 deletions src/rpcclient/rpcclient/darwin/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@


class Reports:
""" equivalent to the data that can be found using the Console app inside the Reports section """

def __init__(self, client, crash_reports_dir):
self._client = client
self.crash_reports = CrashReports(client, crash_reports_dir)

@property
def system_log(self) -> str:
with self._client.fs.open('/var/log/system.log', 'r') as f:
return f.readall().decode()
9 changes: 9 additions & 0 deletions src/rpcclient/rpcclient/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ def stat(self, path: str):
""" stat(filename) at remote. read man for more details. """
raise NotImplementedError()

@path_to_str('path')
def accessible(self, path: str):
""" check if a given path can be accessed. """
try:
self.stat(path)
return True
except BadReturnValueError:
return False

@path_to_str('top')
def walk(self, top: str):
""" provides the same results as os.walk(top) """
Expand Down
2 changes: 1 addition & 1 deletion src/rpcclient/rpcclient/macos/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rpcclient.macos.bluetooth import Bluetooth
from rpcclient.darwin.reports import Reports

CRASH_REPORTS_DIR = '/Library/Logs/DiagnosticReports'
CRASH_REPORTS_DIR = 'Library/Logs/DiagnosticReports'


class MacosClient(DarwinClient):
Expand Down

0 comments on commit 1b830fc

Please sign in to comment.