-
Notifications
You must be signed in to change notification settings - Fork 0
/
aslr.c
37 lines (35 loc) · 895 Bytes
/
aslr.c
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
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include "aslr.h"
void do_memaddr_log(int fd)
{
int i;
int *a = (int *)malloc(sizeof(int));
if(a == NULL){
perror("malloc");
return;
}
char buf[256];
int len = sprintf(buf, "stack addr of PID %d: %p\n", getpid(), &i);
if(write(fd, buf, len) == -1)
perror("write1");
memset(buf, 0, sizeof(buf));
len = sprintf(buf, "heap addr of PID %d: %p\n", getpid(), (void *)a);
if(write(fd, buf, len) == -1)
perror("write2");
free(a);
}
int main(int argc, char *argv[])
{
printf("started PID %d\n", getpid());
char *filename = argv[1];
int fd = open(filename, O_APPEND | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
do_memaddr_log(fd);
close(fd);
return EXIT_SUCCESS;
}