Created
April 15, 2024 16:30
-
-
Save hikari-no-yume/ea99e733f6d99cb9b43c5680b3245a51 to your computer and use it in GitHub Desktop.
test of /proc/xxx/mem
This file contains hidden or 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 <stdlib.h> | |
#include <string.h> | |
void main(int argc, char **argv) | |
{ | |
char *secret = strdup(argv[1]); | |
printf("I have a secret! It is located at %p and is %zu bytes long!\n", secret, strlen(secret)); | |
while (1) {} | |
free(secret); | |
} |
This file contains hidden or 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
#define _GNU_SOURCE /* asprintf isn't in standard C before C23 */ | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <errno.h> | |
int main(int argc, char **argv) | |
{ | |
int pid = atoi(argv[1]); | |
size_t addr = (size_t)strtoll(argv[2], NULL, 0); | |
size_t size = (size_t)strtoll(argv[3], NULL, 0); | |
char *path; | |
asprintf(&path, "/proc/%d/mem", pid); | |
FILE *fp = fopen(path, "r"); | |
if (!fp) { | |
perror("couldn't open file"); | |
return 1; | |
} | |
free(path); | |
fseek(fp, (long)addr, SEEK_SET); | |
char *secret = malloc(size); | |
fread(secret, size, 1, fp); | |
fclose(fp); | |
printf("the secret is: %.*s\n", (int)size, secret); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment