mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-27 04:01:36 +01:00
pagemap_dump!
This commit is contained in:
@@ -17,7 +17,7 @@ Data sources: /proc/PIC/{map,pagemap}
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#define PAGE_SIZE 0x1000
|
#define PAGE_SIZE 0x1000
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char **argv) {
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
char maps_file[BUFSIZ];
|
char maps_file[BUFSIZ];
|
||||||
char pagemap_file[BUFSIZ];
|
char pagemap_file[BUFSIZ];
|
||||||
@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
|
|||||||
int pagemap;
|
int pagemap;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
printf("Usage: %s pid1\n", argv[0]);
|
printf("Usage: %s pid\n", argv[0]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
pid_t pid = (pid_t)strtoul(argv[1], NULL, 0);
|
pid_t pid = (pid_t)strtoul(argv[1], NULL, 0);
|
||||||
@@ -50,45 +50,50 @@ int main(int argc, char *argv[]) {
|
|||||||
for (size_t i = offset; i < (size_t)length; i++) {
|
for (size_t i = offset; i < (size_t)length; i++) {
|
||||||
unsigned long low = 0, high = 0;
|
unsigned long low = 0, high = 0;
|
||||||
if (buffer[i] == '\n' && i) {
|
if (buffer[i] == '\n' && i) {
|
||||||
size_t x = i - 1;
|
const char *lib_name;
|
||||||
while(x && buffer[x] != '\n') x --;
|
size_t y;
|
||||||
if (buffer[x] == '\n') x++;
|
/* Parse a line from maps. Each line contains a range that contains many pages. */
|
||||||
size_t beginning = x;
|
{
|
||||||
while(buffer[x] != '-' && x < sizeof buffer) {
|
size_t x = i - 1;
|
||||||
char c = buffer[x++];
|
while(x && buffer[x] != '\n') x --;
|
||||||
low *= 16;
|
if (buffer[x] == '\n') x++;
|
||||||
if (c >= '0' && c <= '9') {
|
size_t beginning = x;
|
||||||
low += c - '0';
|
while(buffer[x] != '-' && x < sizeof buffer) {
|
||||||
|
char c = buffer[x++];
|
||||||
|
low *= 16;
|
||||||
|
if (c >= '0' && c <= '9') {
|
||||||
|
low += c - '0';
|
||||||
|
}
|
||||||
|
else if (c >= 'a' && c <= 'f') {
|
||||||
|
low += c - 'a' + 10;
|
||||||
|
}
|
||||||
|
else break;
|
||||||
}
|
}
|
||||||
else if (c >= 'a' && c <= 'f') {
|
while(buffer[x] != '-' && x < sizeof buffer) x++;
|
||||||
low += c - 'a' + 10;
|
if (buffer[x] == '-') x++;
|
||||||
|
while(buffer[x] != ' ' && x < sizeof buffer) {
|
||||||
|
char c = buffer[x++];
|
||||||
|
high *= 16;
|
||||||
|
if (c >= '0' && c <= '9') {
|
||||||
|
high += c - '0';
|
||||||
|
}
|
||||||
|
else if (c >= 'a' && c <= 'f') {
|
||||||
|
high += c - 'a' + 10;
|
||||||
|
}
|
||||||
|
else break;
|
||||||
}
|
}
|
||||||
else break;
|
lib_name = 0;
|
||||||
|
for (int field = 0; field < 4; field++) {
|
||||||
|
x++;
|
||||||
|
while(buffer[x] != ' ' && x < sizeof buffer) x++;
|
||||||
|
}
|
||||||
|
while (buffer[x] == ' ' && x < sizeof buffer) x++;
|
||||||
|
y = x;
|
||||||
|
while (buffer[y] != '\n' && y < sizeof buffer) y++;
|
||||||
|
buffer[y] = 0;
|
||||||
|
lib_name = buffer + x;
|
||||||
}
|
}
|
||||||
while(buffer[x] != '-' && x < sizeof buffer) x++;
|
/* Get info about all pages in this page range with pagemap. */
|
||||||
if (buffer[x] == '-') x++;
|
|
||||||
while(buffer[x] != ' ' && x < sizeof buffer) {
|
|
||||||
char c = buffer[x++];
|
|
||||||
high *= 16;
|
|
||||||
if (c >= '0' && c <= '9') {
|
|
||||||
high += c - '0';
|
|
||||||
}
|
|
||||||
else if (c >= 'a' && c <= 'f') {
|
|
||||||
high += c - 'a' + 10;
|
|
||||||
}
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *lib_name = 0;
|
|
||||||
for (int field = 0; field < 4; field++) {
|
|
||||||
x++;
|
|
||||||
while(buffer[x] != ' ' && x < sizeof buffer) x++;
|
|
||||||
}
|
|
||||||
while (buffer[x] == ' ' && x < sizeof buffer) x++;
|
|
||||||
size_t y = x;
|
|
||||||
while (buffer[y] != '\n' && y < sizeof buffer) y++;
|
|
||||||
buffer[y] = 0;
|
|
||||||
lib_name = buffer + x;
|
|
||||||
{
|
{
|
||||||
unsigned long data;
|
unsigned long data;
|
||||||
for (unsigned long i = low; i < high; i += PAGE_SIZE) {
|
for (unsigned long i = low; i < high; i += PAGE_SIZE) {
|
||||||
@@ -108,6 +113,7 @@ int main(int argc, char *argv[]) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
buffer[y] = '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user