mirror of
https://github.com/mvt-project/mvt.git
synced 2026-10-11 10:18:41 +02:00
fix: parse dumpsys ADB output with CRLF line endings
This commit is contained in:
1 parent
777db67291
commit
ff5ebf73cc
2 files changed
+22
-2
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,19 @@ 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
|
||||||
|
|
||||||
|
line_ending_length = 1
|
||||||
end_of_json = content.rfind(b"}\n")
|
end_of_json = content.rfind(b"}\n")
|
||||||
|
crlf_end_of_json = content.rfind(b"}\r\n")
|
||||||
|
if crlf_end_of_json > end_of_json:
|
||||||
|
line_ending_length = 2
|
||||||
|
end_of_json = crlf_end_of_json
|
||||||
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()
|
json_content = content[
|
||||||
|
start_of_json + 2 : end_of_json - line_ending_length - 1
|
||||||
|
].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,18 @@ 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"
|
||||||
|
|
||||||
|
|
||||||
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