• Home
Name Date Size #Lines LOC

..--

.github/workflows/07-Sep-2024-9757

.vscode/07-Sep-2024-337337

c_wrapper/07-Sep-2024-1,7151,393

cmake/07-Sep-2024-54

doc/07-Sep-2024-3,7603,606

elfio/07-Sep-2024-6,8875,348

examples/07-Sep-2024-1,7611,101

tests/07-Sep-2024-4,2693,176

.clang-formatD07-Sep-20241.3 KiB3533

.gitignoreD07-Sep-20241.8 KiB10186

BUILD.gnD07-Sep-2024960 3428

CMakeLists.txtD07-Sep-20244.9 KiB147119

LICENSED07-Sep-20241.1 KiB2217

LICENSE.txtD07-Sep-20241.1 KiB2217

OAT.xmlD07-Sep-20245.1 KiB7023

README-OH.mdD07-Sep-20244.2 KiB10375

README.OpenSourceD07-Sep-2024499 1211

README.mdD07-Sep-2024877 1611

bundle.jsonD07-Sep-2024852 3333

README-OH.md

1# ELFIO
2
3[![Build](https://travis-ci.com/serge1/ELFIO.svg?branch=master)](https://travis-ci.com/serge1/ELFIO)
4![C/C++ CI](https://github.com/serge1/ELFIO/workflows/C/C++%20CI/badge.svg)
5![CodeQL](https://github.com/serge1/ELFIO/workflows/CodeQL/badge.svg)
6[![Documentation](https://img.shields.io/badge/doc-download-brightgreen)](http://elfio.sourceforge.net/elfio.pdf)
7[![License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/serge1/ELFIO/blob/master/COPYING)
8
9ELFIO是一个只有头文件的C++库,用于读取和生成ELF二进制格式文件。它被用作一个独立的库,它不依赖于任何其他产品或项目。
10它遵循ISO C++,可以在各种架构和编译器上编译。
11
12虽然是用C++编写的,但是该库也提供了一个C语言接口封装器。
13
14完整的库文档可以在【ELFIO-教程和用户手册】(http://elfio.sourceforge.net/elfio.pdf)中找到。
15
16
17# 目录结构
18.
19├── elfio_array.hpp                      # array section访问类,提供对array section的处理
20├── elfio_demo.cpp                       # 空源文件,目的是为了编译出动态库
21├── elfio_dump.hpp                       # elf dump类,dump出elf文件的各类信息,例如:elf header、section headers、segment headers等
22├── elfio_dynamic.hpp                    # dynamic section访问类,提供对dynamic section的处理
23├── elfio_header.hpp                     # elf header类,解析elf header的section
24├── elfio.hpp                            # elfio库的主要类,可以创建、加载、保存elf文件
25├── elfio_modinfo.hpp                    # modinfo section访问类,提供对modinfo section的处理
26├── elfio_note.hpp                       # note section访问类,提供对note section的处理
27├── elfio_relocation.hpp                 # relocation section访问类,提供对relocation section的处理
28├── elfio_section.hpp                    # section类
29├── elfio_segment.hpp                    # segment类
30├── elfio_strings.hpp                    # string section访问类,提供对string section的处理
31├── elfio_symbols.hpp                    # symbol section访问类,提供对symbol section的处理
32├── elfio_utils.hpp                      # elf工具类
33├── elfio_version.hpp                    # 定义elfio库版本号
34└── elf_types.hpp                        # elf类型类,定义了elf文件类型、文件版本等
35
36
37# 使用说明
38
39(一)加载elf文件
40
411.  调用elfio类的load\(\)接口加载elf文件。
42
43    ELFIO::elfio elfIo;
44    elfIo.load(fileName);
45
46
47(二)获取section名称
48
491.  遍历elf文件的sections。
502.  调用section_impl的get_name\(\)接口获取section名称。
51
52    ELFIO::elfio elfIo;
53    for (const auto &section : elfIo.sections) {
54        if (section->get_name() == "xxx")
55    }
56
57
58(三)获取section数据
59
601.  遍历elf文件的sections。
612.  调用section_impl的get_data\(\)接口获取section数据。
62
63    ELFIO::elfio elfIo;
64    for (const auto &section : elfIo_.sections) {
65        if (section->get_name() == "xxx") {
66            section->get_data();
67        }
68    }
69
70
71(四)获取symbol section
72
731.  遍历elf文件的symbol sections。
742.  调用symbol_section_accessor的get_symbol\(\)接口获取symbol section。
75
76    const symbol_section_accessor symbols(reader, psec);
77    for (unsigned int i = 0; i < symbols.get_symbols_num(); ++i) {
78        std::string name;
79        Elf64_Addr value;
80        Elf_Xword size;
81        unsigned char bind;
82        unsigned char type;
83        Elf_Half section_index;
84        unsigned char other;
85        symbols.get_symbol(i, name, value, size, bind, type, section_index, other);
86    }
87
88
89(五)获取relocation section
90
911.  调用relocation_section_accessor的get_entry\(\)接口获取relocation section。
92
93    Elf64_Addr offset;
94    Elf64_Addr symbolValue;
95    string symbolName;
96    Elf_Word type;
97    Elf_Sxword addend;
98    Elf_Sxword calcValue;
99    relocation_section_accessor reloc(elfIo_, sec);
100    for (uint32_t i = 0; i < sec->get_size() / sec->get_entry_size(); i++) {
101        reloc.get_entry(i, offset, symbolValue, symbolName, type, addend, calcValue);
102    }
103

README.OpenSource

1[
2    {
3        "Name"                  : "elfio",
4        "License"               : "The MIT License",
5        "License File"          : "COPYING",
6        "Version Number"        : "Release_3.11",
7        "Owner"                 : "lichunlin2@huawei.com",
8        "Upstream URL"          : "http://elfio.sourceforge.net/",
9        "Description"           : "ELFIO is a small, header-only C++ library that provides a simple interface for reading and generating files in ELF binary format."
10    }
11]
12

README.md

1# ELFIO
2
3![C/C++ CI](https://github.com/serge1/ELFIO/workflows/C/C++%20CI/badge.svg)
4![CodeQL](https://github.com/serge1/ELFIO/workflows/CodeQL/badge.svg)
5[![Documentation](https://img.shields.io/badge/doc-download-brightgreen)](http://elfio.sourceforge.net/elfio.pdf)
6[![License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/serge1/ELFIO/blob/master/COPYING)
7
8ELFIO is a header-only C++ library intended for reading and generating
9files in the ELF binary format. It is used as a standalone library - it is not
10dependent on any other product or project. Adhering to ISO C++, it compiles on
11a wide variety of architectures and compilers.
12
13While written in C++, the library also provides a C-language interface wrapper.
14
15The full library documentation can be found in *[ELFIO - Tutorial and User Manual](http://elfio.sourceforge.net/elfio.pdf)*.
16