Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
You can’t perform that action at this time.