From da048d376ba4fdada60e9a634ad3e1dc80d0caca Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Wed, 4 Sep 2024 08:23:02 +0200 Subject: [PATCH] fix: [tests] fix broken tests since last change --- .vscode/launch.json | 8 ++++++++ analysers/ps_everywhere.py | 9 +++++---- analysers/ps_matrix.py | 4 +++- commands.md | 7 ++++++- parsers/powerlogs.py | 2 +- tests/test_analysers_ps_everywhere.py | 1 - 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 09ac084..80be1f6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -141,6 +141,14 @@ "args": "-c 1 parse security_sysdiagnose", "cwd": "${workspaceFolder}/" }, + { + "name": "Python Debugger: parse powerlogs", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/sysdiagnose.py", + "args": "-c 1 parse powerlogs", + "cwd": "${workspaceFolder}/" + }, { "name": "Python Debugger: parse mobileactivation", "type": "debugpy", diff --git a/analysers/ps_everywhere.py b/analysers/ps_everywhere.py index 3e67733..951266f 100644 --- a/analysers/ps_everywhere.py +++ b/analysers/ps_everywhere.py @@ -56,10 +56,9 @@ def execute(self): # processes with full path, no parameters, no threads shutdownlogs_json = ShutdownLogsParser(self.config, self.case_id).get_result() - for section in shutdownlogs_json.values(): + for p in shutdownlogs_json: # not using 'path' but 'command', as the path being appended by the UUID will be counter productive to normalisation - for p in section: - self.add_if_full_command_is_not_in_set(p['command']) + self.add_if_full_command_is_not_in_set(p['command']) print(f"{len(self.all_ps)} entries after shutdownlogs") # processes with full path, no parameters, no threads @@ -86,7 +85,9 @@ def execute(self): # on the other hand it may contain valuable stuff, so we use it in 2 formats # - name::#num_of_threads # - name::thread name - for p in taskinfo_json['tasks']: + for p in taskinfo_json: + if 'name' not in p: + continue self.add_if_full_path_is_not_in_set(p['name']) # add_if_full_path_is_not_in_set(f"{p['name']}::#{len(p['threads'])}") # count is different than in spindumpnosymbols for t in p['threads']: diff --git a/analysers/ps_matrix.py b/analysers/ps_matrix.py index 49a0e05..d6256a5 100644 --- a/analysers/ps_matrix.py +++ b/analysers/ps_matrix.py @@ -31,7 +31,9 @@ def execute(self): taskinfo_json = TaskinfoParser(self.config, self.case_id).get_result() taskinfo_dict = {} - for p in taskinfo_json['tasks']: + for p in taskinfo_json: + if 'pid' not in p: + continue taskinfo_dict[int(p['pid'])] = { 'PID': p['pid'] } diff --git a/commands.md b/commands.md index 113bc72..815726f 100644 --- a/commands.md +++ b/commands.md @@ -17,7 +17,7 @@ find . -type f -name "*.plist" -exec sh -c 'plutil -p $1 > $1.txt' - {} \; # Backup the device with libimobile device -To install +To install ```` apt-get install libimobiledevice-dev libimobiledevice-doc libimobiledevice6 libplist-doc ideviceinstaller libimobiledevice-utils python-imobiledevice python-plist libplist-utils ```` @@ -69,3 +69,8 @@ $find . -type f -name "*.sqlitedb" # Parsing unified logging: https://github.com/ydkhatri/UnifiedLogReader + +# Count rows in powerlogs +db="filename" +for i in `sqlite3 "$db" "SELECT name FROM sqlite_master WHERE type='table';"`; do a=$(sqlite3 "$db" "SELECT COUNT(*) FROM '$i'"); echo -e "$a\t$i"; done | sort -n > powerlogs_cnt + diff --git a/parsers/powerlogs.py b/parsers/powerlogs.py index 2a156ae..39c487e 100644 --- a/parsers/powerlogs.py +++ b/parsers/powerlogs.py @@ -58,5 +58,5 @@ def execute(self) -> list: [print(f" {table}") for table in skipped] return result - def parse_file(path: str) -> dict: + def parse_file_to_json(path: str) -> dict: return sqlite2json.sqlite2struct(path) diff --git a/tests/test_analysers_ps_everywhere.py b/tests/test_analysers_ps_everywhere.py index 07ad2c8..4176d13 100644 --- a/tests/test_analysers_ps_everywhere.py +++ b/tests/test_analysers_ps_everywhere.py @@ -5,7 +5,6 @@ class TestAnalysersPsEverywhere(SysdiagnoseTestCase): - def test_analyse_ps_everywhere(self): for case_id, case in self.sd.cases().items(): print(f"Running PsEverywhereAnalyser for {case_id}")