mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1702086 - Part3: Use PEHeaders::GetVersionInfo. r=gerald
This patch replaces two versions of `GetVersion` in Gecko profiler and baseprofiler with `PEHeaders::GetVersionInfo`. Depends on D115253 Differential Revision: https://phabricator.services.mozilla.com/D115254
This commit is contained in:
parent
4e1b4037be
commit
2755a48956
@ -49,33 +49,6 @@ static void AppendHex(T aValue, std::string& aOut, bool aWithPadding) {
|
||||
}
|
||||
}
|
||||
|
||||
static std::string GetVersion(const wchar_t* dllPath) {
|
||||
DWORD infoSize = GetFileVersionInfoSizeW(dllPath, nullptr);
|
||||
if (infoSize == 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
mozilla::UniquePtr<unsigned char[]> infoData =
|
||||
mozilla::MakeUnique<unsigned char[]>(infoSize);
|
||||
if (!GetFileVersionInfoW(dllPath, 0, infoSize, infoData.get())) {
|
||||
return {};
|
||||
}
|
||||
|
||||
VS_FIXEDFILEINFO* vInfo;
|
||||
UINT vInfoLen;
|
||||
if (!VerQueryValueW(infoData.get(), L"\\", (LPVOID*)&vInfo, &vInfoLen)) {
|
||||
return {};
|
||||
}
|
||||
if (!vInfo) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::to_string(vInfo->dwFileVersionMS >> 16) + '.' +
|
||||
std::to_string(vInfo->dwFileVersionMS & 0xFFFF) + '.' +
|
||||
std::to_string(vInfo->dwFileVersionLS >> 16) + '.' +
|
||||
std::to_string(vInfo->dwFileVersionLS & 0xFFFF);
|
||||
}
|
||||
|
||||
SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() {
|
||||
SharedLibraryInfo sharedLibraryInfo;
|
||||
|
||||
@ -151,6 +124,7 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() {
|
||||
std::string breakpadId;
|
||||
std::string pdbPathStr;
|
||||
std::string pdbNameStr;
|
||||
std::string versionStr;
|
||||
if (handleLock) {
|
||||
mozilla::nt::PEHeaders headers(handleLock.get());
|
||||
if (headers) {
|
||||
@ -174,6 +148,17 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() {
|
||||
pdbNameStr = (pos != std::string::npos) ? pdbPathStr.substr(pos + 1)
|
||||
: pdbPathStr;
|
||||
}
|
||||
|
||||
uint64_t version;
|
||||
if (headers.GetVersionInfo(version)) {
|
||||
versionStr += std::to_string((version >> 48) & 0xFFFF);
|
||||
versionStr += '.';
|
||||
versionStr += std::to_string((version >> 32) & 0xFFFF);
|
||||
versionStr += '.';
|
||||
versionStr += std::to_string((version >> 16) & 0xFFFF);
|
||||
versionStr += '.';
|
||||
versionStr += std::to_string(version & 0xFFFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,7 +166,7 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() {
|
||||
(uintptr_t)module.lpBaseOfDll + module.SizeOfImage,
|
||||
0, // DLLs are always mapped at offset 0 on Windows
|
||||
breakpadId, moduleNameStr, modulePathStr, pdbNameStr,
|
||||
pdbPathStr, GetVersion(aModulePath), "");
|
||||
pdbPathStr, versionStr, "");
|
||||
sharedLibraryInfo.AddSharedLibrary(shlib);
|
||||
};
|
||||
|
||||
|
@ -244,6 +244,20 @@ bool TestModuleLoadedAsData() {
|
||||
"TEST-FAIL | NativeNt | Failed to get PDB info from the module.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t version1, version2;
|
||||
bool result1 = peAsData.GetVersionInfo(version1);
|
||||
bool result2 = pe.GetVersionInfo(version2);
|
||||
if (result1 && result2) {
|
||||
if (version1 != version2) {
|
||||
printf("TEST-FAIL | NativeNt | Version mismatch\n");
|
||||
return false;
|
||||
}
|
||||
} else if (result1 || result2) {
|
||||
printf(
|
||||
"TEST-FAIL | NativeNt | Failed to get PDB info from the module.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -9,40 +9,11 @@
|
||||
#include "shared-libraries.h"
|
||||
#include "nsWindowsHelpers.h"
|
||||
#include "mozilla/NativeNt.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/WindowsEnumProcessModules.h"
|
||||
#include "mozilla/WindowsProcessMitigations.h"
|
||||
#include "mozilla/WindowsVersion.h"
|
||||
#include "nsPrintfCString.h"
|
||||
|
||||
static nsCString GetVersion(const WCHAR* dllPath) {
|
||||
DWORD infoSize = GetFileVersionInfoSizeW(dllPath, nullptr);
|
||||
if (infoSize == 0) {
|
||||
return ""_ns;
|
||||
}
|
||||
|
||||
mozilla::UniquePtr<unsigned char[]> infoData =
|
||||
mozilla::MakeUnique<unsigned char[]>(infoSize);
|
||||
if (!GetFileVersionInfoW(dllPath, 0, infoSize, infoData.get())) {
|
||||
return ""_ns;
|
||||
}
|
||||
|
||||
VS_FIXEDFILEINFO* vInfo;
|
||||
UINT vInfoLen;
|
||||
if (!VerQueryValueW(infoData.get(), L"\\", (LPVOID*)&vInfo, &vInfoLen)) {
|
||||
return ""_ns;
|
||||
}
|
||||
if (!vInfo) {
|
||||
return ""_ns;
|
||||
}
|
||||
|
||||
nsPrintfCString version("%d.%d.%d.%d", vInfo->dwFileVersionMS >> 16,
|
||||
vInfo->dwFileVersionMS & 0xFFFF,
|
||||
vInfo->dwFileVersionLS >> 16,
|
||||
vInfo->dwFileVersionLS & 0xFFFF);
|
||||
return std::move(version);
|
||||
}
|
||||
|
||||
SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() {
|
||||
SharedLibraryInfo sharedLibraryInfo;
|
||||
|
||||
@ -111,6 +82,7 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() {
|
||||
LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE));
|
||||
|
||||
nsAutoCString breakpadId;
|
||||
nsAutoCString versionStr;
|
||||
nsAutoString pdbPathStr;
|
||||
nsAutoString pdbNameStr;
|
||||
if (handleLock && canGetPdbInfo) {
|
||||
@ -139,6 +111,13 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() {
|
||||
pdbNameStr.Cut(0, pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t version;
|
||||
if (headers.GetVersionInfo(version)) {
|
||||
versionStr.AppendPrintf("%d.%d.%d.%d", (version >> 48) & 0xFFFF,
|
||||
(version >> 32) & 0xFFFF,
|
||||
(version >> 16) & 0xFFFF, version & 0xFFFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +125,7 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf() {
|
||||
(uintptr_t)module.lpBaseOfDll + module.SizeOfImage,
|
||||
0, // DLLs are always mapped at offset 0 on Windows
|
||||
breakpadId, moduleNameStr, modulePathStr, pdbNameStr,
|
||||
pdbPathStr, GetVersion(aModulePath), "");
|
||||
pdbPathStr, versionStr, "");
|
||||
sharedLibraryInfo.AddSharedLibrary(shlib);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user