mirror of
https://github.com/FDOS/kernel.git
synced 2025-07-26 15:24:15 +02:00
Let exeflat call UPX itself like in the unstable branch. Simplifies makefile.
git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1353 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
parent
194aa09e69
commit
69d767be50
@ -37,11 +37,7 @@ production: ..\bin\$(TARGET).sys
|
|||||||
copy kernel.map ..\bin\$(TARGET).map
|
copy kernel.map ..\bin\$(TARGET).map
|
||||||
|
|
||||||
kernel.sys: kernel.exe ..\utils\exeflat.exe
|
kernel.sys: kernel.exe ..\utils\exeflat.exe
|
||||||
..\utils\exeflat kernel.exe kernelf.exe 0x60 -S0x10 -S0x74 -E
|
..\utils\exeflat kernel.exe kernel.sys 0x60 -S0x10 -S0x74 $(UPXOPT) $(XUPX)
|
||||||
$(COMSPEC) /c if exist kernelf.exe $(XUPX) kernelf.exe
|
|
||||||
$(COMSPEC) /c if exist kernelf.sys $(XUPX) kernelf.sys
|
|
||||||
..\utils\exeflat kernelf.exe kernel.sys 0x60 $(UPXOPT)
|
|
||||||
-$(RM) kernelf.exe kernelf.sys
|
|
||||||
|
|
||||||
kernel.exe: $(TARGET).lnk $(OBJS) $(LIBS)
|
kernel.exe: $(TARGET).lnk $(OBJS) $(LIBS)
|
||||||
$(LINK) @$(TARGET).lnk;
|
$(LINK) @$(TARGET).lnk;
|
||||||
|
@ -83,7 +83,7 @@ static void usage(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int exeflat(int UPX, const char *srcfile, const char *dstfile,
|
static int exeflat(const char *srcfile, const char *dstfile,
|
||||||
const char *start, short *silentSegments, short silentcount,
|
const char *start, short *silentSegments, short silentcount,
|
||||||
int flat_exe, exe_header *header)
|
int flat_exe, exe_header *header)
|
||||||
{
|
{
|
||||||
@ -100,16 +100,8 @@ static int exeflat(int UPX, const char *srcfile, const char *dstfile,
|
|||||||
|
|
||||||
if ((src = fopen(srcfile, "rb")) == NULL)
|
if ((src = fopen(srcfile, "rb")) == NULL)
|
||||||
{
|
{
|
||||||
if (UPX && strlen(srcfile) > 3)
|
printf("Source file %s could not be opened\n", srcfile);
|
||||||
{
|
exit(1);
|
||||||
strcpy((char *)srcfile + strlen(srcfile) - 3, "sys");
|
|
||||||
if (rename(srcfile, dstfile) == -1)
|
|
||||||
{
|
|
||||||
printf("Source file %s could not be opened\n", srcfile);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (fread(header, sizeof(*header), 1, src) != 1)
|
if (fread(header, sizeof(*header), 1, src) != 1)
|
||||||
{
|
{
|
||||||
@ -208,8 +200,6 @@ static int exeflat(int UPX, const char *srcfile, const char *dstfile,
|
|||||||
|
|
||||||
/* The biggest .sys file that UPX accepts seems to be 65419 bytes long */
|
/* The biggest .sys file that UPX accepts seems to be 65419 bytes long */
|
||||||
compress_sys_file = flat_exe && size < 65420;
|
compress_sys_file = flat_exe && size < 65420;
|
||||||
if (compress_sys_file && strlen(dstfile) > 3)
|
|
||||||
strcpy((char *)dstfile + strlen(dstfile) - 3, "sys");
|
|
||||||
|
|
||||||
if ((dest = fopen(dstfile, "wb+")) == NULL)
|
if ((dest = fopen(dstfile, "wb+")) == NULL)
|
||||||
{
|
{
|
||||||
@ -348,8 +338,9 @@ int main(int argc, char **argv)
|
|||||||
static exe_header header; /* must be initialized to zero */
|
static exe_header header; /* must be initialized to zero */
|
||||||
int UPX = FALSE, flat_exe = FALSE;
|
int UPX = FALSE, flat_exe = FALSE;
|
||||||
int i;
|
int i;
|
||||||
|
size_t sz, len, len2, n;
|
||||||
int compress_sys_file;
|
int compress_sys_file;
|
||||||
char *buffer;
|
char *buffer, *tmpexe, *cmdbuf;
|
||||||
FILE *dest;
|
FILE *dest;
|
||||||
long size;
|
long size;
|
||||||
|
|
||||||
@ -357,7 +348,7 @@ int main(int argc, char **argv)
|
|||||||
if (argc < 4) usage();
|
if (argc < 4) usage();
|
||||||
|
|
||||||
/* do optional argument processing here */
|
/* do optional argument processing here */
|
||||||
for (i = 4; i < argc; i++)
|
for (i = 4; i < argc && !UPX; i++)
|
||||||
{
|
{
|
||||||
char *argptr = argv[i];
|
char *argptr = argv[i];
|
||||||
|
|
||||||
@ -369,7 +360,7 @@ int main(int argc, char **argv)
|
|||||||
switch (toupper(argptr[0]))
|
switch (toupper(argptr[0]))
|
||||||
{
|
{
|
||||||
case 'U':
|
case 'U':
|
||||||
UPX = TRUE;
|
UPX = i;
|
||||||
break;
|
break;
|
||||||
case 'E':
|
case 'E':
|
||||||
flat_exe = TRUE;
|
flat_exe = TRUE;
|
||||||
@ -393,12 +384,56 @@ int main(int argc, char **argv)
|
|||||||
/* arguments left :
|
/* arguments left :
|
||||||
infile outfile relocation offset */
|
infile outfile relocation offset */
|
||||||
|
|
||||||
compress_sys_file = exeflat(UPX, argv[1], argv[2], argv[3],
|
compress_sys_file = exeflat(argv[1], argv[2], argv[3],
|
||||||
silentSegments, silentcount,
|
silentSegments, silentcount,
|
||||||
flat_exe, &header);
|
TRUE, &header);
|
||||||
if (!UPX)
|
if (!UPX || flat_exe)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
/* move kernel.sys tmp$$$$$.exe */
|
||||||
|
tmpexe = argv[2];
|
||||||
|
if (!compress_sys_file)
|
||||||
|
{
|
||||||
|
tmpexe = "tmp$$$$$.exe";
|
||||||
|
rename(argv[2], tmpexe);
|
||||||
|
}
|
||||||
|
|
||||||
|
len2 = strlen(tmpexe) + 1;
|
||||||
|
sz = len2;
|
||||||
|
if (sz < 256) sz = 256;
|
||||||
|
cmdbuf = malloc(sz);
|
||||||
|
len = 0;
|
||||||
|
for (i = UPX+1; i < argc; i++)
|
||||||
|
{
|
||||||
|
n = strlen(argv[i]);
|
||||||
|
if (len + len2 + n + 2 >= sz) {
|
||||||
|
sz *= 2;
|
||||||
|
cmdbuf = realloc(cmdbuf, sz);
|
||||||
|
}
|
||||||
|
if (i > UPX+1)
|
||||||
|
cmdbuf[len++] = ' ';
|
||||||
|
memcpy(cmdbuf + len, argv[i], n + 1);
|
||||||
|
len += n;
|
||||||
|
}
|
||||||
|
cmdbuf[len++] = ' ';
|
||||||
|
memcpy(cmdbuf + len, tmpexe, len2);
|
||||||
|
printf("%s\n", cmdbuf);
|
||||||
|
if (system(cmdbuf))
|
||||||
|
{
|
||||||
|
printf("Problems executing %s\n", cmdbuf);
|
||||||
|
remove(tmpexe);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
free(cmdbuf);
|
||||||
|
|
||||||
|
if (!compress_sys_file)
|
||||||
|
{
|
||||||
|
exeflat(tmpexe, argv[2], argv[3],
|
||||||
|
silentSegments, silentcount,
|
||||||
|
FALSE, &header);
|
||||||
|
remove(tmpexe);
|
||||||
|
}
|
||||||
|
|
||||||
/* argv[2] now contains the final flattened file: just
|
/* argv[2] now contains the final flattened file: just
|
||||||
header and trailer need to be added */
|
header and trailer need to be added */
|
||||||
/* the compressed file has two chunks max */
|
/* the compressed file has two chunks max */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user