-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
44 lines (42 loc) · 850 Bytes
/
Copy pathmain.c
File metadata and controls
44 lines (42 loc) · 850 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
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include "elf.h"
void *read_file(int fd)
{
void *res;
struct stat file_info;
if (fstat(fd, &file_info))
{
perror("stat :");
return NULL;
}
size_t file_size = file_info.st_size;
res = mmap(NULL, file_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
if (res == MAP_FAILED)
{
perror("mmap :");
return NULL;
}
return res;
}
int main(int argc, char **argv)
{
if (argc < 2)
{
write(1, "Error in nb argument \n",22);
return 0;
}
int fd = open(argv[1], O_RDWR);
if (fd == -1)
{
perror("open :");
return -1;
}
Elf64_Ehdr *res = read_file(fd);
printf("%lu\n", res->e_entry);
return 0;
}