Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Unified Diff: snapshot/win/pe_image_reader_test.cc

Issue 1475023004: Get module versions and types from in-memory images (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback (2) Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « snapshot/win/pe_image_reader.cc ('k') | snapshot/win/pe_image_resource_reader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: snapshot/win/pe_image_reader_test.cc
diff --git a/snapshot/win/pe_image_reader_test.cc b/snapshot/win/pe_image_reader_test.cc
index 3928fee92412cbdc92a49fe460ab3f7ddb85f43d..47ba2115d8e37363e6e63106f19c1c896708e6e4 100644
--- a/snapshot/win/pe_image_reader_test.cc
+++ b/snapshot/win/pe_image_reader_test.cc
@@ -17,9 +17,13 @@
#define PSAPI_VERSION 1
#include <psapi.h>
+#include "base/files/file_path.h"
+#include "base/strings/utf_string_conversions.h"
#include "gtest/gtest.h"
#include "snapshot/win/process_reader_win.h"
+#include "test/errors.h"
#include "util/win/get_function.h"
+#include "util/win/module_version.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
@@ -28,9 +32,9 @@ namespace test {
namespace {
BOOL CrashpadGetModuleInformation(HANDLE process,
- HMODULE module,
- MODULEINFO* module_info,
- DWORD cb) {
+ HMODULE module,
+ MODULEINFO* module_info,
+ DWORD cb) {
static const auto get_module_information =
GET_FUNCTION_REQUIRED(L"psapi.dll", ::GetModuleInformation);
return get_module_information(process, module, module_info, cb);
@@ -44,9 +48,10 @@ TEST(PEImageReader, DebugDirectory) {
HMODULE self = reinterpret_cast<HMODULE>(&__ImageBase);
MODULEINFO module_info;
ASSERT_TRUE(CrashpadGetModuleInformation(
- GetCurrentProcess(), self, &module_info, sizeof(module_info)));
+ GetCurrentProcess(), self, &module_info, sizeof(module_info)))
+ << ErrorMessage("GetModuleInformation");
EXPECT_EQ(self, module_info.lpBaseOfDll);
- EXPECT_TRUE(pe_image_reader.Initialize(&process_reader,
+ ASSERT_TRUE(pe_image_reader.Initialize(&process_reader,
reinterpret_cast<WinVMAddress>(self),
module_info.SizeOfImage,
"self"));
@@ -61,6 +66,56 @@ TEST(PEImageReader, DebugDirectory) {
pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix));
}
+TEST(PEImageReader, VSFixedFileInfo) {
+ ProcessReaderWin process_reader;
+ ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess(),
+ ProcessSuspensionState::kRunning));
+
+ const wchar_t kModuleName[] = L"kernel32.dll";
+
+ HMODULE module_handle = GetModuleHandle(kModuleName);
+ ASSERT_TRUE(module_handle) << ErrorMessage("GetModuleHandle");
+
+ MODULEINFO module_info;
+ ASSERT_TRUE(CrashpadGetModuleInformation(
+ GetCurrentProcess(), module_handle, &module_info, sizeof(module_info)))
+ << ErrorMessage("GetModuleInformation");
+ EXPECT_EQ(module_handle, module_info.lpBaseOfDll);
+
+ PEImageReader pe_image_reader;
+ ASSERT_TRUE(
+ pe_image_reader.Initialize(&process_reader,
+ reinterpret_cast<WinVMAddress>(module_handle),
+ module_info.SizeOfImage,
+ base::UTF16ToUTF8(kModuleName)));
+
+ VS_FIXEDFILEINFO observed;
+ ASSERT_TRUE(pe_image_reader.VSFixedFileInfo(&observed));
+
+ EXPECT_EQ(VS_FFI_SIGNATURE, observed.dwSignature);
+ EXPECT_EQ(VS_FFI_STRUCVERSION, observed.dwStrucVersion);
+ EXPECT_EQ(0, observed.dwFileFlags & ~observed.dwFileFlagsMask);
+ EXPECT_EQ(VOS_NT_WINDOWS32, observed.dwFileOS);
+ EXPECT_EQ(VFT_DLL, observed.dwFileType);
+
+ VS_FIXEDFILEINFO expected;
+ ASSERT_TRUE(GetModuleVersionAndType(base::FilePath(kModuleName), &expected));
+
+ EXPECT_EQ(expected.dwSignature, observed.dwSignature);
+ EXPECT_EQ(expected.dwStrucVersion, observed.dwStrucVersion);
+ EXPECT_EQ(expected.dwFileVersionMS, observed.dwFileVersionMS);
+ EXPECT_EQ(expected.dwFileVersionLS, observed.dwFileVersionLS);
+ EXPECT_EQ(expected.dwProductVersionMS, observed.dwProductVersionMS);
+ EXPECT_EQ(expected.dwProductVersionLS, observed.dwProductVersionLS);
+ EXPECT_EQ(expected.dwFileFlagsMask, observed.dwFileFlagsMask);
+ EXPECT_EQ(expected.dwFileFlags, observed.dwFileFlags);
+ EXPECT_EQ(expected.dwFileOS, observed.dwFileOS);
+ EXPECT_EQ(expected.dwFileType, observed.dwFileType);
+ EXPECT_EQ(expected.dwFileSubtype, observed.dwFileSubtype);
+ EXPECT_EQ(expected.dwFileDateMS, observed.dwFileDateMS);
+ EXPECT_EQ(expected.dwFileDateLS, observed.dwFileDateLS);
+}
+
} // namespace
} // namespace test
} // namespace crashpad
« no previous file with comments | « snapshot/win/pe_image_reader.cc ('k') | snapshot/win/pe_image_resource_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698