m4b / goblin

An impish, cross-platform binary parsing crate, written in Rust
MIT License
1.17k stars 156 forks source link

pe: add authenticode support / v2 #362

Closed baloo closed 1 year ago

baloo commented 1 year ago

Alternative to #358

This removes the digest dependency and allows to implement hashing like:

trait AuthenticodeDigest {
    /// [`authenticode_digest`] returns the result of the provided hash algorithm.
    fn authenticode_digest<D: Digest>(&self) -> Output<D>;
}

impl AuthenticodeDigest for PE<'_> {
    fn authenticode_digest<D: Digest>(&self) -> Output<D> {
        let mut digest = D::new();

        for chunk in self.authenticode_ranges() {
            digest.update(chunk);
        }

        digest.finalize()
    }
}

fn main() {
    let mut buf = Vec::new();
    let mut f =
        File::open("/nix/store/bhsxra1hc7yhja2kzw5rdds90i3w3a54-linux-5.10.147/bzImage").unwrap();
    f.read_to_end(&mut buf).unwrap();

    let pe = PE::parse(&buf).unwrap();

    let hash = pe.authenticode_digest::<Sha256>();
    println!("hash: {:x?}", hash);
}
baloo commented 1 year ago

anything missing or can we merge as this?

m4b commented 1 year ago

This is great @baloo sorry for delay and thanks for making these changes!

m4b commented 1 year ago

non-breaking

m4b commented 1 year ago

released in 0.7.0, thank you so much for your patience!