Created
March 27, 2017 09:45
-
-
Save antekone/fec31143d791a4f4ee09930f9f07bd20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
int global_var = 0; | |
int main() { | |
int fd = open("/proc/self/mem", O_RDWR); | |
if(!fd) { | |
printf("can't open /proc/self/mem as O_RDWR\n"); | |
return 1; | |
} | |
printf("- opened /proc/self/mem as rdwr\n"); | |
int* addr = &global_var; | |
printf("- global var address: %p\n", addr); | |
int buf; | |
lseek(fd, (off_t) addr, SEEK_SET); | |
read(fd, &buf, 4); | |
printf("- contents of global_var: 0x%08x (read through /proc/self/mem)\n", buf); | |
buf = 0x12345; | |
printf("- saving 0x%08lx to global_var through /proc/self/mem...\n", buf); | |
lseek(fd, (off_t) addr, SEEK_SET); | |
write(fd, &buf, 4); | |
printf("- contents of global_var: 0x%08x (read directly)\n", global_var); | |
return 0; | |
} |
Author
antekone
commented
Mar 27, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment