File: dump-sections.cc

package info (click to toggle)
libelfin 0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 668 kB
  • sloc: cpp: 4,883; makefile: 189; python: 139; sh: 129; ansic: 10
file content (40 lines) | stat: -rw-r--r-- 1,347 bytes parent folder | download | duplicates (3)
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
#include "elf++.hh"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <inttypes.h>

int main(int argc, char **argv)
{
        if (argc != 2) {
                fprintf(stderr, "usage: %s elf-file\n", argv[0]);
                return 2;
        }

        int fd = open(argv[1], O_RDONLY);
        if (fd < 0) {
                fprintf(stderr, "%s: %s\n", argv[1], strerror(errno));
                return 1;
        }

        elf::elf f(elf::create_mmap_loader(fd));
        int i = 0;
        printf("  [Nr] %-16s %-16s %-16s %s\n",
               "Name", "Type", "Address", "Offset");
        printf("       %-16s %-16s %-15s %5s %4s %5s\n",
               "Size", "EntSize", "Flags", "Link", "Info", "Align");
        for (auto &sec : f.sections()) {
                auto &hdr = sec.get_hdr();
                printf("  [%2d] %-16s %-16s %016" PRIx64 " %08" PRIx64 "\n", i++,
                       sec.get_name().c_str(),
                       to_string(hdr.type).c_str(),
                       hdr.addr, hdr.offset);
                printf("       %016zx %016" PRIx64 " %-15s %5s %4d %5" PRIu64 "\n",
                       sec.size(), hdr.entsize,
                       to_string(hdr.flags).c_str(), to_string(hdr.link).c_str(),
                       (int)hdr.info, hdr.addralign);
        }

        return 0;
}