| 269 | } |
| 270 | |
| 271 | ssize_t |
| 272 | ProcessMemoryManager::readChunkThroughMemFile(remote_addr_t addr, size_t len, char* dst) const |
| 273 | { |
| 274 | if (!d_memfile) { |
| 275 | std::string filepath = "/proc/" + std::to_string(d_pid) + "/mem"; |
| 276 | d_memfile = file_unique_ptr(fopen(filepath.c_str(), "r"), fclose); |
| 277 | if (!d_memfile) { |
| 278 | if (errno == EPERM || errno == EACCES) { |
| 279 | LOG(ERROR) << "Permission denied opening file " << filepath; |
| 280 | throw std::runtime_error(PERM_MESSAGE); |
| 281 | } |
| 282 | LOG(ERROR) << "Failed to open file " << filepath << ": " << std::strerror(errno); |
| 283 | throw std::runtime_error("Failed to open " + filepath); |
| 284 | } |
| 285 | } |
| 286 | fseeko(d_memfile.get(), addr, SEEK_SET); |
| 287 | if (static_cast<off_t>(addr) != ftello(d_memfile.get()) |
| 288 | || len != fread(dst, 1, len, d_memfile.get())) |
| 289 | { |
| 290 | throw InvalidRemoteAddress(); |
| 291 | } |
| 292 | return static_cast<ssize_t>(len); |
| 293 | } |
| 294 | |
| 295 | ssize_t |
| 296 | ProcessMemoryManager::copyMemoryFromProcess(remote_addr_t addr, size_t len, void* dst) const |
nothing calls this directly
no test coverage detected