/****************************************************************** * module_get_type_by_name * * Guesses a filename type from its extension */ enum module_type module_get_type_by_name(const WCHAR* name) { int loader_len, len = strlenW(name); const WCHAR *loader; /* Skip all version extensions (.[digits]) regex: "(\.\d+)*$" */ do { int i = len; while (i && isdigit(name[i - 1])) i--; if (i && name[i - 1] == '.') len = i - 1; else break; } while (len); /* check for terminating .so or .so.[digit] */ /* FIXME: Can't rely solely on extension; have to check magic or * stop using .so on Mac OS X. For now, base on platform. */ if (len > 3 && !memcmp(name + len - 3, S_DotSoW, 3)) #ifdef __APPLE__ return DMT_MACHO; #else return DMT_ELF; #endif if (len > 6 && !strncmpiW(name + len - 6, S_DotDylibW, 6)) return DMT_MACHO; if (len > 4 && !strncmpiW(name + len - 4, S_DotPdbW, 4)) return DMT_PDB; if (len > 4 && !strncmpiW(name + len - 4, S_DotDbgW, 4)) return DMT_DBG; /* wine is also a native module (Mach-O on Mac OS X, ELF elsewhere) */ loader = get_wine_loader_name(); loader_len = strlenW( loader ); if ((len == loader_len || (len > loader_len && name[len - loader_len - 1] == '/')) && !strcmpiW(name + len - loader_len, loader)) { #ifdef __APPLE__ return DMT_MACHO; #else return DMT_ELF; #endif } return DMT_PE; }
static void module_fill_module(const WCHAR* in, WCHAR* out, size_t size) { const WCHAR *loader = get_wine_loader_name(); const WCHAR *ptr, *endptr; size_t len, l; ptr = get_filename(in, endptr = in + strlenW(in)); len = min(endptr - ptr, size - 1); memcpy(out, ptr, len * sizeof(WCHAR)); out[len] = '\0'; if (len > 4 && (l = match_ext(out, len))) out[len - l] = '\0'; else if (len > strlenW(loader) && !strcmpiW(out + len - strlenW(loader), loader)) lstrcpynW(out, S_WineLoaderW, size); else { if (len > 3 && !strcmpiW(&out[len - 3], S_DotSoW) && (l = match_ext(out, len - 3))) strcpyW(&out[len - l - 3], S_ElfW); } while ((*out = tolowerW(*out))) out++; }
/****************************************************************** * macho_search_loader * * Lookup in a running Mach-O process the loader, and sets its Mach-O link * address (for accessing the list of loaded images) in pcs. * If flags is MACHO_INFO_MODULE, the module for the loader is also * added as a module into pcs. */ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_info) { return macho_search_and_load_file(pcs, get_wine_loader_name(), 0, macho_info); }