Added option `--force-execve' which forces the use of the generic

linux/386 format.

committer: mfx <mfx> 977486503 +0000
This commit is contained in:
Markus F.X.J. Oberhumer
2000-12-22 12:01:43 +00:00
parent 47760c37fc
commit dbbc47a334
6 changed files with 56 additions and 36 deletions
+1
View File
@@ -516,6 +516,7 @@ struct options_t {
} tos; } tos;
struct { struct {
unsigned blocksize; unsigned blocksize;
bool force_execve; // force the linux/386 execve format
enum { SCRIPT_MAX = 32 }; enum { SCRIPT_MAX = 32 };
const char *script_name; const char *script_name;
} unix; } unix;
+5 -1
View File
@@ -637,6 +637,9 @@ static int do_option(int optc, const char *arg)
getoptvar(&opt->unix.blocksize, 8192u, ~0u); getoptvar(&opt->unix.blocksize, 8192u, ~0u);
break; break;
case 661: case 661:
opt->unix.force_execve = true;
break;
case 662:
opt->unix.script_name = "/usr/local/lib/upx/upxX"; opt->unix.script_name = "/usr/local/lib/upx/upxX";
if (mfx_optarg && mfx_optarg[0]) if (mfx_optarg && mfx_optarg[0])
set_script_name(mfx_optarg,1); set_script_name(mfx_optarg,1);
@@ -742,8 +745,9 @@ static const struct mfx_option longopts[] =
// dos/sys // dos/sys
// unix // unix
{"blocksize", 0x31, 0, 660}, // --blocksize= {"blocksize", 0x31, 0, 660}, // --blocksize=
{"force-execve", 0x10, 0, 661}, // force linux/386 execve format
#if 0 #if 0
{"script", 0x31, 0, 661}, // --script= {"script", 0x31, 0, 662}, // --script=
#endif #endif
// watcom/le // watcom/le
{"le", 0, 0, 620}, // produce LE output {"le", 0, 0, 620}, // produce LE output
+4 -10
View File
@@ -173,19 +173,13 @@ bool PackLinuxI386elf::canPack()
fi->readx(buf, sizeof(buf)); fi->readx(buf, sizeof(buf));
fi->seek(0, SEEK_SET); fi->seek(0, SEEK_SET);
if (0 != memcmp(buf, "\x7f\x45\x4c\x46\x01\x01\x01", 7)) // ELF 32-bit LSB Elf_LE32_Ehdr const *const ehdr = (Elf_LE32_Ehdr const *)buf;
return false;
// now check the ELF header // now check the ELF header
Elf_LE32_Ehdr const *const ehdr = (Elf_LE32_Ehdr const *)buf; if (checkEhdr(ehdr) != 0)
if (memcmp(buf+8, "FreeBSD", 7) == 0) // branded as FreeBSD
return false;
if (ehdr->e_type != 2) // executable
return false;
if (ehdr->e_machine != 3 && ehdr->e_machine != 6) // Intel 80[34]86
return false;
if (ehdr->e_version != 1) // version
return false; return false;
// additional requirements for linux/elf386
if (ehdr->e_ehsize != sizeof(*ehdr)) { if (ehdr->e_ehsize != sizeof(*ehdr)) {
throwCantPack("invalid Ehdr e_ehsize"); throwCantPack("invalid Ehdr e_ehsize");
return false; return false;
+33 -17
View File
@@ -88,6 +88,31 @@ int PackLinuxI386::getLoaderPrefixSize() const
// //
**************************************************************************/ **************************************************************************/
// basic check of an Linux ELF Ehdr
int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
{
const unsigned char * const buf = ehdr->e_ident;
// NOTE: ELF executables are now handled by p_lx_elf.cpp.
if (memcmp(buf, "\x7f\x45\x4c\x46\x01\x01\x01", 7)) // ELF 32-bit LSB
return -1;
// FIXME: add special checks for uncompresed "vmlinux" kernel
// now check the ELF header
if (!memcmp(buf+8, "FreeBSD", 7)) // branded
return 1;
if (ehdr->e_type != 2) // executable
return 2;
if (ehdr->e_machine != 3 && ehdr->e_machine != 6) // Intel 80[34]86
return 3;
if (ehdr->e_version != 1) // version
return 4;
// success
return 0;
}
bool PackLinuxI386::canPack() bool PackLinuxI386::canPack()
{ {
if (exetype != 0) if (exetype != 0)
@@ -101,25 +126,16 @@ bool PackLinuxI386::canPack()
exetype = 0; exetype = 0;
const unsigned l = get_le32(buf); const unsigned l = get_le32(buf);
#if 0
// NOTE: ELF executables are now handled by p_lx_elf.cpp. int elf = checkEhdr(&ehdr);
if (!memcmp(buf, "\x7f\x45\x4c\x46\x01\x01\x01", 7)) // ELF 32-bit LSB if (elf >= 0)
{ {
// FIXME: add special checks for uncompresed "vmlinux" kernel // NOTE: ELF executables are now handled by p_lx_elf.cpp,
exetype = 1; // so we only handle them here if force_execve
// now check the ELF header if (elf == 0 && opt->unix.force_execve)
if (!memcmp(buf+8, "FreeBSD", 7)) // branded exetype = 1;
exetype = 0;
if (ehdr.e_type != 2) // executable
exetype = 0;
if (ehdr.e_machine != 3 && ehdr.e_machine != 6) // Intel 80[34]86
exetype = 0;
if (ehdr.e_version != 1) // version
exetype = 0;
} }
else else if (l == 0x00640107 || l == 0x00640108 || l == 0x0064010b || l == 0x006400cc)
#endif
if (l == 0x00640107 || l == 0x00640108 || l == 0x0064010b || l == 0x006400cc)
{ {
// OMAGIC / NMAGIC / ZMAGIC / QMAGIC // OMAGIC / NMAGIC / ZMAGIC / QMAGIC
exetype = 2; exetype = 2;
+2
View File
@@ -50,6 +50,8 @@ protected:
virtual int getLoaderSize() const; virtual int getLoaderSize() const;
virtual int getLoaderPrefixSize() const; virtual int getLoaderPrefixSize() const;
virtual int checkEhdr(const Elf_LE32_Ehdr *ehdr) const;
virtual void patchLoader(); virtual void patchLoader();
virtual void patchLoaderChecksum(); virtual void patchLoaderChecksum();
virtual void updateLoader(OutputFile *); virtual void updateLoader(OutputFile *);
+11 -8
View File
@@ -185,17 +185,20 @@ static Packer* try_packers(InputFile *f, try_function func)
// //
// linux // linux
// //
#if 0 if (!opt->unix.force_execve)
if (opt->unix.script_name)
{ {
if ((p = func(new PackLinuxI386sep(f),f)) != NULL) #if 0
if (opt->unix.script_name)
{
if ((p = func(new PackLinuxI386sep(f),f)) != NULL)
return p;
}
#endif
if ((p = func(new PackLinuxI386elf(f),f)) != NULL)
return p;
if ((p = func(new PackLinuxI386sh(f),f)) != NULL)
return p; return p;
} }
#endif
if ((p = func(new PackLinuxI386elf(f),f)) != NULL)
return p;
if ((p = func(new PackLinuxI386sh(f),f)) != NULL)
return p;
if ((p = func(new PackLinuxI386(f),f)) != NULL) if ((p = func(new PackLinuxI386(f),f)) != NULL)
return p; return p;