gecko-dev/toolkit/xre/ModuleVersionInfo.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 строки
4.1 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
Bug 1542830: Part 6 - Rewrite the untrusted modules processor in toolkit/xre; r=mhowell * Significant cleanup to `ModuleEvaluator` * `UntrustedModuleData` holds all of the accumulated untrusted module info for a single process. * `ProcessedModuleLoadEvent` holds information about an individual untrusted module load in a Gecko-friendly, sanitized, format. * Since multiple `ProcessModuleLoadEvent` objects may reference the same module, we store module metadata in a shared `ModuleInfo` structure. * The `UntrustedModulesProcessor` receives the events from `mozglue` and processes them on a background thread: ** It does not start background processing until the main thread has gone idle. The idea here is that we do not want to add any more background work until we are reasonably confident that Gecko is no longer starting up or doing other intense activity. ** Background processing runs at a background priority level, *except* when results are requested by telemetry itself. ** Telemetry requests the data via `UntrustedModulesProcessor::GetProcessedData` which runs at normal priority and returns a promise to the caller. Depends on D43159 Differential Revision: https://phabricator.services.mozilla.com/D43160 --HG-- rename : toolkit/xre/ModuleEvaluator_windows.cpp => toolkit/xre/ModuleEvaluator.cpp rename : toolkit/xre/ModuleEvaluator_windows.cpp => toolkit/xre/ModuleEvaluator.h rename : toolkit/xre/ModuleVersionInfo_windows.cpp => toolkit/xre/ModuleVersionInfo.cpp rename : toolkit/xre/ModuleVersionInfo_windows.h => toolkit/xre/ModuleVersionInfo.h rename : toolkit/xre/ModuleEvaluator_windows.cpp => toolkit/xre/UntrustedModulesData.cpp rename : toolkit/xre/ModuleEvaluator_windows.h => toolkit/xre/UntrustedModulesData.h rename : toolkit/xre/ModuleEvaluator_windows.cpp => toolkit/xre/UntrustedModulesProcessor.cpp rename : toolkit/xre/ModuleEvaluator_windows.h => toolkit/xre/UntrustedModulesProcessor.h extra : moz-landing-system : lando
2019-09-23 23:19:17 +03:00
#include "ModuleVersionInfo.h"
#include "mozilla/UniquePtr.h"
namespace mozilla {
/**
* Gets a string value from a version info block with the specified translation
* and field name.
*
* @param aBlock [in] The binary version resource block
* @param aTranslation [in] The translation ID as obtained in the version
* translation list.
* @param aFieldName [in] Null-terminated name of the desired field
* @param aResult [out] Receives the string value, if successful.
* @return true if successful. aResult is unchanged upon failure.
*/
static bool QueryStringValue(const void* aBlock, DWORD aTranslation,
const wchar_t* aFieldName, nsAString& aResult) {
nsAutoString path;
path.AppendPrintf("\\StringFileInfo\\%02X%02X%02X%02X\\%S",
(aTranslation & 0x0000ff00) >> 8,
(aTranslation & 0x000000ff),
(aTranslation & 0xff000000) >> 24,
(aTranslation & 0x00ff0000) >> 16, aFieldName);
wchar_t* lpBuffer = nullptr;
UINT len = 0;
if (!::VerQueryValueW(aBlock, path.get(), (PVOID*)&lpBuffer, &len)) {
return false;
}
aResult.Assign(lpBuffer, (size_t)len - 1);
return true;
}
/**
* Searches through translations in the version resource for the requested
* field. English(US) is preferred, otherwise we take the first translation
* that succeeds.
*
* @param aBlock [in] The binary version resource block
* @param aTranslations [in] The list of translation IDs available
* @param aNumTrans [in] Number of items in aTranslations
* @param aFieldName [in] Null-terminated name of the desired field
* @param aResult [in] Receives the string value, if successful.
* @return true if successful. aResult is unchanged upon failure.
*/
static bool QueryStringValue(const void* aBlock, const DWORD* aTranslations,
size_t aNumTrans, const wchar_t* aFieldName,
nsAString& aResult) {
static const DWORD kPreferredTranslation =
0x04b00409; // English (US), Unicode
if (QueryStringValue(aBlock, kPreferredTranslation, aFieldName, aResult)) {
return true;
}
for (size_t i = 0; i < aNumTrans; ++i) {
if (QueryStringValue(aBlock, aTranslations[i], aFieldName, aResult)) {
return true;
}
}
return false;
}
bool ModuleVersionInfo::GetFromImage(const nsAString& aPath) {
nsString path(aPath);
DWORD infoSize = GetFileVersionInfoSizeW(path.get(), nullptr);
if (!infoSize) {
return false;
}
auto verInfo = MakeUnique<BYTE[]>(infoSize);
if (!::GetFileVersionInfoW(path.get(), 0, infoSize, verInfo.get())) {
return false;
}
VS_FIXEDFILEINFO* vInfo = nullptr;
UINT vInfoLen = 0;
if (::VerQueryValueW(verInfo.get(), L"\\", (LPVOID*)&vInfo, &vInfoLen)) {
mFileVersion =
VersionNumber(vInfo->dwFileVersionMS, vInfo->dwFileVersionLS);
mProductVersion =
VersionNumber(vInfo->dwProductVersionMS, vInfo->dwProductVersionLS);
}
// Note that regardless the character set indicated, strings are always
// returned as Unicode by the Windows APIs.
DWORD* pTrans = nullptr;
UINT cbTrans = 0;
if (::VerQueryValueW(verInfo.get(), L"\\VarFileInfo\\Translation",
(PVOID*)&pTrans, &cbTrans)) {
size_t numTrans = cbTrans / sizeof(DWORD);
QueryStringValue(verInfo.get(), pTrans, numTrans, L"CompanyName",
mCompanyName);
QueryStringValue(verInfo.get(), pTrans, numTrans, L"ProductName",
mProductName);
QueryStringValue(verInfo.get(), pTrans, numTrans, L"LegalCopyright",
mLegalCopyright);
QueryStringValue(verInfo.get(), pTrans, numTrans, L"FileDescription",
mFileDescription);
}
return true;
}
} // namespace mozilla