6 * Copyright 1995 Alexandre Julliard
8 * Originally distributed under LPGL 2.1 (or later) by the Wine project.
10 * Modified for use with MPlayer, detailed CVS changelog at
11 * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
13 * File now distributed as part of VLC media player with no modifications.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
30 // define for quicktime calls debugging and/or MacOS-level emulation:
33 // define for quicktime debugging (verbose logging):
34 //#define DEBUG_QTX_API
48 #include "wine/windef.h"
49 #include "wine/winerror.h"
50 #include "wine/heap.h"
51 #include "wine/module.h"
52 #include "wine/pe_image.h"
53 #include "wine/debugtools.h"
59 #include "wine/elfdll.h"
66 static int report_func(void *stack_base
, int stack_size
, reg386_t
*reg
, uint32_t *flags
);
67 static int report_func_ret(void *stack_base
, int stack_size
, reg386_t
*reg
, uint32_t *flags
);
71 //#define TRACE printf
73 //WINE_MODREF *local_wm=NULL;
74 modref_list
* local_wm
=NULL
;
78 WINE_MODREF
* MODULE_FindModule(LPCSTR m
)
80 modref_list
* list
=local_wm
;
81 TRACE("FindModule: Module %s request\n", m
);
84 // while(strcmp(m, list->wm->filename))
85 while(!strstr(list
->wm
->filename
, m
))
87 TRACE("%s: %x\n", list
->wm
->filename
, list
->wm
->module
);
92 TRACE("Resolved to %s\n", list
->wm
->filename
);
96 static void MODULE_RemoveFromList(WINE_MODREF
*mod
)
98 modref_list
* list
=local_wm
;
103 if((list
->prev
==NULL
)&&(list
->next
==NULL
))
110 for(;list
;list
=list
->prev
)
115 list
->prev
->next
=list
->next
;
117 list
->next
->prev
=list
->prev
;
127 WINE_MODREF
*MODULE32_LookupHMODULE(HMODULE m
)
129 modref_list
* list
=local_wm
;
130 TRACE("LookupHMODULE: Module %X request\n", m
);
133 TRACE("LookupHMODULE failed\n");
136 while(m
!=list
->wm
->module
)
138 // printf("Checking list %X wm %X module %X\n",
139 // list, list->wm, list->wm->module);
143 TRACE("LookupHMODULE failed\n");
147 TRACE("LookupHMODULE hit %p\n", list
->wm
);
151 /*************************************************************************
154 static WIN_BOOL
MODULE_InitDll( WINE_MODREF
*wm
, DWORD type
, LPVOID lpReserved
)
156 WIN_BOOL retv
= TRUE
;
158 static LPCSTR typeName
[] = { "PROCESS_DETACH", "PROCESS_ATTACH",
159 "THREAD_ATTACH", "THREAD_DETACH" };
163 /* Skip calls for modules loaded with special load flags */
165 if ( ( wm
->flags
& WINE_MODREF_DONT_RESOLVE_REFS
)
166 || ( wm
->flags
& WINE_MODREF_LOAD_AS_DATAFILE
) )
170 TRACE("(%s,%s,%p) - CALL\n", wm
->modname
, typeName
[type
], lpReserved
);
172 /* Call the initialization routine */
176 retv
= PE_InitDLL( wm
, type
, lpReserved
);
180 /* no need to do that, dlopen() already does */
184 ERR("wine_modref type %d not handled.\n", wm
->type
);
189 /* The state of the module list may have changed due to the call
190 to PE_InitDLL. We cannot assume that this module has not been
192 TRACE("(%p,%s,%p) - RETURN %d\n", wm
, typeName
[type
], lpReserved
, retv
);
197 /*************************************************************************
198 * MODULE_DllProcessAttach
200 * Send the process attach notification to all DLLs the given module
201 * depends on (recursively). This is somewhat complicated due to the fact that
203 * - we have to respect the module dependencies, i.e. modules implicitly
204 * referenced by another module have to be initialized before the module
205 * itself can be initialized
207 * - the initialization routine of a DLL can itself call LoadLibrary,
208 * thereby introducing a whole new set of dependencies (even involving
209 * the 'old' modules) at any time during the whole process
211 * (Note that this routine can be recursively entered not only directly
212 * from itself, but also via LoadLibrary from one of the called initialization
215 * Furthermore, we need to rearrange the main WINE_MODREF list to allow
216 * the process *detach* notifications to be sent in the correct order.
217 * This must not only take into account module dependencies, but also
218 * 'hidden' dependencies created by modules calling LoadLibrary in their
219 * attach notification routine.
221 * The strategy is rather simple: we move a WINE_MODREF to the head of the
222 * list after the attach notification has returned. This implies that the
223 * detach notifications are called in the reverse of the sequence the attach
224 * notifications *returned*.
226 * NOTE: Assumes that the process critical section is held!
229 static WIN_BOOL
MODULE_DllProcessAttach( WINE_MODREF
*wm
, LPVOID lpReserved
)
231 WIN_BOOL retv
= TRUE
;
235 /* prevent infinite recursion in case of cyclical dependencies */
236 if ( ( wm
->flags
& WINE_MODREF_MARKER
)
237 || ( wm
->flags
& WINE_MODREF_PROCESS_ATTACHED
) )
240 TRACE("(%s,%p) - START\n", wm
->modname
, lpReserved
);
242 /* Tag current MODREF to prevent recursive loop */
243 wm
->flags
|= WINE_MODREF_MARKER
;
245 /* Recursively attach all DLLs this one depends on */
246 /* for ( i = 0; retv && i < wm->nDeps; i++ )
248 retv = MODULE_DllProcessAttach( wm->deps[i], lpReserved );
250 /* Call DLL entry point */
255 local_wm
->next
= (modref_list
*) malloc(sizeof(modref_list
));
256 local_wm
->next
->prev
=local_wm
;
257 local_wm
->next
->next
=NULL
;
258 local_wm
->next
->wm
=wm
;
259 local_wm
=local_wm
->next
;
263 local_wm
= (modref_list
*)malloc(sizeof(modref_list
));
264 local_wm
->next
=local_wm
->prev
=NULL
;
267 /* Remove recursion flag */
268 wm
->flags
&= ~WINE_MODREF_MARKER
;
272 retv
= MODULE_InitDll( wm
, DLL_PROCESS_ATTACH
, lpReserved
);
274 wm
->flags
|= WINE_MODREF_PROCESS_ATTACHED
;
278 TRACE("(%s,%p) - END\n", wm
->modname
, lpReserved
);
283 /*************************************************************************
284 * MODULE_DllProcessDetach
286 * Send DLL process detach notifications. See the comment about calling
287 * sequence at MODULE_DllProcessAttach. Unless the bForceDetach flag
288 * is set, only DLLs with zero refcount are notified.
290 static void MODULE_DllProcessDetach( WINE_MODREF
* wm
, WIN_BOOL bForceDetach
, LPVOID lpReserved
)
292 // WINE_MODREF *wm=local_wm;
293 modref_list
* l
= local_wm
;
294 wm
->flags
&= ~WINE_MODREF_PROCESS_ATTACHED
;
295 MODULE_InitDll( wm
, DLL_PROCESS_DETACH
, lpReserved
);
305 /***********************************************************************
306 * MODULE_LoadLibraryExA (internal)
308 * Load a PE style module according to the load order.
310 * The HFILE parameter is not used and marked reserved in the SDK. I can
311 * only guess that it should force a file to be mapped, but I rather
312 * ignore the parameter because it would be extremely difficult to
313 * integrate this with different types of module represenations.
316 static WINE_MODREF
*MODULE_LoadLibraryExA( LPCSTR libname
, HFILE hfile
, DWORD flags
)
318 DWORD err
= GetLastError();
321 // module_loadorder_t *plo;
323 SetLastError( ERROR_FILE_NOT_FOUND
);
324 TRACE("Trying native dll '%s'\n", libname
);
325 pwm
= PE_LoadLibraryExA(libname
, flags
);
329 TRACE("Trying ELF dll '%s'\n", libname
);
330 pwm
=(WINE_MODREF
*)ELFDLL_LoadLibraryExA(libname
, flags
);
333 // printf("0x%08x\n", pwm);
337 /* Initialize DLL just loaded */
338 TRACE("Loaded module '%s' at 0x%08x, \n", libname
, pwm
->module
);
339 /* Set the refCount here so that an attach failure will */
340 /* decrement the dependencies through the MODULE_FreeLibrary call. */
343 SetLastError( err
); /* restore last error */
348 WARN("Failed to load module '%s'; error=0x%08lx, \n", libname
, GetLastError());
352 /***********************************************************************
355 * NOTE: Assumes that the process critical section is held!
357 static WIN_BOOL
MODULE_FreeLibrary( WINE_MODREF
*wm
)
359 TRACE("(%s) - START\n", wm
->modname
);
361 /* Recursively decrement reference counts */
362 //MODULE_DecRefCount( wm );
364 /* Call process detach notifications */
365 MODULE_DllProcessDetach( wm
, FALSE
, NULL
);
367 PE_UnloadLibrary(wm
);
374 /***********************************************************************
375 * LoadLibraryExA (KERNEL32)
377 HMODULE WINAPI
LoadLibraryExA(LPCSTR libname
, HANDLE hfile
, DWORD flags
)
380 char* listpath
[] = { "", "", "/usr/lib/win32", "/usr/local/lib/win32", "/usr/lib/codecs", "/usr/local/lib/codecs", 0 };
381 extern char* def_path
;
389 SetLastError(ERROR_INVALID_PARAMETER
);
393 wm
=MODULE_FindModule(libname
);
394 if(wm
) return wm
->module
;
396 // if(fs_installed==0)
399 while (wm
== NULL
&& listpath
[++i
])
404 /* check just original file name */
405 strncpy(path
, libname
, 511);
407 /* check default user path */
408 strncpy(path
, def_path
, 300);
410 else if (strcmp(def_path
, listpath
[i
]))
411 /* path from the list */
412 strncpy(path
, listpath
[i
], 300);
419 strncat(path
, libname
, 100);
422 wm
= MODULE_LoadLibraryExA( path
, hfile
, flags
);
427 strcat(checked
, ", ");
428 strcat(checked
, path
);
435 if ( !MODULE_DllProcessAttach( wm
, NULL
) )
437 WARN_(module
)("Attach failed for module '%s', \n", libname
);
438 MODULE_FreeLibrary(wm
);
439 SetLastError(ERROR_DLL_INIT_FAILED
);
440 MODULE_RemoveFromList(wm
);
446 printf("Win32 LoadLibrary failed to load: %s\n", checked
);
448 if (strstr(libname
,"vp31vfw.dll") && wm
)
452 // sse hack moved from patch dll into runtime patching
453 if (PE_FindExportedFunction(wm
, "DriverProc", TRUE
)==(void*)0x10001000) {
454 fprintf(stderr
, "VP3 DLL found\n");
455 for (i
=0;i
<18;i
++) ((char*)0x10004bd6)[i
]=0x90;
459 // remove a few divs in the VP codecs that make trouble
460 if (strstr(libname
,"vp5vfw.dll") && wm
)
463 if (PE_FindExportedFunction(wm
, "DriverProc", TRUE
)==(void*)0x10003930) {
464 for (i
=0;i
<3;i
++) ((char*)0x10004e86)[i
]=0x90;
465 for (i
=0;i
<3;i
++) ((char*)0x10005a23)[i
]=0x90;
466 for (i
=0;i
<3;i
++) ((char*)0x10005bff)[i
]=0x90;
468 fprintf(stderr
, "Unsupported VP5 version\n");
473 if (strstr(libname
,"vp6vfw.dll") && wm
)
476 if (PE_FindExportedFunction(wm
, "DriverProc", TRUE
)==(void*)0x10003ef0) {
477 // looks like VP 6.1.0.2
478 for (i
=0;i
<6;i
++) ((char*)0x10007268)[i
]=0x90;
479 for (i
=0;i
<6;i
++) ((char*)0x10007e83)[i
]=0x90;
480 for (i
=0;i
<6;i
++) ((char*)0x1000806a)[i
]=0x90;
481 } else if (PE_FindExportedFunction(wm
, "DriverProc", TRUE
)==(void*)0x10004120) {
482 // looks like VP 6.2.0.10
483 for (i
=0;i
<6;i
++) ((char*)0x10007688)[i
]=0x90;
484 for (i
=0;i
<6;i
++) ((char*)0x100082c3)[i
]=0x90;
485 for (i
=0;i
<6;i
++) ((char*)0x100084aa)[i
]=0x90;
486 } else if (PE_FindExportedFunction(wm
, "DriverProc", TRUE
)==(void*)0x10003e70) {
487 // looks like VP 6.0.7.3
488 for (i
=0;i
<6;i
++) ((char*)0x10007559)[i
]=0x90;
489 for (i
=0;i
<6;i
++) ((char*)0x100081c3)[i
]=0x90;
490 for (i
=0;i
<6;i
++) ((char*)0x1000839e)[i
]=0x90;
492 fprintf(stderr
, "Unsupported VP6 version\n");
497 // Windows Media Video 9 Advanced
498 if (strstr(libname
,"wmvadvd.dll") && wm
)
500 // The codec calls IsRectEmpty with coords 0,0,0,0 => result is 0
501 // but it really wants the rectangle to be not empty
502 if (PE_FindExportedFunction(wm
, "CreateInstance", TRUE
)==(void*)0x08c4b812) {
503 // Dll version is 10.0.0.3645
504 *((char*)0x08c48b0f)=0xeb; // Jump always, ignoring IsRectEmpty result
506 fprintf(stderr
, "Unsupported WMVA version\n");
511 if (strstr(libname
,"QuickTime.qts") && wm
)
517 // dispatch_addr = GetProcAddress(wm->module, "theQuickTimeDispatcher", TRUE);
518 dispatch_addr
= PE_FindExportedFunction(wm
, "theQuickTimeDispatcher", TRUE
);
519 if (dispatch_addr
== (void *)0x62924c30)
521 fprintf(stderr
, "QuickTime5 DLLs found\n");
522 ptr
= (void **)0x62b75ca4; // dispatch_ptr
523 for (i
=0;i
<5;i
++) ((char*)0x6299e842)[i
]=0x90; // make_new_region ?
524 for (i
=0;i
<28;i
++) ((char*)0x6299e86d)[i
]=0x90; // call__call_CreateCompatibleDC ?
525 for (i
=0;i
<5;i
++) ((char*)0x6299e898)[i
]=0x90; // jmp_to_call_loadbitmap ?
526 for (i
=0;i
<9;i
++) ((char*)0x6299e8ac)[i
]=0x90; // call__calls_OLE_shit ?
527 for (i
=0;i
<106;i
++) ((char*)0x62a61b10)[i
]=0x90; // disable threads
529 /* CreateThread callers */
530 for (i
=0;i
<5;i
++) ((char*)0x629487c5)[i
]=0x90;
531 for (i
=0;i
<5;i
++) ((char*)0x6294b275)[i
]=0x90;
532 for (i
=0;i
<5;i
++) ((char*)0x629a24b1)[i
]=0x90;
533 for (i
=0;i
<5;i
++) ((char*)0x629afc5a)[i
]=0x90;
534 for (i
=0;i
<5;i
++) ((char*)0x62af799c)[i
]=0x90;
535 for (i
=0;i
<5;i
++) ((char*)0x62af7efe)[i
]=0x90;
536 for (i
=0;i
<5;i
++) ((char*)0x62afa33e)[i
]=0x90;
540 /* TerminateQTML fix */
541 for (i
=0;i
<47;i
++) ((char*)0x62afa3b8)[i
]=0x90; // terminate thread
542 for (i
=0;i
<47;i
++) ((char*)0x62af7f78)[i
]=0x90; // terminate thread
543 for (i
=0;i
<77;i
++) ((char*)0x629a13d5)[i
]=0x90;
544 ((char *)0x6288e0ae)[0] = 0xc3; // font/dc remover
545 for (i
=0;i
<24;i
++) ((char*)0x6287a1ad)[i
]=0x90; // destroy window
547 } else if (dispatch_addr
== (void *)0x6693b330)
549 fprintf(stderr
, "QuickTime6 DLLs found\n");
550 ptr
= (void **)0x66bb9524; // dispatcher_ptr
551 for (i
=0;i
<5;i
++) ((char *)0x66a730cc)[i
]=0x90; // make_new_region
552 for (i
=0;i
<28;i
++) ((char *)0x66a730f7)[i
]=0x90; // call__call_CreateCompatibleDC
553 for (i
=0;i
<5;i
++) ((char *)0x66a73122)[i
]=0x90; // jmp_to_call_loadbitmap
554 for (i
=0;i
<9;i
++) ((char *)0x66a73131)[i
]=0x90; // call__calls_OLE_shit
555 for (i
=0;i
<96;i
++) ((char *)0x66aac852)[i
]=0x90; // disable threads
556 } else if (dispatch_addr
== (void *)0x6693c3e0)
558 fprintf(stderr
, "QuickTime6.3 DLLs found\n");
559 ptr
= (void **)0x66bca01c; // dispatcher_ptr
560 for (i
=0;i
<5;i
++) ((char *)0x66a68f6c)[i
]=0x90; // make_new_region
561 for (i
=0;i
<28;i
++) ((char *)0x66a68f97)[i
]=0x90; // call__call_CreateCompatibleDC
562 for (i
=0;i
<5;i
++) ((char *)0x66a68fc2)[i
]=0x90; // jmp_to_call_loadbitmap
563 for (i
=0;i
<9;i
++) ((char *)0x66a68fd1)[i
]=0x90; // call__calls_OLE_shit
564 for (i
=0;i
<96;i
++) ((char *)0x66ab4722)[i
]=0x90; // disable threads
567 fprintf(stderr
, "Unsupported QuickTime version (%p)\n",
572 fprintf(stderr
,"QuickTime.qts patched!!! old entry=%p\n",ptr
[0]);
575 report_entry
= report_func
;
576 report_ret
= report_func_ret
;
577 wrapper_target
=ptr
[0];
582 return wm
? wm
->module
: 0;
586 /***********************************************************************
587 * LoadLibraryA (KERNEL32)
589 HMODULE WINAPI
LoadLibraryA(LPCSTR libname
) {
590 return LoadLibraryExA(libname
,0,0);
593 /***********************************************************************
596 WIN_BOOL WINAPI
FreeLibrary(HINSTANCE hLibModule
)
598 WIN_BOOL retv
= FALSE
;
601 wm
=MODULE32_LookupHMODULE(hLibModule
);
603 if ( !wm
|| !hLibModule
)
605 SetLastError( ERROR_INVALID_HANDLE
);
609 retv
= MODULE_FreeLibrary( wm
);
611 MODULE_RemoveFromList(wm
);
614 if (local_wm
== NULL
) my_garbagecollection();
619 /***********************************************************************
622 * NOTE: Assumes that the process critical section is held!
624 static void MODULE_DecRefCount( WINE_MODREF
*wm
)
628 if ( wm
->flags
& WINE_MODREF_MARKER
)
631 if ( wm
->refCount
<= 0 )
635 TRACE("(%s) refCount: %d\n", wm
->modname
, wm
->refCount
);
637 if ( wm
->refCount
== 0 )
639 wm
->flags
|= WINE_MODREF_MARKER
;
641 for ( i
= 0; i
< wm
->nDeps
; i
++ )
643 MODULE_DecRefCount( wm
->deps
[i
] );
645 wm
->flags
&= ~WINE_MODREF_MARKER
;
649 /***********************************************************************
650 * GetProcAddress (KERNEL32.257)
652 FARPROC WINAPI
GetProcAddress( HMODULE hModule
, LPCSTR function
)
654 return MODULE_GetProcAddress( hModule
, function
, TRUE
);
660 http://lists.apple.com/archives/quicktime-api/2003/Jan/msg00278.html
663 struct ComponentParameters
{
664 unsigned char flags
; /* call modifiers: sync/async, deferred, immed, etc */
665 unsigned char paramSize
; /* size in bytes of actual parameters passed to this call */
666 short what
; /* routine selector, negative for Component management calls */
667 long params
[1]; /* actual parameters for the indicated routine */
669 typedef struct ComponentParameters ComponentParameters
;
671 static char* component_func(int what
){
672 if (what
< 0) // Range 0: Standard Component Calls
674 case -1: return "kComponentOpenSelect";
675 case -2: return "kComponentCloseSelect";
676 case -3: return "kComponentCanDoSelect";
677 case -4: return "kComponentVersionSelect";
678 case -5: return "kComponentRegisterSelect";
679 case -6: return "kComponentTargetSelect";
680 case -7: return "kComponentUnregisterSelect";
683 if (what
>= 0 && what
<= 0xff) // Range 1: Generic codecs
685 case 0: return "kImageCodecGetCodecInfoSelect";
686 case 1: return "kImageCodecGetCompressionTimeSelect";
687 case 2: return "kImageCodecGetMaxCompressionSizeSelect";
688 case 3: return "kImageCodecPreCompressSelect";
689 case 4: return "kImageCodecBandCompressSelect";
690 case 5: return "kImageCodecPreDecompressSelect";
691 case 6: return "kImageCodecBandDecompressSelect";
692 case 7: return "kImageCodecBusySelect";
693 // finish this list from the above URL
694 case 0x10: return "kImageCodecIsImageDescriptionEquivalentSelect";
695 case 0x12: return "kImageCodecDisposeMemorySelect";
696 case 0x14: return "kImageCodecNewImageBufferMemorySelect";
697 case 0x28: return "kImageCodecRequestGammaLevelSelect";
700 //if (what >= 0x100 && what <= 0x1ff) // Range 2: Specific to QT Photo JPEG codecs
702 if (what
>= 0x200 && what
<= 0x2ff) // Range 3: Base Decompressor
704 case 0: return "Preflight";
705 case 1: return "Initialize";
706 case 2: return "BeginBand";
707 case 3: return "DrawBand";
708 case 4: return "EndBand";
709 case 5: return "QueueStarting";
710 case 6: return "QueueStopping";
716 static int c_level
=0;
718 static int dump_component(char* name
,int type
,void* _orig
, ComponentParameters
*params
,void** glob
){
719 int ( *orig
)(ComponentParameters
*params
, void** glob
) = _orig
;
722 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
));
724 for(i
=0;i
<params
->paramSize
/4;i
++)
725 fprintf(stderr
,"%*s param[%d] = 0x%X\n",3*c_level
,"",i
,params
->params
[i
]);
728 ret
=orig(params
,glob
);
732 fprintf(stderr
,"%*s return=0x%X\n",3*c_level
,"",ret
);
734 fprintf(stderr
,"%*s return=%d\n",3*c_level
,"",ret
);
738 #define DECL_COMPONENT(sname,name,type) \
739 static void* real_ ## sname = NULL; \
740 static int fake_ ## sname(ComponentParameters *params,void** glob){ \
741 return dump_component(name,type,real_ ## sname, params, glob); \
746 #undef DECL_COMPONENT
754 static uint32_t ret_array
[4096];
757 static int report_func(void *stack_base
, int stack_size
, reg386_t
*reg
, uint32_t *flags
)
768 dptr
=0x62b67ae0;dptr
+=2*((reg
->eax
>>16)&255);
769 // printf("FUNC: flag=%d ptr=%p\n",dptr[0],dptr[1]);
771 dptr
=dptr
[1];dptr
+=4*(reg
->eax
&65535);
772 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",dptr[1],dptr[0],dptr[2]);
773 pwrapper
=dptr
[1]; pptr
=dptr
[0]; plen
=dptr
[2];
778 dptr
=0x62b672c0;dptr
+=2*(reg
->eax
&65535);
779 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
780 pptr
=dptr
[0]; plen
=dptr
[1];
783 dptr
=0x62b67c70;dptr
+=2*(reg
->eax
&65535);
784 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
785 pptr
=dptr
[0]; plen
=dptr
[1];
788 dptr
=0x62b68108;if(reg
->eax
&0x8000) dptr
+=2*(reg
->eax
|0xffff0000); else dptr
+=2*(reg
->eax
&65535);
789 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
790 pptr
=dptr
[0]; plen
=dptr
[1];
793 dptr
=0x62b68108;if(reg
->eax
&0x8000) dptr
+=2*(reg
->eax
|0xffff0000); else dptr
+=2*(reg
->eax
&65535);
794 // printf("FUNC: ptr2=%p eax=%p edx=%p\n",0x62924910,dptr[0],dptr[1]);
795 pptr
=dptr
[0]; plen
=dptr
[1];
798 printf("FUNC: unknown ptr & psize!\n");
803 for(i
=0;qt_fv_list
[i
].name
;i
++){
804 if(qt_fv_list
[i
].id
==reg
->eax
){
805 pname
=qt_fv_list
[i
].name
;
810 printf("FUNC[%X/%s]: wrapper=%p func=%p len=%d\n",reg
->eax
,
811 pname
?pname
:"???",pwrapper
,pptr
,plen
);
813 printf("FUNC: caller=%p ebx=%p\n",((uint32_t *)stack_base
)[0],reg
->ebx
);
816 printf("%*sENTER(%d): %s(",ret_i
*2,"",ret_i
,pname
);
818 printf("%*sENTER(%d): %X(",ret_i
*2,"",ret_i
,reg
->eax
);
819 for (i
=0;i
<plen
/4;i
++){
820 unsigned int val
=((uint32_t *)stack_base
)[1+i
];
821 unsigned char* fcc
=&val
;
822 printf("%s0x%X", i
?", ":"",val
);
823 if(fcc
[0]>=0x20 && fcc
[0]<128 &&
824 fcc
[1]>=0x20 && fcc
[1]<128 &&
825 fcc
[2]>=0x20 && fcc
[2]<128 &&
826 fcc
[3]>=0x20 && fcc
[3]<128) printf("='%c%c%c%c'",fcc
[3],fcc
[2],fcc
[1],fcc
[0]);
827 else if(val
>=8 && val
<65536) printf("=%d",val
);
835 // emulate some functions:
837 // memory management:
838 case 0x150011: //NewPtrClear
839 case 0x150012: //NewPtrSysClear
840 reg
->eax
=(uint32_t)malloc(((uint32_t *)stack_base
)[1]);
841 memset((void *)reg
->eax
,0,((uint32_t *)stack_base
)[1]);
843 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i
*2,"",ret_i
, reg
->eax
);
846 case 0x15000F: //NewPtr
847 case 0x150010: //NewPtrSys
848 reg
->eax
=(uint32_t)malloc(((uint32_t *)stack_base
)[1]);
850 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i
*2,"",ret_i
, reg
->eax
);
853 case 0x15002f: //DisposePtr
854 if(((uint32_t *)stack_base
)[1]>=0x60000000)
855 printf("WARNING! Invalid Ptr handle!\n");
857 free((void *)((uint32_t *)stack_base
)[1]);
860 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i
*2,"",ret_i
, reg
->eax
);
864 case 0x1d0033: //QTMLCreateMutex
867 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i
*2,"",ret_i
, reg
->eax
);
870 case 0x1d0034: //QTMLDestroyMutex
871 case 0x1d0035: //QTMLGrabMutex
872 case 0x1d0036: //QTMLReturnMutex
873 case 0x1d003d: //QTMLTryGrabMutex
876 printf("%*sLEAVE(%d): EMULATED! 0x%X\n",ret_i
*2,"",ret_i
, reg
->eax
);
885 // printf("FUNC: ImageCodecInitialize/ImageCodecGetCodecInfo(ci=%p,&icap=%p)\n",((uint32_t *)stack_base)[1],((uint32_t *)stack_base)[4]);
888 printf("FUNC: CountComponents(&desc=%p)\n",((uint32_t *)stack_base
)[1]);
891 printf("FUNC: FindNextComponent(prev=%p,&desc=%p)\n",((uint32_t *)stack_base
)[1],((uint32_t *)stack_base
)[2]);
894 printf("FUNC: OpenComponent(prev=%p)\n",((uint32_t *)stack_base
)[1]);
897 printf("FUNC: QTNewGWorldFromPtr(&pts=%p,fourcc=%.4s,&rect=%p,x1=%p,x2=%p,x3=%p,plane=%p,stride=%d)\n",
898 ((uint32_t *)stack_base
)[1],
899 &(((uint32_t *)stack_base
)[2]),
900 ((uint32_t *)stack_base
)[3],
901 ((uint32_t *)stack_base
)[4],
902 ((uint32_t *)stack_base
)[5],
903 ((uint32_t *)stack_base
)[6],
904 ((uint32_t *)stack_base
)[7],
905 ((uint32_t *)stack_base
)[8]);
908 printf("FUNC: GetGWorldPixMap(gworld=%p)\n",((uint32_t *)stack_base
)[1]);
911 printf("FUNC: Gestalt(fourcc=%.4s, &ret=%p)\n",&(((uint32_t *)stack_base
)[1]),((uint32_t *)stack_base
)[2]);
915 for(i
=0;qt_fv_list
[i
].name
;i
++){
916 if(qt_fv_list
[i
].id
==reg
->eax
){
917 printf("FUNC: %s\n",qt_fv_list
[i
].name
);
924 // print stack/reg information
925 printf("ENTER(%d) stack = %d bytes @ %p\n"
926 "eax = 0x%08x edx = 0x%08x ebx = 0x%08x ecx = 0x%08x\n"
927 "esp = 0x%08x ebp = 0x%08x esi = 0x%08x edi = 0x%08x\n"
928 "flags = 0x%08x\n", ret_i
,
929 stack_size
, stack_base
,
930 reg
->eax
, reg
->edx
, reg
->ebx
, reg
->ecx
,
931 reg
->esp
, reg
->ebp
, reg
->esi
, reg
->edi
,
936 ret_array
[ret_i
]=((uint32_t *)stack_base
)[0];
940 // print first 7 longs in the stack (return address, arg[1], arg[2] ... )
941 printf("stack[] = { ");
943 printf("%08x ", ((uint32_t *)stack_base
)[i
]);
948 // // mess with function parameters
949 // ((uint32_t *)stack_base)[1] = 0x66554433;
951 // // mess with return address...
952 // reg->eax = 0x11223344;
956 static int report_func_ret(void *stack_base
, int stack_size
, reg386_t
*reg
, uint32_t *flags
)
963 ((uint32_t *)stack_base
)[0]=ret_array
[ret_i
];
968 printf("%*sLEAVE(%d): 0x%X",ret_i
*2,"",ret_i
, reg
->eax
);
970 if(err
&& (reg
->eax
>>16)==0) printf(" = %d",err
);
974 // print stack/reg information
975 printf("LEAVE(%d) stack = %d bytes @ %p\n"
976 "eax = 0x%08x edx = 0x%08x ebx = 0x%08x ecx = 0x%08x\n"
977 "esp = 0x%08x ebp = 0x%08x esi = 0x%08x edi = 0x%08x\n"
978 "flags = 0x%08x\n", ret_i
,
979 stack_size
, stack_base
,
980 reg
->eax
, reg
->edx
, reg
->ebx
, reg
->ecx
,
981 reg
->esp
, reg
->ebp
, reg
->esi
, reg
->edi
,
986 // print first 7 longs in the stack (return address, arg[1], arg[2] ... )
987 printf("stack[] = { ");
989 printf("%08x ", ((uint32_t *)stack_base
)[i
]);
996 // // mess with function parameters
997 // ((uint32_t *)stack_base)[1] = 0x66554433;
999 // // mess with return address...
1000 // reg->eax = 0x11223344;
1006 /***********************************************************************
1007 * MODULE_GetProcAddress (internal)
1009 FARPROC
MODULE_GetProcAddress(
1010 HMODULE hModule
, /* [in] current module handle */
1011 LPCSTR function
, /* [in] function to be looked up */
1014 WINE_MODREF
*wm
= MODULE32_LookupHMODULE( hModule
);
1015 // WINE_MODREF *wm=local_wm;
1018 #ifdef DEBUG_QTX_API
1019 if (HIWORD(function
))
1020 fprintf(stderr
,"XXX GetProcAddress(%08lx,%s)\n",(DWORD
)hModule
,function
);
1022 fprintf(stderr
,"XXX GetProcAddress(%08lx,%p)\n",(DWORD
)hModule
,function
);
1025 // TRACE_(win32)("(%08lx,%s)\n",(DWORD)hModule,function);
1027 // TRACE_(win32)("(%08lx,%p)\n",(DWORD)hModule,function);
1030 SetLastError(ERROR_INVALID_HANDLE
);
1036 retproc
= PE_FindExportedFunction( wm
, function
, snoop
);
1037 if (!retproc
) SetLastError(ERROR_PROC_NOT_FOUND
);
1041 retproc
= (FARPROC
) dlsym( (void*) wm
->module
, function
);
1042 if (!retproc
) SetLastError(ERROR_PROC_NOT_FOUND
);
1046 ERR("wine_modref type %d not handled.\n",wm
->type
);
1047 SetLastError(ERROR_INVALID_HANDLE
);
1052 if (HIWORD(function
) && retproc
){
1054 #ifdef DEBUG_QTX_API
1055 #define DECL_COMPONENT(sname,name,type) \
1056 if(!strcmp(function,name)){ \
1057 fprintf(stderr,name "dispatcher catched -> %p\n",retproc); \
1058 real_ ## sname = retproc; retproc = fake_ ## sname; \
1060 #include "qt_comp.h"
1061 #undef DECL_COMPONENT
1064 if(!strcmp(function
,"theQuickTimeDispatcher")
1065 // || !strcmp(function,"_CallComponentFunctionWithStorage")
1066 // || !strcmp(function,"_CallComponent")
1068 fprintf(stderr
,"theQuickTimeDispatcher catched -> %p\n",retproc
);
1069 report_entry
= report_func
;
1070 report_ret
= report_func_ret
;
1071 wrapper_target
=(void(*)(void))retproc
;
1072 retproc
=(FARPROC
)wrapper
;
1081 static int acounter
= 0;
1082 void CodecAlloc(void)
1085 //printf("**************CODEC ALLOC %d\n", acounter);
1088 void CodecRelease(void)
1091 //printf("**************CODEC RELEASE %d\n", acounter);
1096 modref_list
* list
= local_wm
;
1099 //printf("CODECRELEASE %p\n", list);
1100 MODULE_FreeLibrary(list
->wm
);
1101 MODULE_RemoveFromList(list
->wm
);
1102 if (local_wm
== NULL
)
1103 my_garbagecollection();