/* p_lx_elf.h -- This file is part of the UPX executable compressor. Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2023 Laszlo Molnar Copyright (C) 2000-2023 John F. Reiser All Rights Reserved. UPX and the UCL library are free software; you can redistribute them and/or modify them under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Markus F.X.J. Oberhumer Laszlo Molnar John F. Reiser */ #pragma once #ifndef __UPX_P_LX_ELF_H //{ #define __UPX_P_LX_ELF_H 1 typedef upx_uint32_t u32_t; // easier to type; more narrow typedef upx_uint64_t u64_t; // easier to type; more narrow class PackLinuxElf : public PackUnix { typedef PackUnix super; public: PackLinuxElf(InputFile *f); virtual ~PackLinuxElf(); /*virtual void buildLoader(const Filter *);*/ virtual int getVersion() const override { return 14; } // upx-3.96 cannot upack, for instance virtual bool canUnpackVersion(int version) const override { return (version >= 11); } virtual int canUnpack() override { return super::canUnpack(); } // bool, except -1: format known, but not packed protected: virtual const int *getCompressionMethods(int method, int level) const override; // All other virtual functions in this class must be pure virtual // because they depend on Elf32 or Elf64 data structures, which differ. virtual void pack1(OutputFile *, Filter &) override = 0; // generate executable header virtual int pack2(OutputFile *, Filter &) override = 0; // append compressed data virtual off_t pack3(OutputFile *, Filter &) override = 0; // append loader //virtual void pack4(OutputFile *, Filter &) override = 0; // append pack header virtual void generateElfHdr( OutputFile *, void const *proto, unsigned const brka ) = 0; virtual void defineSymbols(Filter const *); virtual void addStubEntrySections(Filter const *, unsigned m_decompr); virtual void unpack(OutputFile *fo) override; unsigned old_data_off, old_data_len; // un_shlib virtual upx_uint64_t elf_unsigned_dynamic(unsigned) const = 0; static unsigned elf_hash(char const *) /*const*/; static unsigned gnu_hash(char const *) /*const*/; protected: static unsigned int const asl_delta = (1u<<12); // --android-shlib extra page unsigned e_type; unsigned e_phnum; /* Program header table entry count */ unsigned e_shnum; unsigned e_shstrndx; MemBuffer file_image; // if ET_DYN investigation MemBuffer lowmem; // at least including PT_LOAD[0] MemBuffer mb_shdr; // Shdr might not be near Phdr MemBuffer mb_dt_offsets; // file offset of various DT_ tables unsigned *dt_offsets; // index by dt_table[] unsigned symnum_end; unsigned strtab_end; char const *dynstr; // from DT_STRTAB unsigned sz_phdrs; // sizeof Phdr[] unsigned sz_elf_hdrs; // all Elf headers unsigned sz_pack2; // after pack2(), before loader unsigned sz_pack2a; // after pack2() of all PT_LOAD unsigned lg2_page; // log2(PAGE_SIZE) unsigned page_size; // 1u<