Skip to content

Commit

Permalink
examples/fake-signing: Make runnable on Linux
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
MarijnS95 committed Jan 27, 2022
1 parent 7ff4869 commit 996f32a
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions examples/validate-fake-signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 996f32a

Please sign in to comment.