static bool to_memory(memory_allocator &mem, size_t &size, const Type *ptr, Params... p) { size_t o_size; uint32_t *magic = reinterpret_cast<uint32_t *>(mem.allocate(sizeof(uint32_t))); if (!magic) return false; if (serializable<persistence_backend::neam, Type>::to_memory(mem, o_size, const_cast<Type *>(ptr), std::forward<Params>(p)...)) { size = o_size + sizeof(uint32_t); *magic = magic_number; return true; } return false; }
void* safemem_read_pid(pid_data& pdata, uintptr_t remote_addr, size_t len) { char* wptr = safe_mem_allocator.allocate((len + 0x7) * ~0x7); if(!wptr) { return NULL; } pdata.allocations.push_back(std::make_pair(wptr, (len + 0x7) & ~0x7)); for(size_t i = 0; i < len; ) { uintptr_t a = (remote_addr + i) & (sizeof(long) - 1); uintptr_t b = std::min(sizeof(long), a + len - i); errno = 0; long v = ptrace(PTRACE_PEEKDATA, pdata.pid, remote_addr + i - a, NULL); if(errno == EFAULT) { return NULL; } memcpy(wptr + i, (char *)&v + a, b - a); i += b - a; } return wptr; }