1/*- 2 * Copyright (c) 2015 Kai Wang 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $Id: libpe.h 3312 2016-01-10 09:23:51Z kaiwang27 $ 27 */ 28 29#ifndef _LIBPE_H_ 30#define _LIBPE_H_ 31 32#include <sys/types.h> 33 34#include "pe.h" 35 36/* Library private data structures */ 37typedef struct _PE PE; 38typedef struct _PE_Scn PE_Scn; 39 40/* Section buffers */ 41typedef struct PE_Buffer { 42 unsigned int pb_align; 43 off_t pb_off; 44 size_t pb_size; 45 void *pb_buf; 46} PE_Buffer; 47 48/* Object types */ 49typedef enum { 50 PE_O_UNKNOWN = 0, 51 PE_O_PE32, 52 PE_O_PE32P, 53 PE_O_COFF, 54} PE_Object; 55 56/* Commands */ 57typedef enum { 58 PE_C_NULL = 0, 59 PE_C_CLR, 60 PE_C_FDDONE, 61 PE_C_FDREAD, 62 PE_C_RDWR, 63 PE_C_READ, 64 PE_C_SET, 65 PE_C_WRITE, 66 PE_C_NUM 67} PE_Cmd; 68 69/* Flags defined by the API. */ 70#define PE_F_DIRTY 0x001U 71#define PE_F_STRIP_DOS_STUB 0x002U 72#define PE_F_STRIP_RICH_HEADER 0x004U 73#define PE_F_STRIP_SYMTAB 0x008U 74#define PE_F_STRIP_DEBUG 0x010U 75#define PE_F_STRIP_SECTION 0x020U 76 77#ifdef __cplusplus 78extern "C" { 79#endif 80 81PE_CoffHdr *pe_coff_header(PE *); 82int pe_cntl(PE *, PE_Cmd); 83PE_DataDir *pe_data_dir(PE *); 84void pe_finish(PE *); 85int pe_flag(PE *, PE_Cmd, unsigned int); 86int pe_flag_buffer(PE_Buffer *, PE_Cmd, unsigned int); 87int pe_flag_coff_header(PE *, PE_Cmd, unsigned int); 88int pe_flag_data_dir(PE *, PE_Cmd, unsigned int); 89int pe_flag_dos_header(PE *, PE_Cmd, unsigned int); 90int pe_flag_opt_header(PE *, PE_Cmd, unsigned int); 91int pe_flag_section_header(PE_Scn *, PE_Cmd, unsigned int); 92int pe_flag_scn(PE_Scn *, PE_Cmd, unsigned int); 93PE_Buffer *pe_getbuffer(PE_Scn *, PE_Buffer *); 94PE_Scn *pe_getscn(PE *, size_t); 95PE *pe_init(int, PE_Cmd, PE_Object); 96PE_Scn *pe_insertscn(PE *, size_t); 97PE_DosHdr *pe_msdos_header(PE *); 98char *pe_msdos_stub(PE *, size_t *); 99size_t pe_ndxscn(PE_Scn *); 100PE_Buffer *pe_newbuffer(PE_Scn *); 101PE_Scn *pe_newscn(PE *); 102PE_Scn *pe_nextscn(PE *, PE_Scn *); 103PE_Object pe_object(PE *); 104PE_OptHdr *pe_opt_header(PE *); 105PE_RichHdr *pe_rich_header(PE *); 106int pe_rich_header_validate(PE *); 107PE_SecHdr *pe_section_header(PE_Scn *); 108off_t pe_update(PE *); 109int pe_update_coff_header(PE *, PE_CoffHdr *); 110int pe_update_opt_header(PE *, PE_OptHdr *); 111int pe_update_data_dir(PE *, PE_DataDir *); 112int ps_update_msdos_header(PE *, PE_DosHdr *); 113int ps_update_msdos_stub(PE *, char *, size_t); 114int pe_update_section_header(PE_Scn *, PE_SecHdr *); 115int pe_update_symtab(PE *, char *, size_t, unsigned int); 116 117#ifdef __cplusplus 118} 119#endif 120 121#endif /* !_LIBPE_H_ */ 122