diff --git a/include/win32.h b/include/win32.h index b714e93..3027fd2 100644 --- a/include/win32.h +++ b/include/win32.h @@ -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(). */ 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 * into guest memory obtained through this context is invalid. */ void vmie_win32_close(vmie_win32* v); diff --git a/src/engine/win32/host.c b/src/engine/win32/host.c index 43fb509..6837668 100644 --- a/src/engine/win32/host.c +++ b/src/engine/win32/host.c @@ -34,6 +34,21 @@ vmie_win32* vmie_win32_open_fd(int fd, uint64_t low) { 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)) void vmie_win32_close(vmie_win32* v) { if (!v) {