Add a read-only win32 context over a file descriptor

vmie_win32_open_ro_fd maps the RAM backing file PROT_READ (via
gpa_from_ro_fd) and does NOT bootstrap; the caller passes a cr3 to each
read call. The read surfaces work this way - sections / functions /
imports / exports / callgraph / hooks, gva_read_text, and the generic
gva_* and scanner surfaces via vmie_win32_mem() - while any write returns
-1 because the mapping is read-only. The RW twin vmie_win32_open_fd and
host_bootstrap are unchanged.
This commit is contained in:
2026-06-20 16:39:08 +03:00
parent 5ea9a3785f
commit 02e63f2ff0
2 changed files with 29 additions and 0 deletions
+14
View File
@@ -92,6 +92,20 @@ vmie_win32* vmie_win32_open(const char* ram_path, uint64_t low);
* NULL on dup/fstat/mmap failure. Free with vmie_win32_close(). */ * NULL on dup/fstat/mmap failure. Free with vmie_win32_close(). */
vmie_win32* vmie_win32_open_fd(int fd, uint64_t low); vmie_win32* vmie_win32_open_fd(int fd, uint64_t low);
/* Open a READ-ONLY context over the RAM backing file `fd`, for a consumer that
* only reads. Unlike vmie_win32_open_fd this does NOT bootstrap (the magic-
* signature handshake needs RW): the caller supplies the address space by passing
* a cr3 to each read call. Every read API that takes a cr3 works - the section /
* function / import / export / callgraph / hook surfaces, gva_read_text, and the
* generic gva_* and scanner surfaces via vmie_win32_mem(); writes (gva_write) -1
* because the mapping is PROT_READ. proc_list/proc_modules are NOT available here:
* they need the bootstrap-recovered profile, which a read-only context does not
* carry. `fd` is BORROWED (dup()'d internally; the caller's fd stays valid after
* this call AND after vmie_win32_close()); an O_RDONLY fd is accepted. `low` is
* the below-4G split, as in vmie_win32_open_fd. Returns a new context, or NULL on
* dup/fstat/mmap failure. Free with vmie_win32_close(). */
vmie_win32* vmie_win32_open_ro_fd(int fd, uint64_t low);
/* Unmap, close, and free a context. Safe on NULL. After this, every pointer /* Unmap, close, and free a context. Safe on NULL. After this, every pointer
* into guest memory obtained through this context is invalid. */ * into guest memory obtained through this context is invalid. */
void vmie_win32_close(vmie_win32* v); void vmie_win32_close(vmie_win32* v);
+15
View File
@@ -34,6 +34,21 @@ vmie_win32* vmie_win32_open_fd(int fd, uint64_t low) {
return v; return v;
} }
/* Read-only context: no bootstrap, the cr3 is supplied per read call. The mem is
* mapped PROT_READ (gpa_from_ro_fd), so every write through it returns -1. */
__attribute__((cold))
vmie_win32* vmie_win32_open_ro_fd(int fd, uint64_t low) {
vmie_win32* v = calloc(1, sizeof *v);
if (!v) {
return NULL;
}
if (gpa_from_ro_fd(&v->mem, fd, low)) {
free(v);
return NULL;
}
return v;
}
__attribute__((cold)) __attribute__((cold))
void vmie_win32_close(vmie_win32* v) { void vmie_win32_close(vmie_win32* v) {
if (!v) { if (!v) {