Created
May 19, 2018 04:46
-
-
Save illustris/6d810d1012019cc62b2ff6d6fa34cae1 to your computer and use it in GitHub Desktop.
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 "libkdump.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) { | |
// initialize libkdump | |
//Configure libkdump | |
libkdump_config_t config; | |
//get default config | |
config = libkdump_get_autoconfig(); | |
// if kaslr offset is passed as an argument | |
if (argc > 3) { | |
//set physical offset to the given address | |
config.physical_offset = strtoull(argv[3], NULL, 0); | |
} | |
//initialize libkdump with this config | |
if(libkdump_init(config) != 0) { | |
return -1; | |
} | |
//get number of bytes to read from the first arg | |
int i = atoi(argv[1]); | |
//get target physical address from the second arg | |
size_t phys_addr = strtoull(argv[2], NULL, 0); | |
//This physical address needs to be converted to the corresponding virtual address in this program's VA space | |
size_t vaddr = libkdump_phys_to_virt(phys_addr); | |
unsigned char buf; | |
//loop to read n bytes | |
for(int j=0;j<i;j++) | |
{ | |
//function call to libkdump to set up instrument and read from address | |
int value = libkdump_read(vaddr); | |
//typecast to byte | |
buf = (char)value; | |
printf("%08llx: %02x %c\n", (unsigned long long)phys_addr, buf, buf); | |
fflush(stdout); | |
// if(buf == 0x00) | |
// break; | |
//seek to next byte | |
vaddr+=1; | |
} | |
// clean up spawned threads and signal handlers | |
if(libkdump_cleanup() != 0) | |
{ | |
return -1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment