#!/usr/bin/env python3 """Exits 0 if the given PE file carries an Authenticode signature, 1 if it does not. `osslsigncode verify` also fails on an untrusted chain, which is the normal result for the SignPath test certificate, so it cannot answer this question on its own. This reads the PE Certificate Table data directory instead, which says whether a signature is present without making any claim about its validity. """ import struct import sys def has_signature(path): with open(path, "rb") as f: data = f.read() pe = struct.unpack_from(" 0 if __name__ == "__main__": signed = has_signature(sys.argv[1]) print("signed" if signed else "unsigned") sys.exit(0 if signed else 1)