32 lines
671 B
C
32 lines
671 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "helpers.h"
|
|
|
|
uint64_t get_base_address(uint32_t pid) {
|
|
char maps_file[MAX_PATH_LEN];
|
|
FILE* file;
|
|
char line[MAX_LINE_LEN];
|
|
uint64_t base_address = 0;
|
|
|
|
snprintf(maps_file, MAX_PATH_LEN, "/proc/%d/maps", pid);
|
|
|
|
file = fopen(maps_file, "r");
|
|
if (file == NULL) {
|
|
perror("fopen");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
while (fgets(line, sizeof(line), file)) {
|
|
char *address = strtok(line, "-");
|
|
if (address != NULL) {
|
|
base_address = strtoul(address, NULL, 16);
|
|
break;
|
|
}
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
return base_address;
|
|
}
|