4 * Copyright 1995 Alexandre Julliard
6 * Modified for use with MPlayer, detailed CVS changelog at
7 * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
12 // define for quicktime calls debugging and/or MacOS-level emulation:
15 // define for quicktime debugging (verbose logging):
16 //#define DEBUG_QTX_API
30 #include "wine/windef.h"
31 #include "wine/winerror.h"
32 #include "wine/heap.h"
33 #include "wine/module.h"
34 #include "wine/pe_image.h"
35 #include "wine/debugtools.h"
41 #include "wine/elfdll.h"
48 static int report_func(void *stack_base, int stack_size, reg386_t *reg, uint32_t *flags);
49 static int report_func_ret(void *stack_base, int stack_size, reg386_t *reg, uint32_t *flags);
53 //#define TRACE printf
55 //WINE_MODREF *local_wm=NULL;
56 modref_list* local_wm=NULL;
60 WINE_MODREF* MODULE_FindModule(LPCSTR m)
62 modref_list* list=local_wm;
63 TRACE("FindModule: Module %s request\n", m);
66 // while(strcmp(m, list->wm->filename))
67 while(!strstr(list->wm->filename, m))
69 TRACE("%s: %x\n", list->wm->filename, list->wm->module);
74 TRACE("Resolved to %s\n", list->wm->filename);
78 static void MODULE_RemoveFromList(WINE_MODREF *mod)
80 modref_list* list=local_wm;
85 if((list->prev==NULL)&&(list->next==NULL))
92 for(;list;list=list->prev)
97 list->prev->next=list->next;
99 list->next->prev=list->prev;
109 WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m)
111 modref_list* list=local_wm;
112 TRACE("LookupHMODULE: Module %X request\n", m);
115 TRACE("LookupHMODULE failed\n");
118 while(m!=list->wm->module)
120 // printf("Checking list %X wm %X module %X\n",
121 // list, list->wm, list->wm->module);
125 TRACE("LookupHMODULE failed\n");
129 TRACE("LookupHMODULE hit %p\n", list->wm);
133 /*************************************************************************
136 static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
138 WIN_BOOL retv = TRUE;
140 static LPCSTR typeName[] = { "PROCESS_DETACH", "PROCESS_ATTACH",
141 "THREAD_ATTACH", "THREAD_DETACH" };
145 /* Skip calls for modules loaded with special load flags */
147 if ( ( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS )
148 || ( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE ) )
152 TRACE("(%s,%s,%p) - CALL\n", wm->modname, typeName[type], lpReserved );
154 /* Call the initialization routine */
158 retv = PE_InitDLL( wm, type, lpReserved );
162 /* no need to do that, dlopen() already does */
166 ERR("wine_modref type %d not handled.\n", wm->type );
171 /* The state of the module list may have changed due to the call
172 to PE_InitDLL. We cannot assume that this module has not been
174 TRACE("(%p,%s,%p) - RETURN %d\n", wm, typeName[type], lpReserved, retv );
179 /*************************************************************************
180 * MODULE_DllProcessAttach
182 * Send the process attach notification to all DLLs the given module
183 * depends on (recursively). This is somewhat complicated due to the fact that
185 * - we have to respect the module dependencies, i.e. modules implicitly
186 * referenced by another module have to be initialized before the module
187 * itself can be initialized
189 * - the initialization routine of a DLL can itself call LoadLibrary,
190 * thereby introducing a whole new set of dependencies (even involving
191 * the 'old' modules) at any time during the whole process
193 * (Note that this routine can be recursively entered not only directly
194 * from itself, but also via LoadLibrary from one of the called initialization
197 * Furthermore, we need to rearrange the main WINE_MODREF list to allow
198 * the process *detach* notifications to be sent in the correct order.
199 * This must not only take into account module dependencies, but also
200 * 'hidden' dependencies created by modules calling LoadLibrary in their
201 * attach notification routine.
203 * The strategy is rather simple: we move a WINE_MODREF to the head of the
204 * list after the attach notification has returned. This implies that the
205 * detach notifications are called in the reverse of the sequence the attach
206 * notifications *returned*.
208 * NOTE: Assumes that the process critical section is held!
211 static WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved )
213 WIN_BOOL retv = TRUE;
217 /* prevent infinite recursion in case of cyclical dependencies */
218 if ( ( wm->flags & WINE_MODREF_MARKER )
219 || ( wm->flags & WINE_MODREF_PROCESS_ATTACHED ) )
222 TRACE("(%s,%p) - START\n", wm->modname, lpReserved );
224 /* Tag current MODREF to prevent recursive loop */
225 wm->flags |= WINE_MODREF_MARKER;
227 /* Recursively attach all DLLs this one depends on */
228 /* for ( i = 0; retv && i < wm->nDeps; i++ )
230 retv = MODULE_DllProcessAttach( wm->deps[i], lpReserved );
232 /* Call DLL entry point */
237 local_wm->next = (modref_list*) malloc(sizeof(modref_list));
238 local_wm->next->prev=local_wm;
239 local_wm->next->next=NULL;
240 local_wm->next->wm=wm;
241 local_wm=local_wm->next;
245 local_wm = (modref_list*)malloc(sizeof(modref_list));
246 local_wm->next=local_wm->prev=NULL;
249 /* Remove recursion flag */
250 wm->flags &= ~WINE_MODREF_MARKER;
254 retv = MODULE_InitDll( wm, DLL_PROCESS_ATTACH, lpReserved );
256 wm->flags |= WINE_MODREF_PROCESS_ATTACHED;
260 TRACE("(%s,%p) - END\n", wm->modname, lpReserved );
265 /*************************************************************************
266 * MODULE_DllProcessDetach
268 * Send DLL process detach notifications. See the comment about calling
269 * sequence at MODULE_DllProcessAttach. Unless the bForceDetach flag
270 * is set, only DLLs with zero refcount are notified.
272 static void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpReserved )
274 // WINE_MODREF *wm=local_wm;
275 modref_list* l = local_wm;
276 wm->flags &= ~WINE_MODREF_PROCESS_ATTACHED;
277 MODULE_InitDll( wm, DLL_PROCESS_DETACH, lpReserved );
287 /***********************************************************************
288 * MODULE_LoadLibraryExA (internal)
290 * Load a PE style module according to the load order.
292 * The HFILE parameter is not used and marked reserved in the SDK. I can
293 * only guess that it should force a file to be mapped, but I rather
294 * ignore the parameter because it would be extremely difficult to
295 * integrate this with different types of module represenations.
298 static WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
300 DWORD err = GetLastError();
303 // module_loadorder_t *plo;
305 SetLastError( ERROR_FILE_NOT_FOUND );
306 TRACE("Trying native dll '%s'\n", libname);
307 pwm = PE_LoadLibraryExA(libname, flags);
311 TRACE("Trying ELF dll '%s'\n", libname);
312 pwm=(WINE_MODREF*)ELFDLL_LoadLibraryExA(libname, flags);
315 // printf("0x%08x\n", pwm);
319 /* Initialize DLL just loaded */
320 TRACE("Loaded module '%s' at 0x%08x, \n", libname, pwm->module);
321 /* Set the refCount here so that an attach failure will */
322 /* decrement the dependencies through the MODULE_FreeLibrary call. */
325 SetLastError( err ); /* restore last error */
330 WARN("Failed to load module '%s'; error=0x%08lx, \n", libname, GetLastError());
334 /***********************************************************************
337 * NOTE: Assumes that the process critical section is held!
339 static WIN_BOOL MODULE_FreeLibrary( WINE_MODREF *wm )
341 TRACE("(%s) - START\n", wm->modname );
343 /* Recursively decrement reference counts */
344 //MODULE_DecRefCount( wm );
346 /* Call process detach notifications */
347 MODULE_DllProcessDetach( wm, FALSE, NULL );
349 PE_UnloadLibrary(wm);
356 /***********************************************************************
357 * LoadLibraryExA (KERNEL32)
359 HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
362 char* listpath[] = { "", "", "/usr/lib/win32", "/usr/local/lib/win32", 0 };
363 extern char* def_path;
371 SetLastError(ERROR_INVALID_PARAMETER);
375 wm=MODULE_FindModule(libname);
376 if(wm) return wm->module;
378 // if(fs_installed==0)
381 while (wm == 0 && listpath[++i])
386 /* check just original file name */
387 strncpy(path, libname, 511);
389 /* check default user path */
390 strncpy(path, def_path, 300);
392 else if (strcmp(def_path, listpath[i]))
393 /* path from the list */
394 strncpy(path, listpath[i], 300);
401 strncat(path, libname, 100);
404 wm = MODULE_LoadLibraryExA( path, hfile, flags );
409 strcat(checked, ", ");
410 strcat(checked, path);
417 if ( !MODULE_DllProcessAttach( wm, NULL ) )
419 WARN_(module)("Attach failed for module '%s', \n", libname);
420 MODULE_FreeLibrary(wm);
421 SetLastError(ERROR_DLL_INIT_FAILED);
422 MODULE_RemoveFromList(wm);
428 printf("Win32 LoadLibrary failed to load: %s\n", checked);
430 if (strstr(libname,"vp31vfw.dll") && wm)
434 // sse hack moved from patch dll into runtime patching
435 if (PE_FindExportedFunction(wm, "DriverProc", TRUE)==(void*)0x10001000) {
436 fprintf(stderr, "VP3 DLL found\n");
437 for (i=0;i<18;i++) ((char*)0x10004bd6)[i]=0x90;
441 // remove a few divs in the VP codecs that make trouble
442 if (strstr(libname,"vp5vfw.dll") && wm)
445 if (PE_FindExportedFunction(wm, "DriverProc", TRUE)==(void*)0x10003930) {
446 for (i=0;i<3;i++) ((char*)0x10004e86)[i]=0x90;
447 for (i=0;i<3;i++) ((char*)0x10005a23)[i]=0x90;
448 for (i=0;i<3;i++) ((char*)0x10005bff)[i]=0x90;
450 fprintf(stderr, "Unsupported VP5 version\n");
455 if (strstr(libname,"vp6vfw.dll") && wm)
458 if (PE_FindExportedFunction(wm, "DriverProc", TRUE)==(void*)0x10003ef0) {
459 // looks like VP 6.1.0.2
460 for (i=0;i<6;i++) ((char*)0x10007268)[i]=0x90;
461 for (i=0;i<6;i++) ((char*)0x10007e83)[i]=0x90;
462 for (i=0;i<6;i++) ((char*)0x1000806a)[i]=0x90;
463 } else if (PE_FindExportedFunction(wm, "DriverProc", TRUE)==(void*)0x10004120) {
464 // looks like VP 6.2.0.10
465 for (i=0;i<6;i++) ((char*)0x10007688)[i]=0x90;
466 for (i=0;i<6;i++) ((char*)0x100082c3)[i]=0x90;
467 for (i=0;i<6;i++) ((char*)0x100084aa)[i]=0x90;
468 } else if (PE_FindExportedFunction(wm, "DriverProc", TRUE)==(void*)0x10003e70) {
469 // looks like VP 6.0.7.3
470 for (i=0;i<6;i++) ((char*)0x10007559)[i]=0x90;
471 for (i=0;i<6;i++) ((char*)0x100081c3)[i]=0x90;
472 for (i=0;i<6;i++) ((char*)0x1000839e)[i]=0x90;
474 fprintf(stderr, "Unsupported VP6 version\n");
479 // Windows Media Video 9 Advanced
480 if (strstr(libname,"wmvadvd.dll") && wm)
482 // The codec calls IsRectEmpty with coords 0,0,0,0 => result is 0
483 // but it really wants the rectangle to be not empty
484 if (PE_FindExportedFunction(wm, "CreateInstance", TRUE)==(void*)0x08c4b812) {
485 // Dll version is 10.0.0.3645
486 *((char*)0x08c48b0f)=0xeb; // Jump always, ignoring IsRectEmpty result
488 fprintf(stderr, "Unsupported WMVA version\n");
493 if (strstr(libname,"QuickTime.qts") && wm)
499 // dispatch_addr = GetProcAddress(wm->module, "theQuickTimeDispatcher", TRUE);
500 dispatch_addr = PE_FindExportedFunction(wm, "theQuickTimeDispatcher", TRUE);
501 if (dispatch_addr == (void *)0x62924c30)
503 fprintf(stderr, "QuickTime5 DLLs found\n");
504 ptr = (void **)0x62b75ca4; // dispatch_ptr
505 for (i=0;i<5;i++) ((char*)0x6299e842)[i]=0x90; // make_new_region ?
506 for (i=0;i<28;i++) ((char*)0x6299e86d)[i]=0x90; // call__call_CreateCompatibleDC ?
507 for (i=0;i<5;i++) ((char*)0x6299e898)[i]=0x90; // jmp_to_call_loadbitmap ?
508 for (i=0;i<9;i++) ((char*)0x6299e8ac)[i]=0x90; // call__calls_OLE_shit ?
509 for (i=0;i<106;i++) ((char*)0x62a61b10)[i]=0x90; // disable threads
511 /* CreateThread callers */
512 for (i=0;i<5;i++) ((char*)0x629487c5)[i]=0x90;
513 for (i=0;i<5;i++) ((char*)0x6294b275)[i]=0x90;
514 for (i=0;i<5;i++) ((char*)0x629a24b1)[i]=0x90;
515 for (i=0;i<5;i++) ((char*)0x629afc5a)[i]=0x90;
516 for (i=0;i<5;i++) ((char*)0x62af799c)[i]=0x90;
517 for (i=0;i<5;i++) ((char*)0x62af7efe)[i]=0x90;
518 for (i=0;i<5;i++) ((char*)0x62afa33e)[i]=0x90;
522 /* TerminateQTML fix */
523 for (i=0;i<47;i++) ((char*)0x62afa3b8)[i]=0x90; // terminate thread
524 for (i=0;i<47;i++) ((char*)0x62af7f78)[i]=0x90; // terminate thread
525 for (i=0;i<77;i++) ((char*)0x629a13d5)[i]=0x90;
526 ((char *)0x6288e0ae)[0] = 0xc3; // font/dc remover
527 for (i=0;i<24;i++) ((char*)0x6287a1ad)[i]=0x90; // destroy window
529 } else if (dispatch_addr == (void *)0x6693b330)
531 fprintf(stderr, "QuickTime6 DLLs found\n");
532 ptr = (void **)0x66bb9524; // dispatcher_ptr
533 for (i=0;i<5;i++) ((char *)0x66a730cc)[i]=0x90; // make_new_region
534 for (i=0;i<28;i++) ((char *)0x66a730f7)[i]=0x90; // call__call_CreateCompatibleDC
535 for (i=0;i<5;i++) ((char *)0x66a73122)[i]=0x90; // jmp_to_call_loadbitmap
536 for (i=0;i<9;i++) ((char *)0x66a73131)[i]=0x90; // call__calls_OLE_shit
537 for (i=0;i<96;i++) ((char *)0x66aac852)[i]=0x90; // disable threads
538 } else if (dispatch_addr == (void *)0x6693c3e0)
540 fprintf(stderr, "QuickTime6.3 DLLs found\n");
541 ptr = (void **)0x66bca01c; // dispatcher_ptr
542 for (i=0;i<5;i++) ((char *)0x66a68f6c)[i]=0x90; // make_new_region
543 for (i=0;i<28;i++) ((char *)0x66a68f97)[i]=0x90; // call__call_CreateCompatibleDC
544 for (i=0;i<5;i++) ((char *)0x66a68fc2)[i]=0x90; // jmp_to_call_loadbitmap
545 for (i=0;i<9;i++) ((char *)0x66a68fd1)[i]=0x90; // call__calls_OLE_shit
546 for (i=0;i<96;i++) ((char *)0x66ab4722)[i]=0x90; // disable threads
549 fprintf(stderr, "Unsupported QuickTime version (%p)\n",
554 fprintf(stderr,"QuickTime.qts patched!!! old entry=%p\n",ptr[0]);
557 report_entry = report_func;
558 report_ret = report_func_ret;
559 wrapper_target=ptr[0];
564 return wm ? wm->module : 0;
568 /***********************************************************************
569 * LoadLibraryA (KERNEL32)
571 HMODULE WINAPI LoadLibraryA(LPCSTR libname) {
572 return LoadLibraryExA(libname,0,0);
575 /***********************************************************************
578 WIN_BOOL WINAPI FreeLibrary(HINSTANCE hLibModule)
580 WIN_BOOL retv = FALSE;
583 wm=MODULE32_LookupHMODULE(hLibModule);
585 if ( !wm || !hLibModule )
587 SetLastError( ERROR_INVALID_HANDLE );
591 retv = MODULE_FreeLibrary( wm );
593 MODULE_RemoveFromList(wm);
596 if (local_wm == NULL) my_garbagecollection();
601 /***********************************************************************
604 * NOTE: Assumes that the process critical section is held!
606 static void MODULE_DecRefCount( WINE_MODREF *wm )
610 if ( wm->flags & WINE_MODREF_MARKER )
613 if ( wm->refCount <= 0 )
617 TRACE("(%s) refCount: %d\n", wm->modname, wm->refCount );
619 if ( wm->refCount == 0 )
621 wm->flags |= WINE_MODREF_MARKER;
623 for ( i = 0; i < wm->nDeps; i++ )
625 MODULE_DecRefCount( wm->deps[i] );
627 wm->flags &= ~WINE_MODREF_MARKER;
631 /***********************************************************************
632 * GetProcAddress (KERNEL32.257)
634 FARPROC WINAPI GetProcAddress( HMODULE hModule, LPCSTR function )
636 return MODULE_GetProcAddress( hModule, function, TRUE );
642 http://lists.apple.com/archives/quicktime-api/2003/Jan/msg00278.html
645 struct ComponentParameters {
646 unsigned char flags; /* call modifiers: sync/async, deferred, immed, etc */
647 unsigned char paramSize; /* size in bytes of actual parameters passed to this call */
648 short what; /* routine selector, negative for Component management calls */
649 long params[1]; /* actual parameters for the indicated routine */
651 typedef struct ComponentParameters ComponentParameters;
653 static char* component_func(int what){
654 if (what < 0) // Range 0: Standard Component Calls
656 case -1: return "kComponentOpenSelect";
657 case -2: return "kComponentCloseSelect";
658 case -3: return "kComponentCanDoSelect";
659 case -4: return "kComponentVersionSelect";
660 case -5: return "kComponentRegisterSelect";
661 case -6: return "kComponentTargetSelect";
662 case -7: return "kComponentUnregisterSelect";
665 if (what >= 0 && what <= 0xff) // Range 1: Generic codecs
667 case 0: return "kImageCodecGetCodecInfoSelect";
668 case 1: return "kImageCodecGetCompressionTimeSelect";
669 case 2: return "kImageCodecGetMaxCompressionSizeSelect";
670 case 3: return "kImageCodecPreCompressSelect";
671 case 4: return "kImageCodecBandCompressSelect";
672 case 5: return "kImageCodecPreDecompressSelect";
673 case 6: return "kImageCodecBandDecompressSelect";
674 case 7: return "kImageCodecBusySelect";
675 // finish this list from the above URL
676 case 0x10: return "kImageCodecIsImageDescriptionEquivalentSelect";
677 case 0x12: return "kImageCodecDisposeMemorySelect";
678 case 0x14: return "kImageCodecNewImageBufferMemorySelect";
679 case 0x28: return "kImageCodecRequestGammaLevelSelect";
682 //if (what >= 0x100 && what <= 0x1ff) // Range 2: Specific to QT Photo JPEG codecs
684 if (what >= 0x200 && what <= 0x2ff) // Range 3: Base Decompressor
686 case 0: return "Preflight";
687 case 1: return "Initialize";
688 case 2: return "BeginBand";
689 case 3: return "DrawBand";
690 case 4: return "EndBand";
691 case 5: return "QueueStarting";
692 case 6: return "QueueStopping";
698 static int c_level=0;
700 static int dump_component(char* name,int type,void* _orig, ComponentParameters *params,void** glob){
701 int ( *orig)(ComponentParameters *params, void** glob) = _orig;
704 fprintf(stderr,"%*sComponentCall: %s flags=0x%X size=%d what=0x%X %s\n",3*c_level,"",name,params->flags, params->paramSize, params->what, component_func(params->what));
706 for(i=0;i<params->paramSize/4;i++)
707 fprintf(stderr,"%*s param[%d] = 0x%X\n",3*c_level,"",i,params->params[i]);
710 ret=orig(params,glob);
714 fprintf(stderr,"%*s return=0x%X\n",3*c_level,"",ret);
716 fprintf(stderr,"%*s return=%d\n",3*c_level,"",ret);
720 #define DECL_COMPONENT(sname,name,type) \
721 static void* real_ ## sname = NULL; \
722 static int fake_ ## sname(ComponentParameters *params,void** glob){ \
723 return dump_component(name,type,real_ ## sname, params, glob); \
728 #undef DECL_COMPONENT
736 static uint32_t ret_array[4096];
739 static int report_func(void *stack_base, int stack_size, reg386_t *reg, uint32_t *flags)
750 dptr=0x62b67ae0;dptr+=2*((reg->eax>>16)&255);
751 // printf("FUNC: flag=%d ptr=%p\n",dptr[0],dptr[1]);
753 dptr=dptr[1];dptr+=4*(reg->eax&65535);
754 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",dptr[1],dptr[0],dptr[2]);
755 pwrapper=dptr[1]; pptr=dptr[0]; plen=dptr[2];
760 dptr=0x62b672c0;dptr+=2*(reg->eax&65535);
761 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
762 pptr=dptr[0]; plen=dptr[1];
765 dptr=0x62b67c70;dptr+=2*(reg->eax&65535);
766 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
767 pptr=dptr[0]; plen=dptr[1];
770 dptr=0x62b68108;if(reg->eax&0x8000) dptr+=2*(reg->eax|0xffff0000); else dptr+=2*(reg->eax&65535);
771 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
772 pptr=dptr[0]; plen=dptr[1];
775 dptr=0x62b68108;if(reg->eax&0x8000) dptr+=2*(reg->eax|0xffff0000); else dptr+=2*(reg->eax&65535);
776 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
777 pptr=dptr[0]; plen=dptr[1];
780 printf("FUNC: unknown ptr & psize!\n");
785 for(i=0;qt_fv_list[i].name;i++){
786 if(qt_fv_list[i].id==reg->eax){
787 pname=qt_fv_list[i].name;
792 printf("FUNC[%X/%s]: wrapper=%p func=%p len=%d\n",reg->eax,
793 pname?pname:"???",pwrapper,pptr,plen);
795 printf("FUNC: caller=%p ebx=%p\n",((uint32_t *)stack_base)[0],reg->ebx);
798 printf("%*sENTER(%d): %s(",ret_i*2,"",ret_i,pname);
800 printf("%*sENTER(%d): %X(",ret_i*2,"",ret_i,reg->eax);
801 for (i=0;i<plen/4;i++){
802 unsigned int val=((uint32_t *)stack_base)[1+i];
803 unsigned char* fcc=&val;
804 printf("%s0x%X", i?", ":"",val);
805 if(fcc[0]>=0x20 && fcc[0]<128 &&
806 fcc[1]>=0x20 && fcc[1]<128 &&
807 fcc[2]>=0x20 && fcc[2]<128 &&
808 fcc[3]>=0x20 && fcc[3]<128) printf("='%c%c%c%c'",fcc[3],fcc[2],fcc[1],fcc[0]);
809 else if(val>=8 && val<65536) printf("=%d",val);
817 // emulate some functions:
819 // memory management:
820 case 0x150011: //NewPtrClear
821 case 0x150012: //NewPtrSysClear
822 reg->eax=(uint32_t)malloc(((uint32_t *)stack_base)[1]);
823 memset((void *)reg->eax,0,((uint32_t *)stack_base)[1]);
825 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i*2,"",ret_i, reg->eax);
828 case 0x15000F: //NewPtr
829 case 0x150010: //NewPtrSys
830 reg->eax=(uint32_t)malloc(((uint32_t *)stack_base)[1]);
832 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i*2,"",ret_i, reg->eax);
835 case 0x15002f: //DisposePtr
836 if(((uint32_t *)stack_base)[1]>=0x60000000)
837 printf("WARNING! Invalid Ptr handle!\n");
839 free((void *)((uint32_t *)stack_base)[1]);
842 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i*2,"",ret_i, reg->eax);
846 case 0x1d0033: //QTMLCreateMutex
849 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i*2,"",ret_i, reg->eax);
852 case 0x1d0034: //QTMLDestroyMutex
853 case 0x1d0035: //QTMLGrabMutex
854 case 0x1d0036: //QTMLReturnMutex
855 case 0x1d003d: //QTMLTryGrabMutex
858 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i*2,"",ret_i, reg->eax);
867 // printf("FUNC: ImageCodecInitialize/ImageCodecGetCodecInfo(ci=%p,&icap=%p)\n",((uint32_t *)stack_base)[1],((uint32_t *)stack_base)[4]);
870 printf("FUNC: CountComponents(&desc=%p)\n",((uint32_t *)stack_base)[1]);
873 printf("FUNC: FindNextComponent(prev=%p,&desc=%p)\n",((uint32_t *)stack_base)[1],((uint32_t *)stack_base)[2]);
876 printf("FUNC: OpenComponent(prev=%p)\n",((uint32_t *)stack_base)[1]);
879 printf("FUNC: QTNewGWorldFromPtr(&pts=%p,fourcc=%.4s,&rect=%p,x1=%p,x2=%p,x3=%p,plane=%p,stride=%d)\n",
880 ((uint32_t *)stack_base)[1],
881 &(((uint32_t *)stack_base)[2]),
882 ((uint32_t *)stack_base)[3],
883 ((uint32_t *)stack_base)[4],
884 ((uint32_t *)stack_base)[5],
885 ((uint32_t *)stack_base)[6],
886 ((uint32_t *)stack_base)[7],
887 ((uint32_t *)stack_base)[8]);
890 printf("FUNC: GetGWorldPixMap(gworld=%p)\n",((uint32_t *)stack_base)[1]);
893 printf("FUNC: Gestalt(fourcc=%.4s, &ret=%p)\n",&(((uint32_t *)stack_base)[1]),((uint32_t *)stack_base)[2]);
897 for(i=0;qt_fv_list[i].name;i++){
898 if(qt_fv_list[i].id==reg->eax){
899 printf("FUNC: %s\n",qt_fv_list[i].name);
906 // print stack/reg information
907 printf("ENTER(%d) stack = %d bytes @ %p\n"
908 "eax = 0x%08x edx = 0x%08x ebx = 0x%08x ecx = 0x%08x\n"
909 "esp = 0x%08x ebp = 0x%08x esi = 0x%08x edi = 0x%08x\n"
910 "flags = 0x%08x\n", ret_i,
911 stack_size, stack_base,
912 reg->eax, reg->edx, reg->ebx, reg->ecx,
913 reg->esp, reg->ebp, reg->esi, reg->edi,
918 ret_array[ret_i]=((uint32_t *)stack_base)[0];
922 // print first 7 longs in the stack (return address, arg[1], arg[2] ... )
923 printf("stack[] = { ");
925 printf("%08x ", ((uint32_t *)stack_base)[i]);
930 // // mess with function parameters
931 // ((uint32_t *)stack_base)[1] = 0x66554433;
933 // // mess with return address...
934 // reg->eax = 0x11223344;
938 static int report_func_ret(void *stack_base, int stack_size, reg386_t *reg, uint32_t *flags)
945 ((uint32_t *)stack_base)[0]=ret_array[ret_i];
950 printf("%*sLEAVE(%d): 0x%X",ret_i*2,"",ret_i, reg->eax);
952 if(err && (reg->eax>>16)==0) printf(" = %d",err);
956 // print stack/reg information
957 printf("LEAVE(%d) stack = %d bytes @ %p\n"
958 "eax = 0x%08x edx = 0x%08x ebx = 0x%08x ecx = 0x%08x\n"
959 "esp = 0x%08x ebp = 0x%08x esi = 0x%08x edi = 0x%08x\n"
960 "flags = 0x%08x\n", ret_i,
961 stack_size, stack_base,
962 reg->eax, reg->edx, reg->ebx, reg->ecx,
963 reg->esp, reg->ebp, reg->esi, reg->edi,
968 // print first 7 longs in the stack (return address, arg[1], arg[2] ... )
969 printf("stack[] = { ");
971 printf("%08x ", ((uint32_t *)stack_base)[i]);
978 // // mess with function parameters
979 // ((uint32_t *)stack_base)[1] = 0x66554433;
981 // // mess with return address...
982 // reg->eax = 0x11223344;
988 /***********************************************************************
989 * MODULE_GetProcAddress (internal)
991 FARPROC MODULE_GetProcAddress(
992 HMODULE hModule, /* [in] current module handle */
993 LPCSTR function, /* [in] function to be looked up */
996 WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
997 // WINE_MODREF *wm=local_wm;
1000 #ifdef DEBUG_QTX_API
1001 if (HIWORD(function))
1002 fprintf(stderr,"XXX GetProcAddress(%08lx,%s)\n",(DWORD)hModule,function);
1004 fprintf(stderr,"XXX GetProcAddress(%08lx,%p)\n",(DWORD)hModule,function);
1007 // TRACE_(win32)("(%08lx,%s)\n",(DWORD)hModule,function);
1009 // TRACE_(win32)("(%08lx,%p)\n",(DWORD)hModule,function);
1012 SetLastError(ERROR_INVALID_HANDLE);
1018 retproc = PE_FindExportedFunction( wm, function, snoop );
1019 if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
1023 retproc = (FARPROC) dlsym( (void*) wm->module, function);
1024 if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
1028 ERR("wine_modref type %d not handled.\n",wm->type);
1029 SetLastError(ERROR_INVALID_HANDLE);
1034 if (HIWORD(function) && retproc){
1036 #ifdef DEBUG_QTX_API
1037 #define DECL_COMPONENT(sname,name,type) \
1038 if(!strcmp(function,name)){ \
1039 fprintf(stderr,name "dispatcher catched -> %p\n",retproc); \
1040 real_ ## sname = retproc; retproc = fake_ ## sname; \
1042 #include "qt_comp.h"
1043 #undef DECL_COMPONENT
1046 if(!strcmp(function,"theQuickTimeDispatcher")
1047 // || !strcmp(function,"_CallComponentFunctionWithStorage")
1048 // || !strcmp(function,"_CallComponent")
1050 fprintf(stderr,"theQuickTimeDispatcher catched -> %p\n",retproc);
1051 report_entry = report_func;
1052 report_ret = report_func_ret;
1053 wrapper_target=(void(*)(void))retproc;
1054 retproc=(FARPROC)wrapper;
1063 static int acounter = 0;
1064 void CodecAlloc(void)
1067 //printf("**************CODEC ALLOC %d\n", acounter);
1070 void CodecRelease(void)
1073 //printf("**************CODEC RELEASE %d\n", acounter);
1078 modref_list* list = local_wm;
1081 //printf("CODECRELEASE %p\n", list);
1082 MODULE_FreeLibrary(list->wm);
1083 MODULE_RemoveFromList(list->wm);
1084 if (local_wm == NULL)
1085 my_garbagecollection();