23 #ifndef ELFIO_DYNAMIC_HPP
24 #define ELFIO_DYNAMIC_HPP
33 : elf_file(elf_file_), dynamic_section(section_) {}
36 Elf_Xword get_entries_num()
const {
39 if (0 != dynamic_section->get_entry_size()) {
40 nRet = dynamic_section->get_size() / dynamic_section->get_entry_size();
47 bool get_entry(Elf_Xword index, Elf_Xword& tag, Elf_Xword& value, std::string& str)
const {
48 if (index >= get_entries_num()) {
52 if (elf_file.get_class() == ELFCLASS32) {
53 generic_get_entry_dyn<Elf32_Dyn>(index, tag, value);
55 generic_get_entry_dyn<Elf64_Dyn>(index, tag, value);
59 if (tag == DT_NEEDED || tag == DT_SONAME || tag == DT_RPATH || tag == DT_RUNPATH) {
61 const char* result = strsec.get_string(value);
75 void add_entry(Elf_Xword& tag, Elf_Xword& value) {
76 if (elf_file.get_class() == ELFCLASS32) {
77 generic_add_entry<Elf32_Dyn>(tag, value);
79 generic_add_entry<Elf64_Dyn>(tag, value);
84 void add_entry(Elf_Xword& tag, std::string& str) {
86 Elf_Xword value = strsec.add_string(str);
87 add_entry(tag, value);
93 Elf_Half get_string_table_index()
const {
return (Elf_Half)dynamic_section->get_link(); }
97 void generic_get_entry_dyn(Elf_Xword index, Elf_Xword& tag, Elf_Xword& value)
const {
101 if (dynamic_section->get_data() == 0 ||
102 (index + 1) * dynamic_section->get_entry_size() > dynamic_section->get_size()) {
108 const T* pEntry =
reinterpret_cast<const T*
>(dynamic_section->get_data() +
109 index * dynamic_section->get_entry_size());
110 tag = convertor(pEntry->d_tag);
129 case DT_INIT_ARRAYSZ:
130 case DT_FINI_ARRAYSZ:
133 case DT_PREINIT_ARRAYSZ:
134 value = convertor(pEntry->d_un.d_val);
148 case DT_PREINIT_ARRAY:
150 value = convertor(pEntry->d_un.d_ptr);
157 void generic_add_entry(Elf_Xword tag, Elf_Xword value) {
179 case DT_INIT_ARRAYSZ:
180 case DT_FINI_ARRAYSZ:
183 case DT_PREINIT_ARRAYSZ:
184 entry.d_un.d_val = convertor(value);
198 case DT_PREINIT_ARRAY:
200 entry.d_un.d_ptr = convertor(value);
204 entry.d_tag = convertor(tag);
206 dynamic_section->append_data(
reinterpret_cast<char*
>(&entry),
sizeof(entry));
211 const elfio& elf_file;
217 #endif // ELFIO_DYNAMIC_HPP