[Wine-patches] [10/23] ntoskrnl.exe: Add hack for UPKey.sys.

Alexander Morozov =?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Пн Янв 19 18:24:00 MSK 2009


For eterhack branch
----------- следующая часть -----------
From 771b824f64d700923195e04d8d1244eaccd89aac Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Mon, 12 Jan 2009 11:44:21 +0300
Subject: [PATCH] ntoskrnl.exe: Add hack for UPKey.sys.

---
 dlls/ntoskrnl.exe/ntoskrnl.c |  129 ++++++++---------------------------------
 1 files changed, 25 insertions(+), 104 deletions(-)

diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c
index 6439c3b..3b27024 100644
--- a/dlls/ntoskrnl.exe/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/ntoskrnl.c
@@ -88,17 +88,6 @@ struct IrpInstance
     IRP *irp;
 };
 
-#if 0
-static struct list MemoryList = LIST_INIT(MemoryList);
-
-struct MemoryRegion
-{
-    struct list entry;
-    void *ptr;
-    int release;
-};
-#endif
-
 static struct list DriverObjExtensions = LIST_INIT(DriverObjExtensions);
 
 struct DriverObjExtension
@@ -129,13 +118,6 @@ struct InterfaceInstance
     UNICODE_STRING *target;
 };
 
-#if 0
-#ifdef __i386__
-#define mem_mask 0xffff
-#define mem_size 0x10000
-#endif
-#endif
-
 #ifdef __i386__
 #define DEFINE_FASTCALL1_ENTRYPOINT( name ) \
     __ASM_GLOBAL_FUNC( name, \
@@ -244,76 +226,6 @@ static void save_pid( DWORD pid )
     LeaveCriticalSection( &cs );
 }
 
-#if 0
-#ifdef __i386__
-static int map_memory( void *addr )
-{
-    struct MemoryRegion *mr;
-    HANDLE process;
-
-    mr = ExAllocatePool( NonPagedPool, sizeof(struct MemoryRegion) );
-    if (mr == NULL)
-        return 1;
-    addr = (void *)((unsigned int)addr & ~mem_mask);
-    mr->ptr = VirtualAlloc( addr, mem_size, MEM_COMMIT | MEM_RESERVE,
-            PAGE_EXECUTE_READWRITE );
-    if (mr->ptr == NULL)
-    {
-        mr->ptr = VirtualAlloc( addr, mem_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
-        if (mr->ptr == NULL)
-        {
-            ExFreePool( mr );
-            return 1;
-        }
-        mr->release = 0;
-    }
-    else
-        mr->release = 1;
-    process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid );
-    if (process == NULL)
-    {
-        VirtualFree( mr->ptr, mem_size, mr->release ? MEM_RELEASE : MEM_DECOMMIT );
-        ExFreePool( mr );
-        return 1;
-    }
-    NtReadVirtualMemory( process, mr->ptr, mr->ptr, mem_size, NULL );
-    CloseHandle( process );
-    list_add_tail( &MemoryList, &mr->entry );
-    return 0;
-}
-
-static void unmap_memory(void)
-{
-    struct MemoryRegion *mr, *mr2;
-    HANDLE process;
-
-    LIST_FOR_EACH_ENTRY_SAFE( mr, mr2, &MemoryList, struct MemoryRegion, entry )
-    {
-        process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid );
-        if (process != NULL)
-        {
-            NtWriteVirtualMemory( process, mr->ptr, mr->ptr, mem_size, NULL );
-            CloseHandle( process );
-        }
-        VirtualFree( mr->ptr, 0, mr->release ? MEM_RELEASE : MEM_DECOMMIT );
-        list_remove( &mr->entry );
-        ExFreePool( mr );
-    }
-}
-
-static LONG WINAPI memory_handler( EXCEPTION_POINTERS* except )
-{
-    if (except->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
-    {
-        char *addr = (char *)except->ExceptionRecord->ExceptionInformation[1];
-        if (!map_memory( addr ))
-            return EXCEPTION_CONTINUE_EXECUTION;
-    }
-    return EXCEPTION_CONTINUE_SEARCH;
-}
-#endif  /* __i386__ */
-#endif
-
 NTSTATUS WINAPI __regs_IofCallDriver( DEVICE_OBJECT *device, IRP *irp );
 
 /* process an ioctl request for a given device */
@@ -325,11 +237,10 @@ static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff,
     NTSTATUS status;
     LARGE_INTEGER count;
     IO_STATUS_BLOCK iosb;
-#if 0
-#ifdef __i386__
-    PVOID mem_handler;
-#endif
-#endif
+    HANDLE process = NULL;
+    CHAR data[146];
+    void *saved_ptr = NULL;
+    ULONG offset = 0;
 
     TRACE( "ioctl %x device %p in_size %u out_size %u\n", code, device, in_size, *out_size );
 
@@ -342,19 +253,29 @@ static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff,
     irp->IoStatus.u.Status = STATUS_NOT_SUPPORTED;
     irpsp->DeviceObject = device;
     device->CurrentIrp = irp;
-#if 0
-#ifdef __i386__
-    mem_handler = RtlAddVectoredExceptionHandler( FALSE, memory_handler );
-#endif
-#endif
+
+    /* HACK for UPKey.sys */
+    if (0x3fc == code) offset = 2;
+    if (0x222044 == code || 0x44c == code || 0x456 == code) offset = 8;
+    if (offset && in_buff)
+    {
+        saved_ptr = *(void**)((char *)in_buff + offset);
+        if (saved_ptr)
+        {
+            *(void**)((char *)in_buff + offset) = &data;
+            process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, get_pid() );
+            if (process != NULL)
+                NtReadVirtualMemory( process, saved_ptr, data, sizeof(data), NULL );
+        }
+    }
+
     KeQueryTickCount( &count );  /* update the global KeTickCount */
     status = __regs_IofCallDriver( device, irp );
-#if 0
-#ifdef __i386__
-    RtlRemoveVectoredExceptionHandler( mem_handler );
-    unmap_memory();
-#endif
-#endif
+    if (process)
+    {
+        NtWriteVirtualMemory( process, saved_ptr, data, sizeof(data), NULL );
+        CloseHandle( process );
+    }
     *out_size = (status == STATUS_SUCCESS) ? iosb.Information : 0;
     return status;
 }
-- 
1.6.0.2.GIT



Подробная информация о списке рассылки Wine-patches