libelf_ehdr.c (165535) | libelf_ehdr.c (210338) |
---|---|
1/*- 2 * Copyright (c) 2006 Joseph Koshy 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 unchanged lines hidden (view full) --- 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 * | 1/*- 2 * Copyright (c) 2006 Joseph Koshy 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 unchanged lines hidden (view full) --- 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 * $FreeBSD: head/lib/libelf/libelf_ehdr.c 165535 2006-12-25 02:22:22Z jkoshy $ | 26 * $FreeBSD: head/lib/libelf/libelf_ehdr.c 210338 2010-07-21 10:25:02Z kaiw $ |
27 */ 28 29#include <sys/cdefs.h> | 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/lib/libelf/libelf_ehdr.c 165535 2006-12-25 02:22:22Z jkoshy $"); | 30__FBSDID("$FreeBSD: head/lib/libelf/libelf_ehdr.c 210338 2010-07-21 10:25:02Z kaiw $"); |
31 32#include <assert.h> 33#include <gelf.h> 34#include <libelf.h> 35#include <stdlib.h> 36 37#include "_libelf.h" 38 39/* 40 * Retrieve counts for sections, phdrs and the section string table index 41 * from section header #0 of the ELF object. 42 */ 43static int 44_libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum, 45 uint16_t strndx) 46{ 47 Elf_Scn *scn; 48 size_t fsz; | 31 32#include <assert.h> 33#include <gelf.h> 34#include <libelf.h> 35#include <stdlib.h> 36 37#include "_libelf.h" 38 39/* 40 * Retrieve counts for sections, phdrs and the section string table index 41 * from section header #0 of the ELF object. 42 */ 43static int 44_libelf_load_extended(Elf *e, int ec, uint64_t shoff, uint16_t phnum, 45 uint16_t strndx) 46{ 47 Elf_Scn *scn; 48 size_t fsz; |
49 void (*xlator)(char *_d, char *_s, size_t _c, int _swap); | 49 int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap); |
50 uint32_t shtype; 51 52 assert(STAILQ_EMPTY(&e->e_u.e_elf.e_scn)); 53 54 fsz = _libelf_fsize(ELF_T_SHDR, ec, e->e_version, 1); 55 assert(fsz > 0); 56 57 if (e->e_rawsize < shoff + fsz) { /* raw file too small */ 58 LIBELF_SET_ERROR(HEADER, 0); 59 return (0); 60 } 61 62 if ((scn = _libelf_allocate_scn(e, (size_t) 0)) == NULL) 63 return (0); 64 65 xlator = _libelf_get_translator(ELF_T_SHDR, ELF_TOMEMORY, ec); | 50 uint32_t shtype; 51 52 assert(STAILQ_EMPTY(&e->e_u.e_elf.e_scn)); 53 54 fsz = _libelf_fsize(ELF_T_SHDR, ec, e->e_version, 1); 55 assert(fsz > 0); 56 57 if (e->e_rawsize < shoff + fsz) { /* raw file too small */ 58 LIBELF_SET_ERROR(HEADER, 0); 59 return (0); 60 } 61 62 if ((scn = _libelf_allocate_scn(e, (size_t) 0)) == NULL) 63 return (0); 64 65 xlator = _libelf_get_translator(ELF_T_SHDR, ELF_TOMEMORY, ec); |
66 (*xlator)((char *) &scn->s_shdr, e->e_rawfile + shoff, (size_t) 1, | 66 (*xlator)((char *) &scn->s_shdr, sizeof(scn->s_shdr), 67 e->e_rawfile + shoff, (size_t) 1, |
67 e->e_byteorder != LIBELF_PRIVATE(byteorder)); 68 69#define GET_SHDR_MEMBER(M) ((ec == ELFCLASS32) ? scn->s_shdr.s_shdr32.M : \ 70 scn->s_shdr.s_shdr64.M) 71 72 if ((shtype = GET_SHDR_MEMBER(sh_type)) != SHT_NULL) { 73 LIBELF_SET_ERROR(SECTION, 0); 74 return (0); --- 25 unchanged lines hidden (view full) --- 100 101void * 102_libelf_ehdr(Elf *e, int ec, int allocate) 103{ 104 void *ehdr; 105 size_t fsz, msz; 106 uint16_t phnum, shnum, strndx; 107 uint64_t shoff; | 68 e->e_byteorder != LIBELF_PRIVATE(byteorder)); 69 70#define GET_SHDR_MEMBER(M) ((ec == ELFCLASS32) ? scn->s_shdr.s_shdr32.M : \ 71 scn->s_shdr.s_shdr64.M) 72 73 if ((shtype = GET_SHDR_MEMBER(sh_type)) != SHT_NULL) { 74 LIBELF_SET_ERROR(SECTION, 0); 75 return (0); --- 25 unchanged lines hidden (view full) --- 101 102void * 103_libelf_ehdr(Elf *e, int ec, int allocate) 104{ 105 void *ehdr; 106 size_t fsz, msz; 107 uint16_t phnum, shnum, strndx; 108 uint64_t shoff; |
108 void (*xlator)(char *_d, char *_s, size_t _c, int _swap); | 109 int (*xlator)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap); |
109 110 assert(ec == ELFCLASS32 || ec == ELFCLASS64); 111 112 if (e == NULL || e->e_kind != ELF_K_ELF) { 113 LIBELF_SET_ERROR(ARGUMENT, 0); 114 return (NULL); 115 } 116 --- 45 unchanged lines hidden (view full) --- 162 163 if (allocate) 164 e->e_flags |= ELF_F_DIRTY; 165 166 if (e->e_cmd == ELF_C_WRITE) 167 return (ehdr); 168 169 xlator = _libelf_get_translator(ELF_T_EHDR, ELF_TOMEMORY, ec); | 110 111 assert(ec == ELFCLASS32 || ec == ELFCLASS64); 112 113 if (e == NULL || e->e_kind != ELF_K_ELF) { 114 LIBELF_SET_ERROR(ARGUMENT, 0); 115 return (NULL); 116 } 117 --- 45 unchanged lines hidden (view full) --- 163 164 if (allocate) 165 e->e_flags |= ELF_F_DIRTY; 166 167 if (e->e_cmd == ELF_C_WRITE) 168 return (ehdr); 169 170 xlator = _libelf_get_translator(ELF_T_EHDR, ELF_TOMEMORY, ec); |
170 (*xlator)(ehdr, e->e_rawfile, (size_t) 1, | 171 (*xlator)(ehdr, msz, e->e_rawfile, (size_t) 1, |
171 e->e_byteorder != LIBELF_PRIVATE(byteorder)); 172 173 /* 174 * If extended numbering is being used, read the correct 175 * number of sections and program header entries. 176 */ 177 if (ec == ELFCLASS32) { 178 phnum = ((Elf32_Ehdr *) ehdr)->e_phnum; --- 26 unchanged lines hidden --- | 172 e->e_byteorder != LIBELF_PRIVATE(byteorder)); 173 174 /* 175 * If extended numbering is being used, read the correct 176 * number of sections and program header entries. 177 */ 178 if (ec == ELFCLASS32) { 179 phnum = ((Elf32_Ehdr *) ehdr)->e_phnum; --- 26 unchanged lines hidden --- |