As stated in the question title. However, I am using a "trick" where i store extra data after the executable to be used at runtime (see here).
Signing my executable appears to break this 'trick' however, so my question is where is the signature stored in the exe (PE) file?
I am usingsigntool
from microsoft to sign my executable.
Check the signature on an EXE or MSI file Right-click the EXE or MSI file and select Properties. Click the Digital Signatures tab to check the signature.
Click File > Info > View Signatures. In the list, on a signature name, click the down-arrow, and then click Signature Details.
Executable signing certificates, commonly referred to as code signing certificates, are digital files you can use to digitally sign executable files (.exe files). The code signing certificate uses a cryptographic hash that validates the executable file's integrity and authenticity.
When a signer digitally signs a document, a cryptographic hash is generated for the document. That cryptographic hash is then encrypted using the sender's private key, which is stored in a secure HSM box. It is then appended to the document and sent to the recipients along with the sender's public key.
An embedded digital signature is always appended to the end of the executable file, whether or not you have custom data attached to it. The attached data is included in the hash of the signature.
The location and size of the signature is stored in the security directory of the PE header. Extracting that information goes like this:
IMAGE_OPTIONAL_HEADER
of the PE file.IMAGE_OPTIONAL_HEADER::DataDirectory
is an array of IMAGE_DATA_DIRECTORY
structures. Index it by IMAGE_DIRECTORY_ENTRY_SECURITY
(undocumented but declared in winnt.h) to locate the entry of the security directory. IMAGE_DATA_DIRECTORY::VirtualAddress
contains the file offset (not the RVA) of the signature and IMAGE_DATA_DIRECTORY::Size
contains the size of the signature.References:
The format of a signed PE file is documented by Microsoft:
Windows Authenticode Portable Executable Signature Format [This link downloads a WORD doc]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With