mirror of
https://github.com/mvt-project/mvt.git
synced 2026-10-02 14:09:47 +02:00
Merge pull request #949 from NeuroSaki987/codex/fix-windows-dumpsys-crlf
fix: parse dumpsys ADB output with CRLF line endings
This commit is contained in:
2 files changed
+44
-3
No files matched your search
@@ -29,7 +29,8 @@ class DumpsysADBArtifact(AndroidArtifact):
|
|||||||
stack = [res]
|
stack = [res]
|
||||||
cur_indent = 0
|
cur_indent = 0
|
||||||
in_multiline = False
|
in_multiline = False
|
||||||
for line in dump_data.strip(b"\n").split(b"\n"):
|
for line in dump_data.strip(b"\r\n").split(b"\n"):
|
||||||
|
line = line.removesuffix(b"\r")
|
||||||
# Track the level of indentation
|
# Track the level of indentation
|
||||||
indent = len(line) - len(line.lstrip())
|
indent = len(line) - len(line.lstrip())
|
||||||
if indent < cur_indent:
|
if indent < cur_indent:
|
||||||
@@ -180,12 +181,18 @@ class DumpsysADBArtifact(AndroidArtifact):
|
|||||||
self.log.error("Unable to find ADB manager state in dumpsys output")
|
self.log.error("Unable to find ADB manager state in dumpsys output")
|
||||||
return
|
return
|
||||||
|
|
||||||
end_of_json = content.rfind(b"}\n")
|
end_of_json = max(content.rfind(b"}\n"), content.rfind(b"}\r\n"))
|
||||||
if end_of_json == -1 or end_of_json <= start_of_json:
|
if end_of_json == -1 or end_of_json <= start_of_json:
|
||||||
self.log.error("Unable to find complete ADB manager state in dumpsys output")
|
self.log.error("Unable to find complete ADB manager state in dumpsys output")
|
||||||
return
|
return
|
||||||
|
|
||||||
json_content = content[start_of_json + 2 : end_of_json - 2].rstrip()
|
# Exclude the final nested closing brace regardless of its line ending.
|
||||||
|
# The indented parser finishes the open debugging_manager at EOF.
|
||||||
|
inner_end = content.rfind(b"}", start_of_json + 2, end_of_json)
|
||||||
|
if inner_end == -1:
|
||||||
|
self.log.error("Unable to find complete ADB manager state in dumpsys output")
|
||||||
|
return
|
||||||
|
json_content = content[start_of_json + 2 : inner_end].rstrip()
|
||||||
|
|
||||||
parsed = self.indented_dump_parser(json_content)
|
parsed = self.indented_dump_parser(json_content)
|
||||||
if parsed.get("debugging_manager") is None:
|
if parsed.get("debugging_manager") is None:
|
||||||
|
|||||||
@@ -130,6 +130,40 @@ class TestDumpsysADBArtifact:
|
|||||||
assert key_store_entry["fingerprint"] == expected_fingerprint
|
assert key_store_entry["fingerprint"] == expected_fingerprint
|
||||||
assert key_store_entry["last_connected"] == "1628501829898"
|
assert key_store_entry["last_connected"] == "1628501829898"
|
||||||
|
|
||||||
|
def test_parsing_adb_xml_with_crlf_line_endings(self):
|
||||||
|
da_adb = DumpsysADBArtifact()
|
||||||
|
file = get_artifact("android_data/dumpsys_adb_xml.txt")
|
||||||
|
with open(file, "rb") as f:
|
||||||
|
data = f.read().replace(b"\r\n", b"\n").replace(b"\n", b"\r\n")
|
||||||
|
|
||||||
|
da_adb.parse(data)
|
||||||
|
|
||||||
|
assert len(da_adb.results) == 1
|
||||||
|
assert da_adb.results[0]["user_keys"][0]["user"] == "user@laptop"
|
||||||
|
assert da_adb.results[0]["keystore"][0]["last_connected"] == "1628501829898"
|
||||||
|
|
||||||
|
def test_parsing_adb_wifi_with_mixed_line_endings(self):
|
||||||
|
da_adb = DumpsysADBArtifact()
|
||||||
|
data = (
|
||||||
|
b"ADB MANAGER STATE (dumpsys adb):\n"
|
||||||
|
b"{\n"
|
||||||
|
b" debugging_manager={\n"
|
||||||
|
b" connected_to_adb=true\n"
|
||||||
|
b" user_keys=QUJDRA== host@example\n"
|
||||||
|
b" adb_wifi={\n"
|
||||||
|
b" enabled=false\n"
|
||||||
|
b" }\n"
|
||||||
|
b" }\r\n"
|
||||||
|
b"}\n"
|
||||||
|
b"--------- duration\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
da_adb.parse(data)
|
||||||
|
|
||||||
|
assert len(da_adb.results) == 1
|
||||||
|
assert da_adb.results[0]["user_keys"][0]["user"] == "host@example"
|
||||||
|
assert da_adb.results[0]["adb_wifi"]["enabled"] == b"false"
|
||||||
|
|
||||||
|
|
||||||
class TestDumpsysADBStateAlerts:
|
class TestDumpsysADBStateAlerts:
|
||||||
def test_no_androidqf_context_preserves_existing_behavior(self):
|
def test_no_androidqf_context_preserves_existing_behavior(self):
|
||||||
|
|||||||
Reference in new issue
Block a user