Line | Count | Source (jump to first uncovered line) |
1 | | /* p_djgpp2.h -- |
2 | | |
3 | | This file is part of the UPX executable compressor. |
4 | | |
5 | | Copyright (C) 1996-2025 Markus Franz Xaver Johannes Oberhumer |
6 | | Copyright (C) 1996-2025 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 | | |
28 | | #pragma once |
29 | | |
30 | | /************************************************************************* |
31 | | // djgpp2/coff |
32 | | **************************************************************************/ |
33 | | |
34 | | class PackDjgpp2 final : public Packer { |
35 | | typedef Packer super; |
36 | | |
37 | | public: |
38 | | explicit PackDjgpp2(InputFile *f); |
39 | 27.6k | virtual int getVersion() const override { return 14; } |
40 | 27.6k | virtual int getFormat() const override { return UPX_F_DJGPP2_COFF; } |
41 | 3 | virtual const char *getName() const override { return "djgpp2/coff"; } |
42 | 0 | virtual const char *getFullName(const Options *) const override { |
43 | 0 | return "i386-dos32.djgpp2.coff"; |
44 | 0 | } |
45 | | virtual const int *getCompressionMethods(int method, int level) const override; |
46 | | virtual const int *getFilters() const override; |
47 | | |
48 | | virtual void pack(OutputFile *fo) override; |
49 | | virtual void unpack(OutputFile *fo) override; |
50 | | |
51 | | virtual tribool canPack() override; |
52 | | virtual tribool canUnpack() override; |
53 | | |
54 | | protected: |
55 | | void handleStub(OutputFile *fo); |
56 | | int readFileHeader(); |
57 | | |
58 | | virtual unsigned findOverlapOverhead(const byte *buf, const byte *tbuf, unsigned range = 0, |
59 | | unsigned upper_limit = ~0u) const override; |
60 | | virtual void buildLoader(const Filter *ft) override; |
61 | | virtual Linker *newLinker() const override; |
62 | | |
63 | | unsigned coff_offset; |
64 | | |
65 | | // based on https://dox.ipxe.org/PeImage_8h_source.html |
66 | | struct alignas(1) dos_header_t { |
67 | | LE16 e_magic; |
68 | | LE16 e_cblp; // Bytes on last page of file |
69 | | LE16 e_cp; // Pages in file |
70 | | LE16 e_crlc; // Relocations |
71 | | LE16 e_cparhdr; // Size of header in paragraphs |
72 | | LE16 e_OMITTED[32 - 5 * 2]; |
73 | | }; // 64 bytes |
74 | | |
75 | | struct alignas(1) external_scnhdr_t { |
76 | | byte _[12]; // name, paddr |
77 | | LE32 vaddr; |
78 | | LE32 size; |
79 | | LE32 scnptr; |
80 | | byte misc[12]; // relptr, lnnoptr, nreloc, nlnno |
81 | | byte __[4]; // flags |
82 | | }; |
83 | | |
84 | | struct alignas(1) coff_header_t { |
85 | | // ext_file_hdr |
86 | | LE16 f_magic; |
87 | | LE16 f_nscns; |
88 | | byte _[4]; // f_timdat |
89 | | LE32 f_symptr; |
90 | | LE32 f_nsyms; |
91 | | byte __[2]; // f_opthdr |
92 | | LE16 f_flags; |
93 | | |
94 | | // aout_hdr |
95 | | LE16 a_magic; |
96 | | byte ___[2]; // a_vstamp |
97 | | LE32 a_tsize; |
98 | | LE32 a_dsize; |
99 | | byte ____[4]; // a_bsize |
100 | | LE32 a_entry; |
101 | | byte _____[8]; // a_text_start a_data_start |
102 | | |
103 | | // section headers |
104 | | external_scnhdr_t sh[3]; |
105 | | }; |
106 | | |
107 | | coff_header_t coff_hdr; |
108 | | external_scnhdr_t *text = nullptr; |
109 | | external_scnhdr_t *data = nullptr; |
110 | | external_scnhdr_t *bss = nullptr; |
111 | | |
112 | | void stripDebug(); |
113 | | }; |
114 | | |
115 | | /* vim:set ts=4 sw=4 et: */ |