]> FriiDump Source - friidump.git/blob - tests/test_xbox_dvd_structure_contract.py
Record A102 and B101 live profile evidence
[friidump.git] / tests / test_xbox_dvd_structure_contract.py
1 #!/usr/bin/env python3
2 """Contract for the standard MMC READ DVD STRUCTURE CDB boundary."""
3
4 from __future__ import annotations
5
6 import argparse
7 from pathlib import Path
8
9
10 def require(text: str, token: str, label: str) -> None:
11     if token not in text:
12         raise SystemExit(f"FAIL: missing {label}: {token}")
13     print(f"PASS: {label}")
14
15
16 def main() -> int:
17     parser = argparse.ArgumentParser()
18     parser.add_argument(
19         "--source-root",
20         type=Path,
21         default=Path(__file__).resolve().parents[1],
22     )
23     args = parser.parse_args()
24
25     source_root = args.source_root.resolve()
26     dvd_drive = (
27         source_root / "libfriidump" / "dvd_drive.c"
28     ).read_text(encoding="utf-8")
29     windows_utils = (
30         source_root / "libfriidump" / "xbox_ref" / "utils.c"
31     ).read_text(encoding="utf-8")
32     dumper = (
33         source_root / "libfriidump" / "dumper.c"
34     ).read_text(encoding="utf-8")
35
36     start = dvd_drive.index("int dvd_read_dvd_structure")
37     end = dvd_drive.index("\n}\n", start) + 3
38     function = dvd_drive[start:end]
39
40     require(
41         function,
42         "mmc.cmd[6] = layer;",
43         "READ DVD STRUCTURE layer is CDB byte 6",
44     )
45     require(
46         function,
47         "mmc.cmd[7] = format;",
48         "READ DVD STRUCTURE format is CDB byte 7",
49     )
50     require(
51         function,
52         "mmc.cmd[8] = (u_int8_t) ((extbufsize & 0xFF00) >> 8);",
53         "allocation length high byte is CDB byte 8",
54     )
55     require(
56         function,
57         "mmc.cmd[9] = (u_int8_t)  (extbufsize & 0x00FF);",
58         "allocation length low byte is CDB byte 9",
59     )
60     require(
61         function,
62         "mmc.cmdlen = 12;",
63         "READ DVD STRUCTURE uses a 12-byte CDB",
64     )
65
66     if "mmc.cmd[11] = format;" in function:
67         raise SystemExit(
68             "FAIL: READ DVD STRUCTURE format is still written to control byte 11"
69         )
70     print("PASS: READ DVD STRUCTURE control byte 11 is not used as Format")
71
72     require(
73         windows_utils,
74         "sptd.Cdb[7] = 0x04;",
75         "copied Windows DMI request uses format byte 7",
76     )
77     require(
78         dumper,
79         "[XBOX-DVD-STRUCTURE] format=0x04 name=DMI cdb_format_byte=7 result=%s",
80         "persistent DMI capture diagnostic",
81     )
82
83     print("XBOX READ DVD STRUCTURE CDB CONTRACT: PASS")
84     return 0
85
86
87 if __name__ == "__main__":
88     raise SystemExit(main())