blob: 058e5c171540aa7de25cf1374a31daf632bb77be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#ifndef PROGRAM_H
#define PROGRAM_H
#include <unistd.h>
#include <libelf.h>
#include <gelf.h>
#include <cstdint>
#include <vector>
class ProgramLoader {
public:
ProgramLoader(char *file);
~ProgramLoader();
size_t get_nsec(); // Returns number of loadable sections
std::uint32_t get_address(size_t sec); // Get target address for given section
std::vector<std::uint8_t> get_data(size_t sec); // Returns bytes of given section
private:
int fd;
Elf *elf;
GElf_Ehdr hdr; // elf file header
size_t n_secs; // number of sections in elf program header
Elf32_Phdr *phdrs; // program section headers
std::vector<size_t> map; // external index to phdrs index
};
#endif // PROGRAM_H
|