CryptoAPI (no, this has nothing to do with licensing! YAY!)

Alexandre Julliard julliard at winehq.com
Thu Dec 20 11:59:25 CST 2001


David Elliott <dfe at tgwbd.org> writes:

> Anyway, if you think the patch you have might help me get RSAENH.DLL
> loaded and a bit further then I could probably have https sites
> working in IE shortly.

If rasenh.dll has the same problem as rsabase.dll, I think this should
help:

Index: loader/module.c
===================================================================
RCS file: /opt/cvs-commit/wine/loader/module.c,v
retrieving revision 1.144
diff -u -r1.144 module.c
--- loader/module.c	2001/12/20 00:19:42	1.144
+++ loader/module.c	2001/12/20 16:08:04
@@ -1284,7 +1284,18 @@
                                             NULL, OPEN_EXISTING, 0, 0 );
                 if (hFile != INVALID_HANDLE_VALUE)
                 {
-                    hmod = PE_LoadImage( hFile, filename, flags );
+                    DWORD type;
+                    MODULE_GetBinaryType( hFile, filename, &type );
+                    if (type == SCS_32BIT_BINARY)
+                    {
+                        HANDLE mapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY,
+                                                             0, 0, NULL );
+                        if (mapping)
+                        {
+                            hmod = (HMODULE)MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
+                            CloseHandle( mapping );
+                        }
+                    }
                     CloseHandle( hFile );
                 }
                 if (hmod) return (HMODULE)((ULONG_PTR)hmod + 1);
Index: loader/pe_resource.c
===================================================================
RCS file: /opt/cvs-commit/wine/loader/pe_resource.c,v
retrieving revision 1.34
diff -u -r1.34 pe_resource.c
--- loader/pe_resource.c	2001/10/14 16:18:53	1.34
+++ loader/pe_resource.c	2001/12/20 16:08:05
@@ -48,6 +48,39 @@
 
 
 /**********************************************************************
+ *  is_data_file_module
+ *
+ * Check if a module handle is for a LOAD_LIBRARY_AS_DATAFILE module.
+ */
+inline static int is_data_file_module( HMODULE hmod )
+{
+    return (ULONG_PTR)hmod & 1;
+}
+
+
+/**********************************************************************
+ *  get_data_file_ptr
+ *
+ * Get a pointer to a given offset in a file mapped as data file.
+ */
+static const void *get_data_file_ptr( const void *base, DWORD offset )
+{
+    const IMAGE_NT_HEADERS *nt = PE_HEADER(base);
+    const IMAGE_SECTION_HEADER *sec = (IMAGE_SECTION_HEADER *)((char *)&nt->OptionalHeader +
+                                                               nt->FileHeader.SizeOfOptionalHeader);
+    int i;
+
+    /* find the section containing the virtual address */
+    for (i = 0; i < nt->FileHeader.NumberOfSections; i++, sec++)
+    {
+        if ((sec->VirtualAddress <= offset) && (sec->VirtualAddress + sec->SizeOfRawData > offset))
+            return (char *)base + sec->PointerToRawData + (offset - sec->VirtualAddress);
+    }
+    return NULL;
+}
+
+
+/**********************************************************************
  *  get_resdir
  *
  * Get the resource directory of a PE module
@@ -62,7 +95,10 @@
     {
         dir = &PE_HEADER(base)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE];
         if (dir->Size && dir->VirtualAddress)
-            ret = (IMAGE_RESOURCE_DIRECTORY *)((char *)base + dir->VirtualAddress);
+        {
+            if (is_data_file_module(hmod)) ret = get_data_file_ptr( base, dir->VirtualAddress );
+            else ret = (IMAGE_RESOURCE_DIRECTORY *)((char *)base + dir->VirtualAddress);
+        }
     }
     return ret;
 }
@@ -272,9 +308,17 @@
  */
 HGLOBAL PE_LoadResource( HMODULE hmod, HRSRC hRsrc )
 {
+    DWORD offset;
     const void *base = get_module_base( hmod );
-    if (!hRsrc) return 0;
-    return (HANDLE)((char *)base + ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->OffsetToData);
+
+    if (!hRsrc || !base) return 0;
+
+    offset = ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->OffsetToData;
+
+    if (is_data_file_module(hmod))
+        return (HANDLE)get_data_file_ptr( base, offset );
+    else
+        return (HANDLE)((char *)base + offset);
 }
 
 

-- 
Alexandre Julliard
julliard at winehq.com




More information about the wine-devel mailing list