#include #ifndef _H_MEMORYMAP #define _H_MEMORYMAP 1 static std::vector split(const std::string& str, char delimiter) { std::vector tokens; std::string token; std::stringstream ss(str); while (std::getline(ss, token, delimiter)) { tokens.push_back(token); } return tokens; } enum Access{ READ = 0x01, WRITE = 0x02, EXECUTE = 0x04, PRIVATE = 0x08, SHARED = 0x10 }; struct MapEntire { uint64_t startAddress; uint64_t endAddress; uint8_t access = 0; uint32_t offset; char path[512] = {0}; MapEntire() { startAddress = 0; endAddress = 0; offset = 0; } explicit MapEntire(const std::string& src) { auto e = split(src, ' '); for(int i=0;i& dst, const std::string& path) { auto f = fopen(path.c_str(), "r"); if(!f){ perror("fopen()"); return false; } dst.clear(); char line[1024]; while(fgets(line, 1024, f)) { dst.emplace_back(line); } fclose(f); return true; } private: char _path[255] = {0}; std::vector _content; public: explicit MemoryMap(int pid) { sprintf(_path, "/proc/%d/maps", pid); readAll(_content, _path); } MapEntire GetItem(int index) { auto u = MapEntire(_content[index]); return u; } size_t Size() { return _content.size(); } std::vector GetModules() { std::vector r; for(int i=0;i