blob: 4ad46b392802e13f9674a2de89f7bffc8d6d01b3 [file] [log] [blame]
Aaron Durbin54ef3062014-03-05 12:12:09 -06001/*
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
23struct buffer;
24
Aaron Durbind0f61652014-03-05 13:09:55 -060025struct parsed_elf {
26 Elf64_Ehdr ehdr;
27 Elf64_Phdr *phdr;
28 Elf64_Shdr *shdr;
29};
30
31#define ELF_PARSE_PHDR (1 << 0)
32#define ELF_PARSE_SHDR (1 << 1)
33
34#define ELF_PARSE_ALL (-1)
35
36/*
37 * Parse an ELF file contained within provide struct buffer. The ELF header
38 * is always parsed while the flags value containing the ELF_PARSE_* values
39 * determine if other parts of the ELF file will be parsed as well.
40 * Returns 0 on success, < 0 error.
41 */
42int parse_elf(const struct buffer *pinput, struct parsed_elf *pelf, int flags);
43
44/*
45 * Clean up memory associated with parsed_elf.
46 */
47void parsed_elf_destroy(struct parsed_elf *pelf);
48
49
Aaron Durbin54ef3062014-03-05 12:12:09 -060050int
51elf_headers(const struct buffer *pinput,
52 uint32_t arch,
53 Elf64_Ehdr *ehdr,
54 Elf64_Phdr **pphdr,
55 Elf64_Shdr **pshdr);
56
57#endif /* ELFPARSING_H */