4 * Copyright 1995 Alexandre Julliard
6 * Modified for use with MPlayer, detailed changelog at
7 * http://svn.mplayerhq.hu/mplayer/trunk/
11 // define for quicktime calls debugging and/or MacOS-level emulation:
14 #endif /* __APPLE__ */
16 // define for quicktime debugging (verbose logging):
17 //#define DEBUG_QTX_API
29 #ifdef HAVE_SYS_MMAN_H
34 #include "wine/windef.h"
35 #include "wine/winerror.h"
36 #include "wine/heap.h"
37 #include "wine/module.h"
38 #include "wine/pe_image.h"
39 #include "wine/debugtools.h"
45 #include "wine/elfdll.h"
53 static int report_func(void *stack_base
, int stack_size
, reg386_t
*reg
, uint32_t *flags
);
54 static int report_func_ret(void *stack_base
, int stack_size
, reg386_t
*reg
, uint32_t *flags
);
58 //#define TRACE printf
60 //WINE_MODREF *local_wm=NULL;
61 modref_list
* local_wm
=NULL
;
65 WINE_MODREF
* MODULE_FindModule(LPCSTR m
)
67 modref_list
* list
=local_wm
;
68 TRACE("FindModule: Module %s request\n", m
);
71 // while(strcmp(m, list->wm->filename))
72 while(!strstr(list
->wm
->filename
, m
))
74 TRACE("%s: %x\n", list
->wm
->filename
, list
->wm
->module
);
79 TRACE("Resolved to %s\n", list
->wm
->filename
);
83 static void MODULE_RemoveFromList(WINE_MODREF
*mod
)
85 modref_list
* list
=local_wm
;
90 if((list
->prev
==NULL
)&&(list
->next
==NULL
))
97 for(;list
;list
=list
->prev
)
102 list
->prev
->next
=list
->next
;
104 list
->next
->prev
=list
->prev
;
114 WINE_MODREF
*MODULE32_LookupHMODULE(HMODULE m
)
116 modref_list
* list
=local_wm
;
117 TRACE("LookupHMODULE: Module %X request\n", m
);
120 TRACE("LookupHMODULE failed\n");
123 while(m
!=list
->wm
->module
)
125 // printf("Checking list %X wm %X module %X\n",
126 // list, list->wm, list->wm->module);
130 TRACE("LookupHMODULE failed\n");
134 TRACE("LookupHMODULE hit %p\n", list
->wm
);
138 /*************************************************************************
141 static WIN_BOOL
MODULE_InitDll( WINE_MODREF
*wm
, DWORD type
, LPVOID lpReserved
)
143 WIN_BOOL retv
= TRUE
;
146 static LPCSTR typeName
[] = { "PROCESS_DETACH", "PROCESS_ATTACH",
147 "THREAD_ATTACH", "THREAD_DETACH" };
153 /* Skip calls for modules loaded with special load flags */
155 if ( ( wm
->flags
& WINE_MODREF_DONT_RESOLVE_REFS
)
156 || ( wm
->flags
& WINE_MODREF_LOAD_AS_DATAFILE
) )
160 TRACE("(%s,%s,%p) - CALL\n", wm
->modname
, typeName
[type
], lpReserved
);
162 /* Call the initialization routine */
166 retv
= PE_InitDLL( wm
, type
, lpReserved
);
170 /* no need to do that, dlopen() already does */
174 ERR("wine_modref type %d not handled.\n", wm
->type
);
179 /* The state of the module list may have changed due to the call
180 to PE_InitDLL. We cannot assume that this module has not been
182 TRACE("(%p,%s,%p) - RETURN %d\n", wm
, typeName
[type
], lpReserved
, retv
);
187 /*************************************************************************
188 * MODULE_DllProcessAttach
190 * Send the process attach notification to all DLLs the given module
191 * depends on (recursively). This is somewhat complicated due to the fact that
193 * - we have to respect the module dependencies, i.e. modules implicitly
194 * referenced by another module have to be initialized before the module
195 * itself can be initialized
197 * - the initialization routine of a DLL can itself call LoadLibrary,
198 * thereby introducing a whole new set of dependencies (even involving
199 * the 'old' modules) at any time during the whole process
201 * (Note that this routine can be recursively entered not only directly
202 * from itself, but also via LoadLibrary from one of the called initialization
205 * Furthermore, we need to rearrange the main WINE_MODREF list to allow
206 * the process *detach* notifications to be sent in the correct order.
207 * This must not only take into account module dependencies, but also
208 * 'hidden' dependencies created by modules calling LoadLibrary in their
209 * attach notification routine.
211 * The strategy is rather simple: we move a WINE_MODREF to the head of the
212 * list after the attach notification has returned. This implies that the
213 * detach notifications are called in the reverse of the sequence the attach
214 * notifications *returned*.
216 * NOTE: Assumes that the process critical section is held!
219 static WIN_BOOL
MODULE_DllProcessAttach( WINE_MODREF
*wm
, LPVOID lpReserved
)
221 WIN_BOOL retv
= TRUE
;
225 /* prevent infinite recursion in case of cyclical dependencies */
226 if ( ( wm
->flags
& WINE_MODREF_MARKER
)
227 || ( wm
->flags
& WINE_MODREF_PROCESS_ATTACHED
) )
230 TRACE("(%s,%p) - START\n", wm
->modname
, lpReserved
);
232 /* Tag current MODREF to prevent recursive loop */
233 wm
->flags
|= WINE_MODREF_MARKER
;
235 /* Recursively attach all DLLs this one depends on */
236 /* for ( i = 0; retv && i < wm->nDeps; i++ )
238 retv = MODULE_DllProcessAttach( wm->deps[i], lpReserved );
240 /* Call DLL entry point */
245 local_wm
->next
= malloc(sizeof(modref_list
));
246 local_wm
->next
->prev
=local_wm
;
247 local_wm
->next
->next
=NULL
;
248 local_wm
->next
->wm
=wm
;
249 local_wm
=local_wm
->next
;
253 local_wm
= malloc(sizeof(modref_list
));
254 local_wm
->next
=local_wm
->prev
=NULL
;
257 /* Remove recursion flag */
258 wm
->flags
&= ~WINE_MODREF_MARKER
;
262 retv
= MODULE_InitDll( wm
, DLL_PROCESS_ATTACH
, lpReserved
);
264 wm
->flags
|= WINE_MODREF_PROCESS_ATTACHED
;
268 TRACE("(%s,%p) - END\n", wm
->modname
, lpReserved
);
273 /*************************************************************************
274 * MODULE_DllProcessDetach
276 * Send DLL process detach notifications. See the comment about calling
277 * sequence at MODULE_DllProcessAttach. Unless the bForceDetach flag
278 * is set, only DLLs with zero refcount are notified.
280 static void MODULE_DllProcessDetach( WINE_MODREF
* wm
, WIN_BOOL bForceDetach
, LPVOID lpReserved
)
282 // WINE_MODREF *wm=local_wm;
283 //modref_list* l = local_wm;
284 wm
->flags
&= ~WINE_MODREF_PROCESS_ATTACHED
;
285 MODULE_InitDll( wm
, DLL_PROCESS_DETACH
, lpReserved
);
295 /***********************************************************************
296 * MODULE_LoadLibraryExA (internal)
298 * Load a PE style module according to the load order.
300 * The HFILE parameter is not used and marked reserved in the SDK. I can
301 * only guess that it should force a file to be mapped, but I rather
302 * ignore the parameter because it would be extremely difficult to
303 * integrate this with different types of module represenations.
306 static WINE_MODREF
*MODULE_LoadLibraryExA( LPCSTR libname
, HFILE hfile
, DWORD flags
)
308 DWORD err
= GetLastError();
310 // module_loadorder_t *plo;
312 SetLastError( ERROR_FILE_NOT_FOUND
);
313 TRACE("Trying native dll '%s'\n", libname
);
314 pwm
= PE_LoadLibraryExA(libname
, flags
);
318 TRACE("Trying ELF dll '%s'\n", libname
);
319 pwm
=(WINE_MODREF
*)ELFDLL_LoadLibraryExA(libname
, flags
);
322 // printf("0x%08x\n", pwm);
326 /* Initialize DLL just loaded */
327 TRACE("Loaded module '%s' at 0x%08x, \n", libname
, pwm
->module
);
328 /* Set the refCount here so that an attach failure will */
329 /* decrement the dependencies through the MODULE_FreeLibrary call. */
332 SetLastError( err
); /* restore last error */
337 WARN("Failed to load module '%s'; error=0x%08lx, \n", libname
, GetLastError());
341 /***********************************************************************
344 * NOTE: Assumes that the process critical section is held!
346 static WIN_BOOL
MODULE_FreeLibrary( WINE_MODREF
*wm
)
348 TRACE("(%s) - START\n", wm
->modname
);
350 /* Call process detach notifications */
351 MODULE_DllProcessDetach( wm
, FALSE
, NULL
);
353 PE_UnloadLibrary(wm
);
360 /***********************************************************************
361 * LoadLibraryExA (KERNEL32)
363 HMODULE WINAPI
LoadLibraryExA(LPCSTR libname
, HANDLE hfile
, DWORD flags
)
366 char* listpath
[] = { "", "", 0 };
374 SetLastError(ERROR_INVALID_PARAMETER
);
378 wm
=MODULE_FindModule(libname
);
379 if(wm
) return wm
->module
;
381 // if(fs_installed==0)
384 // Do not load libraries from a path relative to the current directory
388 while (wm
== 0 && listpath
[++i
])
393 /* check just original file name */
394 strncpy(path
, libname
, 511);
396 /* check default user path */
397 strncpy(path
, codec_path
, 300);
399 else if (strcmp(codec_path
, listpath
[i
]))
400 /* path from the list */
401 strncpy(path
, listpath
[i
], 300);
408 strncat(path
, libname
, 100);
411 wm
= MODULE_LoadLibraryExA( path
, hfile
, flags
);
416 strcat(checked
, ", ");
417 strcat(checked
, path
);
424 if ( !MODULE_DllProcessAttach( wm
, NULL
) )
426 WARN_(module
)("Attach failed for module '%s', \n", libname
);
427 MODULE_FreeLibrary(wm
);
428 SetLastError(ERROR_DLL_INIT_FAILED
);
429 MODULE_RemoveFromList(wm
);
434 if (!wm
&& !strstr(checked
, "avisynth.dll"))
435 printf("Win32 LoadLibrary failed to load: %s\n", checked
);
437 #define RVA(x) ((char *)wm->module+(unsigned int)(x))
438 if (strstr(libname
,"vp31vfw.dll") && wm
)
442 // sse hack moved from patch dll into runtime patching
443 if (PE_FindExportedFunction(wm
, "DriverProc", TRUE
)==RVA(0x1000)) {
444 fprintf(stderr
, "VP3 DLL found\n");
445 for (i
=0;i
<18;i
++) RVA(0x4bd6)[i
]=0x90;
449 // remove a few divs in the VP codecs that make trouble
450 if (strstr(libname
,"vp5vfw.dll") && wm
)
453 if (PE_FindExportedFunction(wm
, "DriverProc", TRUE
)==RVA(0x3930)) {
454 for (i
=0;i
<3;i
++) RVA(0x4e86)[i
]=0x90;
455 for (i
=0;i
<3;i
++) RVA(0x5a23)[i
]=0x90;
456 for (i
=0;i
<3;i
++) RVA(0x5bff)[i
]=0x90;
458 fprintf(stderr
, "Unsupported VP5 version\n");
463 if (strstr(libname
,"vp6vfw.dll") && wm
)
466 if (PE_FindExportedFunction(wm
, "DriverProc", TRUE
)==RVA(0x3ef0)) {
467 // looks like VP 6.1.0.2
468 for (i
=0;i
<6;i
++) RVA(0x7268)[i
]=0x90;
469 for (i
=0;i
<6;i
++) RVA(0x7e83)[i
]=0x90;
470 for (i
=0;i
<6;i
++) RVA(0x806a)[i
]=0x90;
471 } else if (PE_FindExportedFunction(wm
, "DriverProc", TRUE
)==RVA(0x4120)) {
472 // looks like VP 6.2.0.10
473 for (i
=0;i
<6;i
++) RVA(0x7688)[i
]=0x90;
474 for (i
=0;i
<6;i
++) RVA(0x82c3)[i
]=0x90;
475 for (i
=0;i
<6;i
++) RVA(0x84aa)[i
]=0x90;
476 for (i
=0;i
<6;i
++) RVA(0x1d2cc)[i
]=0x90;
477 for (i
=0;i
<6;i
++) RVA(0x2179d)[i
]=0x90;
478 for (i
=0;i
<6;i
++) RVA(0x1977f)[i
]=0x90;
479 } else if (PE_FindExportedFunction(wm
, "DriverProc", TRUE
)==RVA(0x3e70)) {
480 // looks like VP 6.0.7.3
481 for (i
=0;i
<6;i
++) RVA(0x7559)[i
]=0x90;
482 for (i
=0;i
<6;i
++) RVA(0x81c3)[i
]=0x90;
483 for (i
=0;i
<6;i
++) RVA(0x839e)[i
]=0x90;
485 fprintf(stderr
, "Unsupported VP6 version\n");
490 // Windows Media Video 9 Advanced
491 if (strstr(libname
,"wmvadvd.dll") && wm
)
493 // The codec calls IsRectEmpty with coords 0,0,0,0 => result is 0
494 // but it really wants the rectangle to be not empty
495 if (PE_FindExportedFunction(wm
, "CreateInstance", TRUE
)==RVA(0xb812)) {
496 // Dll version is 10.0.0.3645
497 *RVA(0x8b0f)=0xeb; // Jump always, ignoring IsRectEmpty result
499 fprintf(stderr
, "Unsupported WMVA version\n");
504 if (strstr(libname
,"QuickTime.qts") && wm
)
510 // dispatch_addr = GetProcAddress(wm->module, "theQuickTimeDispatcher", TRUE);
511 dispatch_addr
= PE_FindExportedFunction(wm
, "theQuickTimeDispatcher", TRUE
);
512 if (dispatch_addr
== RVA(0x124c30))
514 fprintf(stderr
, "QuickTime5 DLLs found\n");
515 ptr
= (void **)RVA(0x375ca4); // dispatch_ptr
516 for (i
=0;i
<5;i
++) RVA(0x19e842)[i
]=0x90; // make_new_region ?
517 for (i
=0;i
<28;i
++) RVA(0x19e86d)[i
]=0x90; // call__call_CreateCompatibleDC ?
518 for (i
=0;i
<5;i
++) RVA(0x19e898)[i
]=0x90; // jmp_to_call_loadbitmap ?
519 for (i
=0;i
<9;i
++) RVA(0x19e8ac)[i
]=0x90; // call__calls_OLE_shit ?
520 for (i
=0;i
<106;i
++) RVA(0x261b10)[i
]=0x90; // disable threads
522 /* CreateThread callers */
523 for (i
=0;i
<5;i
++) RVA(0x1487c5)[i
]=0x90;
524 for (i
=0;i
<5;i
++) RVA(0x14b275)[i
]=0x90;
525 for (i
=0;i
<5;i
++) RVA(0x1a24b1)[i
]=0x90;
526 for (i
=0;i
<5;i
++) RVA(0x1afc5a)[i
]=0x90;
527 for (i
=0;i
<5;i
++) RVA(0x2f799c)[i
]=0x90;
528 for (i
=0;i
<5;i
++) RVA(0x2f7efe)[i
]=0x90;
529 for (i
=0;i
<5;i
++) RVA(0x2fa33e)[i
]=0x90;
533 /* TerminateQTML fix */
534 for (i
=0;i
<47;i
++) RVA(0x2fa3b8)[i
]=0x90; // terminate thread
535 for (i
=0;i
<47;i
++) RVA(0x2f7f78)[i
]=0x90; // terminate thread
536 for (i
=0;i
<77;i
++) RVA(0x1a13d5)[i
]=0x90;
537 RVA(0x08e0ae)[0] = 0xc3; // font/dc remover
538 for (i
=0;i
<24;i
++) RVA(0x07a1ad)[i
]=0x90; // destroy window
540 } else if (dispatch_addr
== RVA(0x13b330))
542 fprintf(stderr
, "QuickTime6 DLLs found\n");
543 ptr
= (void **)RVA(0x3b9524); // dispatcher_ptr
544 for (i
=0;i
<5;i
++) RVA(0x2730cc)[i
]=0x90; // make_new_region
545 for (i
=0;i
<28;i
++) RVA(0x2730f7)[i
]=0x90; // call__call_CreateCompatibleDC
546 for (i
=0;i
<5;i
++) RVA(0x273122)[i
]=0x90; // jmp_to_call_loadbitmap
547 for (i
=0;i
<9;i
++) RVA(0x273131)[i
]=0x90; // call__calls_OLE_shit
548 for (i
=0;i
<96;i
++) RVA(0x2ac852)[i
]=0x90; // disable threads
549 } else if (dispatch_addr
== RVA(0x13c3e0))
551 fprintf(stderr
, "QuickTime6.3 DLLs found\n");
552 ptr
= (void **)RVA(0x3ca01c); // dispatcher_ptr
553 for (i
=0;i
<5;i
++) RVA(0x268f6c)[i
]=0x90; // make_new_region
554 for (i
=0;i
<28;i
++) RVA(0x268f97)[i
]=0x90; // call__call_CreateCompatibleDC
555 for (i
=0;i
<5;i
++) RVA(0x268fc2)[i
]=0x90; // jmp_to_call_loadbitmap
556 for (i
=0;i
<9;i
++) RVA(0x268fd1)[i
]=0x90; // call__calls_OLE_shit
557 for (i
=0;i
<96;i
++) RVA(0x2b4722)[i
]=0x90; // disable threads
560 fprintf(stderr
, "Unsupported QuickTime version (%p)\n",
565 fprintf(stderr
,"QuickTime.qts patched!!! old entry=%p\n",ptr
[0]);
568 report_entry
= report_func
;
569 report_ret
= report_func_ret
;
570 wrapper_target
=ptr
[0];
576 return wm
? wm
->module
: 0;
580 /***********************************************************************
581 * LoadLibraryA (KERNEL32)
583 HMODULE WINAPI
LoadLibraryA(LPCSTR libname
) {
584 return LoadLibraryExA(libname
,0,0);
587 /***********************************************************************
590 WIN_BOOL WINAPI
FreeLibrary(HINSTANCE hLibModule
)
592 WIN_BOOL retv
= FALSE
;
595 wm
=MODULE32_LookupHMODULE(hLibModule
);
597 if ( !wm
|| !hLibModule
)
599 SetLastError( ERROR_INVALID_HANDLE
);
603 retv
= MODULE_FreeLibrary( wm
);
605 MODULE_RemoveFromList(wm
);
608 if (local_wm
== NULL
) my_garbagecollection();
613 /***********************************************************************
614 * GetProcAddress (KERNEL32.257)
616 FARPROC WINAPI
GetProcAddress( HMODULE hModule
, LPCSTR function
)
618 return MODULE_GetProcAddress( hModule
, function
, TRUE
);
624 http://lists.apple.com/archives/quicktime-api/2003/Jan/msg00278.html
627 struct ComponentParameters
{
628 unsigned char flags
; /* call modifiers: sync/async, deferred, immed, etc */
629 unsigned char paramSize
; /* size in bytes of actual parameters passed to this call */
630 short what
; /* routine selector, negative for Component management calls */
631 long params
[1]; /* actual parameters for the indicated routine */
633 typedef struct ComponentParameters ComponentParameters
;
635 static char* component_func(int what
){
636 if (what
< 0) // Range 0: Standard Component Calls
638 case -1: return "kComponentOpenSelect";
639 case -2: return "kComponentCloseSelect";
640 case -3: return "kComponentCanDoSelect";
641 case -4: return "kComponentVersionSelect";
642 case -5: return "kComponentRegisterSelect";
643 case -6: return "kComponentTargetSelect";
644 case -7: return "kComponentUnregisterSelect";
647 if (what
>= 0 && what
<= 0xff) // Range 1: Generic codecs
649 case 0: return "kImageCodecGetCodecInfoSelect";
650 case 1: return "kImageCodecGetCompressionTimeSelect";
651 case 2: return "kImageCodecGetMaxCompressionSizeSelect";
652 case 3: return "kImageCodecPreCompressSelect";
653 case 4: return "kImageCodecBandCompressSelect";
654 case 5: return "kImageCodecPreDecompressSelect";
655 case 6: return "kImageCodecBandDecompressSelect";
656 case 7: return "kImageCodecBusySelect";
657 // finish this list from the above URL
658 case 0x10: return "kImageCodecIsImageDescriptionEquivalentSelect";
659 case 0x12: return "kImageCodecDisposeMemorySelect";
660 case 0x14: return "kImageCodecNewImageBufferMemorySelect";
661 case 0x28: return "kImageCodecRequestGammaLevelSelect";
664 //if (what >= 0x100 && what <= 0x1ff) // Range 2: Specific to QT Photo JPEG codecs
666 if (what
>= 0x200 && what
<= 0x2ff) // Range 3: Base Decompressor
668 case 0: return "Preflight";
669 case 1: return "Initialize";
670 case 2: return "BeginBand";
671 case 3: return "DrawBand";
672 case 4: return "EndBand";
673 case 5: return "QueueStarting";
674 case 6: return "QueueStopping";
680 static int c_level
=0;
682 static int dump_component(char* name
, int type
, void* orig
, ComponentParameters
*params
,void** glob
){
683 int ( *orig
)(ComponentParameters
*params
, void** glob
) = orig
;
686 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
));
688 for(i
=0;i
<params
->paramSize
/4;i
++)
689 fprintf(stderr
,"%*s param[%d] = 0x%X\n",3*c_level
,"",i
,params
->params
[i
]);
692 ret
=orig(params
,glob
);
696 fprintf(stderr
,"%*s return=0x%X\n",3*c_level
,"",ret
);
698 fprintf(stderr
,"%*s return=%d\n",3*c_level
,"",ret
);
702 #define DECL_COMPONENT(sname,name,type) \
703 static void* real_ ## sname = NULL; \
704 static int fake_ ## sname(ComponentParameters *params,void** glob){ \
705 return dump_component(name,type,real_ ## sname, params, glob); \
708 #include "qt_comp_template.c"
710 #undef DECL_COMPONENT
719 uint32_t _System
DosQueryMem(void *, uint32_t *, uint32_t *);
722 static int is_invalid_ptr_handle(void *p
)
728 if(DosQueryMem(p
, &cb
, &fl
))
731 // Occasionally, ptr with 'EXEC' attr is passed.
732 // On OS/2, however, malloc() never sets 'EXEC' attr.
733 // So ptr with 'EXEC' attr is invalid.
739 return (uint32_t)p
>= 0x60000000;
743 static uint32_t ret_array
[4096];
746 static int report_func(void *stack_base
, int stack_size
, reg386_t
*reg
, uint32_t *flags
)
757 dptr
=0x62b67ae0;dptr
+=2*((reg
->eax
>>16)&255);
758 // printf("FUNC: flag=%d ptr=%p\n",dptr[0],dptr[1]);
760 dptr
=dptr
[1];dptr
+=4*(reg
->eax
&65535);
761 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",dptr[1],dptr[0],dptr[2]);
762 pwrapper
=dptr
[1]; pptr
=dptr
[0]; plen
=dptr
[2];
767 dptr
=0x62b672c0;dptr
+=2*(reg
->eax
&65535);
768 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
769 pptr
=dptr
[0]; plen
=dptr
[1];
772 dptr
=0x62b67c70;dptr
+=2*(reg
->eax
&65535);
773 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
774 pptr
=dptr
[0]; plen
=dptr
[1];
777 dptr
=0x62b68108;if(reg
->eax
&0x8000) dptr
+=2*(reg
->eax
|0xffff0000); else dptr
+=2*(reg
->eax
&65535);
778 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
779 pptr
=dptr
[0]; plen
=dptr
[1];
782 dptr
=0x62b68108;if(reg
->eax
&0x8000) dptr
+=2*(reg
->eax
|0xffff0000); else dptr
+=2*(reg
->eax
&65535);
783 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
784 pptr
=dptr
[0]; plen
=dptr
[1];
787 printf("FUNC: unknown ptr & psize!\n");
792 for(i
=0;qt_fv_list
[i
].name
;i
++){
793 if(qt_fv_list
[i
].id
==reg
->eax
){
794 pname
=qt_fv_list
[i
].name
;
799 printf("FUNC[%X/%s]: wrapper=%p func=%p len=%d\n",reg
->eax
,
800 pname
?pname
:"???",pwrapper
,pptr
,plen
);
802 printf("FUNC: caller=%p ebx=%p\n",((uint32_t *)stack_base
)[0],reg
->ebx
);
805 printf("%*sENTER(%d): %s(",ret_i
*2,"",ret_i
,pname
);
807 printf("%*sENTER(%d): %X(",ret_i
*2,"",ret_i
,reg
->eax
);
808 for (i
=0;i
<plen
/4;i
++){
809 unsigned int val
=((uint32_t *)stack_base
)[1+i
];
810 unsigned char* fcc
=&val
;
811 printf("%s0x%X", i
?", ":"",val
);
812 if(fcc
[0]>=0x20 && fcc
[0]<128 &&
813 fcc
[1]>=0x20 && fcc
[1]<128 &&
814 fcc
[2]>=0x20 && fcc
[2]<128 &&
815 fcc
[3]>=0x20 && fcc
[3]<128) printf("='%c%c%c%c'",fcc
[3],fcc
[2],fcc
[1],fcc
[0]);
816 else if(val
>=8 && val
<65536) printf("=%d",val
);
823 // emulate some functions:
825 // memory management:
826 case 0x150011: //NewPtrClear
827 case 0x150012: //NewPtrSysClear
828 reg
->eax
= malloc(((uint32_t *)stack_base
)[1]);
829 memset((void *)reg
->eax
,0,((uint32_t *)stack_base
)[1]);
831 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i
*2,"",ret_i
, reg
->eax
);
834 case 0x15000F: //NewPtr
835 case 0x150010: //NewPtrSys
836 reg
->eax
= malloc(((uint32_t *)stack_base
)[1]);
838 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i
*2,"",ret_i
, reg
->eax
);
841 case 0x15002f: //DisposePtr
842 if(is_invalid_ptr_handle(((void **)stack_base
)[1]))
843 printf("WARNING! Invalid Ptr handle!\n");
845 free(((void **)stack_base
)[1]);
848 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i
*2,"",ret_i
, reg
->eax
);
852 case 0x1d0033: //QTMLCreateMutex
855 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i
*2,"",ret_i
, reg
->eax
);
858 case 0x1d0034: //QTMLDestroyMutex
859 case 0x1d0035: //QTMLGrabMutex
860 case 0x1d0036: //QTMLReturnMutex
861 case 0x1d003d: //QTMLTryGrabMutex
864 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i
*2,"",ret_i
, reg
->eax
);
872 // printf("FUNC: ImageCodecInitialize/ImageCodecGetCodecInfo(ci=%p,&icap=%p)\n",((uint32_t *)stack_base)[1],((uint32_t *)stack_base)[4]);
875 printf("FUNC: CountComponents(&desc=%p)\n",((uint32_t *)stack_base
)[1]);
878 printf("FUNC: FindNextComponent(prev=%p,&desc=%p)\n",((uint32_t *)stack_base
)[1],((uint32_t *)stack_base
)[2]);
881 printf("FUNC: OpenComponent(prev=%p)\n",((uint32_t *)stack_base
)[1]);
884 printf("FUNC: QTNewGWorldFromPtr(&pts=%p,fourcc=%.4s,&rect=%p,x1=%p,x2=%p,x3=%p,plane=%p,stride=%d)\n",
885 ((uint32_t *)stack_base
)[1],
886 &(((uint32_t *)stack_base
)[2]),
887 ((uint32_t *)stack_base
)[3],
888 ((uint32_t *)stack_base
)[4],
889 ((uint32_t *)stack_base
)[5],
890 ((uint32_t *)stack_base
)[6],
891 ((uint32_t *)stack_base
)[7],
892 ((uint32_t *)stack_base
)[8]);
895 printf("FUNC: GetGWorldPixMap(gworld=%p)\n",((uint32_t *)stack_base
)[1]);
898 printf("FUNC: Gestalt(fourcc=%.4s, &ret=%p)\n",&(((uint32_t *)stack_base
)[1]),((uint32_t *)stack_base
)[2]);
902 for(i
=0;qt_fv_list
[i
].name
;i
++){
903 if(qt_fv_list
[i
].id
==reg
->eax
){
904 printf("FUNC: %s\n",qt_fv_list
[i
].name
);
911 // print stack/reg information
912 printf("ENTER(%d) stack = %d bytes @ %p\n"
913 "eax = 0x%08x edx = 0x%08x ebx = 0x%08x ecx = 0x%08x\n"
914 "esp = 0x%08x ebp = 0x%08x esi = 0x%08x edi = 0x%08x\n"
915 "flags = 0x%08x\n", ret_i
,
916 stack_size
, stack_base
,
917 reg
->eax
, reg
->edx
, reg
->ebx
, reg
->ecx
,
918 reg
->esp
, reg
->ebp
, reg
->esi
, reg
->edi
,
923 ret_array
[ret_i
]=((uint32_t *)stack_base
)[0];
927 // print first 7 longs in the stack (return address, arg[1], arg[2] ... )
928 printf("stack[] = { ");
930 printf("%08x ", ((uint32_t *)stack_base
)[i
]);
935 // // mess with function parameters
936 // ((uint32_t *)stack_base)[1] = 0x66554433;
938 // // mess with return address...
939 // reg->eax = 0x11223344;
943 static int report_func_ret(void *stack_base
, int stack_size
, reg386_t
*reg
, uint32_t *flags
)
952 ((uint32_t *)stack_base
)[0]=ret_array
[ret_i
];
957 printf("%*sLEAVE(%d): 0x%X",ret_i
*2,"",ret_i
, reg
->eax
);
959 if(err
&& (reg
->eax
>>16)==0) printf(" = %d",err
);
963 // print stack/reg information
964 printf("LEAVE(%d) stack = %d bytes @ %p\n"
965 "eax = 0x%08x edx = 0x%08x ebx = 0x%08x ecx = 0x%08x\n"
966 "esp = 0x%08x ebp = 0x%08x esi = 0x%08x edi = 0x%08x\n"
967 "flags = 0x%08x\n", ret_i
,
968 stack_size
, stack_base
,
969 reg
->eax
, reg
->edx
, reg
->ebx
, reg
->ecx
,
970 reg
->esp
, reg
->ebp
, reg
->esi
, reg
->edi
,
975 // print first 7 longs in the stack (return address, arg[1], arg[2] ... )
976 printf("stack[] = { ");
978 printf("%08x ", ((uint32_t *)stack_base
)[i
]);
985 // // mess with function parameters
986 // ((uint32_t *)stack_base)[1] = 0x66554433;
988 // // mess with return address...
989 // reg->eax = 0x11223344;
995 /***********************************************************************
996 * MODULE_GetProcAddress (internal)
998 FARPROC
MODULE_GetProcAddress(
999 HMODULE hModule
, /* [in] current module handle */
1000 LPCSTR function
, /* [in] function to be looked up */
1003 WINE_MODREF
*wm
= MODULE32_LookupHMODULE( hModule
);
1004 // WINE_MODREF *wm=local_wm;
1007 #ifdef DEBUG_QTX_API
1008 if (HIWORD(function
))
1009 fprintf(stderr
,"XXX GetProcAddress(%08lx,%s)\n",(DWORD
)hModule
,function
);
1011 fprintf(stderr
,"XXX GetProcAddress(%08lx,%p)\n",(DWORD
)hModule
,function
);
1014 // TRACE_(win32)("(%08lx,%s)\n",(DWORD)hModule,function);
1016 // TRACE_(win32)("(%08lx,%p)\n",(DWORD)hModule,function);
1019 SetLastError(ERROR_INVALID_HANDLE
);
1025 retproc
= PE_FindExportedFunction( wm
, function
, snoop
);
1026 if (!retproc
) SetLastError(ERROR_PROC_NOT_FOUND
);
1030 retproc
= (FARPROC
) dlsym( (void*) wm
->module
, function
);
1031 if (!retproc
) SetLastError(ERROR_PROC_NOT_FOUND
);
1035 ERR("wine_modref type %d not handled.\n",wm
->type
);
1036 SetLastError(ERROR_INVALID_HANDLE
);
1041 if (HIWORD(function
) && retproc
){
1043 #ifdef DEBUG_QTX_API
1044 #define DECL_COMPONENT(sname,name,type) \
1045 if(!strcmp(function,name)){ \
1046 fprintf(stderr,name "dispatcher catched -> %p\n",retproc); \
1047 real_ ## sname = retproc; retproc = fake_ ## sname; \
1049 #include "qt_comp_template.c"
1050 #undef DECL_COMPONENT
1053 if(!strcmp(function
,"theQuickTimeDispatcher")
1054 // || !strcmp(function,"CallComponentFunctionWithStorage")
1055 // || !strcmp(function,"CallComponent")
1057 fprintf(stderr
,"theQuickTimeDispatcher catched -> %p\n",retproc
);
1058 report_entry
= report_func
;
1059 report_ret
= report_func_ret
;
1060 wrapper_target
=(void(*)(void))retproc
;
1061 retproc
=(FARPROC
)wrapper
;
1070 static int acounter
= 0;
1071 void CodecAlloc(void)
1074 //printf("**************CODEC ALLOC %d\n", acounter);
1077 void CodecRelease(void)
1080 //printf("**************CODEC RELEASE %d\n", acounter);
1085 modref_list
* list
= local_wm
;
1088 //printf("CODECRELEASE %p\n", list);
1089 MODULE_FreeLibrary(list
->wm
);
1090 MODULE_RemoveFromList(list
->wm
);
1091 if (local_wm
== NULL
)
1092 my_garbagecollection();