Skip to content

Instantly share code, notes, and snippets.

@masami256
Created March 19, 2018 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save masami256/c1a279e01914fc15a8566e0a156502c7 to your computer and use it in GitHub Desktop.
Save masami256/c1a279e01914fc15a8566e0a156502c7 to your computer and use it in GitHub Desktop.
dump vdso
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/auxv.h>
#include <unistd.h>
static void *find_vdso_start_address(void)
{
return (void *) getauxval(AT_SYSINFO_EHDR);
}
static long get_page_size(void)
{
return sysconf(_SC_PAGESIZE);
}
static void write_buf(char *buf, size_t size)
{
FILE *fp;
fp = fopen("vdso_dump.so", "wb");
if (!fp) {
perror("fopen");
exit(-1);
}
fwrite(buf, size, 1, fp);
fclose(fp);
}
int main(int argc, char **argv)
{
int npages = 2;
char *buf;
if (argc == 2)
npages = atoi(argv[1]);
printf("[*]read %d pages\n", npages);
long buf_size = get_page_size() * npages;
buf = malloc(buf_size);
memset(buf, 0x0, buf_size);
void *vdso = find_vdso_start_address();
printf("[*]vdso start address is %p\n", vdso);
memcpy(buf, vdso, buf_size);
printf("[*]write data\n");
write_buf(buf, buf_size);
free(buf);
printf("[*]Done.\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment