1 /* 2 * Copyright 2011 Red Hat, Inc. 3 * All rights reserved. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 * Author(s): Peter Jones <pjones@redhat.com> 18 */ 19 #ifndef LIBDPE_H 20 #define LIBDPE_H 1 21 22 #include <sys/types.h> 23 24 #include <libdpe/pe.h> 25 26 typedef enum { 27 PE_K_NONE, 28 PE_K_MZ, 29 PE_K_PE_OBJ, 30 PE_K_PE_EXE, 31 PE_K_PE_ROM, 32 PE_K_PE64_OBJ, 33 PE_K_PE64_EXE, 34 PE_K_NUM /* terminating entry */ 35 } Pe_Kind; 36 37 typedef enum { 38 PE_C_NULL, 39 PE_C_READ, 40 PE_C_RDWR, 41 PE_C_WRITE, 42 PE_C_CLR, 43 PE_C_SET, 44 PE_C_FDDONE, 45 PE_C_FDREAD, 46 PE_C_READ_MMAP, 47 PE_C_RDWR_MMAP, 48 PE_C_WRITE_MMAP, 49 PE_C_READ_MMAP_PRIVATE, 50 PE_C_EMPTY, 51 PE_C_NUM /* last entry */ 52 } Pe_Cmd; 53 54 typedef enum { 55 PE_DATA_DIR_EXPORTS = 1, 56 PE_DATA_DIR_IMPORTS, 57 PE_DATA_DIR_RESOURCES, 58 PE_DATA_DIR_EXCEPTIONS, 59 PE_DATA_DIR_CERTIFICATES, 60 PE_DATA_DIR_BASE_RELOCATIONS, 61 PE_DATA_DIR_DEBUG, 62 PE_DATA_DIR_ARCH, 63 PE_DATA_DIR_GLOBAL_POINTER, 64 PE_DATA_TLS, 65 PE_DATA_LOAD_CONFIG, 66 PE_DATA_BOUND_IMPORT, 67 PE_DATA_IMPORT_ADDRESS, 68 PE_DATA_DELAY_IMPORTS, 69 PE_DATA_CLR_RUNTIME_HEADER, 70 PE_DATA_RESERVED, 71 PE_DATA_NUM /* last entry */ 72 } Pe_DataDir_Type; 73 74 typedef struct Pe Pe; 75 typedef struct Pe_Scn Pe_Scn; 76 77 extern Pe *pe_begin(int fildes, Pe_Cmd cmd, Pe *ref); 78 extern Pe *pe_clone(Pe *pe, Pe_Cmd cmd); 79 extern Pe *pe_memory(char *image, size_t size); 80 extern int pe_end(Pe *pe); 81 extern off_t pe_update(Pe *pe, Pe_Cmd cmd); 82 extern Pe_Kind pe_kind(Pe *Pe) __attribute__ ((__pure__)); 83 extern Pe_Scn *pe_nextscn(Pe *pe, Pe_Scn *scn); 84 extern Pe_Scn *pe_getscn(Pe *pe, size_t idx); 85 extern struct section_header *pe_getshdr(Pe_Scn *scn, struct section_header *dst); 86 extern struct pe_hdr *pe_getpehdr(Pe *pe, struct pe_hdr *pehdr); 87 extern char *pe_rawfile(Pe *pe, size_t *ptr); 88 extern int pe_getdatadir(Pe *pe, data_directory **dd); 89 extern void *pe_getopthdr(Pe *pe); 90 extern uint32_t pe_get_file_alignment(Pe *pe); 91 extern uint32_t pe_get_scn_alignment(Pe *pe); 92 extern int pe_set_image_size(Pe *pe); 93 94 extern int pe_extend_file(Pe *pe, size_t size, uint32_t *new_space, int align); 95 extern int pe_freespace(Pe *pe, uint32_t offset, size_t size); 96 extern int pe_shorten_file(Pe *pe, size_t size); 97 98 extern int pe_clearcert(Pe *pe); 99 extern int pe_alloccert(Pe *pe, size_t len); 100 extern int pe_populatecert(Pe *pe, void *cert, size_t len); 101 102 extern int pe_errno(void); 103 extern const char *pe_errmsg(int error); 104 105 #endif /* LIBDPE_H */ 106