Upx_Doxygen
https://github.com/upx/upx
p_lx_exc.h
1 /* p_lx_exc.h --
2 
3  This file is part of the UPX executable compressor.
4 
5  Copyright (C) 1996-2016 Markus Franz Xaver Johannes Oberhumer
6  Copyright (C) 1996-2016 Laszlo Molnar
7  All Rights Reserved.
8 
9  UPX and the UCL library are free software; you can redistribute them
10  and/or modify them under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of
12  the License, or (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; see the file COPYING.
21  If not, write to the Free Software Foundation, Inc.,
22  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24  Markus F.X.J. Oberhumer Laszlo Molnar
25  <markus@oberhumer.com> <ezerotven+github@gmail.com>
26 
27  John F. Reiser
28  <jreiser@users.sourceforge.net>
29  */
30 
31 
32 #ifndef __UPX_P_LX_EXC_H
33 #define __UPX_P_LX_EXC_H 1
34 
35 
36 /*************************************************************************
37 // linux/386 (generic "execve" format)
38 **************************************************************************/
39 
41 {
42  typedef PackUnixLe32 super;
43 public:
45  virtual void generateElfHdr(
46  OutputFile *,
47  void const *proto,
48  unsigned const brka
49  );
50  virtual int getFormat() const { return UPX_F_LINUX_i386; }
51  virtual const char *getName() const { return "linux.exec/i386"; }
52  virtual const char *getFullName(const options_t *) const { return "i386-linux.elf.execve"; }
53  virtual const int *getCompressionMethods(int method, int level) const;
54  virtual const int *getFilters() const;
55  virtual void buildLoader(const Filter *);
56 
57  virtual bool canPack();
58 
59 protected:
60  virtual void pack1(OutputFile *, Filter &); // generate executable header
61  // virtual void pack2(OutputFile *, Filter &); // append compressed data
62  // virtual void pack3(OutputFile *, Filter &); // append loader
63  virtual void pack4(OutputFile *, Filter &); // append PackHeader
64 
65  // loader util
66  virtual Linker* newLinker() const;
67  virtual int getLoaderPrefixSize() const;
68  virtual void buildLinuxLoader(
69  upx_byte const *const proto, // assembly-only sections
70  unsigned const szproto,
71  upx_byte const *const fold, // linked assembly + C section
72  unsigned const szfold,
73  Filter const *ft
74  );
75 
76  // patch util
77  virtual void patchLoader();
78  virtual void patchLoaderChecksum();
79  virtual void updateLoader(OutputFile *);
80 
81  // ELF util
82  virtual int checkEhdr(const Elf_LE32_Ehdr *ehdr) const;
83 
84  enum {
85  UPX_ELF_MAGIC = 0x5850557f // "\x7fUPX"
86  };
87 
88  unsigned n_mru;
89 
90  __packed_struct(cprElfHdr1)
91  Elf_LE32_Ehdr ehdr;
92  Elf_LE32_Phdr phdr[1];
93  l_info linfo;
94  __packed_struct_end()
95 
96  __packed_struct(cprElfHdr2)
97  Elf_LE32_Ehdr ehdr;
98  Elf_LE32_Phdr phdr[2];
99  l_info linfo;
100  __packed_struct_end()
101 
102  __packed_struct(cprElfHdr3)
103  Elf_LE32_Ehdr ehdr;
104  Elf_LE32_Phdr phdr[3];
105  l_info linfo;
106  __packed_struct_end()
107 
108  cprElfHdr3 elfout;
109 
110  struct Elf32_Note {
111  unsigned namesz; // 8
112  unsigned descsz; // 4
113  unsigned type; // 1
114  char text[0x18 - 4*4]; // "OpenBSD"
115  unsigned end; // 0
116  } elfnote;
117 
118  unsigned char ei_osabi;
119  char const *osabi_note;
120 
121  static void compileTimeAssertions() {
122  COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 52 + 1*32 + 12)
123  COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 52 + 2*32 + 12)
124  COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 52 + 3*32 + 12)
125  COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
126  COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
127  COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
128  }
129 };
130 
131 
133 {
134  typedef PackLinuxI386 super;
135 public:
137  virtual int getFormat() const { return UPX_F_BSD_i386; }
138  virtual const char *getName() const { return "bsd.exec/i386"; }
139  virtual const char *getFullName(const options_t *) const { return "i386-bsd.elf.execve"; }
140 
141 protected:
142  virtual void pack1(OutputFile *, Filter &); // generate executable header
143 
144  virtual void buildLoader(const Filter *);
145 };
146 #endif /* already included */
147 
148 /* vim:set ts=4 sw=4 et: */
Definition: linker.h:35
Definition: p_lx_exc.h:132
Definition: options.h:45
Definition: file.h:89
Definition: file.h:121
Definition: p_unix.h:161
Definition: filter.h:53
Definition: p_lx_exc.h:40
Definition: p_lx_exc.h:110