From 996f32a7fbf23fd8fd5ccb476daf98968c7fc1f9 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Wed, 12 Jan 2022 11:14:33 +0100 Subject: [PATCH] examples/fake-signing: Make runnable on Linux The main reason for fake signing is making it run on Linux - and not depend on `dxil.dll` on Windows - so it's great if this example runs on Linux as well to see it all working even if that requires a few nasty cfg blocks. Note that this is done with `cfg!()` and regular `if` blocks instead of attributes, such that this code lints and compiles on both Windows and Linux even if the `validate_dxil()` codepath is never entered on the latter (and that way includes, `let mut all_matches` etc don't need to be `#[cfg(windows)]`'ed out either). --- examples/validate-fake-signing.rs | 39 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/examples/validate-fake-signing.rs b/examples/validate-fake-signing.rs index 0d45905..351fab9 100644 --- a/examples/validate-fake-signing.rs +++ b/examples/validate-fake-signing.rs @@ -26,27 +26,38 @@ fn main() { let without_digest = get_digest(&dxil); - let validated_dxil = validate_dxil(&dxil).unwrap(); - - let with_digest = get_digest(&validated_dxil); - let result = fake_sign_dxil_in_place(&mut dxil); assert!(result); let fake_signed_digest = get_digest(&dxil); - println!( - "\tAfter compilation: {:?}\n\tAfter dxil.dll: {:?}\n\tAfter fake signing: {:?}", - without_digest, with_digest, fake_signed_digest - ); - - if fake_signed_digest != with_digest { - println!("---- Mismatch in file {} ----", idx); - all_matches &= false; + if cfg!(windows) { + let validated_dxil = validate_dxil(&dxil).unwrap(); + + let with_digest = get_digest(&validated_dxil); + + println!( + "\tAfter compilation: {:?}\n\tAfter dxil.dll: {:?}\n\tAfter fake signing: {:?}", + without_digest, with_digest, fake_signed_digest + ); + + if fake_signed_digest != with_digest { + println!("---- Mismatch in file {} ----", idx); + all_matches &= false; + } + } else { + println!( + "\tAfter compilation: {:?}\n\tAfter fake signing: {:?}", + without_digest, fake_signed_digest + ); } } - if all_matches { - println!("Success"); + if cfg!(windows) { + if all_matches { + println!("Success"); + } + } else { + println!("Warning: Signatures not validated against `dxil.dll` - this is only possible on Windows"); } }