-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCOFFSymbol.cpp
More file actions
54 lines (49 loc) · 1.67 KB
/
Copy pathCOFFSymbol.cpp
File metadata and controls
54 lines (49 loc) · 1.67 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
#include "COFFSymbol.hpp"
#include "AllocationException.hpp"
#include <string>
COFFSymbol::COFFSymbol() {
}
COFFSymbol::~COFFSymbol() {
delete[] name;
}
void COFFSymbol::parse(Buffer buffer, size_t symbol_table_ptr, uint32_t* index, COFFHeader* coff_header) {
nSymbol symbol_struct = buffer.get<nSymbol>(symbol_table_ptr + (sizeof(nSymbol) * (*index)));
// Retrieve the name
if(symbol_struct.zero == 0) {
// The string is located in the string table
uint32_t offset = symbol_struct.offset;
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 = &symbol_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';
}
}
this->value = symbol_struct.value;
this->section_number = symbol_struct.section_number;
this->type = symbol_struct.type;
this->cclass = symbol_struct.cclass;
this->auxiliary_number = symbol_struct.auxiliary_number;
*index += auxiliary_number;
}