parse_packageinfo

Function parse_packageinfo 

Source
pub fn parse_packageinfo(input: &[u8]) -> Result<Vdf<'_>>
Expand description

Parse packageinfo.vdf format binary data.

This function returns zero-copy data where possible - strings are borrowed from the input buffer.

Format:

  • 4 bytes: Magic number + version (0x06565527 for v39, 0x06565528 for v40)
    • Upper 3 bytes: 0x065655 (magic)
    • Lower 1 byte: version (27 = 39, 28 = 40)
  • 4 bytes: Universe
  • Repeated package entries until package_id == 0xFFFFFFFF:
    • 4 bytes: Package ID (uint32)
    • 20 bytes: SHA-1 hash
    • 4 bytes: Change number (uint32)
    • 8 bytes: PICS token (uint64, only in v40+)
    • Binary VDF blob (KeyValues1 binary) with package metadata
Examples found in repository?
examples/dump_vdf.rs (line 69)
44fn main() {
45    let args: Vec<String> = env::args().collect();
46    if args.len() < 2 {
47        eprintln!("Usage: {} <vdf_file> [--text]", args[0]);
48        eprintln!(
49            "  --text: force text format parsing (default: auto-detect based on file extension)"
50        );
51        std::process::exit(1);
52    }
53
54    let path = Path::new(&args[1]);
55    let force_text = args.len() > 2 && args[2] == "--text";
56
57    let result = if force_text || path.extension().is_some_and(|e| e == "vdf") {
58        // Try text first for .vdf files
59        let content = std::fs::read_to_string(path);
60        if let Ok(content) = content {
61            parse_text(&content).map(|v| v.into_owned())
62        } else {
63            // Fall back to binary
64            let data = std::fs::read(path).expect("Failed to read file");
65            if path
66                .file_name()
67                .is_some_and(|n| n.to_str().is_some_and(|s| s.contains("packageinfo")))
68            {
69                binary::parse_packageinfo(&data).map(|v| v.into_owned())
70            } else if path
71                .file_name()
72                .is_some_and(|n| n.to_str().is_some_and(|s| s.contains("appinfo")))
73            {
74                binary::parse_appinfo(&data).map(|v| v.into_owned())
75            } else {
76                parse_binary(&data).map(|v| v.into_owned())
77            }
78        }
79    } else {
80        // Binary parsing
81        let data = std::fs::read(path).expect("Failed to read file");
82        if path
83            .file_name()
84            .is_some_and(|n| n.to_str().is_some_and(|s| s.contains("packageinfo")))
85        {
86            binary::parse_packageinfo(&data).map(|v| v.into_owned())
87        } else if path
88            .file_name()
89            .is_some_and(|n| n.to_str().is_some_and(|s| s.contains("appinfo")))
90        {
91            binary::parse_appinfo(&data).map(|v| v.into_owned())
92        } else {
93            parse_binary(&data).map(|v| v.into_owned())
94        }
95    };
96
97    match result {
98        Ok(vdf) => {
99            println!("\"{}\" {}", vdf.key(), dump_value(vdf.value(), 0));
100        }
101        Err(e) => {
102            eprintln!("Error parsing VDF: {:?}", e);
103            std::process::exit(1);
104        }
105    }
106}