Path: blob/main/contrib/elftoolchain/libpe/libpe.h
39478 views
/*-1* Copyright (c) 2015 Kai Wang2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*25* $Id: libpe.h 3312 2016-01-10 09:23:51Z kaiwang27 $26*/2728#ifndef _LIBPE_H_29#define _LIBPE_H_3031#include <sys/types.h>3233#include "pe.h"3435/* Library private data structures */36typedef struct _PE PE;37typedef struct _PE_Scn PE_Scn;3839/* Section buffers */40typedef struct PE_Buffer {41unsigned int pb_align;42off_t pb_off;43size_t pb_size;44void *pb_buf;45} PE_Buffer;4647/* Object types */48typedef enum {49PE_O_UNKNOWN = 0,50PE_O_PE32,51PE_O_PE32P,52PE_O_COFF,53} PE_Object;5455/* Commands */56typedef enum {57PE_C_NULL = 0,58PE_C_CLR,59PE_C_FDDONE,60PE_C_FDREAD,61PE_C_RDWR,62PE_C_READ,63PE_C_SET,64PE_C_WRITE,65PE_C_NUM66} PE_Cmd;6768/* Flags defined by the API. */69#define PE_F_DIRTY 0x001U70#define PE_F_STRIP_DOS_STUB 0x002U71#define PE_F_STRIP_RICH_HEADER 0x004U72#define PE_F_STRIP_SYMTAB 0x008U73#define PE_F_STRIP_DEBUG 0x010U74#define PE_F_STRIP_SECTION 0x020U7576#ifdef __cplusplus77extern "C" {78#endif7980PE_CoffHdr *pe_coff_header(PE *);81int pe_cntl(PE *, PE_Cmd);82PE_DataDir *pe_data_dir(PE *);83void pe_finish(PE *);84int pe_flag(PE *, PE_Cmd, unsigned int);85int pe_flag_buffer(PE_Buffer *, PE_Cmd, unsigned int);86int pe_flag_coff_header(PE *, PE_Cmd, unsigned int);87int pe_flag_data_dir(PE *, PE_Cmd, unsigned int);88int pe_flag_dos_header(PE *, PE_Cmd, unsigned int);89int pe_flag_opt_header(PE *, PE_Cmd, unsigned int);90int pe_flag_section_header(PE_Scn *, PE_Cmd, unsigned int);91int pe_flag_scn(PE_Scn *, PE_Cmd, unsigned int);92PE_Buffer *pe_getbuffer(PE_Scn *, PE_Buffer *);93PE_Scn *pe_getscn(PE *, size_t);94PE *pe_init(int, PE_Cmd, PE_Object);95PE_Scn *pe_insertscn(PE *, size_t);96PE_DosHdr *pe_msdos_header(PE *);97char *pe_msdos_stub(PE *, size_t *);98size_t pe_ndxscn(PE_Scn *);99PE_Buffer *pe_newbuffer(PE_Scn *);100PE_Scn *pe_newscn(PE *);101PE_Scn *pe_nextscn(PE *, PE_Scn *);102PE_Object pe_object(PE *);103PE_OptHdr *pe_opt_header(PE *);104PE_RichHdr *pe_rich_header(PE *);105int pe_rich_header_validate(PE *);106PE_SecHdr *pe_section_header(PE_Scn *);107off_t pe_update(PE *);108int pe_update_coff_header(PE *, PE_CoffHdr *);109int pe_update_opt_header(PE *, PE_OptHdr *);110int pe_update_data_dir(PE *, PE_DataDir *);111int ps_update_msdos_header(PE *, PE_DosHdr *);112int ps_update_msdos_stub(PE *, char *, size_t);113int pe_update_section_header(PE_Scn *, PE_SecHdr *);114int pe_update_symtab(PE *, char *, size_t, unsigned int);115116#ifdef __cplusplus117}118#endif119120#endif /* !_LIBPE_H_ */121122123