custom logic around finding 'forward' exports

This commit is contained in:
Folkert 2022-09-17 14:42:36 +02:00
parent 0da6484618
commit 92514a1499
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -48,6 +48,24 @@ mod tests {
#[test]
fn check_exports_coff() {
// NOTE: this does not work
//
// let target = target_lexicon::Triple {
// architecture: target_lexicon::Architecture::X86_64,
// operating_system: target_lexicon::OperatingSystem::Windows,
// binary_format: target_lexicon::BinaryFormat::Coff,
// ..target_lexicon::Triple::host()
// };
//
// check_exports(&target);
//
// Because our exports point back into the .edata section, they are considered "forward"
// exports: they aren't actually defined in this .dll and hence not considered exports by
// the `object` crate.
}
#[test]
fn check_exports_coff_manual() {
let target = target_lexicon::Triple {
architecture: target_lexicon::Architecture::X86_64,
operating_system: target_lexicon::OperatingSystem::Windows,
@ -55,6 +73,30 @@ mod tests {
..target_lexicon::Triple::host()
};
check_exports(&target);
let custom_names = ["foo".to_string(), "bar".to_string()];
let bytes = generate(&target, &custom_names).unwrap();
let object = object::read::pe::PeFile64::parse(bytes.as_slice()).unwrap();
let exports = {
let mut exports = Vec::new();
if let Some(export_table) = object.export_table().unwrap() {
for (name_pointer, _address_index) in export_table.name_iter() {
let name = export_table.name_from_pointer(name_pointer).unwrap();
// here the standard `.exports()` checks for `if !export_table.is_forward(address)`
exports.push(name)
}
}
exports
};
for custom in custom_names {
assert!(
exports.iter().any(|name| *name == custom.as_bytes()),
"missing {}",
&custom
);
}
}
}