1295484Semaste/*- 2295484Semaste * Copyright (c) 2015 Kai Wang 3295484Semaste * All rights reserved. 4295484Semaste * 5295484Semaste * Redistribution and use in source and binary forms, with or without 6295484Semaste * modification, are permitted provided that the following conditions 7295484Semaste * are met: 8295484Semaste * 1. Redistributions of source code must retain the above copyright 9295484Semaste * notice, this list of conditions and the following disclaimer. 10295484Semaste * 2. Redistributions in binary form must reproduce the above copyright 11295484Semaste * notice, this list of conditions and the following disclaimer in the 12295484Semaste * documentation and/or other materials provided with the distribution. 13295484Semaste * 14295484Semaste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15295484Semaste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16295484Semaste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17295484Semaste * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18295484Semaste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19295484Semaste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20295484Semaste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21295484Semaste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22295484Semaste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23295484Semaste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24295484Semaste * SUCH DAMAGE. 25295484Semaste * 26295484Semaste * $Id: libpe.h 3312 2016-01-10 09:23:51Z kaiwang27 $ 27295484Semaste */ 28295484Semaste 29295484Semaste#ifndef _LIBPE_H_ 30295484Semaste#define _LIBPE_H_ 31295484Semaste 32295484Semaste#include <sys/types.h> 33295484Semaste 34295484Semaste#include "pe.h" 35295484Semaste 36295484Semaste/* Library private data structures */ 37295484Semastetypedef struct _PE PE; 38295484Semastetypedef struct _PE_Scn PE_Scn; 39295484Semaste 40295484Semaste/* Section buffers */ 41295484Semastetypedef struct PE_Buffer { 42295484Semaste unsigned int pb_align; 43295484Semaste off_t pb_off; 44295484Semaste size_t pb_size; 45295484Semaste void *pb_buf; 46295484Semaste} PE_Buffer; 47295484Semaste 48295484Semaste/* Object types */ 49295484Semastetypedef enum { 50295484Semaste PE_O_UNKNOWN = 0, 51295484Semaste PE_O_PE32, 52295484Semaste PE_O_PE32P, 53295484Semaste PE_O_COFF, 54295484Semaste} PE_Object; 55295484Semaste 56295484Semaste/* Commands */ 57295484Semastetypedef enum { 58295484Semaste PE_C_NULL = 0, 59295484Semaste PE_C_CLR, 60295484Semaste PE_C_FDDONE, 61295484Semaste PE_C_FDREAD, 62295484Semaste PE_C_RDWR, 63295484Semaste PE_C_READ, 64295484Semaste PE_C_SET, 65295484Semaste PE_C_WRITE, 66295484Semaste PE_C_NUM 67295484Semaste} PE_Cmd; 68295484Semaste 69295484Semaste/* Flags defined by the API. */ 70295484Semaste#define PE_F_DIRTY 0x001U 71295484Semaste#define PE_F_STRIP_DOS_STUB 0x002U 72295484Semaste#define PE_F_STRIP_RICH_HEADER 0x004U 73295484Semaste#define PE_F_STRIP_SYMTAB 0x008U 74295484Semaste#define PE_F_STRIP_DEBUG 0x010U 75295484Semaste#define PE_F_STRIP_SECTION 0x020U 76295484Semaste 77295484Semaste#ifdef __cplusplus 78295484Semasteextern "C" { 79295484Semaste#endif 80295484Semaste 81295484SemastePE_CoffHdr *pe_coff_header(PE *); 82295484Semasteint pe_cntl(PE *, PE_Cmd); 83295484SemastePE_DataDir *pe_data_dir(PE *); 84295484Semastevoid pe_finish(PE *); 85295484Semasteint pe_flag(PE *, PE_Cmd, unsigned int); 86295484Semasteint pe_flag_buffer(PE_Buffer *, PE_Cmd, unsigned int); 87295484Semasteint pe_flag_coff_header(PE *, PE_Cmd, unsigned int); 88295484Semasteint pe_flag_data_dir(PE *, PE_Cmd, unsigned int); 89295484Semasteint pe_flag_dos_header(PE *, PE_Cmd, unsigned int); 90295484Semasteint pe_flag_opt_header(PE *, PE_Cmd, unsigned int); 91295484Semasteint pe_flag_section_header(PE_Scn *, PE_Cmd, unsigned int); 92295484Semasteint pe_flag_scn(PE_Scn *, PE_Cmd, unsigned int); 93295484SemastePE_Buffer *pe_getbuffer(PE_Scn *, PE_Buffer *); 94295484SemastePE_Scn *pe_getscn(PE *, size_t); 95295484SemastePE *pe_init(int, PE_Cmd, PE_Object); 96295484SemastePE_Scn *pe_insertscn(PE *, size_t); 97295484SemastePE_DosHdr *pe_msdos_header(PE *); 98295484Semastechar *pe_msdos_stub(PE *, size_t *); 99295484Semastesize_t pe_ndxscn(PE_Scn *); 100295484SemastePE_Buffer *pe_newbuffer(PE_Scn *); 101295484SemastePE_Scn *pe_newscn(PE *); 102295484SemastePE_Scn *pe_nextscn(PE *, PE_Scn *); 103295484SemastePE_Object pe_object(PE *); 104295484SemastePE_OptHdr *pe_opt_header(PE *); 105295484SemastePE_RichHdr *pe_rich_header(PE *); 106295484Semasteint pe_rich_header_validate(PE *); 107295484SemastePE_SecHdr *pe_section_header(PE_Scn *); 108295484Semasteoff_t pe_update(PE *); 109295484Semasteint pe_update_coff_header(PE *, PE_CoffHdr *); 110295484Semasteint pe_update_opt_header(PE *, PE_OptHdr *); 111295484Semasteint pe_update_data_dir(PE *, PE_DataDir *); 112295484Semasteint ps_update_msdos_header(PE *, PE_DosHdr *); 113295484Semasteint ps_update_msdos_stub(PE *, char *, size_t); 114295484Semasteint pe_update_section_header(PE_Scn *, PE_SecHdr *); 115295484Semasteint pe_update_symtab(PE *, char *, size_t, unsigned int); 116295484Semaste 117295484Semaste#ifdef __cplusplus 118295484Semaste} 119295484Semaste#endif 120295484Semaste 121295484Semaste#endif /* !_LIBPE_H_ */ 122