/*********************************************************************** * MSACM_RegisterAllDrivers() */ void MSACM_RegisterAllDrivers(void) { static const WCHAR msacm32[] = {'m','s','a','c','m','3','2','.','d','l','l','\0'}; static const WCHAR msacmW[] = {'M','S','A','C','M','.'}; static const WCHAR drv32[] = {'d','r','i','v','e','r','s','3','2','\0'}; static const WCHAR sys[] = {'s','y','s','t','e','m','.','i','n','i','\0'}; static const WCHAR drvkey[] = {'S','o','f','t','w','a','r','e','\\', 'M','i','c','r','o','s','o','f','t','\\', 'W','i','n','d','o','w','s',' ','N','T','\\', 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', 'D','r','i','v','e','r','s','3','2','\0'}; DWORD i, cnt, bufLen, lRet, type; WCHAR buf[2048], valname[64], *name, *s; FILETIME lastWrite; HKEY hKey; /* FIXME: What if the user edits system.ini while the program is running? * Does Windows handle that? */ if (MSACM_pFirstACMDriverID) return; lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, drvkey, 0, KEY_QUERY_VALUE, &hKey); if (lRet == ERROR_SUCCESS) { RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0); for (i = 0; i < cnt; i++) { bufLen = sizeof(buf) / sizeof(buf[0]); lRet = RegEnumKeyExW(hKey, i, buf, &bufLen, 0, 0, 0, &lastWrite); if (lRet != ERROR_SUCCESS) continue; if (strncmpiW(buf, msacmW, sizeof(msacmW)/sizeof(msacmW[0]))) continue; if (!(name = strchrW(buf, '='))) continue; *name = 0; MSACM_RegisterDriver(buf, name + 1, 0); } i = 0; cnt = sizeof(valname) / sizeof(*valname); bufLen = sizeof(buf); while(RegEnumValueW(hKey, i, valname, &cnt, 0, &type, (BYTE*)buf, &bufLen) == ERROR_SUCCESS){ if(!strncmpiW(valname, msacmW, sizeof(msacmW) / sizeof(*msacmW))) MSACM_RegisterDriver(valname, buf, 0); ++i; } RegCloseKey( hKey ); } if (GetPrivateProfileSectionW(drv32, buf, sizeof(buf)/sizeof(buf[0]), sys)) { for(s = buf; *s; s += strlenW(s) + 1) { if (strncmpiW(s, msacmW, sizeof(msacmW)/sizeof(msacmW[0]))) continue; if (!(name = strchrW(s, '='))) continue; *name = 0; MSACM_RegisterDriver(s, name + 1, 0); *name = '='; } } MSACM_ReorderDriversByPriority(); MSACM_RegisterDriver(msacm32, msacm32, 0); }
static BOOL use_gecko_script(LPCWSTR url) { static const WCHAR fileW[] = {'f','i','l','e',':'}; static const WCHAR aboutW[] = {'a','b','o','u','t',':'}; static const WCHAR resW[] = {'r','e','s',':'}; return strncmpiW(fileW, url, sizeof(fileW)/sizeof(WCHAR)) && strncmpiW(aboutW, url, sizeof(aboutW)/sizeof(WCHAR)) && strncmpiW(resW, url, sizeof(resW)/sizeof(WCHAR)); }
/****************************************************************** * 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 LPCWSTR skip_schema(LPCWSTR url) { static const WCHAR its_schema[] = {'i','t','s',':'}; static const WCHAR msits_schema[] = {'m','s','-','i','t','s',':'}; static const WCHAR mk_schema[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':'}; if(!strncmpiW(its_schema, url, sizeof(its_schema)/sizeof(WCHAR))) return url+sizeof(its_schema)/sizeof(WCHAR); if(!strncmpiW(msits_schema, url, sizeof(msits_schema)/sizeof(WCHAR))) return url+sizeof(msits_schema)/sizeof(WCHAR); if(!strncmpiW(mk_schema, url, sizeof(mk_schema)/sizeof(WCHAR))) return url+sizeof(mk_schema)/sizeof(WCHAR); return NULL; }
static INT build_domain(PLSA_REFERENCED_DOMAIN_LIST currentList, PLSA_UNICODE_STRING domain) { ULONG count; ULONG sid_size = 0,domain_size = 0; BOOL handled = FALSE; SID_NAME_USE use; for (count = 0; count < currentList->Entries; count ++) { if ((currentList->Domains[count].Name.Length == domain->Length) && (strncmpiW(currentList->Domains[count].Name.Buffer,domain->Buffer,(domain->Length / sizeof(WCHAR))) == 0)) { HeapFree(GetProcessHeap(),0,domain->Buffer); return count; } } if (currentList->Entries > 0) currentList->Domains = HeapReAlloc(GetProcessHeap(),0,currentList->Domains, (currentList->Entries + 1) * sizeof(LSA_TRUST_INFORMATION)); else currentList->Domains = HeapAlloc(GetProcessHeap(),0,sizeof(LSA_TRUST_INFORMATION)); currentList->Domains[currentList->Entries].Name = *domain; lookup_name( domain, NULL, &sid_size, NULL, &domain_size, &use, &handled ); domain_size = 0; currentList->Domains[currentList->Entries].Sid = HeapAlloc(GetProcessHeap(),0,sid_size); lookup_name( domain, currentList->Domains[currentList->Entries].Sid, &sid_size, NULL, &domain_size, &use, &handled ); currentList->Entries++; return currentList->Entries-1; }
/****************************************************************** * module_is_container_loaded * * checks whether the native container, for a (supposed) PE builtin is * already loaded */ static BOOL module_is_container_loaded(const struct process* pcs, const WCHAR* ImageName, DWORD64 base) { size_t len; struct module* module; PCWSTR filename, modname; if (!base) return FALSE; filename = get_filename(ImageName, NULL); len = strlenW(filename); for (module = pcs->lmodules; module; module = module->next) { if ((module->type == DMT_ELF || module->type == DMT_MACHO) && base >= module->module.BaseOfImage && base < module->module.BaseOfImage + module->module.ImageSize) { modname = get_filename(module->module.LoadedImageName, NULL); if (!strncmpiW(modname, filename, len) && !memcmp(modname + len, S_DotSoW, 3 * sizeof(WCHAR))) { return TRUE; } } } /* likely a native PE module */ WARN("Couldn't find container for %s\n", debugstr_w(ImageName)); return FALSE; }
static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p) { HTMLImgElement *This = impl_from_IHTMLImgElement(iface); const PRUnichar *src; nsAString src_str; nsresult nsres; HRESULT hres = S_OK; static const WCHAR blockedW[] = {'B','L','O','C','K','E','D',':',':',0}; TRACE("(%p)->(%p)\n", This, p); nsAString_Init(&src_str, NULL); nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str); if(NS_SUCCEEDED(nsres)) { nsAString_GetData(&src_str, &src); if(!strncmpiW(src, blockedW, sizeof(blockedW)/sizeof(WCHAR)-1)) { TRACE("returning BLOCKED::\n"); *p = SysAllocString(blockedW); if(!*p) hres = E_OUTOFMEMORY; }else { hres = nsuri_to_url(src, TRUE, p); } }else { ERR("GetSrc failed: %08x\n", nsres); hres = E_FAIL; } nsAString_Finish(&src_str); return hres; }
static HRESULT write_predefined_strings(HMODULE hm, LPCWSTR ini_path) { WCHAR mod_path[MAX_PATH + 2]; WCHAR sys_mod_path[MAX_PATH + 2]; WCHAR sys_root[MAX_PATH]; *mod_path = '\"'; if (!GetModuleFileNameW(hm, mod_path + 1, sizeof(mod_path) / sizeof(WCHAR) - 2)) return E_FAIL; lstrcatW(mod_path, quote); WritePrivateProfileStringW(Strings, MOD_PATH, mod_path, ini_path); *sys_root = '\0'; GetEnvironmentVariableW(SystemRoot, sys_root, sizeof(sys_root) / sizeof(WCHAR)); if(!strncmpiW(sys_root, mod_path + 1, strlenW(sys_root))) { *sys_mod_path = '\"'; strcpyW(sys_mod_path + 1, escaped_SystemRoot); strcatW(sys_mod_path, mod_path + 1 + strlenW(sys_root)); } else { FIXME("SYS_MOD_PATH needs more work\n"); strcpyW(sys_mod_path, mod_path); } WritePrivateProfileStringW(Strings, SYS_MOD_PATH, sys_mod_path, ini_path); return S_OK; }
static void expand_command(install_ctx_t *ctx, const WCHAR *cmd, WCHAR *buf, size_t *size) { const WCHAR *ptr = cmd, *prev_ptr = cmd; size_t len = 0, len2; static const WCHAR expand_dirW[] = {'%','E','X','T','R','A','C','T','_','D','I','R','%'}; while((ptr = strchrW(ptr, '%'))) { if(buf) memcpy(buf+len, prev_ptr, ptr-prev_ptr); len += ptr-prev_ptr; if(!strncmpiW(ptr, expand_dirW, sizeof(expand_dirW)/sizeof(WCHAR))) { len2 = strlenW(ctx->tmp_dir); if(buf) memcpy(buf+len, ctx->tmp_dir, len2*sizeof(WCHAR)); len += len2; ptr += sizeof(expand_dirW)/sizeof(WCHAR); }else { FIXME("Can't expand %s\n", debugstr_w(ptr)); if(buf) buf[len] = '%'; len++; ptr++; } prev_ptr = ptr; } if(buf) strcpyW(buf+len, prev_ptr); *size = len + strlenW(prev_ptr) + 1; }
/*********************************************************************** * MSACM_RegisterDriverFromRegistry() */ PWINE_ACMDRIVERID MSACM_RegisterDriverFromRegistry(LPCWSTR pszRegEntry) { static const WCHAR msacmW[] = {'M','S','A','C','M','.'}; static const WCHAR drvkey[] = {'S','o','f','t','w','a','r','e','\\', 'M','i','c','r','o','s','o','f','t','\\', 'W','i','n','d','o','w','s',' ','N','T','\\', 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', 'D','r','i','v','e','r','s','3','2','\0'}; WCHAR buf[2048]; DWORD bufLen, lRet; HKEY hKey; PWINE_ACMDRIVERID padid = NULL; /* The requested registry entry must have the format msacm.XXXXX in order to be recognized in any future sessions of msacm */ if (0 == strncmpiW(buf, msacmW, sizeof(msacmW)/sizeof(WCHAR))) { lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, drvkey, 0, KEY_QUERY_VALUE, &hKey); if (lRet != ERROR_SUCCESS) { WARN("unable to open registry key - 0x%08x\n", lRet); } else { bufLen = sizeof(buf); lRet = RegQueryValueExW(hKey, pszRegEntry, NULL, NULL, (LPBYTE)buf, &bufLen); if (lRet != ERROR_SUCCESS) { WARN("unable to query requested subkey %s - 0x%08x\n", debugstr_w(pszRegEntry), lRet); } else { MSACM_RegisterDriver(pszRegEntry, buf, 0); } RegCloseKey( hKey ); } } return padid; }
/* Adds domain info to referenced domain list. Domain list is stored as plain buffer, layout is: LSA_REFERENCED_DOMAIN_LIST, LSA_TRUST_INFORMATION array, domain data array of { domain name data (WCHAR buffer), SID data } Parameters: list [I] referenced list pointer domain [I] domain name string data [IO] pointer to domain data array */ static LONG lsa_reflist_add_domain(LSA_REFERENCED_DOMAIN_LIST *list, LSA_UNICODE_STRING *domain, char **data) { ULONG sid_size = 0,domain_size = 0; BOOL handled = FALSE; SID_NAME_USE use; LONG i; for (i = 0; i < list->Entries; i++) { /* try to reuse index */ if ((list->Domains[i].Name.Length == domain->Length) && (!strncmpiW(list->Domains[i].Name.Buffer, domain->Buffer, (domain->Length / sizeof(WCHAR))))) { return i; } } /* no matching domain found, store name */ list->Domains[list->Entries].Name.Length = domain->Length; list->Domains[list->Entries].Name.MaximumLength = domain->MaximumLength; list->Domains[list->Entries].Name.Buffer = (WCHAR*)*data; memcpy(list->Domains[list->Entries].Name.Buffer, domain->Buffer, domain->MaximumLength); *data += domain->MaximumLength; /* get and store SID data */ list->Domains[list->Entries].Sid = *data; lookup_name(domain, NULL, &sid_size, NULL, &domain_size, &use, &handled); domain_size = 0; lookup_name(domain, list->Domains[list->Entries].Sid, &sid_size, NULL, &domain_size, &use, &handled); *data += sid_size; return list->Entries++; }
static enum content get_content_type(LPCOLESTR name, CLSID *control_id) { WCHAR new_urlW[MAX_PATH]; DWORD size = MAX_PATH; WCHAR mshtml_prefixW[] = {'m','s','h','t','m','l',':','\0'}; if (!name || !name[0]) { WARN("name %s\n", wine_dbgstr_w(name)); return IsEmpty; } if (CLSIDFromString(name, control_id) == S_OK || CLSIDFromProgID(name, control_id) == S_OK) return IsGUID; if (PathIsURLW (name) || UrlApplySchemeW(name, new_urlW, &size, URL_APPLY_GUESSSCHEME|URL_APPLY_GUESSFILE) == S_OK) { *control_id = CLSID_WebBrowser; return IsURL; } if (!strncmpiW(name, mshtml_prefixW, 7)) { FIXME("mshtml prefix not implemented\n"); *control_id = CLSID_WebBrowser; return IsHTML; } return IsUnknown; }
static inline BOOL path_rootname_cmp(const WCHAR *input_path, const WCHAR *rootkey_name) { DWORD length = strlenW(rootkey_name); return (!strncmpiW(input_path, rootkey_name, length) && (input_path[length] == 0 || input_path[length] == '\\')); }
/************************************************************************** * ISF_NetworkPlaces_fnParseDisplayName */ static HRESULT WINAPI ISF_NetworkPlaces_fnParseDisplayName (IShellFolder2 * iface, HWND hwndOwner, LPBC pbcReserved, LPOLESTR lpszDisplayName, DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes) { static const WCHAR wszEntireNetwork[] = {'E','n','t','i','r','e','N','e','t','w','o','r','k'}; /* not nul-terminated */ IGenericSFImpl *This = impl_from_IShellFolder2(iface); HRESULT hr = E_INVALIDARG; LPCWSTR szNext = NULL; WCHAR szElement[MAX_PATH]; LPITEMIDLIST pidlTemp = NULL; int len; TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", This, hwndOwner, pbcReserved, lpszDisplayName, debugstr_w (lpszDisplayName), pchEaten, ppidl, pdwAttributes); *ppidl = NULL; szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH); len = strlenW(szElement); if (len == sizeof(wszEntireNetwork)/sizeof(wszEntireNetwork[0]) && !strncmpiW(szElement, wszEntireNetwork, sizeof(wszEntireNetwork)/sizeof(wszEntireNetwork[0]))) { pidlTemp = _ILCreateEntireNetwork(); if (pidlTemp) hr = S_OK; else hr = E_OUTOFMEMORY; } else FIXME("not implemented for %s\n", debugstr_w(lpszDisplayName)); if (SUCCEEDED(hr) && pidlTemp) { if (szNext && *szNext) { hr = SHELL32_ParseNextElement(iface, hwndOwner, pbcReserved, &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes); } else { if (pdwAttributes && *pdwAttributes) hr = SHELL32_GetItemAttributes((IShellFolder *)&This->IShellFolder2_iface, pidlTemp, pdwAttributes); } } if (SUCCEEDED(hr)) *ppidl = pidlTemp; else ILFree(pidlTemp); TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr); return hr; }
static LPCWSTR COMM_ParseOnOff(LPCWSTR ptr, LPDWORD lponoff) { static const WCHAR onW[] = {'o','n',0}; static const WCHAR offW[] = {'o','f','f',0}; if(!strncmpiW(onW, ptr, 2)) { ptr += 2; *lponoff = 1; } else if(!strncmpiW(offW, ptr, 3)) { ptr += 3; *lponoff = 0; } else return NULL; return ptr; }
static DWORD get_type_from_name(LPCWSTR name) { HANDLE hfile; if (!strncmpiW(name, portname_LPT, sizeof(portname_LPT) / sizeof(WCHAR) -1)) return PORT_IS_LPT; if (!strncmpiW(name, portname_COM, sizeof(portname_COM) / sizeof(WCHAR) -1)) return PORT_IS_COM; if (!strcmpiW(name, portname_FILE)) return PORT_IS_FILE; if (name[0] == '/') return PORT_IS_UNIXNAME; if (name[0] == '|') return PORT_IS_PIPE; if (!strncmpW(name, portname_CUPS, sizeof(portname_CUPS) / sizeof(WCHAR) -1)) return PORT_IS_CUPS; if (!strncmpW(name, portname_LPR, sizeof(portname_LPR) / sizeof(WCHAR) -1)) return PORT_IS_LPR; /* Must be a file or a directory. Does the file exist ? */ hfile = CreateFileW(name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); TRACE("%p for OPEN_EXISTING on %s\n", hfile, debugstr_w(name)); if (hfile == INVALID_HANDLE_VALUE) { /* Can we create the file? */ hfile = CreateFileW(name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL); TRACE("%p for OPEN_ALWAYS\n", hfile); } if (hfile != INVALID_HANDLE_VALUE) { CloseHandle(hfile); return PORT_IS_FILENAME; } /* We can't use the name. use GetLastError() for the reason */ return PORT_IS_UNKNOWN; }
static int match_ext(const WCHAR* ptr, size_t len) { const WCHAR* const *e; size_t l; for (e = ext; *e; e++) { l = strlenW(*e); if (l >= len) return FALSE; if (strncmpiW(&ptr[len - l], *e, l)) continue; return l; } return 0; }
static LPCWSTR ENV_FindVariable(PCWSTR var, PCWSTR name, unsigned namelen) { for (; *var; var += strlenW(var) + 1) { /* match var names, but avoid setting a var with a name including a '=' * (a starting '=' is valid though) */ if (strncmpiW(var, name, namelen) == 0 && var[namelen] == '=' && strchrW(var + 1, '=') == var + namelen) { return var + namelen + 1; } } return NULL; }
/* check if file name matches against one of the files specification */ static BOOL match_files( const WCHAR *name ) { int i; if (!*opt_files) return TRUE; for (i = 0; opt_files[i]; i++) { unsigned int len = strlenW( opt_files[i] ); /* FIXME: do smarter matching, and wildcards */ if (!len) continue; if (strncmpiW( name, opt_files[i], len )) continue; if (opt_files[i][len - 1] == '\\' || !name[len] || name[len] == '\\') return TRUE; } return FALSE; }
/*********************************************************************** * VersionInfo32_FindChild [internal] */ static VS_VERSION_INFO_STRUCT32 *VersionInfo32_FindChild( VS_VERSION_INFO_STRUCT32 *info, LPCWSTR szKey, UINT cbKey ) { VS_VERSION_INFO_STRUCT32 *child = VersionInfo32_Children( info ); while ( (DWORD)child < (DWORD)info + info->wLength ) { if ( !strncmpiW( child->szKey, szKey, cbKey ) ) return child; child = VersionInfo32_Next( child ); } return NULL; }
static BOOL use_gecko_script(HTMLWindow *window) { DWORD zone; HRESULT hres; static const WCHAR aboutW[] = {'a','b','o','u','t',':'}; hres = IInternetSecurityManager_MapUrlToZone(window->secmgr, window->url, &zone, 0); if(FAILED(hres)) { WARN("Could not map %s to zone: %08x\n", debugstr_w(window->url), hres); return TRUE; } TRACE("zone %d\n", zone); return zone != URLZONE_LOCAL_MACHINE && zone != URLZONE_TRUSTED && strncmpiW(aboutW, window->url, sizeof(aboutW)/sizeof(WCHAR)); }
static BOOL parse_ua_compatible(const WCHAR *p, compat_mode_t *r) { static const WCHAR ie_eqW[] = {'I','E','='}; static const WCHAR edgeW[] = {'e','d','g','e',0}; TRACE("%s\n", debugstr_w(p)); if(strncmpiW(ie_eqW, p, ARRAY_SIZE(ie_eqW))) return FALSE; p += 3; if(!strcmpiW(p, edgeW)) { *r = COMPAT_MODE_IE11; return TRUE; } return parse_compat_version(p, r); }
/********************************************************************** * find_entry_by_name * * Find an entry by name in a resource directory * Copied from loader/pe_resource.c */ static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_name( const IMAGE_RESOURCE_DIRECTORY *dir, LPCSTR name, const void *root ) { const IMAGE_RESOURCE_DIRECTORY *ret = NULL; LPWSTR nameW; DWORD namelen; if (!HIWORD(name)) return find_entry_by_id( dir, LOWORD(name), root ); if (name[0] == '#') { return find_entry_by_id( dir, atoi(name+1), root ); } namelen = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 ); if ((nameW = HeapAlloc( GetProcessHeap(), 0, namelen * sizeof(WCHAR) ))) { const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry; const IMAGE_RESOURCE_DIR_STRING_U *str; int min, max, res, pos; MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, namelen ); namelen--; /* remove terminating null */ entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1); min = 0; max = dir->NumberOfNamedEntries - 1; while (min <= max) { pos = (min + max) / 2; str = (const IMAGE_RESOURCE_DIR_STRING_U *)((const char *)root + entry[pos].u.s.NameOffset); res = strncmpiW( nameW, str->NameString, str->Length ); if (!res && namelen == str->Length) { ret = (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + entry[pos].u2.s2.OffsetToDirectory); break; } if (res < 0) max = pos - 1; else min = pos + 1; } HeapFree( GetProcessHeap(), 0, nameW ); } return ret; }
/****************************************************************** * module_is_container_loaded * * checks whether the native container, for a (supposed) PE builtin is * already loaded */ static BOOL module_is_container_loaded(const struct process* pcs, const WCHAR* ImageName, DWORD64 base) { size_t len; struct module* module; PCWSTR filename, modname; static WCHAR* dll_prefix; static int dll_prefix_len; if (!dll_prefix) { dll_prefix_len = MultiByteToWideChar( CP_UNIXCP, 0, DLLPREFIX, -1, NULL, 0 ); dll_prefix = HeapAlloc( GetProcessHeap(), 0, dll_prefix_len * sizeof(WCHAR) ); MultiByteToWideChar( CP_UNIXCP, 0, DLLPREFIX, -1, dll_prefix, dll_prefix_len ); dll_prefix_len--; } if (!base) return FALSE; filename = get_filename(ImageName, NULL); len = strlenW(filename); for (module = pcs->lmodules; module; module = module->next) { if ((module->type == DMT_ELF || module->type == DMT_MACHO) && base >= module->module.BaseOfImage && base < module->module.BaseOfImage + module->module.ImageSize) { modname = get_filename(module->module.LoadedImageName, NULL); if (dll_prefix_len && !strncmpW( modname, dll_prefix, dll_prefix_len )) modname += dll_prefix_len; if (!strncmpiW(modname, filename, len) && !memcmp(modname + len, S_DotSoW, 3 * sizeof(WCHAR))) { return TRUE; } } } /* likely a native PE module */ WARN("Couldn't find container for %s\n", debugstr_w(ImageName)); return FALSE; }
static HRESULT WINAPI ITS_IParseDisplayNameImpl_ParseDisplayName( IParseDisplayName *iface, IBindCtx * pbc, LPOLESTR pszDisplayName, ULONG * pchEaten, IMoniker ** ppmkOut) { static const WCHAR szPrefix[] = { '@','M','S','I','T','S','t','o','r','e',':',0 }; const DWORD prefix_len = (sizeof szPrefix/sizeof szPrefix[0])-1; DWORD n; ITS_IParseDisplayNameImpl *This = impl_from_IParseDisplayName(iface); TRACE("%p %s %p %p\n", This, debugstr_w( pszDisplayName ), pchEaten, ppmkOut ); if( strncmpiW( pszDisplayName, szPrefix, prefix_len ) ) return MK_E_SYNTAX; /* search backwards for a double colon */ for( n = strlenW( pszDisplayName ) - 3; prefix_len <= n; n-- ) if( ( pszDisplayName[n] == ':' ) && ( pszDisplayName[n+1] == ':' ) ) break; if( n < prefix_len ) return MK_E_SYNTAX; if( !pszDisplayName[n+2] ) return MK_E_SYNTAX; *pchEaten = strlenW( pszDisplayName ) - n - 3; return ITS_IMoniker_create( ppmkOut, &pszDisplayName[prefix_len], n-prefix_len ); }
/*********************************************************************** * COMM_Parse* (Internal) * * The following COMM_Parse* functions are used by the BuildCommDCB * functions to help parse the various parts of the device control string. */ static LPCWSTR COMM_ParseStart(LPCWSTR ptr) { static const WCHAR comW[] = {'C','O','M',0}; /* The device control string may optionally start with "COMx" followed by an optional ':' and spaces. */ if(!strncmpiW(ptr, comW, 3)) { ptr += 3; /* Allow any com port above 0 as Win 9x does (NT only allows values for com ports which are actually present) */ if(*ptr < '1' || *ptr > '9') return NULL; /* Advance pointer past port number */ while(*ptr >= '0' && *ptr <= '9') ptr++; /* The com port number must be followed by a ':' or ' ' */ if(*ptr != ':' && *ptr != ' ') return NULL; /* Advance pointer to beginning of next parameter */ while(*ptr == ' ') ptr++; if(*ptr == ':') { ptr++; while(*ptr == ' ') ptr++; } } /* The device control string must not start with a space. */ else if(*ptr == ' ') return NULL; return ptr; }
/*********************************************************************** * HlinkParseDisplayName (HLINK.@) */ HRESULT WINAPI HlinkParseDisplayName(LPBC pibc, LPCWSTR pwzDisplayName, BOOL fNoForceAbs, ULONG *pcchEaten, IMoniker **ppimk) { static const WCHAR file_colonW[] = {'f','i','l','e',':'}; ULONG eaten = 0; HRESULT hres; TRACE("(%p %s %x %p %p)\n", pibc, debugstr_w(pwzDisplayName), fNoForceAbs, pcchEaten, ppimk); if(fNoForceAbs) FIXME("Unsupported fNoForceAbs\n"); if(!strncmpiW(pwzDisplayName, file_colonW, sizeof(file_colonW)/sizeof(WCHAR))) { pwzDisplayName += sizeof(file_colonW)/sizeof(WCHAR); eaten += sizeof(file_colonW)/sizeof(WCHAR); while(*pwzDisplayName == '/') { pwzDisplayName++; eaten++; } }else { hres = MkParseDisplayNameEx(pibc, pwzDisplayName, pcchEaten, ppimk); if(SUCCEEDED(hres)) return hres; hres = MkParseDisplayName(pibc, pwzDisplayName, pcchEaten, ppimk); if(SUCCEEDED(hres)) return hres; } hres = CreateFileMoniker(pwzDisplayName, ppimk); if(SUCCEEDED(hres)) *pcchEaten = eaten + strlenW(pwzDisplayName); return hres; }
/********************************************************************* * _wcsnicoll (MSVCRT.@) */ INT CDECL MSVCRT__wcsnicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2, MSVCRT_size_t count ) { /* FIXME: handle collates */ return strncmpiW( str1, str2, count ); }
/********************************************************************* * _wcsnicmp (NTDLL.@) */ INT __cdecl NTDLL__wcsnicmp( LPCWSTR str1, LPCWSTR str2, INT n ) { return strncmpiW( str1, str2, n ); }
/****************************************************************************** * RtlSetEnvironmentVariable [NTDLL.@] */ NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name, PUNICODE_STRING value) { INT len, old_size; LPWSTR p, env; NTSTATUS nts = STATUS_VARIABLE_NOT_FOUND; MEMORY_BASIC_INFORMATION mbi; TRACE("(%p, %s, %s)\n", penv, debugstr_us(name), debugstr_us(value)); if (!name || !name->Buffer || !name->Length) return STATUS_INVALID_PARAMETER_1; len = name->Length / sizeof(WCHAR); /* variable names can't contain a '=' except as a first character */ for (p = name->Buffer + 1; p < name->Buffer + len; p++) if (*p == '=') return STATUS_INVALID_PARAMETER; if (!penv) { RtlAcquirePebLock(); env = NtCurrentTeb()->Peb->ProcessParameters->Environment; } else env = *penv; /* compute current size of environment */ for (p = env; *p; p += strlenW(p) + 1); old_size = p + 1 - env; /* Find a place to insert the string */ for (p = env; *p; p += strlenW(p) + 1) { if (!strncmpiW(name->Buffer, p, len) && (p[len] == '=')) break; } if (!value && !*p) goto done; /* Value to remove doesn't exist */ /* Realloc the buffer */ len = value ? len + value->Length / sizeof(WCHAR) + 2 : 0; if (*p) len -= strlenW(p) + 1; /* The name already exists */ if (len < 0) { LPWSTR next = p + strlenW(p) + 1; /* We know there is a next one */ memmove(next + len, next, (old_size - (next - env)) * sizeof(WCHAR)); } nts = NtQueryVirtualMemory(NtCurrentProcess(), env, 0, &mbi, sizeof(mbi), NULL); if (nts != STATUS_SUCCESS) goto done; if ((old_size + len) * sizeof(WCHAR) > mbi.RegionSize) { LPWSTR new_env; SIZE_T new_size = (old_size + len) * sizeof(WCHAR); new_env = NULL; nts = NtAllocateVirtualMemory(NtCurrentProcess(), (void**)&new_env, 0, &new_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (nts != STATUS_SUCCESS) goto done; memmove(new_env, env, (p - env) * sizeof(WCHAR)); assert(len > 0); memmove(new_env + (p - env) + len, p, (old_size - (p - env)) * sizeof(WCHAR)); p = new_env + (p - env); RtlDestroyEnvironment(env); if (!penv) NtCurrentTeb()->Peb->ProcessParameters->Environment = new_env; else *penv = new_env; } else { if (len > 0) memmove(p + len, p, (old_size - (p - env)) * sizeof(WCHAR)); } /* Set the new string */ if (value) { memcpy( p, name->Buffer, name->Length ); p += name->Length / sizeof(WCHAR); *p++ = '='; memcpy( p, value->Buffer, value->Length ); p[value->Length / sizeof(WCHAR)] = 0; } done: if (!penv) RtlReleasePebLock(); return nts; }