/*static*/ HBITMAP Win32UIBinding::LoadImageAsBitmap(std::string& path, int sizeX, int sizeY) { std::string ext = path.substr(path.size() - 4, 4); UINT flags = LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_LOADTRANSPARENT | LR_CREATEDIBSECTION; std::wstring widePath(::UTF8ToWide(path)); HBITMAP h = 0; if (_stricmp(ext.c_str(), ".ico") == 0) { HICON hicon = (HICON) LoadImageW(NULL, widePath.c_str(), IMAGE_ICON, sizeX, sizeY, LR_LOADFROMFILE); h = Win32UIBinding::IconToBitmap(hicon, sizeX, sizeY); DestroyIcon(hicon); } else if (_stricmp(ext.c_str(), ".bmp") == 0) { h = (HBITMAP) LoadImageW( NULL, widePath.c_str(), IMAGE_BITMAP, sizeX, sizeY, flags); } else if (_stricmp(ext.c_str(), ".png") == 0) { h = LoadPNGAsBitmap(path, sizeX, sizeY); } loadedBMPs.push_back(h); return h; }
/*static*/ HICON Win32UIBinding::LoadImageAsIcon(std::string& path, int sizeX, int sizeY) { std::string ext = path.substr(path.size() - 4, 4); UINT flags = LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_LOADTRANSPARENT | LR_CREATEDIBSECTION; std::wstring widePath(::UTF8ToWide(path)); HICON h = 0; if (_stricmp(ext.c_str(), ".ico") == 0) { h = (HICON) LoadImageW(NULL, widePath.c_str(), IMAGE_ICON, sizeX, sizeY, LR_LOADFROMFILE); } else if (_stricmp(ext.c_str(), ".bmp") == 0) { HBITMAP bitmap = (HBITMAP) LoadImageW( NULL, widePath.c_str(), IMAGE_BITMAP, sizeX, sizeY, flags); h = Win32UIBinding::BitmapToIcon(bitmap, sizeX, sizeY); DeleteObject(bitmap); } else if (_stricmp(ext.c_str(), ".png") == 0) { HBITMAP bitmap = LoadPNGAsBitmap(path, sizeX, sizeY); h = Win32UIBinding::BitmapToIcon(bitmap, sizeX, sizeY); DeleteObject(bitmap); } loadedICOs.push_back(h); return (HICON) h; }
/*static*/ HICON UIWin::LoadImageAsIcon(std::string& path, int sizeX, int sizeY) { UINT flags = LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_LOADTRANSPARENT | LR_CREATEDIBSECTION; const char* ext = path.c_str() + path.size() - 4; std::wstring widePath(::UTF8ToWide(path)); HICON h = 0; if (_stricmp(ext, ".ico") == 0) { h = (HICON) LoadImageW(0, widePath.c_str(), IMAGE_ICON, sizeX, sizeY, LR_LOADFROMFILE); } else if (_stricmp(ext, ".bmp") == 0) { HBITMAP bitmap = (HBITMAP) LoadImageW(0, widePath.c_str(), IMAGE_BITMAP, sizeX, sizeY, flags); h = UIWin::BitmapToIcon(bitmap, sizeX, sizeY); DeleteObject(bitmap); } else if (_stricmp(ext, ".png") == 0) { HBITMAP bitmap = LoadPNGAsBitmap(path, sizeX, sizeY); h = UIWin::BitmapToIcon(bitmap, sizeX, sizeY); DeleteObject(bitmap); } else { throw ValueException::FromFormat("Unsupported image file: %s", path); } loadedICOs.push_back(h); return (HICON) h; }
/*static*/ HBITMAP UIWin::LoadImageAsBitmap(std::string& path, int sizeX, int sizeY) { UINT flags = LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_LOADTRANSPARENT | LR_CREATEDIBSECTION; std::wstring widePath(::UTF8ToWide(path)); const char* ext = path.c_str() + path.size() - 4; HBITMAP h = 0; if (_stricmp(ext, ".ico") == 0) { HICON hicon = (HICON) LoadImageW(NULL, widePath.c_str(), IMAGE_ICON, sizeX, sizeY, LR_LOADFROMFILE); h = UIWin::IconToBitmap(hicon, sizeX, sizeY); DestroyIcon(hicon); } else if (_stricmp(ext, ".bmp") == 0) { h = (HBITMAP) LoadImageW( NULL, widePath.c_str(), IMAGE_BITMAP, sizeX, sizeY, flags); } else if (_stricmp(ext, ".png") == 0) { h = LoadPNGAsBitmap(path, sizeX, sizeY); } else { throw ValueException::FromFormat("Unsupported image file: %s", path); } loadedBMPs.push_back(h); return h; }
/** @Status Caveat @Notes This function can only find libraries in the root of the current package. The mode parameter is ignored. In addition, error information is not available on failure. */ void* dlopen(const char* path, int mode) { try { // We can only load libraries from within our own package or any dependent // packages, so absolute paths are not much use to us. From whatever path // we're given, just strip off everything but the leaf file name and try // to load that. This isn't always correct, but it is sometimes correct. std::wstring widePath(path, path + strlen(path)); DWORD pathLength = GetFullPathNameW(widePath.c_str(), 0, nullptr, nullptr); auto fullPath = std::make_unique<WCHAR[]>(pathLength); LPWSTR fileName = nullptr; GetFullPathNameW(widePath.c_str(), pathLength, fullPath.get(), &fileName); return LoadPackagedLibrary(fileName, 0); } catch (...) { } return NULL; }
static HMODULE SafeLoadRuntimeDLL(string& path) { if (!FileUtils::IsFile(path)) { ShowError(string("Couldn't find required file: ") + path); return false; } wstring widePath(KrollUtils::UTF8ToWide(path)); HMODULE module = LoadLibraryExW(widePath.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH); if (!module) { string msg("Couldn't load file ("); msg.append(path); msg.append("): "); msg.append(KrollUtils::Win32Utils::QuickFormatMessage(GetLastError())); ShowError(msg); } return module; }
Module* Host::CreateModule(std::string& path) { std::wstring widePath(UTF8ToWide(path)); HMODULE module = LoadLibraryExW(widePath.c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (!module) { throw ValueException::FromFormat("Error loading module (%d): %s: %s\n", GetLastError(), path.c_str(), Win32Utils::QuickFormatMessage(GetLastError()).c_str()); } // get the module factory ModuleCreator* create = (ModuleCreator*)GetProcAddress(module, "CreateModule"); if (!create) { throw ValueException::FromFormat( "Couldn't find ModuleCreator entry point for %s\n", path.c_str()); } return create(this, FileUtils::GetDirectory(path).c_str()); }
PRBool nsProfileMigrator::ImportRegistryProfiles(const nsACString& aAppName) { nsresult rv; nsCOMPtr<nsIToolkitProfileService> profileSvc (do_GetService(NS_PROFILESERVICE_CONTRACTID)); NS_ENSURE_TRUE(profileSvc, NS_ERROR_FAILURE); nsCOMPtr<nsIProperties> dirService (do_GetService("@mozilla.org/file/directory_service;1")); NS_ENSURE_TRUE(dirService, NS_ERROR_FAILURE); nsCOMPtr<nsILocalFile> regFile; #ifdef XP_WIN rv = dirService->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(regFile)); NS_ENSURE_SUCCESS(rv, PR_FALSE); regFile->AppendNative(aAppName); regFile->AppendNative(NS_LITERAL_CSTRING("registry.dat")); #elif defined(XP_MACOSX) rv = dirService->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(regFile)); NS_ENSURE_SUCCESS(rv, PR_FALSE); regFile->AppendNative(aAppName); regFile->AppendNative(NS_LITERAL_CSTRING("Application Registry")); #elif defined(XP_OS2) rv = dirService->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(regFile)); NS_ENSURE_SUCCESS(rv, PR_FALSE); regFile->AppendNative(aAppName); regFile->AppendNative(NS_LITERAL_CSTRING("registry.dat")); #elif defined(XP_BEOS) rv = dirService->Get(NS_BEOS_SETTINGS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(regFile)); NS_ENSURE_SUCCESS(rv, PR_FALSE); regFile->AppendNative(aAppName); regFile->AppendNative(NS_LITERAL_CSTRING("appreg")); #else rv = dirService->Get(NS_UNIX_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(regFile)); NS_ENSURE_SUCCESS(rv, PR_FALSE); nsCAutoString dotAppName; ToLowerCase(aAppName, dotAppName); dotAppName.Insert('.', 0); regFile->AppendNative(dotAppName); regFile->AppendNative(NS_LITERAL_CSTRING("appreg")); #endif nsCAutoString path; rv = regFile->GetNativePath(path); NS_ENSURE_SUCCESS(rv, PR_FALSE); if (NR_StartupRegistry()) return PR_FALSE; PRBool migrated = PR_FALSE; HREG reg = nsnull; RKEY profiles = 0; REGENUM enumstate = 0; char profileName[MAXREGNAMELEN]; if (NR_RegOpen(path.get(), ®)) goto cleanup; if (NR_RegGetKey(reg, ROOTKEY_COMMON, "Profiles", &profiles)) goto cleanup; while (!NR_RegEnumSubkeys(reg, profiles, &enumstate, profileName, MAXREGNAMELEN, REGENUM_CHILDREN)) { #ifdef DEBUG_bsmedberg printf("Found profile %s.\n", profileName); #endif RKEY profile = 0; if (NR_RegGetKey(reg, profiles, profileName, &profile)) { NS_ERROR("Could not get the key that was enumerated."); continue; } char profilePath[MAXPATHLEN]; if (NR_RegGetEntryString(reg, profile, "directory", profilePath, MAXPATHLEN)) continue; nsCOMPtr<nsILocalFile> profileFile (do_CreateInstance("@mozilla.org/file/local;1")); if (!profileFile) continue; #if defined (XP_MACOSX) rv = profileFile->SetPersistentDescriptor(nsDependentCString(profilePath)); #else NS_ConvertUTF8toUTF16 widePath(profilePath); rv = profileFile->InitWithPath(widePath); #endif if (NS_FAILED(rv)) continue; nsCOMPtr<nsIToolkitProfile> tprofile; profileSvc->CreateProfile(profileFile, nsnull, nsDependentCString(profileName), getter_AddRefs(tprofile)); migrated = PR_TRUE; } cleanup: if (reg) NR_RegClose(reg); NR_ShutdownRegistry(); return migrated; }
bool GMPLoaderImpl::Load(const char* aUTF8LibPath, uint32_t aUTF8LibPathLen, char* aOriginSalt, uint32_t aOriginSaltLen, const GMPPlatformAPI* aPlatformAPI) { std::string nodeId; #ifdef HASH_NODE_ID_WITH_DEVICE_ID if (aOriginSaltLen > 0) { std::vector<uint8_t> deviceId; int volumeId; if (!rlz_lib::GetRawMachineId(&deviceId, &volumeId)) { return false; } SHA256Context ctx; SHA256_Begin(&ctx); SHA256_Update(&ctx, (const uint8_t*)aOriginSalt, aOriginSaltLen); SHA256_Update(&ctx, deviceId.data(), deviceId.size()); SHA256_Update(&ctx, (const uint8_t*)&volumeId, sizeof(int)); uint8_t digest[SHA256_LENGTH] = {0}; unsigned int digestLen = 0; SHA256_End(&ctx, digest, &digestLen, SHA256_LENGTH); // Overwrite all data involved in calculation as it could potentially // identify the user, so there's no chance a GMP can read it and use // it for identity tracking. SecureMemset(&ctx, 0, sizeof(ctx)); SecureMemset(aOriginSalt, 0, aOriginSaltLen); SecureMemset(&volumeId, 0, sizeof(volumeId)); SecureMemset(deviceId.data(), '*', deviceId.size()); deviceId.clear(); if (!rlz_lib::BytesToString(digest, SHA256_LENGTH, &nodeId)) { return false; } if (!PR_GetEnv("MOZ_GMP_DISABLE_NODE_ID_CLEANUP")) { // We've successfully bound the origin salt to node id. // rlz_lib::GetRawMachineId and/or the system functions it // called could have left user identifiable data on the stack, // so carefully zero the stack down to the guard page. uint8_t* top; uint8_t* bottom; if (!GetStackAfterCurrentFrame(&top, &bottom)) { return false; } assert(top >= bottom); // Inline instructions equivalent to RtlSecureZeroMemory(). // We can't just use RtlSecureZeroMemory here directly, as in debug // builds, RtlSecureZeroMemory() can't be inlined, and the stack // memory it uses would get wiped by itself running, causing crashes. for (volatile uint8_t* p = (volatile uint8_t*)bottom; p < top; p++) { *p = 0; } } } else #endif { nodeId = std::string(aOriginSalt, aOriginSalt + aOriginSaltLen); } // Start the sandbox now that we've generated the device bound node id. // This must happen after the node id is bound to the device id, as // generating the device id requires privileges. if (mSandboxStarter && !mSandboxStarter->Start(aUTF8LibPath)) { return false; } // Load the GMP. PRLibSpec libSpec; #ifdef XP_WIN int pathLen = MultiByteToWideChar(CP_UTF8, 0, aUTF8LibPath, -1, nullptr, 0); if (pathLen == 0) { return false; } nsAutoArrayPtr<wchar_t> widePath(new wchar_t[pathLen]); if (MultiByteToWideChar(CP_UTF8, 0, aUTF8LibPath, -1, widePath, pathLen) == 0) { return false; } libSpec.value.pathname_u = widePath; libSpec.type = PR_LibSpec_PathnameU; #else libSpec.value.pathname = aUTF8LibPath; libSpec.type = PR_LibSpec_Pathname; #endif mLib = PR_LoadLibraryWithFlags(libSpec, 0); if (!mLib) { return false; } GMPInitFunc initFunc = reinterpret_cast<GMPInitFunc>(PR_FindFunctionSymbol(mLib, "GMPInit")); if (!initFunc) { return false; } if (initFunc(aPlatformAPI) != GMPNoErr) { return false; } GMPSetNodeIdFunc setNodeIdFunc = reinterpret_cast<GMPSetNodeIdFunc>(PR_FindFunctionSymbol(mLib, "GMPSetNodeId")); if (setNodeIdFunc) { setNodeIdFunc(nodeId.c_str(), nodeId.size()); } mGetAPIFunc = reinterpret_cast<GMPGetAPIFunc>(PR_FindFunctionSymbol(mLib, "GMPGetAPI")); if (!mGetAPIFunc) { return false; } return true; }