-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsections.c
More file actions
63 lines (58 loc) · 2.12 KB
/
sections.c
File metadata and controls
63 lines (58 loc) · 2.12 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Display the section headers of an ELF object
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <elf.h>
#include <sys/types.h>
#include <search.h>
#include <sys/time.h>
#include "../include/libelfmaster.h"
int main(int argc, char **argv)
{
elfobj_t obj;
elf_error_t error;
elf_section_iterator_t s_iter;
struct elf_section section;
struct elf_plt plt;
size_t count = 0;
if (argc < 2) {
printf("Usage: %s <binary>\n", argv[0]);
exit(EXIT_SUCCESS);
}
if (elf_open_object(argv[1], &obj,
ELF_LOAD_F_SMART|ELF_LOAD_F_FORENSICS, &error) == false) {
fprintf(stderr, "%s\n", elf_error_msg(&error));
return -1;
}
if (obj.flags & ELF_SHDRS_F)
printf("*** Section Headers:\n");
/*
* The iterator simply won't print anything if there are no sections
* so we don't have to nest this block of code
*/
elf_section_iterator_init(&obj, &s_iter);
while (elf_section_iterator_next(&s_iter, §ion) == ELF_ITER_OK) {
struct elf_section tmp_section;
printf("\nSection %u\n", count++);
printf("Name: %s\n", section.name ? section.name : "");
printf("Addr: %#lx\n", section.address);
printf("Off: %#lx\n", section.offset);
printf("Size: %#lx\n", section.size);
printf("Info: %u\n", section.info);
printf("Flags: %C%C%C\n", section.flags & SHF_ALLOC ? 'A' : ' ',
section.flags & SHF_EXECINSTR ? 'X' : ' ',
section.flags & SHF_WRITE ? 'W' : ' ');
if (elf_section_by_index(&obj, section.link, &tmp_section) == true) {
if (tmp_section.name != NULL)
printf("Link: %s\n", tmp_section.name);
else
printf("Link: %u\n", section.link);
} else {
printf("Link: %u\n", section.link);
}
printf("Align: %lx\n", section.align);
printf("EntSiz: %lu\n", section.entsize);
}
}