diff --git a/doc/CHANGES.txt b/doc/CHANGES.txt index ce43748..9d4fd75 100644 --- a/doc/CHANGES.txt +++ b/doc/CHANGES.txt @@ -65,6 +65,8 @@ Changes since PyInstaller 1.3 * Sometimes the temporary directory did not get removed upon program exit, when running on Linux. * Fixed random segfaults at startup on 64-bit platforms (like x86-64). + + Executables built with PyInstaller under Windows can now be digitally + signed. PyInstaller 1.3 --------------- diff --git a/source/common/launch.c b/source/common/launch.c index 7cb179a..0e29090 100644 --- a/source/common/launch.c +++ b/source/common/launch.c @@ -262,6 +262,44 @@ int setPaths(char const * archivePath, char const * archiveName) return 0; } +int checkCookie(int filelen) +{ + if (fseek(f_fp, filelen-(int)sizeof(COOKIE), SEEK_SET)) + return -1; + + /* Read the Cookie, and check its MAGIC bytes */ + fread(&f_cookie, sizeof(COOKIE), 1, f_fp); + if (strncmp(f_cookie.magic, MAGIC, strlen(MAGIC))) + return -1; + + return 0; +} + +int findDigitalSignature() +{ +#ifdef WIN32 + /* There might be a digital signature attached. Let's see. */ + char buf[2]; + int offset = 0; + fseek(f_fp, 0, SEEK_SET); + fread(buf, 1, 2, f_fp); + if (!(buf[0] == 'M' && buf[1] == 'Z')) + return -1; + /* Skip MSDOS header */ + fseek(f_fp, 60, SEEK_SET); + /* Read offset to PE header */ + fread(&offset, 4, 1, f_fp); + /* Jump to the fields that contain digital signature info */ + fseek(f_fp, offset+152, SEEK_SET); + fread(&offset, 4, 1, f_fp); + if (offset == 0) + return -1; + VS("%s contains a digital signature\n", f_archivename); + return offset; +#else + return -1; +#endif +} /* * Open the archive @@ -269,6 +307,9 @@ int setPaths(char const * archivePath, char const * archiveName) */ int openArchive() { +#ifdef WIN32 + int i; +#endif int filelen; /* Physically open the file */ @@ -281,18 +322,32 @@ int openArchive() /* Seek to the Cookie at the end of the file. */ fseek(f_fp, 0, SEEK_END); filelen = ftell(f_fp); - if (fseek(f_fp, -(int)sizeof(COOKIE), SEEK_END)) - { - VS("%s appears to be an invalid archive\n", f_archivename); - return -1; - } - /* Read the Cookie, and check its MAGIC bytes */ - fread(&f_cookie, sizeof(COOKIE), 1, f_fp); - if (strncmp(f_cookie.magic, MAGIC, strlen(MAGIC))) + if (checkCookie(filelen) < 0) { - VS("%s has bad magic!\n", f_archivename); - return -1; + VS("%s does not contain an embedded package\n", f_archivename); +#ifndef WIN32 + return -1; +#else + filelen = findDigitalSignature(); + if (filelen < 1) + return -1; + /* The digital signature has been aligned to 8-bytes boundary. + We need to look for our cookie taking into account some + padding. */ + for (i = 0; i < 8; ++i) + { + if (checkCookie(filelen) >= 0) + break; + --filelen; + } + if (i == 8) + { + VS("%s does not contain an embedded package, even skipping the signature\n", f_archivename); + return -1; + } + VS("package found skipping digital signature in %s\n", f_archivename); +#endif } /* From the cookie, calculate the archive start */ diff --git a/support/loader/inprocsrvr_6dc.dll b/support/loader/inprocsrvr_6dc.dll index 0d53dd1..1cfa663 100644 Binary files a/support/loader/inprocsrvr_6dc.dll and b/support/loader/inprocsrvr_6dc.dll differ diff --git a/support/loader/inprocsrvr_6dw.dll b/support/loader/inprocsrvr_6dw.dll index 8e9f271..e5bf880 100644 Binary files a/support/loader/inprocsrvr_6dw.dll and b/support/loader/inprocsrvr_6dw.dll differ diff --git a/support/loader/inprocsrvr_6rc.dll b/support/loader/inprocsrvr_6rc.dll index 4d19e1a..604db1b 100644 Binary files a/support/loader/inprocsrvr_6rc.dll and b/support/loader/inprocsrvr_6rc.dll differ diff --git a/support/loader/inprocsrvr_6rw.dll b/support/loader/inprocsrvr_6rw.dll index 0552c1f..e376c07 100644 Binary files a/support/loader/inprocsrvr_6rw.dll and b/support/loader/inprocsrvr_6rw.dll differ diff --git a/support/loader/inprocsrvr_7dc.dll b/support/loader/inprocsrvr_7dc.dll index 166fa1b..a8ab3f0 100644 Binary files a/support/loader/inprocsrvr_7dc.dll and b/support/loader/inprocsrvr_7dc.dll differ diff --git a/support/loader/inprocsrvr_7dw.dll b/support/loader/inprocsrvr_7dw.dll index 1e72652..428939c 100644 Binary files a/support/loader/inprocsrvr_7dw.dll and b/support/loader/inprocsrvr_7dw.dll differ diff --git a/support/loader/inprocsrvr_7rc.dll b/support/loader/inprocsrvr_7rc.dll index afc7e31..0efb2b6 100644 Binary files a/support/loader/inprocsrvr_7rc.dll and b/support/loader/inprocsrvr_7rc.dll differ diff --git a/support/loader/inprocsrvr_7rw.dll b/support/loader/inprocsrvr_7rw.dll index f3e3fba..2a9e3f1 100644 Binary files a/support/loader/inprocsrvr_7rw.dll and b/support/loader/inprocsrvr_7rw.dll differ diff --git a/support/loader/run_6dc.exe b/support/loader/run_6dc.exe index fea69b5..d5bff6c 100644 Binary files a/support/loader/run_6dc.exe and b/support/loader/run_6dc.exe differ diff --git a/support/loader/run_6dw.exe b/support/loader/run_6dw.exe index 85f0b8e..f56dc96 100644 Binary files a/support/loader/run_6dw.exe and b/support/loader/run_6dw.exe differ diff --git a/support/loader/run_6rc.exe b/support/loader/run_6rc.exe index f53ea3c..f9de2bb 100644 Binary files a/support/loader/run_6rc.exe and b/support/loader/run_6rc.exe differ diff --git a/support/loader/run_6rw.exe b/support/loader/run_6rw.exe index 34caf36..be03c9d 100644 Binary files a/support/loader/run_6rw.exe and b/support/loader/run_6rw.exe differ diff --git a/support/loader/run_7dc.exe b/support/loader/run_7dc.exe index afc5fba..1c437ed 100644 Binary files a/support/loader/run_7dc.exe and b/support/loader/run_7dc.exe differ diff --git a/support/loader/run_7dw.exe b/support/loader/run_7dw.exe index 07f4f52..9aac1d2 100644 Binary files a/support/loader/run_7dw.exe and b/support/loader/run_7dw.exe differ diff --git a/support/loader/run_7rc.exe b/support/loader/run_7rc.exe index ac2f2c4..6956552 100644 Binary files a/support/loader/run_7rc.exe and b/support/loader/run_7rc.exe differ diff --git a/support/loader/run_7rw.exe b/support/loader/run_7rw.exe index 316d75b..35df955 100644 Binary files a/support/loader/run_7rw.exe and b/support/loader/run_7rw.exe differ