Skip to content

Instantly share code, notes, and snippets.

@moyix
Created January 11, 2018 00:49
Show Gist options
  • Save moyix/01aa2682d70f6283ccbb7c9c5d44b65f to your computer and use it in GitHub Desktop.
Save moyix/01aa2682d70f6283ccbb7c9c5d44b65f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iterator>
int main(int argc, char **argv) {
std::string line;
std::ifstream infile("/proc/self/maps");
while (std::getline(infile, line)) {
std::istringstream ss(line);
std::istream_iterator<std::string> begin(ss);
std::istream_iterator<std::string> end;
std::vector<std::string> vstrings(begin, end);
if (vstrings[vstrings.size()-1] == "[vvar]") {
int dash = vstrings[0].find('-');
std::string sstart = vstrings[0].substr(0, dash);
std::string send = vstrings[0].substr(dash+1, std::string::npos);
unsigned long start = strtoul(sstart.c_str(), NULL, 16);
unsigned long end = strtoul(send.c_str(), NULL, 16);
printf("Found vvar area from %#lx - %#lx, dumping...\n", start, end);
for (uintptr_t addr = start; addr < end; addr += 16) {
uint8_t *buf = (uint8_t *)addr;
printf("%16lx ", addr);
for (int i = 0; i < 16; i++) printf("%02x ", buf[i]);
printf("|");
for (int i = 0; i < 16; i++) printf("%c", ((buf[i] > 31) && (buf[i] < 127)) ? buf[i] : '.');
printf("|\n");
}
// Sleep to let gdb attach
while (1) sleep(1);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment