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