From 80b89c048ce8168a5dd42fd59ec0432d9adf40d9 Mon Sep 17 00:00:00 2001 From: midipix Date: Wed, 17 Jan 2018 21:03:22 +0000 Subject: __ntapi_init(), fork: obtain and keep a handle to the running process. --- src/internal/ntapi.c | 19 +++++++++++++++++++ src/internal/ntapi_impl.h | 1 + 2 files changed, 20 insertions(+) (limited to 'src/internal') diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index 06a70fe..1b06bcc 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -93,6 +93,8 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) int32_t status; void * hntdll; size_t block_size; + nt_oa oa; + nt_cid cid; ntapi_zw_allocate_virtual_memory * pfn_zw_allocate_virtual_memory; char fname_allocate_virtual_memory[] = "ZwAllocateVirtualMemory"; @@ -446,6 +448,23 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) (uintptr_t *)&___ntapi, sizeof(ntapi_vtbl)); + /* process handle */ + oa.len = sizeof(oa); + oa.root_dir = 0; + oa.obj_name = 0; + oa.obj_attr = 0; + oa.sec_desc = 0; + oa.sec_qos = 0; + + cid.process_id = pe_get_current_process_id(); + cid.thread_id = pe_get_current_thread_id(); + + if ((status = __ntapi->zw_open_process( + &internals->hprocess, + NT_PROCESS_ALL_ACCESS, + &oa,&cid))) + return status; + /* process token */ if ((status = __ntapi->zw_open_process_token( NT_CURRENT_PROCESS_HANDLE, diff --git a/src/internal/ntapi_impl.h b/src/internal/ntapi_impl.h index 870e5fd..4c26f55 100644 --- a/src/internal/ntapi_impl.h +++ b/src/internal/ntapi_impl.h @@ -82,6 +82,7 @@ typedef struct __attr_ptr_size_aligned__ _ntapi_internals { nt_port_name * subsystem; nt_security_descriptor seq_desc; nt_security_quality_of_service seq_qos; + void * hprocess; void * htoken; void * hport_tty_session; void * hport_tty_daemon; -- cgit v1.2.3