⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module.c

📁 linux下的MPEG1
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Modules * * Copyright 1995 Alexandre Julliard */// define for quicktime calls debugging and/or MacOS-level emulation:#define EMU_QTX_API// define for quicktime debugging (verbose logging)://#define DEBUG_QTX_API#include "config.h"#include <assert.h>#include <errno.h>#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/mman.h>#include <sys/types.h>#include "windef.h"#include "winerror.h"#include "heap.h"#include "module.h"#include "pe_image.h"#include "debugtools.h"#ifdef HAVE_LIBDL#include <dlfcn.h>#include "elfdll.h"#endif#include "win32.h"#include "driver.h"#include "ext.h"#ifdef EMU_QTX_API#include "wrapper.h"int report_func(void *stack_base, int stack_size, reg386_t *reg, u_int32_t *flags);int report_func_ret(void *stack_base, int stack_size, reg386_t *reg, u_int32_t *flags);#endif//#undef TRACE//#define TRACE printf//WINE_MODREF *local_wm=NULL;modref_list* local_wm=NULL;HANDLE SegptrHeap;WINE_MODREF* MODULE_FindModule(LPCSTR m){    modref_list* list=local_wm;    TRACE("FindModule: Module %s request\n", m);    if(list==NULL)	return NULL;//    while(strcmp(m, list->wm->filename))    while(!strstr(list->wm->filename, m))    {	TRACE("%s: %x\n", list->wm->filename, list->wm->module);	list=list->prev;	if(list==NULL)	    return NULL;    }    TRACE("Resolved to %s\n", list->wm->filename);    return list->wm;}static void MODULE_RemoveFromList(WINE_MODREF *mod){    modref_list* list=local_wm;    if(list==0)	return;    if(mod==0)	return;    if((list->prev==NULL)&&(list->next==NULL))    {	free(list);	local_wm=NULL;//	uninstall_fs();	return;    }    for(;list;list=list->prev)    {	if(list->wm==mod)	{	    if(list->prev)		list->prev->next=list->next;	    if(list->next)		list->next->prev=list->prev;	    if(list==local_wm)		local_wm=list->prev;	    free(list);	    return;	}    }}WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m){    modref_list* list=local_wm;    TRACE("LookupHMODULE: Module %X request\n", m);    if(list==NULL)    {	TRACE("LookupHMODULE failed\n");	return NULL;    }    while(m!=list->wm->module)    {//      printf("Checking list %X wm %X module %X\n",//	list, list->wm, list->wm->module);	list=list->prev;	if(list==NULL)	{	    TRACE("LookupHMODULE failed\n");	    return NULL;	}    }    TRACE("LookupHMODULE hit %p\n", list->wm);    return list->wm;}/************************************************************************* *		MODULE_InitDll */static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved ){    WIN_BOOL retv = TRUE;#ifdef LOG    static LPCSTR typeName[] = { "PROCESS_DETACH", "PROCESS_ATTACH",                                 "THREAD_ATTACH", "THREAD_DETACH" };#endif    assert( wm );    /* Skip calls for modules loaded with special load flags */    if (    ( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS )         || ( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE ) )        return TRUE;#ifdef LOG    TRACE("(%s,%s,%p) - CALL\n", wm->modname, typeName[type], lpReserved );#else    TRACE("(%s,%p) - CALL\n", wm->modname, lpReserved );#endif        /* Call the initialization routine */    switch ( wm->type )    {    case MODULE32_PE:        retv = PE_InitDLL( wm, type, lpReserved );        break;    case MODULE32_ELF:        /* no need to do that, dlopen() already does */        break;    default:        ERR("wine_modref type %d not handled.\n", wm->type );        retv = FALSE;        break;    }    /* The state of the module list may have changed due to the call       to PE_InitDLL. We cannot assume that this module has not been       deleted.  */#ifdef LOG    TRACE("(%p,%s,%p) - RETURN %d\n", wm, typeName[type], lpReserved, retv );#else    TRACE("(%p,%p) - RETURN %d\n", wm, lpReserved, retv );#endif        return retv;}/************************************************************************* *		MODULE_DllProcessAttach * * Send the process attach notification to all DLLs the given module * depends on (recursively). This is somewhat complicated due to the fact that * * - we have to respect the module dependencies, i.e. modules implicitly *   referenced by another module have to be initialized before the module *   itself can be initialized * * - the initialization routine of a DLL can itself call LoadLibrary, *   thereby introducing a whole new set of dependencies (even involving *   the 'old' modules) at any time during the whole process * * (Note that this routine can be recursively entered not only directly *  from itself, but also via LoadLibrary from one of the called initialization *  routines.) * * Furthermore, we need to rearrange the main WINE_MODREF list to allow * the process *detach* notifications to be sent in the correct order. * This must not only take into account module dependencies, but also * 'hidden' dependencies created by modules calling LoadLibrary in their * attach notification routine. * * The strategy is rather simple: we move a WINE_MODREF to the head of the * list after the attach notification has returned.  This implies that the * detach notifications are called in the reverse of the sequence the attach * notifications *returned*. * * NOTE: Assumes that the process critical section is held! * */static WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved ){    WIN_BOOL retv = TRUE;    /* int i; -- not used */    assert( wm );    /* prevent infinite recursion in case of cyclical dependencies */    if (    ( wm->flags & WINE_MODREF_MARKER )         || ( wm->flags & WINE_MODREF_PROCESS_ATTACHED ) )        return retv;    TRACE("(%s,%p) - START\n", wm->modname, lpReserved );    /* Tag current MODREF to prevent recursive loop */    wm->flags |= WINE_MODREF_MARKER;    /* Recursively attach all DLLs this one depends on *//*    for ( i = 0; retv && i < wm->nDeps; i++ )        if ( wm->deps[i] )            retv = MODULE_DllProcessAttach( wm->deps[i], lpReserved );*/    /* Call DLL entry point */    //local_wm=wm;    if(local_wm)    {	local_wm->next = (modref_list*) malloc(sizeof(modref_list));        local_wm->next->prev=local_wm;        local_wm->next->next=NULL;        local_wm->next->wm=wm;        local_wm=local_wm->next;    }    else    {	local_wm = (modref_list*)malloc(sizeof(modref_list));	local_wm->next=local_wm->prev=NULL;	local_wm->wm=wm;    }    /* Remove recursion flag */    wm->flags &= ~WINE_MODREF_MARKER;    if ( retv )    {        retv = MODULE_InitDll( wm, DLL_PROCESS_ATTACH, lpReserved );        if ( retv )            wm->flags |= WINE_MODREF_PROCESS_ATTACHED;    }    TRACE("(%s,%p) - END\n", wm->modname, lpReserved );    return retv;}/************************************************************************* *		MODULE_DllProcessDetach * * Send DLL process detach notifications.  See the comment about calling * sequence at MODULE_DllProcessAttach.  Unless the bForceDetach flag * is set, only DLLs with zero refcount are notified. */static void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpReserved ){    //    WINE_MODREF *wm=local_wm;    /* modref_list* l = local_wm; -- not used */    wm->flags &= ~WINE_MODREF_PROCESS_ATTACHED;    MODULE_InitDll( wm, DLL_PROCESS_DETACH, lpReserved );/*    while (l)    {	modref_list* f = l;	l = l->next;	free(f);    }    local_wm = 0;*/}/*********************************************************************** *	MODULE_LoadLibraryExA	(internal) * * Load a PE style module according to the load order. * * The HFILE parameter is not used and marked reserved in the SDK. I can * only guess that it should force a file to be mapped, but I rather * ignore the parameter because it would be extremely difficult to * integrate this with different types of module represenations. * */static WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags ){	DWORD err = GetLastError();	WINE_MODREF *pwm;	/* int i; -- not used *///	module_loadorder_t *plo;        SetLastError( ERROR_FILE_NOT_FOUND );	TRACE("Trying native dll '%s'\n", libname);	pwm = PE_LoadLibraryExA(libname, flags);#ifdef HAVE_LIBDL	if(!pwm)	{    	    TRACE("Trying ELF dll '%s'\n", libname);	    pwm=(WINE_MODREF*)ELFDLL_LoadLibraryExA(libname, flags);	}#endif//		printf("0x%08x\n", pwm);//		break;	if(pwm)	{		/* Initialize DLL just loaded */		TRACE("Loaded module '%s' at 0x%08x, \n", libname, pwm->module);		/* Set the refCount here so that an attach failure will */		/* decrement the dependencies through the MODULE_FreeLibrary call. */		pwm->refCount++;                SetLastError( err );  /* restore last error */		return pwm;	}	WARN("Failed to load module '%s'; error=0x%08lx, \n", libname, GetLastError());	return NULL;}/*********************************************************************** *           MODULE_FreeLibrary * * NOTE: Assumes that the process critical section is held! */static WIN_BOOL MODULE_FreeLibrary( WINE_MODREF *wm ){    TRACE("(%s) - START\n", wm->modname );    /* Recursively decrement reference counts */    //MODULE_DecRefCount( wm );    /* Call process detach notifications */    MODULE_DllProcessDetach( wm, FALSE, NULL );    PE_UnloadLibrary(wm);    TRACE("END\n");    return TRUE;}/*********************************************************************** *           LoadLibraryExA   (KERNEL32) */HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags){	WINE_MODREF *wm = 0;	char path[512];	char checked[2000];        int i = -1;        checked[0] = 0;	if(!libname)	{		SetLastError(ERROR_INVALID_PARAMETER);		return 0;	}	wm=MODULE_FindModule(libname);	if(wm) return wm->module;//	if(fs_installed==0)//	    install_fs();	for (i = 0; !wm && (i < 2); i++)	{	    memset (&path, 0, sizeof (path));	    if (i == 0) {	        /* check just original file name */	        strncpy(path, libname, sizeof(path) - 1);            } else {	        /* check default user path */                snprintf(path, sizeof(path), "%s/%s", win32_def_path, libname);	    }	    wm = MODULE_LoadLibraryExA( path, hfile, flags );	    if (!wm)	    {		if (checked[0])		    strcat(checked, ", ");		strcat(checked, path);                checked[1500] = 0;	    }	}	if ( wm )	{		if ( !MODULE_DllProcessAttach( wm, NULL ) )		{			WARN_(module)("Attach failed for module '%s', \n", libname);			MODULE_FreeLibrary(wm);			SetLastError(ERROR_DLL_INIT_FAILED);			MODULE_RemoveFromList(wm);			wm = NULL;		}	}	if (!wm)	    printf("wine/module: Win32 LoadLibrary failed to load: %s\n", checked);        // remove a few divs in the VP codecs that make trouble        if (strstr(libname,"vp5vfw.dll") && wm)        {          int i;          if (PE_FindExportedFunction(wm, "DriverProc", TRUE)==(void*)0x10003930) {            for (i=0;i<3;i++) ((char*)0x10004e86)[i]=0x90;            for (i=0;i<3;i++) ((char*)0x10005a23)[i]=0x90;            for (i=0;i<3;i++) ((char*)0x10005bff)[i]=0x90;          } else {            printf("wine/module: Unsupported VP5 version\n");            return 0;          }        }        if (strstr(libname,"vp6vfw.dll") && wm)        {          int i;          if (PE_FindExportedFunction(wm, "DriverProc", TRUE)==(void*)0x10003ef0) {            // looks like VP 6.1.0.2            for (i=0;i<6;i++) ((char*)0x10007268)[i]=0x90;            for (i=0;i<6;i++) ((char*)0x10007e83)[i]=0x90;            for (i=0;i<6;i++) ((char*)0x1000806a)[i]=0x90;          } else if (PE_FindExportedFunction(wm, "DriverProc", TRUE)==(void*)0x10004120) {            // looks like VP 6.2.0.10            for (i=0;i<6;i++) ((char*)0x10007688)[i]=0x90;            for (i=0;i<6;i++) ((char*)0x100082c3)[i]=0x90;            for (i=0;i<6;i++) ((char*)0x100084aa)[i]=0x90;          } else if (PE_FindExportedFunction(wm, "DriverProc", TRUE)==(void*)0x10003e70) {            // looks like VP 6.0.7.3            for (i=0;i<6;i++) ((char*)0x10007559)[i]=0x90;            for (i=0;i<6;i++) ((char*)0x100081c3)[i]=0x90;            for (i=0;i<6;i++) ((char*)0x1000839e)[i]=0x90;          } else {            printf("wine/module: Unsupported VP6 version\n");            return 0;          }        }	if (strstr(libname,"QuickTime.qts") && wm)	{	    void** ptr;	    void *dispatch_addr;	    int i;//	    dispatch_addr = GetProcAddress(wm->module, "theQuickTimeDispatcher", TRUE);	    dispatch_addr = PE_FindExportedFunction(wm, "theQuickTimeDispatcher", TRUE);	    if (dispatch_addr == (void *)0x62924c30)	    {	        printf ("wine/module: QuickTime5 DLLs found\n");		ptr = (void **)0x62b75ca4; // dispatch_ptr	        for (i=0;i<5;i++)  ((char*)0x6299e842)[i]=0x90; // make_new_region ?	        for (i=0;i<28;i++) ((char*)0x6299e86d)[i]=0x90; // call__call_CreateCompatibleDC ?		for (i=0;i<5;i++)  ((char*)0x6299e898)[i]=0x90; // jmp_to_call_loadbitmap ?	        for (i=0;i<9;i++)  ((char*)0x6299e8ac)[i]=0x90; // call__calls_OLE_shit ?	        for (i=0;i<106;i++) ((char*)0x62a61b10)[i]=0x90; // disable threads#if 0		/* CreateThread callers */		for (i=0;i<5;i++) ((char*)0x629487c5)[i]=0x90;		for (i=0;i<5;i++) ((char*)0x6294b275)[i]=0x90;		for (i=0;i<5;i++) ((char*)0x629a24b1)[i]=0x90;		for (i=0;i<5;i++) ((char*)0x629afc5a)[i]=0x90;		for (i=0;i<5;i++) ((char*)0x62af799c)[i]=0x90;		for (i=0;i<5;i++) ((char*)0x62af7efe)[i]=0x90;		for (i=0;i<5;i++) ((char*)0x62afa33e)[i]=0x90;#endif#if 0		/* TerminateQTML fix */		for (i=0;i<47;i++) ((char*)0x62afa3b8)[i]=0x90; // terminate thread		for (i=0;i<47;i++) ((char*)0x62af7f78)[i]=0x90; // terminate thread		for (i=0;i<77;i++) ((char*)0x629a13d5)[i]=0x90;		((char *)0x6288e0ae)[0] = 0xc3; // font/dc remover		for (i=0;i<24;i++) ((char*)0x6287a1ad)[i]=0x90; // destroy window#endif	    } else if (dispatch_addr == (void *)0x6693b330)	    {	        printf ("wine/module: QuickTime6 DLLs found\n");		ptr = (void **)0x66bb9524; // dispatcher_ptr		for (i=0;i<5;i++)  ((char *)0x66a730cc)[i]=0x90; // make_new_region		for (i=0;i<28;i++) ((char *)0x66a730f7)[i]=0x90; // call__call_CreateCompatibleDC		for (i=0;i<5;i++)  ((char *)0x66a73122)[i]=0x90; // jmp_to_call_loadbitmap		for (i=0;i<9;i++)  ((char *)0x66a73131)[i]=0x90; // call__calls_OLE_shit		for (i=0;i<96;i++) ((char *)0x66aac852)[i]=0x90; // disable threads	    } else if (dispatch_addr == (void *)0x6693c3e0)	    {    		printf ("wine/module: QuickTime6.3 DLLs found\n");		ptr = (void **)0x66bca01c; // dispatcher_ptr		for (i=0;i<5;i++)  ((char *)0x66a68f6c)[i]=0x90; // make_new_region		for (i=0;i<28;i++) ((char *)0x66a68f97)[i]=0x90; // call__call_CreateCompatibleDC		for (i=0;i<5;i++)  ((char *)0x66a68fc2)[i]=0x90; // jmp_to_call_loadbitmap		for (i=0;i<9;i++)  ((char *)0x66a68fd1)[i]=0x90; // call__calls_OLE_shit		for (i=0;i<96;i++) ((char *)0x66ab4722)[i]=0x90; // disable threads	    } else	    {	        printf ("wine/module: Unsupported QuickTime version (%p)\n",			dispatch_addr);		return 0;	    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -