summaryrefslogtreecommitdiffstats
path: root/loader/win32.c
diff options
context:
space:
mode:
authorsesse <sesse@b3059339-0415-0410-9bf9-f77b7e298cf2>2010-03-05 23:09:36 +0000
committersesse <sesse@b3059339-0415-0410-9bf9-f77b7e298cf2>2010-03-05 23:09:36 +0000
commitfbb74e16a38d6a5af31a7fb369195988f7414766 (patch)
tree15a3b5dc3b936b9a3d61bf652f381bf29261746b /loader/win32.c
parent75f3bd09ea815d3db0790d40f679fde172b336dc (diff)
downloadmpv-fbb74e16a38d6a5af31a7fb369195988f7414766.tar.bz2
mpv-fbb74e16a38d6a5af31a7fb369195988f7414766.tar.xz
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 ). git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30848 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'loader/win32.c')
-rw-r--r--loader/win32.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/loader/win32.c b/loader/win32.c
index e224d24aec..08985a28e1 100644
--- a/loader/win32.c
+++ b/loader/win32.c
@@ -569,16 +569,30 @@ static HMODULE WINAPI expGetDriverModuleHandle(DRVR* pdrv)
#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);