-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelocation_section.h
More file actions
60 lines (59 loc) · 2.31 KB
/
relocation_section.h
File metadata and controls
60 lines (59 loc) · 2.31 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
/*
* Auto-added header
* File: relocation_section.h
* Author: camradeling
* Email: camradeling@gmail.com
* 2025
*/
//------------------------------------------------------------------------------------------------------------------------------
#ifndef RELOCATION_SECTION_H
#define RELOCATION_SECTION_H
//------------------------------------------------------------------------------------------------------------------------------
#include <stdint.h>
#include <string>
#include <iterator>
#include <vector>
#include <algorithm>
#include <memory>
#include <elf.h>
//------------------------------------------------------------------------------------------------------------------------------
#include "section.h"
#include "logger.h"
#include "rel.h"
#include "memory_helpers.h"
//------------------------------------------------------------------------------------------------------------------------------
namespace ElfMan
{
//------------------------------------------------------------------------------------------------------------------------------
class RelocationSection : public Section {
public:
RelocationSection(Elf32_Shdr* header, const uint8_t* buffer, uint32_t total_sz, ObjectFile* obj)
: Section(header, obj)
{
ElfMan::Memory::InputMemoryStream stream(buffer, total_sz);
int index = 0;
while (stream.size()) {
Elf32_Rel rhdr;
stream.read(rhdr);
LOG_DEBUG("found relocation r_offset 0x%08X, r_info 0x%08X", rhdr.r_offset, rhdr.r_info);
auto rel = std::make_shared<ElfMan::Rel>(&rhdr, obj);
relocations.push_back(rel);
rel->index = index++;
}
}
virtual std::vector<uint8_t> serialize() {
std::vector<uint8_t> result;
for (auto rel : relocations)
{
result.insert(result.end(), (char*)&rel->rhdr, (char*)&rel->rhdr+sizeof(rel->rhdr));
}
return result;
}
std::vector<std::shared_ptr<ElfMan::Rel>> relocations;
private:
static bool registered;
};
//------------------------------------------------------------------------------------------------------------------------------
} //namespace ElfMan
//------------------------------------------------------------------------------------------------------------------------------
#endif/*RELOCATION_SECTION_H*/