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
29
30
31
32
33
34
35
36
37
38
39
#include "util/header/elf.h"
#include <asm-generic/errno-base.h>
#include <fcntl.h>
int main(int argc, char **argv) {
if (argc != 3) return EINVAL;
int32_t fd = open(argv[1], O_RDONLY);
if (fd == -1) {
close(fd);
return ENOENT;
}
Elf64_Ehdr header;
int8_t result;
if ((result = process_header(fd, &header)) != 0) {
close(fd);
return result;
}
if ((result = process_segments(fd, &header)) != 0) {
close(fd);
return result;
}
Elf64_Shdr string_table_section;
if ((result = read_string_table(fd, &header, &string_table_section)) != 0) {
close(fd);
return result;
}
Elf64_Shdr section;
result = find_section(fd, &header, &string_table_section, argv[2], §ion);
if (result != 0) {
close(fd);
return result;
}
((void(*)(void)) section.sh_addr)(); // NOLINT
close(fd);
return 0;
}