Aaron Durbin | 54ef306 | 2014-03-05 12:12:09 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Google, Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA |
| 16 | */ |
| 17 | |
| 18 | #ifndef ELFPARSING_H |
| 19 | #define ELFPARSING_H |
| 20 | |
| 21 | #include "elf.h" |
| 22 | |
| 23 | struct buffer; |
| 24 | |
Aaron Durbin | d0f6165 | 2014-03-05 13:09:55 -0600 | [diff] [blame] | 25 | struct parsed_elf { |
| 26 | Elf64_Ehdr ehdr; |
| 27 | Elf64_Phdr *phdr; |
| 28 | Elf64_Shdr *shdr; |
Aaron Durbin | ccb5ad8 | 2014-03-05 13:57:30 -0600 | [diff] [blame^] | 29 | /* |
| 30 | * The relocs array contains pointers to arrays of relocation |
| 31 | * structures. Each index into the relocs array corresponds to its |
| 32 | * corresponding section index. i.e. if a section i is of type SHT_REL |
| 33 | * or SHT_RELA then the corresponding index into the relocs array will |
| 34 | * contain the associated relocations. Otherwise thee entry will be |
| 35 | * NULL. |
| 36 | */ |
| 37 | Elf64_Rela **relocs; |
Aaron Durbin | d0f6165 | 2014-03-05 13:09:55 -0600 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | #define ELF_PARSE_PHDR (1 << 0) |
| 41 | #define ELF_PARSE_SHDR (1 << 1) |
Aaron Durbin | ccb5ad8 | 2014-03-05 13:57:30 -0600 | [diff] [blame^] | 42 | #define ELF_PARSE_RELOC (1 << 2) |
Aaron Durbin | d0f6165 | 2014-03-05 13:09:55 -0600 | [diff] [blame] | 43 | |
| 44 | #define ELF_PARSE_ALL (-1) |
| 45 | |
| 46 | /* |
| 47 | * Parse an ELF file contained within provide struct buffer. The ELF header |
| 48 | * is always parsed while the flags value containing the ELF_PARSE_* values |
| 49 | * determine if other parts of the ELF file will be parsed as well. |
| 50 | * Returns 0 on success, < 0 error. |
| 51 | */ |
| 52 | int parse_elf(const struct buffer *pinput, struct parsed_elf *pelf, int flags); |
| 53 | |
| 54 | /* |
| 55 | * Clean up memory associated with parsed_elf. |
| 56 | */ |
| 57 | void parsed_elf_destroy(struct parsed_elf *pelf); |
| 58 | |
| 59 | |
Aaron Durbin | 54ef306 | 2014-03-05 12:12:09 -0600 | [diff] [blame] | 60 | int |
| 61 | elf_headers(const struct buffer *pinput, |
| 62 | uint32_t arch, |
| 63 | Elf64_Ehdr *ehdr, |
| 64 | Elf64_Phdr **pphdr, |
| 65 | Elf64_Shdr **pshdr); |
| 66 | |
| 67 | #endif /* ELFPARSING_H */ |