1 /* 2 * ELF payload decoding support. 3 * 4 * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <exec/segment.h> 25 26 27 28 /* Generic program segment interface. */ 29 30 template <typename PROGRAM_HEADER> 31 class ProgramSegmentVariant : public Segment 32 { 33 protected: 34 PROGRAM_HEADER *_header; 35 36 public: 37 explicit ProgramSegmentVariant(PROGRAM_HEADER *header); 38 39 bool loadable(); 40 offset_t file_contents(); 41 offset_t file_offset(); 42 l4_addr_t region_address(); 43 offset_t region_size(); 44 l4re_rm_flags_t region_flags(); 45 }; 46 47 48 49 /* Generic interface for an ELF payload. */ 50 51 class Payload 52 { 53 protected: 54 Segment **_segments = NULL; 55 56 public: 57 virtual ~Payload(); 58 59 virtual l4_addr_t entry_point() = 0; 60 virtual offset_t header_extent() = 0; 61 virtual offset_t program_header_extent() = 0; 62 virtual unsigned int segments(); 63 virtual Segment *segment(unsigned int i) = 0; 64 }; 65 66 template <typename HEADER, typename PROGRAM_HEADER> 67 class PayloadVariant : public Payload 68 { 69 protected: 70 HEADER *_header; 71 72 public: 73 explicit PayloadVariant(HEADER *header); 74 75 l4_addr_t entry_point(); 76 offset_t header_extent(); 77 offset_t program_header_extent(); 78 unsigned int segments(); 79 Segment *segment(unsigned int i); 80 }; 81 82 83 84 /* Return the appropriate payload object. */ 85 86 Payload *get_payload(char *buf); 87 88 /* vim: tabstop=2 expandtab shiftwidth=2 89 */