-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSectionEntry.cpp
More file actions
61 lines (55 loc) · 2.07 KB
/
SectionEntry.cpp
File metadata and controls
61 lines (55 loc) · 2.07 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
61
#include "SectionEntry.hpp"
#include "Utils.hpp"
#include "AllocationException.hpp"
SectionEntry::SectionEntry() {
}
SectionEntry::~SectionEntry() {
delete[] name;
}
void SectionEntry::parse(Buffer buffer, size_t offset, uint16_t* index, COFFHeader* coff_header) {
// Copy data structure
nSectionEntry entry_struct = buffer.get<nSectionEntry>(offset + (*index) * sizeof(nSectionEntry));
// Retrieve the name
if(entry_struct.name[0] == '/') {
// The string is located in the string table
char* offset_str = &entry_struct.name[1];
uint32_t offset = std::stoi(std::string(offset_str));
char* string = coff_header->getString(offset);
size_t string_len = strlen(string) + 1;
// Copy it
this->name = new char[string_len];
if(!name) {
throw new AllocationException();
}
memcpy(name, string, string_len);
} else {
// Is the string null terminated?
char* string = &entry_struct.name[0];
bool null_term = string[7] == '\0';
if(null_term) {
size_t string_len = strlen(string) + 1;
this->name = new char[string_len];
if(!name) {
throw new AllocationException();
}
memcpy(name, string, string_len);
} else {
this->name = new char[9];
if(!name) {
throw new AllocationException();
}
memcpy(name, string, 8);
name[8] = '\0';
}
}
// Copy the rest of the data
this->virtual_size = entry_struct.virtual_size;
this->virtual_address = entry_struct.virtual_address;
this->raw_data_size = entry_struct.raw_data_size;
this->raw_data_ptr = entry_struct.raw_data_ptr;
this->relocation_ptr = entry_struct.relocation_ptr;
this->line_number_ptr = entry_struct.line_number_ptr;
this->number_of_relocation = entry_struct.number_of_relocation;
this->number_of_line_number = entry_struct.number_of_line_number;
this->characteristics = entry_struct.characteristics;
}