Skip to content

Commit

Permalink
more stricter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkent030315 committed Nov 2, 2024
1 parent 912526b commit 1af1c97
Showing 1 changed file with 97 additions and 1 deletion.
98 changes: 97 additions & 1 deletion src/pe/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ impl<'a> Iterator for ResourceStringIterator<'a> {
}

/// Represents a resource string entry.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq)]
pub struct ResourceString<'a> {
/// The length, in bytes, of this String structure.
pub len: u16,
Expand Down Expand Up @@ -1521,6 +1521,7 @@ mod tests {
assert_eq!(it_vec.is_ok(), true);
let it_vec = it_vec.unwrap();

assert_eq!(it_vec[0].is_binary_data(), true);
assert_eq!(it_vec[0].key_string(), VS_VERSION_INFO_KEY);
assert_eq!(
it_vec[0].value,
Expand All @@ -1531,27 +1532,122 @@ mod tests {
0x00, 0x00, 0x00, 0x00, 0x53, 0x00, 0x74, 0x00, 0x72, 0x00
]
);

assert_eq!(it_vec[1].r#type, 103); // Invalid, seems broken by RC (resource compiler)
assert_eq!(it_vec[1].key_string(), "FileInfo");
assert_eq!(
it_vec[1].value,
&[
0xb4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x34, 0x00, 0x30, 0x00, 0x39, 0x00,
0x30, 0x00, 0x34, 0x00, 0x45, 0x00, 0x34, 0x00, 0x00, 0x00, 0x58, 0x00, 0x36, 0x00,
0x00, 0x00, 0x43, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x70, 0x00, 0x61, 0x00, 0x6e, 0x00,
0x79, 0x00, 0x4e, 0x00, 0x61, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00,
0x50, 0x00, 0x79, 0x00, 0x74, 0x00, 0x68, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x20, 0x00,
0x53, 0x00, 0x6f, 0x00, 0x66, 0x00, 0x74, 0x00, 0x77, 0x00, 0x61, 0x00, 0x72, 0x00,
0x65, 0x00, 0x20, 0x00, 0x46, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x6e, 0x00, 0x64, 0x00,
0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00,
]
);

assert_eq!(it_vec[2].is_binary_data(), true);
assert_eq!(it_vec[2].key_string(), "FileDescription");
assert_eq!(it_vec[2].value_string(), "Python 3.11.3 (64-bit)");
assert_eq!(
it_vec[2].value,
&[
0x50, 0x00, 0x79, 0x00, 0x74, 0x00, 0x68, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x20, 0x00,
0x33, 0x00, 0x2e, 0x00, 0x31, 0x00, 0x31, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x20, 0x00,
0x28, 0x00, 0x36, 0x00, 0x34, 0x00, 0x2d, 0x00, 0x62, 0x00, 0x69, 0x00, 0x74, 0x00,
0x29, 0x00, 0x00, 0x00, 0x00, 0x00,
]
);

assert_eq!(it_vec[3].is_binary_data(), true);
assert_eq!(it_vec[3].key_string(), "FileVersion");
assert_eq!(it_vec[3].value_string(), "3.11.3150.0");
assert_eq!(
it_vec[3].value,
&[
0x33, 0x00, 0x2e, 0x00, 0x31, 0x00, 0x31, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x31, 0x00,
0x35, 0x00, 0x30, 0x00, 0x2e, 0x00, 0x30, 0x00, 0x00, 0x00,
]
);

assert_eq!(it_vec[4].is_text_data(), true);
assert_eq!(it_vec[4].key_string(), "InternalName");
assert_eq!(it_vec[4].value_string(), "setup");
assert_eq!(
it_vec[4].value,
&[0x73, 0x00, 0x65, 0x00, 0x74, 0x00, 0x75, 0x00, 0x70, 0x00, 0x00, 0x00,]
);

assert_eq!(it_vec[5].is_binary_data(), true);
assert_eq!(it_vec[5].key_string(), "LegalCopyright");
assert_eq!(
it_vec[5].value_string(),
"Copyright (c) Python Software Foundation. All rights reserved."
);
assert_eq!(
it_vec[5].value,
&[
0x43, 0x00, 0x6f, 0x00, 0x70, 0x00, 0x79, 0x00, 0x72, 0x00, 0x69, 0x00, 0x67, 0x00,
0x68, 0x00, 0x74, 0x00, 0x20, 0x00, 0x28, 0x00, 0x63, 0x00, 0x29, 0x00, 0x20, 0x00,
0x50, 0x00, 0x79, 0x00, 0x74, 0x00, 0x68, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x20, 0x00,
0x53, 0x00, 0x6f, 0x00, 0x66, 0x00, 0x74, 0x00, 0x77, 0x00, 0x61, 0x00, 0x72, 0x00,
0x65, 0x00, 0x20, 0x00, 0x46, 0x00, 0x6f, 0x00, 0x75, 0x00, 0x6e, 0x00, 0x64, 0x00,
0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x2e, 0x00, 0x20, 0x00,
0x41, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x20, 0x00, 0x72, 0x00, 0x69, 0x00, 0x67, 0x00,
0x68, 0x00, 0x74, 0x00, 0x73, 0x00, 0x20, 0x00, 0x72, 0x00, 0x65, 0x00, 0x73, 0x00,
0x65, 0x00, 0x72, 0x00, 0x76, 0x00, 0x65, 0x00, 0x64, 0x00, 0x2e, 0x00, 0x00, 0x00,
0x00, 0x00,
]
);

assert_eq!(it_vec[6].is_binary_data(), true);
assert_eq!(it_vec[6].key_string(), "OriginalFilename");
assert_eq!(it_vec[6].value_string(), "python-3.11.3-amd64.exe");
assert_eq!(
it_vec[6].value,
&[
0x70, 0x00, 0x79, 0x00, 0x74, 0x00, 0x68, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x2d, 0x00,
0x33, 0x00, 0x2e, 0x00, 0x31, 0x00, 0x31, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x2d, 0x00,
0x61, 0x00, 0x6d, 0x00, 0x64, 0x00, 0x36, 0x00, 0x34, 0x00, 0x2e, 0x00, 0x65, 0x00,
0x78, 0x00, 0x65, 0x00, 0x00, 0x00,
]
);

assert_eq!(it_vec[7].is_binary_data(), true);
assert_eq!(it_vec[7].key_string(), "ProductName");
assert_eq!(it_vec[7].value_string(), "Python 3.11.3 (64-bit)");
assert_eq!(
it_vec[7].value,
&[
0x50, 0x00, 0x79, 0x00, 0x74, 0x00, 0x68, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x20, 0x00,
0x33, 0x00, 0x2e, 0x00, 0x31, 0x00, 0x31, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x20, 0x00,
0x28, 0x00, 0x36, 0x00, 0x34, 0x00, 0x2d, 0x00, 0x62, 0x00, 0x69, 0x00, 0x74, 0x00,
0x29, 0x00, 0x00, 0x00, 0x00, 0x00,
]
);

assert_eq!(it_vec[8].is_binary_data(), true);
assert_eq!(it_vec[8].key_string(), "ProductVersion");
assert_eq!(it_vec[8].value_string(), "3.11.3150.0");
assert_eq!(
it_vec[8].value,
&[
0x33, 0x00, 0x2e, 0x00, 0x31, 0x00, 0x31, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x31, 0x00,
0x35, 0x00, 0x30, 0x00, 0x2e, 0x00, 0x30, 0x00, 0x00, 0x00,
]
);

assert_eq!(it_vec[9].is_binary_data(), true);
assert_eq!(it_vec[9].key_string(), "VarFileInfo");
assert_eq!(it_vec[9].value, &[]);

assert_eq!(it_vec[9].is_binary_data(), true);
assert_eq!(it_vec[10].key_string(), "Translation");
assert_eq!(it_vec[10].value, &[0x09, 0x04, 0xe4, 0x04]);

assert_eq!(it_vec.get(11), None);
}
}

0 comments on commit 1af1c97

Please sign in to comment.