From 920274e93acf0ab87fe787c3027908672837af4b Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Mon, 28 May 2007 18:45:52 +0000 Subject: [PATCH] Fix stack for UPX-compressed kernels via a .sys file; adjust the threshold from 64K to the real UPX limit which is 65420. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1333 6ac86273-5f31-0410-b378-82cca8765d1b --- utils/exeflat.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/utils/exeflat.c b/utils/exeflat.c index 394c104..6802c70 100644 --- a/utils/exeflat.c +++ b/utils/exeflat.c @@ -248,7 +248,8 @@ int main(int argc, char **argv) } if (flat_exe) { - compress_sys_file = size < 0x10000L; + /* The biggest .sys file that UPX accepts seems to be 65419 bytes long */ + compress_sys_file = size < 65420; if (compress_sys_file && strlen(argv[2]) > 3) strcpy(argv[2] + strlen(argv[2]) - 3, "sys"); } @@ -360,10 +361,14 @@ int main(int argc, char **argv) *(short *)&trailer[1] = (short)size + 0x20; *(short *)&trailer[23] = header.exInitSS; *(short *)&trailer[28] = header.exInitSP; - if (compress_sys_file) + if (compress_sys_file) { /* replace by jmp word ptr [6]: ff 26 06 00 (the .SYS strategy handler which will unpack) */ *(long *)&trailer[30] = 0x000626ffL; + /* set up a 4K stack for the UPX decompressor to work with */ + *(short *)&trailer[23] = 0x1000; + *(short *)&trailer[28] = 0x1000; + } fwrite(trailer, 1, sizeof trailer, dest); } if (flat_exe && compress_sys_file) {