From ea3a3b6e1c19bf8350c4da04238c681ee0d6501b Mon Sep 17 00:00:00 2001 From: John Reiser Date: Mon, 3 Jul 2006 05:47:01 -0700 Subject: [PATCH 1/2] Elf32_Ehdr::ELFOSABI_LINUX --- src/main.cpp | 3 ++- src/p_lx_elf.cpp | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4c8e6435..cc915a5b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -739,7 +739,7 @@ static int do_option(int optc, const char *arg) opt->o_unix.make_ptinterp = true; break; case 666: // Linux - opt->o_unix.osabi0 = 0; // Elf32_Ehdr::ELFOSABI_LINUX + opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX; break; case 667: // FreeBSD opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_FREEBSD; @@ -904,6 +904,7 @@ static const struct mfx_option longopts[] = prepare_shortopts(buf,"123456789hH?V",longopts), mfx_optind = 0; mfx_opterr = 1; + opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX; while ((optc = mfx_getopt_long(argc, argv, buf, longopts, &longind)) >= 0) { if (do_option(optc, argv[mfx_optind-1]) != 0) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 117ee062..a393b2d8 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -572,6 +572,7 @@ PackLinuxElf32x86::buildLoader(const Filter *ft) { unsigned char tmp[sizeof(linux_i386elf_fold)]; memcpy(tmp, linux_i386elf_fold, sizeof(linux_i386elf_fold)); + ((Elf32_Ehdr *)tmp)->e_ident[Elf32_Ehdr::EI_OSABI] = ei_osabi; checkPatch(NULL, 0, 0, 0); // reset if (opt->o_unix.is_ptinterp) { unsigned j; @@ -935,6 +936,7 @@ PackLinuxElf32::generateElfHdr( cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout; cprElfHdr3 *const h3 = (cprElfHdr3 *)&elfout; memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK + h3->ehdr.e_ident[Elf32_Ehdr::EI_OSABI] = ei_osabi; assert(get_native32(&h2->ehdr.e_phoff) == sizeof(Elf32_Ehdr)); h2->ehdr.e_shoff = 0; @@ -1866,7 +1868,7 @@ PackLinuxElf32x86::PackLinuxElf32x86(InputFile *f) : super(f) e_machine = Elf32_Ehdr::EM_386; ei_class = Elf32_Ehdr::ELFCLASS32; ei_data = Elf32_Ehdr::ELFDATA2LSB; - ei_osabi = Elf32_Ehdr::ELFOSABI_NONE; // ELFOSABI_LINUX + ei_osabi = Elf32_Ehdr::ELFOSABI_LINUX; } PackLinuxElf32x86::~PackLinuxElf32x86() From 18fe124696cff28ba3d9e2a55ff2d0b17a4fcc18 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Mon, 3 Jul 2006 05:51:45 -0700 Subject: [PATCH 2/2] ::generateElfHdr() sets .e_ident[Elf32_Ehdr::EI_OSABI] --- src/p_lx_elf.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index a393b2d8..4e0d0bef 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -99,11 +99,15 @@ int PackLinuxElf64::checkEhdr(Elf64_Ehdr const *ehdr) const { const unsigned char * const buf = ehdr->e_ident; + unsigned osabi0 = buf[Elf32_Ehdr::EI_OSABI]; + if (0==osabi0) { + osabi0 = opt->o_unix.osabi0; + } if (0!=memcmp(buf, "\x7f\x45\x4c\x46", 4) // "\177ELF" || buf[Elf64_Ehdr::EI_CLASS]!=ei_class || buf[Elf64_Ehdr::EI_DATA] !=ei_data - || buf[Elf64_Ehdr::EI_OSABI] !=ei_osabi + || osabi0!=ei_osabi ) { return -1; } @@ -572,7 +576,6 @@ PackLinuxElf32x86::buildLoader(const Filter *ft) { unsigned char tmp[sizeof(linux_i386elf_fold)]; memcpy(tmp, linux_i386elf_fold, sizeof(linux_i386elf_fold)); - ((Elf32_Ehdr *)tmp)->e_ident[Elf32_Ehdr::EI_OSABI] = ei_osabi; checkPatch(NULL, 0, 0, 0); // reset if (opt->o_unix.is_ptinterp) { unsigned j; @@ -601,8 +604,6 @@ PackBSDElf32x86::buildLoader(const Filter *ft) { unsigned char tmp[sizeof(bsd_i386elf_fold)]; memcpy(tmp, bsd_i386elf_fold, sizeof(bsd_i386elf_fold)); - ((Elf32_Ehdr *)tmp)->e_ident[Elf32_Ehdr::EI_OSABI] = ei_osabi; - ((Elf32_Ehdr *)tmp)->e_ident[Elf32_Ehdr::EI_ABIVERSION] = 0; checkPatch(NULL, 0, 0, 0); // reset if (opt->o_unix.is_ptinterp) { unsigned j; @@ -988,6 +989,7 @@ PackLinuxElf64::generateElfHdr( cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout; cprElfHdr3 *const h3 = (cprElfHdr3 *)&elfout; memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK + h3->ehdr.e_ident[Elf32_Ehdr::EI_OSABI] = ei_osabi; assert(get_native32(&h2->ehdr.e_phoff) == sizeof(Elf64_Ehdr)); h2->ehdr.e_shoff = 0;