-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathElf.cpp
More file actions
45 lines (33 loc) · 745 Bytes
/
Elf.cpp
File metadata and controls
45 lines (33 loc) · 745 Bytes
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
#include <elf.h>
#include "Elf.hpp"
void* elf::Open(const char* filename) {
if(filename == NULL)
return NULL;
FILE* fp = fopen(filename, "r");
if(!fp) {
return NULL;
}
fseeko(fp, 0, SEEK_END);
off_t elf_len = ftello(fp);
rewind(fp);
if(elf_len == 0) {
fclose(fp);
return NULL;
}
void* elf_data = malloc((size_t) elf_len);
if(fread(elf_data, 1, (size_t) elf_len, fp) != elf_len) {
fclose(fp);
return NULL;
}
fclose(fp);
return elf_data;
}
uint8_t elf::GetClass(void *data) {
Elf64_Ehdr* head = (Elf64_Ehdr*) data;
return (head->e_ident[EI_CLASS]);
}
void elf::Close(void* data) {
if(data) {
free(data);
}
}