aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--win32/mingw.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index f96b5b49a..26b046f1a 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -472,22 +472,30 @@ static int has_exec_format(const char *name)
472 * Poke about in file to see if it's a PE binary. I've just copied 472 * Poke about in file to see if it's a PE binary. I've just copied
473 * the magic from the file command. 473 * the magic from the file command.
474 */ 474 */
475 if (buf[0] == 'M' && buf[1] == 'Z' && n > 0x3f) { 475 if (buf[0] == 'M' && buf[1] == 'Z') {
476 offset = (buf[0x19] << 8) + buf[0x18]; 476 /* Actually Portable Executable */
477 if (offset > 0x3f) { 477 /* See ape/ape.S at https://github.com/jart/cosmopolitan */
478 offset = (buf[0x3f] << 24) + (buf[0x3e] << 16) + 478 if (n > 9 && memcmp(buf + 2, "qFpD='\n", 7) == 0)
479 (buf[0x3d] << 8) + buf[0x3c]; 479 return 1;
480 if (offset < sizeof(buf)-100) { 480
481 if (memcmp(buf+offset, "PE\0\0", 4) == 0) { 481 if (n > 0x3f) {
482 sig = (buf[offset+25] << 8) + buf[offset+24]; 482 offset = (buf[0x19] << 8) + buf[0x18];
483 if (sig == 0x10b || sig == 0x20b) { 483 if (offset > 0x3f) {
484 sig = (buf[offset+23] << 8) + buf[offset+22]; 484 offset = (buf[0x3f] << 24) + (buf[0x3e] << 16) +
485 if ((sig & 0x2000) != 0) { 485 (buf[0x3d] << 8) + buf[0x3c];
486 /* DLL */ 486 if (offset < sizeof(buf)-100) {
487 return 0; 487 if (memcmp(buf+offset, "PE\0\0", 4) == 0) {
488 sig = (buf[offset+25] << 8) + buf[offset+24];
489 if (sig == 0x10b || sig == 0x20b) {
490 sig = (buf[offset+23] << 8) + buf[offset+22];
491 if ((sig & 0x2000) != 0) {
492 /* DLL */
493 return 0;
494 }
495 sig = buf[offset+92];
496 return (sig == 1 || sig == 2 || sig == 3
497 || sig == 7);
488 } 498 }
489 sig = buf[offset+92];
490 return (sig == 1 || sig == 2 || sig == 3 || sig == 7);
491 } 499 }
492 } 500 }
493 } 501 }