winsign.pefile

PE file format support.

This module provides various structures and methods that represent Windows PE files, with a specific focus on the parts of the format required for signing.

winsign.pefile.add_signature(infile, outfile, signature)

Add a signature to a PE file.

winsign.pefile.calc_authenticode_digest(f, alg='sha256')

Calculate the authenticode digest for file.

Parameters:
  • f (file object) – opened PE file

  • alg (str) – digest algorithm to use. Defaults to sha256.

Returns:

The authenicode digest as a byte string

winsign.pefile.calc_checksum(f, checksum_offset)

Calculate the PE file checksum.

Parameters:
  • f (file object) – PE file opened for reading

  • checksum_offset (int) – where in the PE file the checksum is located

Returns:

integer checksum

winsign.pefile.get_certificates(f)

Return the set of certificates in the PE file.

Parameters:

f (file object) – PE file opened for reading

Returns:

List of certificate objects, or None if there are none

winsign.pefile.is_pefile(filename)

Determine if a file is a PE file or not.

Parameters:

filename (str) – path to file to check

Returns:

True if the file appears to be a PE file False otherwise

winsign.pefile.is_signed(filename)

Determine if a PE file is signed or not.

This does not verify the signatures, it merely returns whether a file contains signatures or not.

Parameters:

filename (str) – path to file to check

Returns:

True if the file has signatures False otherwise

async winsign.pefile.sign_file(infile, outfile, digest_algo, certs, signer, url=None, comment=None, crosscert=None, timestamp_style=None, timestamp_url=None, authenticode_timestamp=None)

Sign a file.