[MPlayer-cvslog] r30848 - trunk/loader/win32.c

sesse subversion at mplayerhq.hu
Sat Mar 6 00:09:37 CET 2010


Author: sesse
Date: Sat Mar  6 00:09:36 2010
New Revision: 30848

Log:
Make GetModuleHandle(NULL) return a valid pointer.

Some codecs, and more recently Microsoft's CRT library, expect GetModuleHandle(NULL)
to return a pointer to the program's PE header mapped in memory. Thus, just returning
0x0 or 0x1 won't do it anymore, so create a minimal PE header and return that.

Patch originally by Gianluigi Tiesi ( mplayer (at) netfarm (dot) it ).

Modified:
   trunk/loader/win32.c

Modified: trunk/loader/win32.c
==============================================================================
--- trunk/loader/win32.c	Fri Mar  5 22:39:27 2010	(r30847)
+++ trunk/loader/win32.c	Sat Mar  6 00:09:36 2010	(r30848)
@@ -569,16 +569,30 @@ static HMODULE WINAPI expGetDriverModule
 #define	MODULE_HANDLE_winmm	((HMODULE)0x128)
 #define	MODULE_HANDLE_psapi	((HMODULE)0x129)
 
+// Fake PE header, since some software (and the Microsoft CRT v8 and newer)
+// assume GetModuleHandle(NULL) returns a pointer to a PE header.
+// We simulate a very simple header with only one section.
+//
+// NOTE: If you have a section called .mixcrt, the Microsoft CRT will assume
+// it's running in a POSIX binary, and stop using EncodePointer/DecodePointer.
+static const struct {
+    IMAGE_DOS_HEADER doshdr;
+    IMAGE_NT_HEADERS nthdr;
+    IMAGE_SECTION_HEADER opthdr;
+} __attribute__((__packed__)) mp_exe = {
+    .doshdr.e_lfanew = sizeof(IMAGE_DOS_HEADER),
+    .nthdr.FileHeader.NumberOfSections = 1,
+    .nthdr.FileHeader.SizeOfOptionalHeader =
+        sizeof(IMAGE_NT_HEADERS) - FIELD_OFFSET(IMAGE_NT_HEADERS, OptionalHeader), /* 0xe0 */
+    .opthdr.Name = ".text"
+};
+
 static HMODULE WINAPI expGetModuleHandleA(const char* name)
 {
     WINE_MODREF* wm;
     HMODULE result;
     if(!name)
-#ifdef CONFIG_QTX_CODECS
-	result=1;
-#else
-	result=0;
-#endif
+	result=(HMODULE)&mp_exe.doshdr;
     else
     {
 	wm=MODULE_FindModule(name);


More information about the MPlayer-cvslog mailing list