win32.c
资源名称:vlc-1.0.5.zip [点击查看]
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:138k
源码类别:
midi
开发平台:
Unix_Linux
- printf("CreateWindowEx() called okeyn");
- return 1;
- }
- static int WINAPI expwaveOutGetNumDevs(void)
- {
- dbgprintf("waveOutGetNumDevs() => 0n");
- return 0;
- }
- #endif
- /*
- * Returns the number of milliseconds, modulo 2^32, since the start
- * of the wineserver.
- */
- static int WINAPI expGetTickCount(void)
- {
- static int tcstart = 0;
- struct timeval t;
- int tc;
- gettimeofday( &t, NULL );
- tc = ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - tcstart;
- if (tcstart == 0)
- {
- tcstart = 0;
- tc = 0;
- }
- dbgprintf("GetTickCount() => %dn", tc);
- return tc;
- }
- static int WINAPI expCreateFontA(void)
- {
- dbgprintf("CreateFontA() => 0x0n");
- return 1;
- }
- /* tried to get pvmjpg work in a different way - no success */
- static int WINAPI expDrawTextA(int hDC, char* lpString, int nCount,
- LPRECT lpRect, unsigned int uFormat)
- {
- dbgprintf("expDrawTextA(%p,...) => 8n", hDC);
- return 8;
- }
- static int WINAPI expGetPrivateProfileIntA(const char* appname,
- const char* keyname,
- int default_value,
- const char* filename)
- {
- int size=255;
- char buffer[256];
- char* fullname;
- int result;
- buffer[255]=0;
- if(!(appname && keyname && filename) )
- {
- dbgprintf("GetPrivateProfileIntA('%s', '%s', %d, '%s') => %dn", appname, keyname, default_value, filename, default_value );
- return default_value;
- }
- fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename));
- strcpy(fullname, "Software\IniFileMapping\");
- strcat(fullname, appname);
- strcat(fullname, "\");
- strcat(fullname, keyname);
- strcat(fullname, "\");
- strcat(fullname, filename);
- result=RegQueryValueExA(HKEY_LOCAL_MACHINE, fullname, NULL, NULL, (int*)buffer, &size);
- if((size>=0)&&(size<256))
- buffer[size]=0;
- // printf("GetPrivateProfileIntA(%s, %s, %s) -> %sn", appname, keyname, filename, buffer);
- free(fullname);
- if(result)
- result=default_value;
- else
- result=atoi(buffer);
- dbgprintf("GetPrivateProfileIntA('%s', '%s', %d, '%s') => %dn", appname, keyname, default_value, filename, result);
- return result;
- }
- static int WINAPI expGetProfileIntA(const char* appname,
- const char* keyname,
- int default_value)
- {
- dbgprintf("GetProfileIntA -> ");
- return expGetPrivateProfileIntA(appname, keyname, default_value, "default");
- }
- static int WINAPI expGetPrivateProfileStringA(const char* appname,
- const char* keyname,
- const char* def_val,
- char* dest, unsigned int len,
- const char* filename)
- {
- int result;
- int size;
- char* fullname;
- dbgprintf("GetPrivateProfileStringA('%s', '%s', def_val '%s', 0x%x, 0x%x, '%s')", appname, keyname, def_val, dest, len, filename );
- if(!(appname && keyname && filename) ) return 0;
- fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename));
- strcpy(fullname, "Software\IniFileMapping\");
- strcat(fullname, appname);
- strcat(fullname, "\");
- strcat(fullname, keyname);
- strcat(fullname, "\");
- strcat(fullname, filename);
- size=len;
- result=RegQueryValueExA(HKEY_LOCAL_MACHINE, fullname, NULL, NULL, (int*)dest, &size);
- free(fullname);
- if(result)
- {
- strncpy(dest, def_val, size);
- if (strlen(def_val)< size) size = strlen(def_val);
- }
- dbgprintf(" => %d ( '%s' )n", size, dest);
- return size;
- }
- static int WINAPI expWritePrivateProfileStringA(const char* appname,
- const char* keyname,
- const char* string,
- const char* filename)
- {
- int size=256;
- char* fullname;
- dbgprintf("WritePrivateProfileStringA('%s', '%s', '%s', '%s')", appname, keyname, string, filename );
- if(!(appname && keyname && filename) )
- {
- dbgprintf(" => -1n");
- return -1;
- }
- fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename));
- strcpy(fullname, "Software\IniFileMapping\");
- strcat(fullname, appname);
- strcat(fullname, "\");
- strcat(fullname, keyname);
- strcat(fullname, "\");
- strcat(fullname, filename);
- RegSetValueExA(HKEY_LOCAL_MACHINE, fullname, 0, REG_SZ, (int*)string, strlen(string));
- // printf("RegSetValueExA(%s,%d)n", string, strlen(string));
- // printf("WritePrivateProfileStringA(%s, %s, %s, %s)n", appname, keyname, string, filename );
- free(fullname);
- dbgprintf(" => 0n");
- return 0;
- }
- unsigned int _GetPrivateProfileIntA(const char* appname, const char* keyname, INT default_value, const char* filename)
- {
- return expGetPrivateProfileIntA(appname, keyname, default_value, filename);
- }
- int _GetPrivateProfileStringA(const char* appname, const char* keyname,
- const char* def_val, char* dest, unsigned int len, const char* filename)
- {
- return expGetPrivateProfileStringA(appname, keyname, def_val, dest, len, filename);
- }
- int _WritePrivateProfileStringA(const char* appname, const char* keyname,
- const char* string, const char* filename)
- {
- return expWritePrivateProfileStringA(appname, keyname, string, filename);
- }
- static int WINAPI expDefDriverProc(int _private, int id, int msg, int arg1, int arg2)
- {
- dbgprintf("DefDriverProc(0x%x, 0x%x, 0x%x, 0x%x, 0x%x) => 0n", _private, id, msg, arg1, arg2);
- return 0;
- }
- static int WINAPI expSizeofResource(int v1, int v2)
- {
- int result=SizeofResource(v1, v2);
- dbgprintf("SizeofResource(0x%x, 0x%x) => %dn", v1, v2, result);
- return result;
- }
- static int WINAPI expGetLastError()
- {
- int result=GetLastError();
- dbgprintf("GetLastError() => 0x%xn", result);
- return result;
- }
- static void WINAPI expSetLastError(int error)
- {
- dbgprintf("SetLastError(0x%x)n", error);
- SetLastError(error);
- }
- static int WINAPI expStringFromGUID2(GUID* guid, char* str, int cbMax)
- {
- int result=snprintf(str, cbMax, "%.8x-%.4x-%.4x-%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
- guid->f1, guid->f2, guid->f3,
- (unsigned char)guid->f4[0], (unsigned char)guid->f4[1],
- (unsigned char)guid->f4[2], (unsigned char)guid->f4[3],
- (unsigned char)guid->f4[4], (unsigned char)guid->f4[5],
- (unsigned char)guid->f4[6], (unsigned char)guid->f4[7]);
- dbgprintf("StringFromGUID2(0x%x, 0x%x='%s', %d) => %dn", guid, str, str, cbMax, result);
- return result;
- }
- static int WINAPI expGetFileVersionInfoSizeA(const char* name, int* lpHandle)
- {
- dbgprintf("GetFileVersionInfoSizeA(0x%x='%s', 0x%X) => 0n", name, name, lpHandle);
- return 0;
- }
- static int WINAPI expIsBadStringPtrW(const short* string, int nchars)
- {
- int result;
- if(string==0)result=1; else result=0;
- dbgprintf("IsBadStringPtrW(0x%x, %d) => %d", string, nchars, result);
- if(string)wch_print(string);
- return result;
- }
- static int WINAPI expIsBadStringPtrA(const char* string, int nchars)
- {
- return expIsBadStringPtrW((const short*)string, nchars);
- }
- static long WINAPI expInterlockedExchangeAdd( long* dest, long incr )
- {
- long ret;
- __asm__ __volatile__
- (
- "lock; xaddl %0,(%1)"
- : "=r" (ret)
- : "r" (dest), "0" (incr)
- : "memory"
- );
- return ret;
- }
- static long WINAPI expInterlockedCompareExchange( unsigned long* dest, unsigned long exchange, unsigned long comperand)
- {
- unsigned long retval = *dest;
- if(*dest == comperand)
- *dest = exchange;
- return retval;
- }
- static long WINAPI expInterlockedIncrement( long* dest )
- {
- long result=expInterlockedExchangeAdd( dest, 1 ) + 1;
- dbgprintf("InterlockedIncrement(0x%x => %d) => %dn", dest, *dest, result);
- return result;
- }
- static long WINAPI expInterlockedDecrement( long* dest )
- {
- long result=expInterlockedExchangeAdd( dest, -1 ) - 1;
- dbgprintf("InterlockedDecrement(0x%x => %d) => %dn", dest, *dest, result);
- return result;
- }
- static void WINAPI expOutputDebugStringA( const char* string )
- {
- dbgprintf("OutputDebugStringA(0x%x='%s')n", string);
- fprintf(stderr, "DEBUG: %sn", string);
- }
- static int WINAPI expGetDC(int hwnd)
- {
- dbgprintf("GetDC(0x%x) => 1n", hwnd);
- return 1;
- }
- static int WINAPI expReleaseDC(int hwnd, int hdc)
- {
- dbgprintf("ReleaseDC(0x%x, 0x%x) => 1n", hwnd, hdc);
- return 1;
- }
- static int WINAPI expGetDesktopWindow()
- {
- dbgprintf("GetDesktopWindow() => 0n");
- return 0;
- }
- static int cursor[100];
- static int WINAPI expLoadCursorA(int handle,LPCSTR name)
- {
- dbgprintf("LoadCursorA(%d, 0x%x='%s') => 0x%xn", handle, name, (int)&cursor[0]);
- return (int)&cursor[0];
- }
- static int WINAPI expSetCursor(void *cursor)
- {
- dbgprintf("SetCursor(0x%x) => 0x%xn", cursor, cursor);
- return (int)cursor;
- }
- static int WINAPI expGetCursorPos(void *cursor)
- {
- dbgprintf("GetCursorPos(0x%x) => 0x%xn", cursor, cursor);
- return 1;
- }
- #ifdef QTX
- static int show_cursor = 0;
- static int WINAPI expShowCursor(int show)
- {
- dbgprintf("ShowCursor(%d) => %dn", show, show);
- if (show)
- show_cursor++;
- else
- show_cursor--;
- return show_cursor;
- }
- #endif
- static int WINAPI expRegisterWindowMessageA(char *message)
- {
- dbgprintf("RegisterWindowMessageA(%s)n", message);
- return 1;
- }
- static int WINAPI expGetProcessVersion(int pid)
- {
- dbgprintf("GetProcessVersion(%d)n", pid);
- return 1;
- }
- static int WINAPI expGetCurrentThread(void)
- {
- #warning FIXME!
- dbgprintf("GetCurrentThread() => %xn", 0xcfcf9898);
- return 0xcfcf9898;
- }
- static int WINAPI expGetOEMCP(void)
- {
- dbgprintf("GetOEMCP()n");
- return 1;
- }
- static int WINAPI expGetCPInfo(int cp,void *info)
- {
- dbgprintf("GetCPInfo()n");
- return 0;
- }
- #ifdef QTX
- #define SM_CXSCREEN 0
- #define SM_CYSCREEN 1
- #define SM_XVIRTUALSCREEN 76
- #define SM_YVIRTUALSCREEN 77
- #define SM_CXVIRTUALSCREEN 78
- #define SM_CYVIRTUALSCREEN 79
- #define SM_CMONITORS 80
- #endif
- static int WINAPI expGetSystemMetrics(int index)
- {
- dbgprintf("GetSystemMetrics(%d)n", index);
- #ifdef QTX
- switch(index)
- {
- case SM_XVIRTUALSCREEN:
- case SM_YVIRTUALSCREEN:
- return 0;
- case SM_CXSCREEN:
- case SM_CXVIRTUALSCREEN:
- return PSEUDO_SCREEN_WIDTH;
- case SM_CYSCREEN:
- case SM_CYVIRTUALSCREEN:
- return PSEUDO_SCREEN_HEIGHT;
- case SM_CMONITORS:
- return 1;
- }
- #endif
- return 1;
- }
- static int WINAPI expGetSysColor(int index)
- {
- dbgprintf("GetSysColor(%d) => 1n", index);
- return 1;
- }
- static int WINAPI expGetSysColorBrush(int index)
- {
- dbgprintf("GetSysColorBrush(%d)n", index);
- return 1;
- }
- static int WINAPI expGetSystemPaletteEntries(int hdc, int iStartIndex, int nEntries, void* lppe)
- {
- dbgprintf("GetSystemPaletteEntries(0x%x, 0x%x, 0x%x, 0x%x) => 0n",
- hdc, iStartIndex, nEntries, lppe);
- return 0;
- }
- /*
- typedef struct _TIME_ZONE_INFORMATION {
- long Bias;
- char StandardName[32];
- SYSTEMTIME StandardDate;
- long StandardBias;
- char DaylightName[32];
- SYSTEMTIME DaylightDate;
- long DaylightBias;
- } TIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;
- */
- static int WINAPI expGetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
- {
- const short name[]={'C', 'e', 'n', 't', 'r', 'a', 'l', ' ', 'S', 't', 'a',
- 'n', 'd', 'a', 'r', 'd', ' ', 'T', 'i', 'm', 'e', 0};
- const short pname[]={'C', 'e', 'n', 't', 'r', 'a', 'l', ' ', 'D', 'a', 'y',
- 'l', 'i', 'g', 'h', 't', ' ', 'T', 'i', 'm', 'e', 0};
- dbgprintf("GetTimeZoneInformation(0x%x) => TIME_ZONE_ID_STANDARDn");
- memset(lpTimeZoneInformation, 0, sizeof(TIME_ZONE_INFORMATION));
- lpTimeZoneInformation->Bias=360;//GMT-6
- memcpy(lpTimeZoneInformation->StandardName, name, sizeof(name));
- lpTimeZoneInformation->StandardDate.wMonth=10;
- lpTimeZoneInformation->StandardDate.wDay=5;
- lpTimeZoneInformation->StandardDate.wHour=2;
- lpTimeZoneInformation->StandardBias=0;
- memcpy(lpTimeZoneInformation->DaylightName, pname, sizeof(pname));
- lpTimeZoneInformation->DaylightDate.wMonth=4;
- lpTimeZoneInformation->DaylightDate.wDay=1;
- lpTimeZoneInformation->DaylightDate.wHour=2;
- lpTimeZoneInformation->DaylightBias=-60;
- return TIME_ZONE_ID_STANDARD;
- }
- static void WINAPI expGetLocalTime(SYSTEMTIME* systime)
- {
- time_t local_time;
- struct tm *local_tm;
- struct timeval tv;
- dbgprintf("GetLocalTime(0x%x)n");
- gettimeofday(&tv, NULL);
- local_time=tv.tv_sec;
- local_tm=localtime(&local_time);
- systime->wYear = local_tm->tm_year + 1900;
- systime->wMonth = local_tm->tm_mon + 1;
- systime->wDayOfWeek = local_tm->tm_wday;
- systime->wDay = local_tm->tm_mday;
- systime->wHour = local_tm->tm_hour;
- systime->wMinute = local_tm->tm_min;
- systime->wSecond = local_tm->tm_sec;
- systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
- dbgprintf(" Year: %dn Month: %dn Day of week: %dn"
- " Day: %dn Hour: %dn Minute: %dn Second: %dn"
- " Milliseconds: %dn",
- systime->wYear, systime->wMonth, systime->wDayOfWeek, systime->wDay,
- systime->wHour, systime->wMinute, systime->wSecond, systime->wMilliseconds);
- }
- static int WINAPI expGetSystemTime(SYSTEMTIME* systime)
- {
- time_t local_time;
- struct tm *local_tm;
- struct timeval tv;
- dbgprintf("GetSystemTime(0x%x)n", systime);
- gettimeofday(&tv, NULL);
- local_time=tv.tv_sec;
- local_tm=gmtime(&local_time);
- systime->wYear = local_tm->tm_year + 1900;
- systime->wMonth = local_tm->tm_mon + 1;
- systime->wDayOfWeek = local_tm->tm_wday;
- systime->wDay = local_tm->tm_mday;
- systime->wHour = local_tm->tm_hour;
- systime->wMinute = local_tm->tm_min;
- systime->wSecond = local_tm->tm_sec;
- systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
- dbgprintf(" Year: %dn Month: %dn Day of week: %dn"
- " Day: %dn Hour: %dn Minute: %dn Second: %dn"
- " Milliseconds: %dn",
- systime->wYear, systime->wMonth, systime->wDayOfWeek, systime->wDay,
- systime->wHour, systime->wMinute, systime->wSecond, systime->wMilliseconds);
- return 0;
- }
- #define SECS_1601_TO_1970 ((369 * 365 + 89) * 86400ULL)
- static void WINAPI expGetSystemTimeAsFileTime(FILETIME* systime)
- {
- struct tm *local_tm;
- struct timeval tv;
- unsigned long long secs;
- dbgprintf("GetSystemTime(0x%x)n", systime);
- gettimeofday(&tv, NULL);
- secs = (tv.tv_sec + SECS_1601_TO_1970) * 10000000;
- secs += tv.tv_usec * 10;
- systime->dwLowDateTime = secs & 0xffffffff;
- systime->dwHighDateTime = (secs >> 32);
- }
- static int WINAPI expGetEnvironmentVariableA(const char* name, char* field, int size)
- {
- char *p;
- // printf("%s %x %xn", name, field, size);
- if(field)field[0]=0;
- /*
- p = getenv(name);
- if (p) strncpy(field,p,size);
- */
- if (strcmp(name,"__MSVCRT_HEAP_SELECT")==0)
- strcpy(field,"__GLOBAL_HEAP_SELECTED,1");
- dbgprintf("GetEnvironmentVariableA(0x%x='%s', 0x%x, %d) => %dn", name, name, field, size, strlen(field));
- return strlen(field);
- }
- static int WINAPI expSetEnvironmentVariableA(const char *name, const char *value)
- {
- dbgprintf("SetEnvironmentVariableA(%s, %s)n", name, value);
- return 0;
- }
- static void* WINAPI expCoTaskMemAlloc(ULONG cb)
- {
- return my_mreq(cb, 0);
- }
- static void WINAPI expCoTaskMemFree(void* cb)
- {
- my_release(cb);
- }
- void* CoTaskMemAlloc(unsigned long cb)
- {
- return expCoTaskMemAlloc(cb);
- }
- void CoTaskMemFree(void* cb)
- {
- expCoTaskMemFree(cb);
- }
- struct COM_OBJECT_INFO
- {
- GUID clsid;
- long (*GetClassObject) (GUID* clsid, const GUID* iid, void** ppv);
- };
- static struct COM_OBJECT_INFO* com_object_table=0;
- static int com_object_size=0;
- int RegisterComClass(const GUID* clsid, GETCLASSOBJECT gcs)
- {
- if(!clsid || !gcs)
- return -1;
- com_object_table=realloc(com_object_table, sizeof(struct COM_OBJECT_INFO)*(++com_object_size));
- com_object_table[com_object_size-1].clsid=*clsid;
- com_object_table[com_object_size-1].GetClassObject=gcs;
- return 0;
- }
- int UnregisterComClass(const GUID* clsid, GETCLASSOBJECT gcs)
- {
- int found = 0;
- int i = 0;
- if(!clsid || !gcs)
- return -1;
- if (com_object_table == 0)
- printf("Warning: UnregisterComClass() called without any registered classn");
- while (i < com_object_size)
- {
- if (found && i > 0)
- {
- memcpy(&com_object_table[i - 1].clsid,
- &com_object_table[i].clsid, sizeof(GUID));
- com_object_table[i - 1].GetClassObject =
- com_object_table[i].GetClassObject;
- }
- else if (memcmp(&com_object_table[i].clsid, clsid, sizeof(GUID)) == 0
- && com_object_table[i].GetClassObject == gcs)
- {
- found++;
- }
- i++;
- }
- if (found)
- {
- if (--com_object_size == 0)
- {
- free(com_object_table);
- com_object_table = 0;
- }
- }
- return 0;
- }
- const GUID IID_IUnknown =
- {
- 0x00000000, 0x0000, 0x0000,
- {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}
- };
- const GUID IID_IClassFactory =
- {
- 0x00000001, 0x0000, 0x0000,
- {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}
- };
- static long WINAPI expCoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter,
- long dwClsContext, const GUID* riid, void** ppv)
- {
- int i;
- struct COM_OBJECT_INFO* ci=0;
- for(i=0; i<com_object_size; i++)
- if(!memcmp(rclsid, &com_object_table[i].clsid, sizeof(GUID)))
- ci=&com_object_table[i];
- if(!ci)return REGDB_E_CLASSNOTREG;
- // in 'real' world we should mess with IClassFactory here
- i=ci->GetClassObject(rclsid, riid, ppv);
- return i;
- }
- long CoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter,
- long dwClsContext, const GUID* riid, void** ppv)
- {
- return expCoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv);
- }
- static int WINAPI expIsRectEmpty(CONST RECT *lprc)
- {
- int r = 0;
- int w,h;
- //trapbug();
- if (lprc)
- {
- w = lprc->right - lprc->left;
- h = lprc->bottom - lprc->top;
- if (w <= 0 || h <= 0)
- r = 1;
- }
- else
- r = 1;
- dbgprintf("IsRectEmpty(%p) => %sn", lprc, (r) ? "TRUE" : "FALSE");
- //printf("Rect: left: %d, top: %d, right: %d, bottom: %dn", lprc->left, lprc->top, lprc->right, lprc->bottom);
- // return 0; // wmv9?
- return r; // TM20
- }
- static int _adjust_fdiv=0; //what's this? - used to adjust division
- static unsigned int WINAPI expGetTempPathA(unsigned int len, char* path)
- {
- dbgprintf("GetTempPathA(%d, 0x%x)", len, path);
- if(len<5)
- {
- dbgprintf(" => 0n");
- return 0;
- }
- strcpy(path, "/tmp");
- dbgprintf(" => 5 ( '/tmp' )n");
- return 5;
- }
- /*
- FYI:
- typedef struct
- {
- DWORD dwFileAttributes;
- FILETIME ftCreationTime;
- FILETIME ftLastAccessTime;
- FILETIME ftLastWriteTime;
- DWORD nFileSizeHigh;
- DWORD nFileSizeLow;
- DWORD dwReserved0;
- DWORD dwReserved1;
- CHAR cFileName[260];
- CHAR cAlternateFileName[14];
- } WIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
- */
- static DIR* qtx_dir=NULL;
- static WIN_BOOL WINAPI expFindNextFileA(HANDLE h,LPWIN32_FIND_DATAA lpfd)
- {
- #ifdef QTX
- dbgprintf("FindNextFileA(0x%x, 0x%x) => 0n", h, lpfd);
- if(h==FILE_HANDLE_quicktimeqtx){
- struct dirent* d;
- if(!qtx_dir) return 0;
- while((d=readdir(qtx_dir))){
- char* x=strrchr(d->d_name,'.');
- if(!x) continue;
- if(strcmp(x,".qtx")) continue;
- strcpy(lpfd->cFileName,d->d_name);
- // sprintf(lpfd->cAlternateFileName,"%-8s.qtx",d->d_name);
- strcpy(lpfd->cAlternateFileName,"foobar.qtx");
- printf("### FindNext: %sn",lpfd->cFileName);
- return 1;
- }
- closedir(qtx_dir); qtx_dir=NULL;
- return 0;
- }
- #endif
- return 0;
- }
- static HANDLE WINAPI expFindFirstFileA(LPCSTR s, LPWIN32_FIND_DATAA lpfd)
- {
- dbgprintf("FindFirstFileA(0x%x='%s', 0x%x) => 0n", s, s, lpfd);
- // printf("n### FindFirstFileA('%s')...n",s);
- #ifdef QTX
- if(strstr(s, "quicktime\*.QTX")){
- dbgprintf("FindFirstFileA(0x%x='%s', 0x%x) => QTXn", s, s, lpfd);
- printf("n### Searching for QuickTime plugins (*.qtx) at %s...n",def_path);
- qtx_dir=opendir(def_path);
- if(!qtx_dir) return (HANDLE)-1;
- memset(lpfd,0,sizeof(*lpfd));
- if(expFindNextFileA(FILE_HANDLE_quicktimeqtx,lpfd))
- return FILE_HANDLE_quicktimeqtx;
- printf("loader: Couldn't find the QuickTime plugins (.qtx files) at %sn",def_path);
- return (HANDLE)-1;
- }
- #if 0
- if(strstr(s, "QuickTime.qts")){
- dbgprintf("FindFirstFileA(0x%x='%s', 0x%x) => QTSn", s, s, lpfd);
- // if(!strcmp(s,"C:\windows\QuickTime.qts\QuickTime.qts\*.QTX"))
- // return (HANDLE)-1;
- strcpy(lpfd->cFileName, "QuickTime.qts");
- strcpy(lpfd->cAlternateFileName, "QuickT~1.qts");
- return FILE_HANDLE_quicktimeqts;
- }
- #endif
- #endif
- if(strstr(s, "*.vwp")){
- // hack for VoxWare codec plugins:
- strcpy(lpfd->cFileName, "msms001.vwp");
- strcpy(lpfd->cAlternateFileName, "msms001.vwp");
- return (HANDLE)0;
- }
- // return 'file not found'
- return (HANDLE)-1;
- }
- static WIN_BOOL WINAPI expFindClose(HANDLE h)
- {
- dbgprintf("FindClose(0x%x) => 0n", h);
- #ifdef QTX
- // if(h==FILE_HANDLE_quicktimeqtx && qtx_dir){
- // closedir(qtx_dir);
- // qtx_dir=NULL;
- // }
- #endif
- return 0;
- }
- static UINT WINAPI expSetErrorMode(UINT i)
- {
- dbgprintf("SetErrorMode(%d) => 0n", i);
- return 0;
- }
- static UINT WINAPI expGetWindowsDirectoryA(LPSTR s,UINT c)
- {
- char windir[]="c:\windows";
- int result;
- strncpy(s, windir, c);
- result=1+((c<strlen(windir))?c:strlen(windir));
- dbgprintf("GetWindowsDirectoryA(0x%x, %d) => %dn", s, c, result);
- return result;
- }
- #ifdef QTX
- static UINT WINAPI expGetCurrentDirectoryA(UINT c, LPSTR s)
- {
- char curdir[]="c:\";
- int result;
- strncpy(s, curdir, c);
- result=1+((c<strlen(curdir))?c:strlen(curdir));
- dbgprintf("GetCurrentDirectoryA(0x%x, %d) => %dn", s, c, result);
- return result;
- }
- static int WINAPI expSetCurrentDirectoryA(const char *pathname)
- {
- dbgprintf("SetCurrentDirectoryA(0x%x = %s) => 1n", pathname, pathname);
- #if 0
- if (strrchr(pathname, '\'))
- chdir(strcat(strrchr(pathname, '\')+1, '/'));
- else
- chdir(pathname);
- #endif
- return 1;
- }
- static int WINAPI expCreateDirectoryA(const char *pathname, void *sa)
- {
- dbgprintf("CreateDirectory(0x%x = %s, 0x%x) => 1n",
- pathname, pathname, sa);
- #if 0
- p = strrchr(pathname, '\')+1;
- strcpy(&buf[0], p); /* should be strncpy */
- if (!strlen(p))
- {
- buf[0] = '.';
- buf[1] = 0;
- }
- #if 0
- if (strrchr(pathname, '\'))
- mkdir(strcat(strrchr(pathname, '\')+1, '/'), 666);
- else
- mkdir(pathname, 666);
- #endif
- mkdir(&buf);
- #endif
- return 1;
- }
- #endif
- static WIN_BOOL WINAPI expDeleteFileA(LPCSTR s)
- {
- dbgprintf("DeleteFileA(0x%x='%s') => 0n", s, s);
- return 0;
- }
- static WIN_BOOL WINAPI expFileTimeToLocalFileTime(const FILETIME* cpf, LPFILETIME pf)
- {
- dbgprintf("FileTimeToLocalFileTime(0x%x, 0x%x) => 0n", cpf, pf);
- return 0;
- }
- static UINT WINAPI expGetTempFileNameA(LPCSTR cs1,LPCSTR cs2,UINT i,LPSTR ps)
- {
- char mask[16]="/tmp/AP_XXXXXX";
- int result;
- dbgprintf("GetTempFileNameA(0x%x='%s', 0x%x='%s', %d, 0x%x)", cs1, cs1, cs2, cs2, i, ps);
- if(i && i<10)
- {
- dbgprintf(" => -1n");
- return -1;
- }
- result=mkstemp(mask);
- sprintf(ps, "AP%d", result);
- dbgprintf(" => %dn", strlen(ps));
- return strlen(ps);
- }
- //
- // This func might need proper implementation if we want AngelPotion codec.
- // They try to open APmpeg4v1.apl with it.
- // DLL will close opened file with CloseHandle().
- //
- static HANDLE WINAPI expCreateFileA(LPCSTR cs1,DWORD i1,DWORD i2,
- LPSECURITY_ATTRIBUTES p1, DWORD i3,DWORD i4,HANDLE i5)
- {
- dbgprintf("CreateFileA(0x%x='%s', %d, %d, 0x%x, %d, %d, 0x%x)n", cs1, cs1, i1,
- i2, p1, i3, i4, i5);
- if((!cs1) || (strlen(cs1)<2))return -1;
- #ifdef QTX
- if(strstr(cs1, "QuickTime.qts"))
- {
- int result;
- char* tmp=(char*)malloc(strlen(def_path)+50);
- strcpy(tmp, def_path);
- strcat(tmp, "/");
- strcat(tmp, "QuickTime.qts");
- result=open(tmp, O_RDONLY);
- free(tmp);
- return result;
- }
- if(strstr(cs1, ".qtx"))
- {
- int result;
- char* tmp=(char*)malloc(strlen(def_path)+250);
- char* x=strrchr(cs1,'\');
- sprintf(tmp,"%s/%s",def_path,x?(x+1):cs1);
- // printf("### Open: %s -> %sn",cs1,tmp);
- result=open(tmp, O_RDONLY);
- free(tmp);
- return result;
- }
- #endif
- if(strncmp(cs1, "AP", 2) == 0)
- {
- int result;
- char* tmp=(char*)malloc(strlen(def_path)+50);
- strcpy(tmp, def_path);
- strcat(tmp, "/");
- strcat(tmp, "APmpg4v1.apl");
- result=open(tmp, O_RDONLY);
- free(tmp);
- return result;
- }
- if (strstr(cs1, "vp3"))
- {
- int r;
- int flg = 0;
- char* tmp=(char*)malloc(20 + strlen(cs1));
- strcpy(tmp, "/tmp/");
- strcat(tmp, cs1);
- r = 4;
- while (tmp[r])
- {
- if (tmp[r] == ':' || tmp[r] == '\')
- tmp[r] = '_';
- r++;
- }
- if (GENERIC_READ & i1)
- flg |= O_RDONLY;
- else if (GENERIC_WRITE & i1)
- {
- flg |= O_WRONLY;
- printf("Warning: openning filename %s %d (flags; 0x%x) for writen", tmp, r, flg);
- }
- r=open(tmp, flg);
- free(tmp);
- return r;
- }
- // Needed by wnvplay1.dll
- if (strstr(cs1, "WINNOV.bmp"))
- {
- int r;
- r=open("/dev/null", 0);
- return r;
- }
- #if 0
- /* we need this for some virtualdub filters */
- {
- int r;
- int flg = 0;
- if (GENERIC_READ & i1)
- flg |= O_RDONLY;
- else if (GENERIC_WRITE & i1)
- {
- flg |= O_WRONLY;
- printf("Warning: openning filename %s %d (flags; 0x%x) for writen", cs1, r, flg);
- }
- r=open(cs1, flg);
- return r;
- }
- #endif
- return atoi(cs1+2);
- }
- static UINT WINAPI expGetSystemDirectoryA(
- char* lpBuffer, // address of buffer for system directory
- UINT uSize // size of directory buffer
- ){
- dbgprintf("GetSystemDirectoryA(%p,%d)n", lpBuffer,uSize);
- if(!lpBuffer) strcpy(lpBuffer,".");
- return 1;
- }
- /*
- static char sysdir[]=".";
- static LPCSTR WINAPI expGetSystemDirectoryA()
- {
- dbgprintf("GetSystemDirectoryA() => 0x%x='%s'n", sysdir, sysdir);
- return sysdir;
- }
- */
- static DWORD WINAPI expGetFullPathNameA
- (
- LPCTSTR lpFileName,
- DWORD nBufferLength,
- LPTSTR lpBuffer,
- LPTSTR lpFilePart
- ){
- if(!lpFileName) return 0;
- dbgprintf("GetFullPathNameA('%s',%d,%p,%p)n",lpFileName,nBufferLength,
- lpBuffer, lpFilePart);
- #if 0
- #ifdef QTX
- strcpy(lpFilePart, "Quick123.qts");
- #else
- strcpy(lpFilePart, lpFileName);
- #endif
- #else
- if (strrchr(lpFileName, '\'))
- lpFilePart = strrchr(lpFileName, '\');
- else
- lpFilePart = (LPTSTR)lpFileName;
- #endif
- strcpy(lpBuffer, lpFileName);
- // strncpy(lpBuffer, lpFileName, rindex(lpFileName, '\')-lpFileName);
- return strlen(lpBuffer);
- }
- static DWORD WINAPI expGetShortPathNameA
- (
- LPCSTR longpath,
- LPSTR shortpath,
- DWORD shortlen
- ){
- if(!longpath) return 0;
- dbgprintf("GetShortPathNameA('%s',%p,%d)n",longpath,shortpath,shortlen);
- strcpy(shortpath,longpath);
- return strlen(shortpath);
- }
- static WIN_BOOL WINAPI expReadFile(HANDLE h,LPVOID pv,DWORD size,LPDWORD rd,LPOVERLAPPED unused)
- {
- int result;
- dbgprintf("ReadFile(%d, 0x%x, %d -> 0x%x)n", h, pv, size, rd);
- result=read(h, pv, size);
- if(rd)*rd=result;
- if(!result)return 0;
- return 1;
- }
- static WIN_BOOL WINAPI expWriteFile(HANDLE h,LPCVOID pv,DWORD size,LPDWORD wr,LPOVERLAPPED unused)
- {
- int result;
- dbgprintf("WriteFile(%d, 0x%x, %d -> 0x%x)n", h, pv, size, wr);
- if(h==1234)h=1;
- result=write(h, pv, size);
- if(wr)*wr=result;
- if(!result)return 0;
- return 1;
- }
- static DWORD WINAPI expSetFilePointer(HANDLE h, LONG val, LPLONG ext, DWORD whence)
- {
- int wh;
- dbgprintf("SetFilePointer(%d, 0x%x, 0x%x = %d, %d)n", h, val, ext, *ext, whence);
- //why would DLL want temporary file with >2Gb size?
- switch(whence)
- {
- case FILE_BEGIN:
- wh=SEEK_SET;break;
- case FILE_END:
- wh=SEEK_END;break;
- case FILE_CURRENT:
- wh=SEEK_CUR;break;
- default:
- return -1;
- }
- #ifdef QTX
- if (val == 0 && ext != 0)
- val = val&(*ext);
- #endif
- return lseek(h, val, wh);
- }
- static HDRVR WINAPI expOpenDriverA(LPCSTR szDriverName, LPCSTR szSectionName,
- LPARAM lParam2)
- {
- dbgprintf("OpenDriverA(0x%x='%s', 0x%x='%s', 0x%x) => -1n", szDriverName, szDriverName, szSectionName, szSectionName, lParam2);
- return -1;
- }
- static HDRVR WINAPI expOpenDriver(LPCSTR szDriverName, LPCSTR szSectionName,
- LPARAM lParam2)
- {
- dbgprintf("OpenDriver(0x%x='%s', 0x%x='%s', 0x%x) => -1n", szDriverName, szDriverName, szSectionName, szSectionName, lParam2);
- return -1;
- }
- static WIN_BOOL WINAPI expGetProcessAffinityMask(HANDLE hProcess,
- LPDWORD lpProcessAffinityMask,
- LPDWORD lpSystemAffinityMask)
- {
- dbgprintf("GetProcessAffinityMask(0x%x, 0x%x, 0x%x) => 1n",
- hProcess, lpProcessAffinityMask, lpSystemAffinityMask);
- if(lpProcessAffinityMask)*lpProcessAffinityMask=1;
- if(lpSystemAffinityMask)*lpSystemAffinityMask=1;
- return 1;
- }
- static int WINAPI expMulDiv(int nNumber, int nNumerator, int nDenominator)
- {
- static const long long max_int=0x7FFFFFFFLL;
- static const long long min_int=-0x80000000LL;
- long long tmp=(long long)nNumber*(long long)nNumerator;
- dbgprintf("expMulDiv %d * %d / %dn", nNumber, nNumerator, nDenominator);
- if(!nDenominator)return 1;
- tmp/=nDenominator;
- if(tmp<min_int) return 1;
- if(tmp>max_int) return 1;
- return (int)tmp;
- }
- static LONG WINAPI explstrcmpiA(const char* str1, const char* str2)
- {
- LONG result=strcasecmp(str1, str2);
- dbgprintf("strcmpi(0x%x='%s', 0x%x='%s') => %dn", str1, str1, str2, str2, result);
- return result;
- }
- static LONG WINAPI explstrlenA(const char* str1)
- {
- LONG result=strlen(str1);
- dbgprintf("strlen(0x%x='%.50s') => %dn", str1, str1, result);
- return result;
- }
- static LONG WINAPI explstrcpyA(char* str1, const char* str2)
- {
- int result= (int) strcpy(str1, str2);
- dbgprintf("strcpy(0x%.50x, 0x%.50x='%.50s') => %dn", str1, str2, str2, result);
- return result;
- }
- static LONG WINAPI explstrcpynA(char* str1, const char* str2,int len)
- {
- int result;
- if (strlen(str2)>len)
- result = (int) strncpy(str1, str2,len);
- else
- result = (int) strcpy(str1,str2);
- dbgprintf("strncpy(0x%x, 0x%x='%s' len %d strlen %d) => %xn", str1, str2, str2,len, strlen(str2),result);
- return result;
- }
- static LONG WINAPI explstrcatA(char* str1, const char* str2)
- {
- int result= (int) strcat(str1, str2);
- dbgprintf("strcat(0x%x, 0x%x='%s') => %dn", str1, str2, str2, result);
- return result;
- }
- static LONG WINAPI expInterlockedExchange(long *dest, long l)
- {
- long retval = *dest;
- *dest = l;
- return retval;
- }
- static void WINAPI expInitCommonControls(void)
- {
- dbgprintf("InitCommonControls called!n");
- return;
- }
- #ifdef QTX
- /* needed by QuickTime.qts */
- static HWND WINAPI expCreateUpDownControl (DWORD style, INT x, INT y, INT cx, INT cy,
- HWND parent, INT id, HINSTANCE inst,
- HWND buddy, INT maxVal, INT minVal, INT curVal)
- {
- dbgprintf("CreateUpDownControl(...)n");
- return 0;
- }
- #endif
- /* alex: implement this call! needed for 3ivx */
- static HRESULT WINAPI expCoCreateFreeThreadedMarshaler(void *pUnkOuter, void **ppUnkInner)
- {
- dbgprintf("CoCreateFreeThreadedMarshaler(%p, %p) called!n",
- pUnkOuter, ppUnkInner);
- // return 0;
- return ERROR_CALL_NOT_IMPLEMENTED;
- }
- static int WINAPI expDuplicateHandle(HANDLE hSourceProcessHandle, // handle to source process
- HANDLE hSourceHandle, // handle to duplicate
- HANDLE hTargetProcessHandle, // handle to target process
- HANDLE* lpTargetHandle, // duplicate handle
- DWORD dwDesiredAccess, // requested access
- int bInheritHandle, // handle inheritance option
- DWORD dwOptions // optional actions
- )
- {
- dbgprintf("DuplicateHandle(%p, %p, %p, %p, 0x%x, %d, %d) calledn",
- hSourceProcessHandle, hSourceHandle, hTargetProcessHandle,
- lpTargetHandle, dwDesiredAccess, bInheritHandle, dwOptions);
- *lpTargetHandle = hSourceHandle;
- return 1;
- }
- // required by PIM1 codec (used by win98 PCTV Studio capture sw)
- static HRESULT WINAPI expCoInitialize(
- LPVOID lpReserved /* [in] pointer to win32 malloc interface
- (obsolete, should be NULL) */
- )
- {
- /*
- * Just delegate to the newer method.
- */
- return 0; //CoInitializeEx(lpReserved, COINIT_APARTMENTTHREADED);
- }
- static DWORD WINAPI expSetThreadAffinityMask
- (
- HANDLE hThread,
- DWORD dwThreadAffinityMask
- ){
- return 0;
- };
- /*
- * no WINAPI functions - CDECL
- */
- static void* expmalloc(int size)
- {
- //printf("malloc");
- // return malloc(size);
- void* result=my_mreq(size,0);
- dbgprintf("malloc(0x%x) => 0x%xn", size,result);
- if(result==0)
- printf("WARNING: malloc() failedn");
- return result;
- }
- static void expfree(void* mem)
- {
- // return free(mem);
- dbgprintf("free(%p)n", mem);
- my_release(mem);
- }
- /* needed by atrac3.acm */
- static void *expcalloc(int num, int size)
- {
- void* result=my_mreq(num*size,1);
- dbgprintf("calloc(%d,%d) => %pn", num,size,result);
- if(result==0)
- printf("WARNING: calloc() failedn");
- return result;
- }
- static void* expnew(int size)
- {
- // printf("NEW:: Call from address %08xn STACK DUMP:n", *(-1+(int*)&size));
- // printf("%08x %08x %08x %08xn",
- // size, *(1+(int*)&size),
- // *(2+(int*)&size),*(3+(int*)&size));
- void* result;
- assert(size >= 0);
- result=my_mreq(size,0);
- dbgprintf("new(%d) => %pn", size, result);
- if (result==0)
- printf("WARNING: new() failedn");
- return result;
- }
- static int expdelete(void* memory)
- {
- dbgprintf("delete(%p)n", memory);
- my_release(memory);
- return 0;
- }
- /*
- * local definition - we need only the last two members at this point
- * otherwice we would have to introduce here GUIDs and some more types..
- */
- typedef struct __attribute__((__packed__))
- {
- char hay[0x3C];
- void* pbUnknown; //0x3C
- unsigned long cbFormat; //0x40
- char* pbFormat; //0x44
- } MY_MEDIA_TYPE;
- static HRESULT WINAPI expMoCopyMediaType(MY_MEDIA_TYPE* dest, const MY_MEDIA_TYPE* src)
- {
- if (!dest || !src)
- return E_POINTER;
- memcpy(dest, src, sizeof(MY_MEDIA_TYPE));
- if (dest->cbFormat)
- {
- dest->pbFormat = (char*) my_mreq(dest->cbFormat, 0);
- if (!dest->pbFormat)
- return E_OUTOFMEMORY;
- memcpy(dest->pbFormat, src->pbFormat, dest->cbFormat);
- }
- return S_OK;
- }
- static HRESULT WINAPI expMoInitMediaType(MY_MEDIA_TYPE* dest, DWORD cbFormat)
- {
- if (!dest)
- return E_POINTER;
- dest->pbUnknown = NULL;
- dest->cbFormat = cbFormat;
- if (cbFormat)
- {
- dest->pbFormat = (char*) my_mreq(cbFormat, 0);
- if (!dest->pbFormat)
- return E_OUTOFMEMORY;
- }
- else
- {
- dest->pbFormat=NULL;
- }
- return S_OK;
- }
- static HRESULT WINAPI expMoCreateMediaType(MY_MEDIA_TYPE** dest, DWORD cbFormat)
- {
- if (!dest)
- return E_POINTER;
- *dest = my_mreq(sizeof(MY_MEDIA_TYPE), 0);
- return expMoInitMediaType(*dest, cbFormat);
- }
- static HRESULT WINAPI expMoDuplicateMediaType(MY_MEDIA_TYPE** dest, const void* src)
- {
- if (!dest)
- return E_POINTER;
- *dest = my_mreq(sizeof(MY_MEDIA_TYPE), 0);
- return expMoCopyMediaType(*dest, src);
- }
- static HRESULT WINAPI expMoFreeMediaType(MY_MEDIA_TYPE* dest)
- {
- if (!dest)
- return E_POINTER;
- if (dest->pbFormat)
- {
- my_release(dest->pbFormat);
- dest->pbFormat = 0;
- dest->cbFormat = 0;
- }
- return S_OK;
- }
- static HRESULT WINAPI expMoDeleteMediaType(MY_MEDIA_TYPE* dest)
- {
- if (!dest)
- return E_POINTER;
- expMoFreeMediaType(dest);
- my_release(dest);
- return S_OK;
- }
- static int exp_snprintf( char *str, int size, const char *format, ... )
- {
- int x;
- va_list va;
- va_start(va, format);
- x=snprintf(str,size,format,va);
- dbgprintf("_snprintf( 0x%x, %d, %s, ... ) => %dn",str,size,format,x);
- va_end(va);
- return x;
- }
- #if 0
- static int exp_initterm(int v1, int v2)
- {
- dbgprintf("_initterm(0x%x, 0x%x) => 0n", v1, v2);
- return 0;
- }
- #else
- /* merged from wine - 2002.04.21 */
- typedef void (*_INITTERMFUNC)();
- static int exp_initterm(_INITTERMFUNC *start, _INITTERMFUNC *end)
- {
- dbgprintf("_initterm(0x%x, 0x%x) %pn", start, end, *start);
- while (start < end)
- {
- if (*start)
- {
- //printf("call _initfunc: from: %p %dn", *start);
- // ok this trick with push/pop is necessary as otherwice
- // edi/esi registers are being trashed
- void* p = *start;
- __asm__ __volatile__
- (
- "pushl %%ebx nt"
- "pushl %%ecx nt"
- "pushl %%edx nt"
- "pushl %%edi nt"
- "pushl %%esi nt"
- "call *%%eax nt"
- "popl %%esi nt"
- "popl %%edi nt"
- "popl %%edx nt"
- "popl %%ecx nt"
- "popl %%ebx nt"
- :
- : "a"(p)
- : "memory"
- );
- //printf("done %p %d:%dn", end);
- }
- start++;
- }
- return 0;
- }
- #endif
- static void* exp__dllonexit()
- {
- // FIXME extract from WINE
- return NULL;
- }
- static int expwsprintfA(char* string, const char* format, ...)
- {
- va_list va;
- int result;
- va_start(va, format);
- result = vsprintf(string, format, va);
- dbgprintf("wsprintfA(0x%x, '%s', ...) => %dn", string, format, result);
- va_end(va);
- return result;
- }
- static int expsprintf(char* str, const char* format, ...)
- {
- va_list args;
- int r;
- dbgprintf("sprintf(0x%x, %s)n", str, format);
- va_start(args, format);
- r = vsprintf(str, format, args);
- va_end(args);
- return r;
- }
- static int expsscanf(const char* str, const char* format, ...)
- {
- va_list args;
- int r;
- dbgprintf("sscanf(%s, %s)n", str, format);
- va_start(args, format);
- r = vsscanf(str, format, args);
- va_end(args);
- return r;
- }
- static void* expfopen(const char* path, const char* mode)
- {
- printf("fopen: "%s" mode:%sn", path, mode);
- //return fopen(path, mode);
- return fdopen(0, mode); // everything on screen
- }
- static int expfprintf(void* stream, const char* format, ...)
- {
- va_list args;
- int r = 0;
- dbgprintf("fprintf(%p, %s, ...)n", stream, format);
- #if 1
- va_start(args, format);
- r = vfprintf((FILE*) stream, format, args);
- va_end(args);
- #endif
- return r;
- }
- static int expprintf(const char* format, ...)
- {
- va_list args;
- int r;
- dbgprintf("printf(%s, ...)n", format);
- va_start(args, format);
- r = vprintf(format, args);
- va_end(args);
- return r;
- }
- static char* expgetenv(const char* varname)
- {
- char* v = getenv(varname);
- dbgprintf("getenv(%s) => %sn", varname, v);
- return v;
- }
- static void* expwcscpy(WCHAR* dst, const WCHAR* src)
- {
- WCHAR* p = dst;
- while ((*p++ = *src++))
- ;
- return dst;
- }
- static char* expstrrchr(char* string, int value)
- {
- char* result=strrchr(string, value);
- if(result)
- dbgprintf("strrchr(0x%x='%s', %d) => 0x%x='%s'", string, string, value, result, result);
- else
- dbgprintf("strrchr(0x%x='%s', %d) => 0", string, string, value);
- return result;
- }
- static char* expstrchr(char* string, int value)
- {
- char* result=strchr(string, value);
- if(result)
- dbgprintf("strchr(0x%x='%s', %d) => 0x%x='%s'", string, string, value, result, result);
- else
- dbgprintf("strchr(0x%x='%s', %d) => 0", string, string, value);
- return result;
- }
- static int expstrlen(char* str)
- {
- int result=strlen(str);
- dbgprintf("strlen(0x%x='%s') => %dn", str, str, result);
- return result;
- }
- static char* expstrcpy(char* str1, const char* str2)
- {
- char* result= strcpy(str1, str2);
- dbgprintf("strcpy(0x%x, 0x%x='%s') => %pn", str1, str2, str2, result);
- return result;
- }
- static char* expstrncpy(char* str1, const char* str2, size_t count)
- {
- char* result= strncpy(str1, str2, count);
- dbgprintf("strncpy(0x%x, 0x%x='%s', %d) => %pn", str1, str2, str2, count, result);
- return result;
- }
- static int expstrcmp(const char* str1, const char* str2)
- {
- int result=strcmp(str1, str2);
- dbgprintf("strcmp(0x%x='%s', 0x%x='%s') => %dn", str1, str1, str2, str2, result);
- return result;
- }
- static int expstrncmp(const char* str1, const char* str2,int x)
- {
- int result=strncmp(str1, str2,x);
- dbgprintf("strcmp(0x%x='%s', 0x%x='%s') => %dn", str1, str1, str2, str2, result);
- return result;
- }
- static char* expstrcat(char* str1, const char* str2)
- {
- char* result = strcat(str1, str2);
- dbgprintf("strcat(0x%x='%s', 0x%x='%s') => %pn", str1, str1, str2, str2, result);
- return result;
- }
- static char* exp_strdup(const char* str1)
- {
- int l = strlen(str1);
- char* result = (char*) my_mreq(l + 1,0);
- if (result)
- strcpy(result, str1);
- dbgprintf("_strdup(0x%x='%s') => %pn", str1, str1, result);
- return result;
- }
- static int expisalnum(int c)
- {
- int result= (int) isalnum(c);
- dbgprintf("isalnum(0x%x='%c' => %dn", c, c, result);
- return result;
- }
- static int expisspace(int c)
- {
- int result= (int) isspace(c);
- dbgprintf("isspace(0x%x='%c' => %dn", c, c, result);
- return result;
- }
- static int expisalpha(int c)
- {
- int result= (int) isalpha(c);
- dbgprintf("isalpha(0x%x='%c' => %dn", c, c, result);
- return result;
- }
- static int expisdigit(int c)
- {
- int result= (int) isdigit(c);
- dbgprintf("isdigit(0x%x='%c' => %dn", c, c, result);
- return result;
- }
- static void* expmemmove(void* dest, void* src, int n)
- {
- void* result = memmove(dest, src, n);
- dbgprintf("memmove(0x%x, 0x%x, %d) => %pn", dest, src, n, result);
- return result;
- }
- static int expmemcmp(void* dest, void* src, int n)
- {
- int result = memcmp(dest, src, n);
- dbgprintf("memcmp(0x%x, 0x%x, %d) => %dn", dest, src, n, result);
- return result;
- }
- static void* expmemcpy(void* dest, void* src, int n)
- {
- void *result = memcpy(dest, src, n);
- dbgprintf("memcpy(0x%x, 0x%x, %d) => %pn", dest, src, n, result);
- return result;
- }
- static void* expmemset(void* dest, int c, size_t n)
- {
- void *result = memset(dest, c, n);
- dbgprintf("memset(0x%x, %d, %d) => %pn", dest, c, n, result);
- return result;
- }
- static time_t exptime(time_t* t)
- {
- time_t result = time(t);
- dbgprintf("time(0x%x) => %dn", t, result);
- return result;
- }
- static int exprand(void)
- {
- return rand();
- }
- static void expsrand(int seed)
- {
- srand(seed);
- }
- #if 1
- // preferred compilation with -O2 -ffast-math !
- static double explog10(double x)
- {
- /*printf("Log10 %f => %f 0x%Lxn", x, log10(x), *((int64_t*)&x));*/
- return log10(x);
- }
- static double expcos(double x)
- {
- /*printf("Cos %f => %f 0x%Lxn", x, cos(x), *((int64_t*)&x));*/
- return cos(x);
- }
- /* doens't work */
- static long exp_ftol_wrong(double x)
- {
- return (long) x;
- }
- #else
- static void explog10(void)
- {
- __asm__ __volatile__
- (
- "fldl 8(%esp) nt"
- "fldln2 nt"
- "fxch %st(1) nt"
- "fyl2x nt"
- );
- }
- static void expcos(void)
- {
- __asm__ __volatile__
- (
- "fldl 8(%esp) nt"
- "fcos nt"
- );
- }
- #endif
- // this seem to be the only how to make this function working properly
- // ok - I've spent tremendous amount of time (many many many hours
- // of debuging fixing & testing - it's almost unimaginable - kabi
- // _ftol - operated on the float value which is already on the FPU stack
- static void exp_ftol(void)
- {
- __asm__ __volatile__
- (
- "sub $12, %esp nt"
- "fstcw -2(%ebp) nt"
- "wait nt"
- "movw -2(%ebp), %ax nt"
- "orb $0x0C, %ah nt"
- "movw %ax, -4(%ebp) nt"
- "fldcw -4(%ebp) nt"
- "fistpl -12(%ebp) nt"
- "fldcw -2(%ebp) nt"
- "movl -12(%ebp), %eax nt"
- //Note: gcc 3.03 does not do the following op if it
- // knows that ebp=esp
- "movl %ebp, %esp nt"
- );
- }
- #define FPU_DOUBLES(var1,var2) double var1,var2;
- __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : );
- __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
- static double exp_CIpow(void)
- {
- FPU_DOUBLES(x,y);
- dbgprintf("_CIpow(%lf, %lf)n", x, y);
- return pow(x, y);
- }
- static double exppow(double x, double y)
- {
- /*printf("Pow %f %f 0x%Lx 0x%Lx => %fn", x, y, *((int64_t*)&x), *((int64_t*)&y), pow(x, y));*/
- return pow(x, y);
- }
- static double expldexp(double x, int expo)
- {
- /*printf("Cos %f => %f 0x%Lxn", x, cos(x), *((int64_t*)&x));*/
- return ldexp(x, expo);
- }
- static double expfrexp(double x, int* expo)
- {
- /*printf("Cos %f => %f 0x%Lxn", x, cos(x), *((int64_t*)&x));*/
- return frexp(x, expo);
- }
- static int exp_stricmp(const char* s1, const char* s2)
- {
- return strcasecmp(s1, s2);
- }
- /* from declaration taken from Wine sources - this fountion seems to be
- * undocumented in any M$ doc */
- static int exp_setjmp3(void* jmpbuf, int x)
- {
- //dbgprintf("!!!!UNIMPLEMENTED: setjmp3(%p, %d) => 0n", jmpbuf, x);
- //return 0;
- __asm__ __volatile__
- (
- //"mov 4(%%esp), %%edx nt"
- "mov (%%esp), %%eax nt"
- "mov %%eax, (%%edx) nt" // store ebp
- //"mov %%ebp, (%%edx) nt"
- "mov %%ebx, 4(%%edx) nt"
- "mov %%edi, 8(%%edx) nt"
- "mov %%esi, 12(%%edx) nt"
- "mov %%esp, 16(%%edx) nt"
- "mov 4(%%esp), %%eax nt"
- "mov %%eax, 20(%%edx) nt"
- "movl $0x56433230, 32(%%edx) nt" // VC20 ??
- "movl $0, 36(%%edx) nt"
- : // output
- : "d"(jmpbuf) // input
- : "eax"
- );
- #if 1
- __asm__ __volatile__
- (
- "mov %%fs:0, %%eax nt" // unsure
- "mov %%eax, 24(%%edx) nt"
- "cmp $0xffffffff, %%eax nt"
- "jnz l1 nt"
- "mov %%eax, 28(%%edx) nt"
- "l1: nt"
- :
- :
- : "eax"
- );
- #endif
- return 0;
- }
- static DWORD WINAPI expGetCurrentProcessId(void)
- {
- dbgprintf("GetCurrentProcessId(void) => %dn", getpid());
- return getpid(); //(DWORD)NtCurrentTeb()->pid;
- }
- typedef struct {
- UINT wPeriodMin;
- UINT wPeriodMax;
- } TIMECAPS, *LPTIMECAPS;
- static MMRESULT WINAPI exptimeGetDevCaps(LPTIMECAPS lpCaps, UINT wSize)
- {
- dbgprintf("timeGetDevCaps(%p, %u) !n", lpCaps, wSize);
- lpCaps->wPeriodMin = 1;
- lpCaps->wPeriodMax = 65535;
- return 0;
- }
- static MMRESULT WINAPI exptimeBeginPeriod(UINT wPeriod)
- {
- dbgprintf("timeBeginPeriod(%u) !n", wPeriod);
- if (wPeriod < 1 || wPeriod > 65535) return 96+1; //TIMERR_NOCANDO;
- return 0;
- }
- #ifdef QTX
- static MMRESULT WINAPI exptimeEndPeriod(UINT wPeriod)
- {
- dbgprintf("timeEndPeriod(%u) !n", wPeriod);
- if (wPeriod < 1 || wPeriod > 65535) return 96+1; //TIMERR_NOCANDO;
- return 0;
- }
- #endif
- static void WINAPI expGlobalMemoryStatus(
- LPMEMORYSTATUS lpmem
- ) {
- static MEMORYSTATUS cached_memstatus;
- static int cache_lastchecked = 0;
- SYSTEM_INFO si;
- FILE *f;
- if (time(NULL)==cache_lastchecked) {
- memcpy(lpmem,&cached_memstatus,sizeof(MEMORYSTATUS));
- return;
- }
- #if 1
- f = fopen( "/proc/meminfo", "r" );
- if (f)
- {
- char buffer[256];
- int total, used, free, shared, buffers, cached;
- lpmem->dwLength = sizeof(MEMORYSTATUS);
- lpmem->dwTotalPhys = lpmem->dwAvailPhys = 0;
- lpmem->dwTotalPageFile = lpmem->dwAvailPageFile = 0;
- while (fgets( buffer, sizeof(buffer), f ))
- {
- /* old style /proc/meminfo ... */
- if (sscanf( buffer, "Mem: %d %d %d %d %d %d", &total, &used, &free, &shared, &buffers, &cached ))
- {
- lpmem->dwTotalPhys += total;
- lpmem->dwAvailPhys += free + buffers + cached;
- }
- if (sscanf( buffer, "Swap: %d %d %d", &total, &used, &free ))
- {
- lpmem->dwTotalPageFile += total;
- lpmem->dwAvailPageFile += free;
- }
- /* new style /proc/meminfo ... */
- if (sscanf(buffer, "MemTotal: %d", &total))
- lpmem->dwTotalPhys = total*1024;
- if (sscanf(buffer, "MemFree: %d", &free))
- lpmem->dwAvailPhys = free*1024;
- if (sscanf(buffer, "SwapTotal: %d", &total))
- lpmem->dwTotalPageFile = total*1024;
- if (sscanf(buffer, "SwapFree: %d", &free))
- lpmem->dwAvailPageFile = free*1024;
- if (sscanf(buffer, "Buffers: %d", &buffers))
- lpmem->dwAvailPhys += buffers*1024;
- if (sscanf(buffer, "Cached: %d", &cached))
- lpmem->dwAvailPhys += cached*1024;
- }
- fclose( f );
- if (lpmem->dwTotalPhys)
- {
- DWORD TotalPhysical = lpmem->dwTotalPhys+lpmem->dwTotalPageFile;
- DWORD AvailPhysical = lpmem->dwAvailPhys+lpmem->dwAvailPageFile;
- lpmem->dwMemoryLoad = (TotalPhysical-AvailPhysical)
- / (TotalPhysical / 100);
- }
- } else
- #endif
- {
- /* FIXME: should do something for other systems */
- lpmem->dwMemoryLoad = 0;
- lpmem->dwTotalPhys = 16*1024*1024;
- lpmem->dwAvailPhys = 16*1024*1024;
- lpmem->dwTotalPageFile = 16*1024*1024;
- lpmem->dwAvailPageFile = 16*1024*1024;
- }
- expGetSystemInfo(&si);
- lpmem->dwTotalVirtual = si.lpMaximumApplicationAddress-si.lpMinimumApplicationAddress;
- /* FIXME: we should track down all the already allocated VM pages and substract them, for now arbitrarily remove 64KB so that it matches NT */
- lpmem->dwAvailVirtual = lpmem->dwTotalVirtual-64*1024;
- memcpy(&cached_memstatus,lpmem,sizeof(MEMORYSTATUS));
- cache_lastchecked = time(NULL);
- /* it appears some memory display programs want to divide by these values */
- if(lpmem->dwTotalPageFile==0)
- lpmem->dwTotalPageFile++;
- if(lpmem->dwAvailPageFile==0)
- lpmem->dwAvailPageFile++;
- }
- /**********************************************************************
- * SetThreadPriority [KERNEL32.@] Sets priority for thread.
- *
- * RETURNS
- * Success: TRUE
- * Failure: FALSE
- */
- static WIN_BOOL WINAPI expSetThreadPriority(
- HANDLE hthread, /* [in] Handle to thread */
- INT priority) /* [in] Thread priority level */
- {
- dbgprintf("SetThreadPriority(%p,%d)n",hthread,priority);
- return TRUE;
- }
- static void WINAPI expExitProcess( DWORD status )
- {
- printf("EXIT - code %ldn",status);
- exit(status);
- }
- static INT WINAPI expMessageBoxA(HWND hWnd, LPCSTR text, LPCSTR title, UINT type){
- printf("MSGBOX '%s' '%s' (%d)n",text,title,type);
- #ifdef QTX
- if (type == MB_ICONHAND && !strlen(text) && !strlen(title))
- return IDIGNORE;
- #endif
- return IDOK;
- }
- /* these are needed for mss1 */
- /* defined in stubs.s */
- void exp_EH_prolog(void);
- #include <netinet/in.h>
- static WINAPI inline unsigned long int exphtonl(unsigned long int hostlong)
- {
- // dbgprintf("htonl(%x) => %xn", hostlong, htonl(hostlong));
- return htonl(hostlong);
- }
- static WINAPI inline unsigned long int expntohl(unsigned long int netlong)
- {
- // dbgprintf("ntohl(%x) => %xn", netlong, ntohl(netlong));
- return ntohl(netlong);
- }
- static void WINAPI expVariantInit(void* p)
- {
- printf("InitCommonControls called!n");
- return;
- }
- static int WINAPI expRegisterClassA(const void/*WNDCLASSA*/ *wc)
- {
- dbgprintf("RegisterClassA(%p) => random idn", wc);
- return time(NULL); /* be precise ! */
- }
- static int WINAPI expUnregisterClassA(const char *className, HINSTANCE hInstance)
- {
- dbgprintf("UnregisterClassA(%s, %p) => 0n", className, hInstance);
- return 0;
- }
- #ifdef QTX
- /* should be fixed bcs it's not fully strlen equivalent */
- static int expSysStringByteLen(void *str)
- {
- dbgprintf("SysStringByteLen(%p) => %dn", str, strlen(str));
- return strlen(str);
- }
- static int expDirectDrawCreate(void)
- {
- dbgprintf("DirectDrawCreate(...) => NULLn");
- return 0;
- }
- #if 1
- typedef struct tagPALETTEENTRY {
- BYTE peRed;
- BYTE peGreen;
- BYTE peBlue;
- BYTE peFlags;
- } PALETTEENTRY;
- /* reversed the first 2 entries */
- typedef struct tagLOGPALETTE {
- WORD palNumEntries;
- WORD palVersion;
- PALETTEENTRY palPalEntry[1];
- } LOGPALETTE;
- static HPALETTE WINAPI expCreatePalette(CONST LOGPALETTE *lpgpl)
- {
- HPALETTE test;
- int i;
- dbgprintf("CreatePalette(%x) => NULLn", lpgpl);
- i = sizeof(LOGPALETTE)+((lpgpl->palNumEntries-1)*sizeof(PALETTEENTRY));
- test = (HPALETTE)malloc(i);
- memcpy((void *)test, lpgpl, i);
- return test;
- }
- #else
- static int expCreatePalette(void)
- {
- dbgprintf("CreatePalette(...) => NULLn");
- return NULL;
- }
- #endif
- static int WINAPI expGetClientRect(HWND win, RECT *r)
- {
- dbgprintf("GetClientRect(0x%x, 0x%x) => 1n", win, r);
- r->right = PSEUDO_SCREEN_WIDTH;
- r->left = 0;
- r->bottom = PSEUDO_SCREEN_HEIGHT;
- r->top = 0;
- return 1;
- }
- #if 0
- typedef struct tagPOINT {
- LONG x;
- LONG y;
- } POINT, *PPOINT;
- #endif
- static int WINAPI expClientToScreen(HWND win, POINT *p)
- {
- dbgprintf("ClientToScreen(0x%x, 0x%x = %d,%d) => 1n", win, p, p->x, p->y);
- p->x = 0;
- p->y = 0;
- return 1;
- }
- #endif
- /* for m3jpeg */
- static int WINAPI expSetThreadIdealProcessor(HANDLE thread, int proc)
- {
- dbgprintf("SetThreadIdealProcessor(0x%x, %x) => 0n", thread, proc);
- return 0;
- }
- static int WINAPI expMessageBeep(int type)
- {
- dbgprintf("MessageBeep(%d) => 1n", type);
- return 1;
- }
- static int WINAPI expDialogBoxParamA(void *inst, const char *name,
- HWND parent, void *dialog_func, void *init_param)
- {
- dbgprintf("DialogBoxParamA(0x%x, 0x%x = %s, 0x%x, 0x%x, 0x%x) => 0x42424242n",
- inst, name, name, parent, dialog_func, init_param);
- return 0x42424242;
- }
- /* needed by imagepower mjpeg2k */
- static void *exprealloc(void *ptr, size_t size)
- {
- dbgprintf("realloc(0x%x, %x)n", ptr, size);
- if (!ptr)
- return my_mreq(size,0);
- else
- return my_realloc(ptr, size);
- }
- /* Fake GetOpenFileNameA from comdlg32.dll for ViVD codec */
- static WIN_BOOL WINAPI expGetOpenFileNameA(/*LPOPENFILENAMEA*/ void* lpfn)
- {
- return 1;
- }
- static double expfloor(double x)
- {
- dbgprintf("floor(%lf)n", x);
- return floor(x);
- }
- #define FPU_DOUBLE(var) double var;
- __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
- static double exp_CIcos(void)
- {
- FPU_DOUBLE(x);
- dbgprintf("_CIcos(%lf)n", x);
- return cos(x);
- }
- static double exp_CIsin(void)
- {
- FPU_DOUBLE(x);
- dbgprintf("_CIsin(%lf)n", x);
- return sin(x);
- }
- struct exports
- {
- char name[64];
- int id;
- void* func;
- };
- struct libs
- {
- char name[64];
- int length;
- struct exports* exps;
- };
- #define FF(X,Y)
- {#X, Y, (void*)exp##X},
- struct exports exp_kernel32[]=
- {
- FF(GetVolumeInformationA,-1)
- FF(GetDriveTypeA,-1)
- FF(GetLogicalDriveStringsA,-1)
- FF(IsBadWritePtr, 357)
- FF(IsBadReadPtr, 354)
- FF(IsBadStringPtrW, -1)
- FF(IsBadStringPtrA, -1)
- FF(DisableThreadLibraryCalls, -1)
- FF(CreateThread, -1)
- FF(CreateEventA, -1)
- FF(SetEvent, -1)
- FF(ResetEvent, -1)
- FF(WaitForSingleObject, -1)
- #ifdef QTX
- FF(WaitForMultipleObjects, -1)
- FF(ExitThread, -1)
- FF(CreateMutexA,-1)
- FF(ReleaseMutex,-1)
- #endif
- FF(GetSystemInfo, -1)
- FF(GetVersion, 332)
- FF(HeapCreate, 461)
- FF(HeapAlloc, -1)
- FF(HeapDestroy, -1)
- FF(HeapFree, -1)
- FF(HeapSize, -1)
- FF(HeapReAlloc,-1)
- FF(GetProcessHeap, -1)
- FF(VirtualAlloc, -1)
- FF(VirtualFree, -1)
- FF(InitializeCriticalSection, -1)
- FF(EnterCriticalSection, -1)
- FF(LeaveCriticalSection, -1)
- FF(DeleteCriticalSection, -1)
- FF(TlsAlloc, -1)
- FF(TlsFree, -1)
- FF(TlsGetValue, -1)
- FF(TlsSetValue, -1)
- FF(GetCurrentThreadId, -1)
- FF(GetCurrentProcess, -1)
- FF(LocalAlloc, -1)
- FF(LocalReAlloc,-1)
- FF(LocalLock, -1)
- FF(GlobalAlloc, -1)
- FF(GlobalReAlloc, -1)
- FF(GlobalLock, -1)
- FF(GlobalSize, -1)
- FF(MultiByteToWideChar, 427)
- FF(WideCharToMultiByte, -1)
- FF(GetVersionExA, -1)
- FF(CreateSemaphoreA, -1)
- FF(QueryPerformanceCounter, -1)
- FF(QueryPerformanceFrequency, -1)
- FF(LocalHandle, -1)
- FF(LocalUnlock, -1)
- FF(LocalFree, -1)
- FF(GlobalHandle, -1)
- FF(GlobalUnlock, -1)
- FF(GlobalFree, -1)
- FF(LoadResource, -1)
- FF(ReleaseSemaphore, -1)
- FF(FindResourceA, -1)
- FF(LockResource, -1)
- FF(FreeResource, -1)
- FF(SizeofResource, -1)
- FF(CloseHandle, -1)
- FF(GetCommandLineA, -1)
- FF(GetEnvironmentStringsW, -1)
- FF(FreeEnvironmentStringsW, -1)
- FF(FreeEnvironmentStringsA, -1)
- FF(GetEnvironmentStrings, -1)
- FF(GetStartupInfoA, -1)
- FF(GetStdHandle, -1)
- FF(GetFileType, -1)
- #ifdef QTX
- FF(GetFileAttributesA, -1)
- #endif
- FF(SetHandleCount, -1)
- FF(GetACP, -1)
- FF(GetModuleFileNameA, -1)
- FF(SetUnhandledExceptionFilter, -1)
- FF(LoadLibraryA, -1)
- FF(GetProcAddress, -1)
- FF(FreeLibrary, -1)
- FF(CreateFileMappingA, -1)
- FF(OpenFileMappingA, -1)
- FF(MapViewOfFile, -1)
- FF(UnmapViewOfFile, -1)
- FF(Sleep, -1)
- FF(GetModuleHandleA, -1)
- FF(GetProfileIntA, -1)
- FF(GetPrivateProfileIntA, -1)
- FF(GetPrivateProfileStringA, -1)
- FF(WritePrivateProfileStringA, -1)
- FF(GetLastError, -1)
- FF(SetLastError, -1)
- FF(InterlockedIncrement, -1)
- FF(InterlockedDecrement, -1)
- FF(GetTimeZoneInformation, -1)
- FF(OutputDebugStringA, -1)
- FF(GetLocalTime, -1)
- FF(GetSystemTime, -1)
- FF(GetSystemTimeAsFileTime, -1)
- FF(GetEnvironmentVariableA, -1)
- FF(SetEnvironmentVariableA, -1)
- FF(RtlZeroMemory,-1)
- FF(RtlMoveMemory,-1)
- FF(RtlFillMemory,-1)
- FF(GetTempPathA,-1)
- FF(FindFirstFileA,-1)
- FF(FindNextFileA,-1)
- FF(FindClose,-1)
- FF(FileTimeToLocalFileTime,-1)
- FF(DeleteFileA,-1)
- FF(ReadFile,-1)
- FF(WriteFile,-1)
- FF(SetFilePointer,-1)
- FF(GetTempFileNameA,-1)
- FF(CreateFileA,-1)
- FF(GetSystemDirectoryA,-1)
- FF(GetWindowsDirectoryA,-1)
- #ifdef QTX
- FF(GetCurrentDirectoryA,-1)
- FF(SetCurrentDirectoryA,-1)
- FF(CreateDirectoryA,-1)
- #endif
- FF(GetShortPathNameA,-1)
- FF(GetFullPathNameA,-1)
- FF(SetErrorMode, -1)
- FF(IsProcessorFeaturePresent, -1)
- FF(GetProcessAffinityMask, -1)
- FF(InterlockedExchange, -1)
- FF(InterlockedCompareExchange, -1)
- FF(MulDiv, -1)
- FF(lstrcmpiA, -1)
- FF(lstrlenA, -1)
- FF(lstrcpyA, -1)
- FF(lstrcatA, -1)
- FF(lstrcpynA,-1)
- FF(GetProcessVersion,-1)
- FF(GetCurrentThread,-1)
- FF(GetOEMCP,-1)
- FF(GetCPInfo,-1)
- FF(DuplicateHandle,-1)
- FF(GetTickCount, -1)
- FF(SetThreadAffinityMask,-1)
- FF(GetCurrentProcessId,-1)
- FF(GlobalMemoryStatus,-1)
- FF(SetThreadPriority,-1)
- FF(ExitProcess,-1)
- {"LoadLibraryExA", -1, (void*)&LoadLibraryExA},
- FF(SetThreadIdealProcessor,-1)
- };
- struct exports exp_msvcrt[]={
- FF(malloc, -1)
- FF(_initterm, -1)
- FF(__dllonexit, -1)
- FF(_snprintf,-1)
- FF(free, -1)
- {"??3@YAXPAX@Z", -1, expdelete},
- {"??2@YAPAXI@Z", -1, expnew},
- {"_adjust_fdiv", -1, (void*)&_adjust_fdiv},
- FF(strrchr, -1)
- FF(strchr, -1)
- FF(strlen, -1)
- FF(strcpy, -1)
- FF(strncpy, -1)
- FF(wcscpy, -1)
- FF(strcmp, -1)
- FF(strncmp, -1)
- FF(strcat, -1)
- FF(_stricmp,-1)
- FF(_strdup,-1)
- FF(_setjmp3,-1)
- FF(isalnum, -1)
- FF(isspace, -1)
- FF(isalpha, -1)
- FF(isdigit, -1)
- FF(memmove, -1)
- FF(memcmp, -1)
- FF(memset, -1)
- FF(memcpy, -1)
- FF(time, -1)
- FF(rand, -1)
- FF(srand, -1)
- FF(log10, -1)
- FF(pow, -1)
- FF(cos, -1)
- FF(_ftol,-1)
- FF(_CIpow,-1)
- FF(_CIcos,-1)
- FF(_CIsin,-1)
- FF(ldexp,-1)
- FF(frexp,-1)
- FF(sprintf,-1)
- FF(sscanf,-1)
- FF(fopen,-1)
- FF(fprintf,-1)
- FF(printf,-1)
- FF(getenv,-1)
- FF(floor,-1)
- /* needed by frapsvid.dll */
- {"strstr",-1,(char *)&strstr},
- {"qsort",-1,(void *)&qsort},
- #ifdef MPLAYER
- FF(_EH_prolog,-1)
- #endif
- FF(calloc,-1)
- {"ceil",-1,(void*)&ceil},
- /* needed by imagepower mjpeg2k */
- {"clock",-1,(void*)&clock},
- {"memchr",-1,(void*)&memchr},
- {"vfprintf",-1,(void*)&vfprintf},
- // {"realloc",-1,(void*)&realloc},
- FF(realloc,-1)
- {"puts",-1,(void*)&puts}
- };
- struct exports exp_winmm[]={
- FF(GetDriverModuleHandle, -1)
- FF(timeGetTime, -1)
- FF(DefDriverProc, -1)
- FF(OpenDriverA, -1)
- FF(OpenDriver, -1)
- FF(timeGetDevCaps, -1)
- FF(timeBeginPeriod, -1)
- #ifdef QTX
- FF(timeEndPeriod, -1)
- FF(waveOutGetNumDevs, -1)
- #endif
- };
- struct exports exp_user32[]={
- FF(LoadIconA,-1)
- FF(LoadStringA, -1)
- FF(wsprintfA, -1)
- FF(GetDC, -1)
- FF(GetDesktopWindow, -1)
- FF(ReleaseDC, -1)
- FF(IsRectEmpty, -1)
- FF(LoadCursorA,-1)
- FF(SetCursor,-1)
- FF(GetCursorPos,-1)
- #ifdef QTX
- FF(ShowCursor,-1)
- #endif
- FF(RegisterWindowMessageA,-1)
- FF(GetSystemMetrics,-1)
- FF(GetSysColor,-1)
- FF(GetSysColorBrush,-1)
- FF(GetWindowDC, -1)
- FF(DrawTextA, -1)
- FF(MessageBoxA, -1)
- FF(RegisterClassA, -1)
- FF(UnregisterClassA, -1)
- #ifdef QTX
- FF(GetWindowRect, -1)
- FF(MonitorFromWindow, -1)
- FF(MonitorFromRect, -1)
- FF(MonitorFromPoint, -1)
- FF(EnumDisplayMonitors, -1)
- FF(GetMonitorInfoA, -1)
- FF(EnumDisplayDevicesA, -1)
- FF(GetClientRect, -1)
- FF(ClientToScreen, -1)
- FF(IsWindowVisible, -1)
- FF(GetActiveWindow, -1)
- FF(GetClassNameA, -1)
- FF(GetClassInfoA, -1)
- FF(GetWindowLongA, -1)
- FF(EnumWindows, -1)
- FF(GetWindowThreadProcessId, -1)
- FF(CreateWindowExA, -1)
- #endif
- FF(MessageBeep, -1)
- FF(DialogBoxParamA, -1)
- };
- struct exports exp_advapi32[]={
- FF(RegCloseKey, -1)
- FF(RegCreateKeyA, -1)
- FF(RegCreateKeyExA, -1)
- FF(RegEnumKeyExA, -1)
- FF(RegEnumValueA, -1)
- FF(RegOpenKeyA, -1)
- FF(RegOpenKeyExA, -1)
- FF(RegQueryValueExA, -1)
- FF(RegSetValueExA, -1)
- FF(RegQueryInfoKeyA, -1)
- };
- struct exports exp_gdi32[]={
- FF(CreateCompatibleDC, -1)
- FF(CreateFontA, -1)
- FF(DeleteDC, -1)
- FF(DeleteObject, -1)
- FF(GetDeviceCaps, -1)
- FF(GetSystemPaletteEntries, -1)
- #ifdef QTX
- FF(CreatePalette, -1)
- FF(GetObjectA, -1)
- FF(CreateRectRgn, -1)
- #endif
- };
- struct exports exp_version[]={
- FF(GetFileVersionInfoSizeA, -1)
- };
- struct exports exp_ole32[]={
- FF(CoCreateFreeThreadedMarshaler,-1)
- FF(CoCreateInstance, -1)
- FF(CoInitialize, -1)
- FF(CoTaskMemAlloc, -1)
- FF(CoTaskMemFree, -1)
- FF(StringFromGUID2, -1)
- };
- // do we really need crtdll ???
- // msvcrt is the correct place probably...
- struct exports exp_crtdll[]={
- FF(memcpy, -1)
- FF(wcscpy, -1)
- };
- struct exports exp_comctl32[]={
- FF(StringFromGUID2, -1)
- FF(InitCommonControls, 17)
- #ifdef QTX
- FF(CreateUpDownControl, 16)
- #endif
- };
- struct exports exp_wsock32[]={
- FF(htonl,8)
- FF(ntohl,14)
- };
- struct exports exp_msdmo[]={
- FF(memcpy, -1) // just test
- FF(MoCopyMediaType, -1)
- FF(MoCreateMediaType, -1)
- FF(MoDeleteMediaType, -1)
- FF(MoDuplicateMediaType, -1)
- FF(MoFreeMediaType, -1)
- FF(MoInitMediaType, -1)
- };
- struct exports exp_oleaut32[]={
- FF(VariantInit, 8)
- #ifdef QTX
- FF(SysStringByteLen, 149)
- #endif
- };
- /* realplayer8:
- DLL Name: PNCRT.dll
- vma: Hint/Ord Member-Name
- 22ff4 615 free
- 2302e 250 _ftol
- 22fea 666 malloc
- 2303e 609 fprintf
- 2305e 167 _adjust_fdiv
- 23052 280 _initterm
- 22ffc 176 _beginthreadex
- 23036 284 _iob
- 2300e 85 __CxxFrameHandler
- 23022 411 _purecall
- */
- #ifdef REALPLAYER
- struct exports exp_pncrt[]={
- FF(malloc, -1) // just test
- FF(free, -1) // just test
- FF(fprintf, -1) // just test
- {"_adjust_fdiv", -1, (void*)&_adjust_fdiv},
- FF(_ftol,-1)
- FF(_initterm, -1)
- {"??3@YAXPAX@Z", -1, expdelete},
- {"??2@YAPAXI@Z", -1, expnew},
- FF(__dllonexit, -1)
- FF(strncpy, -1)
- FF(_CIpow,-1)
- FF(calloc,-1)
- FF(memmove, -1)
- };
- #endif
- #ifdef QTX
- struct exports exp_ddraw[]={
- FF(DirectDrawCreate, -1)
- };
- #endif
- struct exports exp_comdlg32[]={
- FF(GetOpenFileNameA, -1)
- };
- #define LL(X)
- {#X".dll", sizeof(exp_##X)/sizeof(struct exports), exp_##X},
- struct libs libraries[]={
- LL(kernel32)
- LL(msvcrt)
- LL(winmm)
- LL(user32)
- LL(advapi32)
- LL(gdi32)
- LL(version)
- LL(ole32)
- LL(oleaut32)
- LL(crtdll)
- LL(comctl32)
- LL(wsock32)
- LL(msdmo)
- #ifdef REALPLAYER
- LL(pncrt)
- #endif
- #ifdef QTX
- LL(ddraw)
- #endif
- LL(comdlg32)
- };
- static void ext_stubs(void)
- {
- // expects:
- // ax position index
- // cx address of printf function
- #if 1
- __asm__ __volatile__
- (
- "push %%edx nt"
- "movl $0xdeadbeef, %%eax nt"
- "movl $0xdeadbeef, %%edx nt"
- "shl $5, %%eax nt" // ax * 32
- "addl $0xdeadbeef, %%eax nt" // overwrite export_names
- "pushl %%eax nt"
- "pushl $0xdeadbeef nt" // overwrite called_unk
- "call *%%edx nt" // printf (via dx)
- "addl $8, %%esp nt"
- "xorl %%eax, %%eax nt"
- "pop %%edx nt"
- :
- :
- : "eax"
- );
- #else
- __asm__ __volatile__
- (
- "push %%edx nt"
- "movl $0, %%eax nt"
- "movl $0, %%edx nt"
- "shl $5, %%eax nt" // ax * 32
- "addl %0, %%eax nt"
- "pushl %%eax nt"
- "pushl %1 nt"
- "call *%%edx nt" // printf (via dx)
- "addl $8, %%esp nt"
- "xorl %%eax, %%eax nt"
- "pop %%edx nt"
- ::"m"(*export_names), "m"(*called_unk)
- : "memory", "edx", "eax"
- );
- #endif
- }
- //static void add_stub(int pos)
- extern int unk_exp1;
- static int pos=0;
- static char extcode[20000];// place for 200 unresolved exports
- static const char* called_unk = "Called unk_%sn";
- static void* add_stub(void)
- {
- // generated code in runtime!
- char* answ = (char*)extcode+pos*0x30;
- #if 0
- memcpy(answ, &unk_exp1, 0x64);
- *(int*)(answ+9)=pos;
- *(int*)(answ+47)-=((int)answ-(int)&unk_exp1);
- #endif
- memcpy(answ, ext_stubs, 0x2f); // 0x2c is current size
- //answ[4] = 0xb8; // movl $0, eax (0xb8 0x00000000)
- *((int*) (answ + 5)) = pos;
- //answ[9] = 0xba; // movl $0, edx (0xba 0x00000000)
- *((long*) (answ + 10)) = (long)printf;
- //answ[17] = 0x05; // addl $0, eax (0x05 0x00000000)
- *((long*) (answ + 18)) = (long)export_names;
- //answ[23] = 0x68; // pushl $0 (0x68 0x00000000)
- *((long*) (answ + 24)) = (long)called_unk;
- pos++;
- return (void*)answ;
- }
- void* LookupExternal(const char* library, int ordinal)
- {
- int i,j;
- if(library==0)
- {
- printf("ERROR: library=0n");
- return (void*)ext_unknown;
- }
- // printf("%x %xn", &unk_exp1, &unk_exp2);
- dbgprintf("External func %s:%dn", library, ordinal);
- for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++)
- {
- if(strcasecmp(library, libraries[i].name))
- continue;
- for(j=0; j<libraries[i].length; j++)
- {
- if(ordinal!=libraries[i].exps[j].id)
- continue;
- //printf("Hit: 0x%pn", libraries[i].exps[j].func);
- return libraries[i].exps[j].func;
- }
- }
- #ifndef LOADLIB_TRY_NATIVE
- /* hack for truespeech and vssh264*/
- if (!strcmp(library, "tsd32.dll") || !strcmp(library,"vssh264dec.dll") || !strcmp(library,"LCMW2.dll") || !strcmp(library,"VDODEC32.dll"))
- #endif
- /* ok, this is a hack, and a big memory leak. should be fixed. - alex */
- {
- int hand;
- WINE_MODREF *wm;
- void *func;
- hand = LoadLibraryA(library);
- if (!hand)
- goto no_dll;
- wm = MODULE32_LookupHMODULE(hand);
- if (!wm)
- {
- FreeLibrary(hand);
- goto no_dll;
- }
- func = PE_FindExportedFunction(wm, (LPCSTR) ordinal, 0);
- if (!func)
- {
- printf("No such ordinal in external dlln");
- FreeLibrary((int)hand);
- goto no_dll;
- }
- printf("External dll loaded (offset: 0x%x, func: %p)n",
- hand, func);
- return func;
- }
- no_dll:
- if(pos>150)return 0;
- sprintf(export_names[pos], "%s:%d", library, ordinal);
- return add_stub();
- }
- void* LookupExternalByName(const char* library, const char* name)
- {
- char* answ;
- int i,j;
- // return (void*)ext_unknown;
- if(library==0)
- {
- printf("ERROR: library=0n");
- return (void*)ext_unknown;
- }
- if(name==0)
- {
- printf("ERROR: name=0n");
- return (void*)ext_unknown;
- }
- dbgprintf("External func %s:%sn", library, name);
- for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++)
- {
- if(strcasecmp(library, libraries[i].name))
- continue;
- for(j=0; j<libraries[i].length; j++)
- {
- if(strcmp(name, libraries[i].exps[j].name))
- continue;
- // printf("Hit: 0x%08Xn", libraries[i].exps[j].func);
- return libraries[i].exps[j].func;
- }
- }
- #ifndef LOADLIB_TRY_NATIVE
- /* hack for vss h264 */
- if (!strcmp(library,"vssh264core.dll"))
- #endif
- /* ok, this is a hack, and a big memory leak. should be fixed. - alex */
- {
- int hand;
- WINE_MODREF *wm;
- void *func;
- hand = LoadLibraryA(library);
- if (!hand)
- goto no_dll_byname;
- wm = MODULE32_LookupHMODULE(hand);
- if (!wm)
- {
- FreeLibrary(hand);
- goto no_dll_byname;
- }
- func = PE_FindExportedFunction(wm, name, 0);
- if (!func)
- {
- printf("No such name in external dlln");
- FreeLibrary((int)hand);
- goto no_dll_byname;
- }
- printf("External dll loaded (offset: 0x%x, func: %p)n",
- hand, func);
- return func;
- }
- no_dll_byname:
- if(pos>150)return 0;// to many symbols
- strcpy(export_names[pos], name);
- return add_stub();
- }
- void my_garbagecollection(void)
- {
- #ifdef GARBAGE
- int unfree = 0, unfreecnt = 0;
- int max_fatal = 8;
- free_registry();
- while (last_alloc)
- {
- alloc_header* mem = last_alloc + 1;
- unfree += my_size(mem);
- unfreecnt++;
- if (my_release(mem) != 0)
- // avoid endless loop when memory is trashed
- if (--max_fatal < 0)
- break;
- }
- dbgprintf("Total Unfree %d bytes cnt %d [%p,%d]n",unfree, unfreecnt, last_alloc, alccnt);
- #endif
- g_tls = NULL;
- list = NULL;
- }