README-OH.md
1# ELFIO
2
3[](https://travis-ci.com/serge1/ELFIO)
4
5
6[](http://elfio.sourceforge.net/elfio.pdf)
7[](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 §ion : 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 §ion : 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