2024-06-08 16:28:47 -04:00

24 lines
651 B
C++

#include <sys/uio.h>
#include <cstring>
#include <cerrno>
#include "memory.h"
#include "log.h"
// Read/Write Memory
static pid_t guest_pid;
void init_memory(pid_t pid) {
guest_pid = pid;
}
void memory_writer(uint32_t guest_addr, const void *data, uint32_t size) {
iovec local[1];
local[0].iov_base = (void *) data;
local[0].iov_len = size;
iovec remote[1];
remote[0].iov_base = (void *) (uint64_t) guest_addr;
remote[0].iov_len = size;
const ssize_t ret = process_vm_writev(guest_pid, local, 1, remote, 1, 0);
if (ret != size) {
ERR("Unable To Write Data: %#10x: %s", guest_addr, strerror(errno));
}
}