1 /* 2 * ELF payload decoding support. 3 * 4 * Copyright (C) 2022, 2023, 2024 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 rm_flags_t region_flags(); 45 }; 46 47 48 49 /* Generic interface for an ELF payload. */ 50 51 class Payload 52 { 53 public: 54 virtual ~Payload(); 55 56 virtual l4_addr_t entry_point() = 0; 57 virtual offset_t header_extent() = 0; 58 virtual offset_t program_header_extent() = 0; 59 virtual unsigned int segments(); 60 virtual Segment *segment(unsigned int i) = 0; 61 }; 62 63 template <typename HEADER, typename PROGRAM_HEADER> 64 class PayloadVariant : public Payload 65 { 66 protected: 67 HEADER *_header; 68 Segment **_segments = NULL; 69 unsigned int _nsegments; 70 71 public: 72 explicit PayloadVariant(HEADER *header); 73 74 virtual ~PayloadVariant(); 75 76 l4_addr_t entry_point(); 77 offset_t header_extent(); 78 offset_t program_header_extent(); 79 unsigned int segments(); 80 Segment *segment(unsigned int i); 81 }; 82 83 84 85 /* Return the appropriate payload object. */ 86 87 Payload *exec_open_payload(char *buf); 88 89 /* vim: tabstop=2 expandtab shiftwidth=2 90 */