/* try to load a pre-compiled fake dll */ static void *load_fake_dll( const WCHAR *name, SIZE_T *size ) { const char *build_dir = wine_get_build_dir(); const char *path; char *file, *ptr; void *data = NULL; unsigned int i, pos, len, namelen, maxlen = 0; WCHAR *p; int res = 0; if ((p = strrchrW( name, '\\' ))) name = p + 1; i = 0; len = strlenW( name ); if (build_dir) maxlen = strlen(build_dir) + sizeof("/programs/") + len; while ((path = wine_dll_enum_load_path( i++ ))) maxlen = max( maxlen, strlen(path) ); maxlen += sizeof("/fakedlls") + len + sizeof(".fake"); if (!(file = HeapAlloc( GetProcessHeap(), 0, maxlen ))) return NULL; pos = maxlen - len - sizeof(".fake"); if (!dll_name_WtoA( file + pos, name, len )) goto done; file[--pos] = '/'; if (build_dir) { strcpy( file + pos + len + 1, ".fake" ); /* try as a dll */ ptr = file + pos; namelen = len + 1; if (namelen > 4 && !memcmp( ptr + namelen - 4, ".dll", 4 )) namelen -= 4; ptr = prepend( ptr, ptr, namelen ); ptr = prepend( ptr, "/dlls", sizeof("/dlls") - 1 ); ptr = prepend( ptr, build_dir, strlen(build_dir) ); if ((res = read_file( ptr, &data, size ))) goto done; /* now as a program */ ptr = file + pos; namelen = len + 1; if (namelen > 4 && !memcmp( ptr + namelen - 4, ".exe", 4 )) namelen -= 4; ptr = prepend( ptr, ptr, namelen ); ptr = prepend( ptr, "/programs", sizeof("/programs") - 1 ); ptr = prepend( ptr, build_dir, strlen(build_dir) ); if ((res = read_file( ptr, &data, size ))) goto done; } file[pos + len + 1] = 0; for (i = 0; (path = wine_dll_enum_load_path( i )); i++) { ptr = prepend( file + pos, "/fakedlls", sizeof("/fakedlls") - 1 ); ptr = prepend( ptr, path, strlen(path) ); if ((res = read_file( ptr, &data, size ))) break; } done: HeapFree( GetProcessHeap(), 0, file ); if (res == 1) return data; return NULL; }
/****************************************************************** * macho_load_file_from_dll_path * * Tries to load a Mach-O file from the dll path */ static BOOL macho_load_file_from_dll_path(HANDLE hProcess, const WCHAR* filename, unsigned long load_addr, struct macho_info* macho_info) { BOOL ret = FALSE; unsigned int index = 0; const char *path; TRACE("(%p, %s, 0x%08lx, %p)\n", hProcess, debugstr_w(filename), load_addr, macho_info); while (!ret && (path = wine_dll_enum_load_path( index++ ))) { WCHAR *name; unsigned len; len = MultiByteToWideChar(CP_UNIXCP, 0, path, -1, NULL, 0); name = HeapAlloc( GetProcessHeap(), 0, (len + lstrlenW(filename) + 2) * sizeof(WCHAR) ); if (!name) break; MultiByteToWideChar(CP_UNIXCP, 0, path, -1, name, len); strcatW( name, S_SlashW ); strcatW( name, filename ); ret = macho_load_file(hProcess, name, load_addr, macho_info); HeapFree( GetProcessHeap(), 0, name ); } TRACE(" => %d\n", ret); return ret; }
/* create fake dlls in dirname for all the files we can find */ static BOOL create_wildcard_dlls( const WCHAR *dirname ) { const char *build_dir = wine_get_build_dir(); const char *path; unsigned int i, maxlen = 0; char *file; WCHAR *dest; if (build_dir) maxlen = strlen(build_dir) + sizeof("/programs/"); for (i = 0; (path = wine_dll_enum_load_path(i)); i++) maxlen = max( maxlen, strlen(path) ); maxlen += 2 * max_dll_name_len + 2 + sizeof(".dll.fake"); if (!(file = HeapAlloc( GetProcessHeap(), 0, maxlen ))) return FALSE; if (!(dest = HeapAlloc( GetProcessHeap(), 0, (strlenW(dirname) + max_dll_name_len) * sizeof(WCHAR) ))) { HeapFree( GetProcessHeap(), 0, file ); return FALSE; } strcpyW( dest, dirname ); dest[strlenW(dest) - 1] = 0; /* remove wildcard */ if (build_dir) { strcpy( file, build_dir ); strcat( file, "/dlls" ); install_lib_dir( dest, file, ".dll" ); strcpy( file, build_dir ); strcat( file, "/programs" ); install_lib_dir( dest, file, ".exe" ); } for (i = 0; (path = wine_dll_enum_load_path( i )); i++) { strcpy( file, path ); strcat( file, "/fakedlls" ); install_lib_dir( dest, file, NULL ); } HeapFree( GetProcessHeap(), 0, file ); HeapFree( GetProcessHeap(), 0, dest ); return TRUE; }
/* load the list of available libraries */ static void load_library_list( HWND dialog ) { unsigned int i = 0; const char *path, *build_dir = wine_get_build_dir(); char item1[256], item2[256]; HCURSOR old_cursor = SetCursor( LoadCursorW(0, (LPWSTR)IDC_WAIT) ); if (build_dir) { char *dir = HeapAlloc( GetProcessHeap(), 0, strlen(build_dir) + sizeof("/dlls") ); strcpy( dir, build_dir ); strcat( dir, "/dlls" ); load_library_list_from_dir( dialog, dir, TRUE ); HeapFree( GetProcessHeap(), 0, dir ); } while ((path = wine_dll_enum_load_path( i++ ))) load_library_list_from_dir( dialog, path, FALSE ); /* get rid of duplicate entries */ SendDlgItemMessageA( dialog, IDC_DLLCOMBO, CB_GETLBTEXT, 0, (LPARAM)item1 ); i = 1; while (SendDlgItemMessageA( dialog, IDC_DLLCOMBO, CB_GETLBTEXT, i, (LPARAM)item2 ) >= 0) { if (!strcmp( item1, item2 )) { SendDlgItemMessageA( dialog, IDC_DLLCOMBO, CB_DELETESTRING, i, 0 ); } else { strcpy( item1, item2 ); i++; } } SetCursor( old_cursor ); }