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

Unified Diff: chrome/browser/safe_browsing/module_integrity_verifier_unittest.cc

Issue 434163002: Changes to module_integrity_verifier.cc that allow the function VerifyModule (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patchHunting2
Patch Set: Created 6 years, 5 months 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
Index: chrome/browser/safe_browsing/module_integrity_verifier_unittest.cc
diff --git a/chrome/browser/safe_browsing/module_integrity_verifier_unittest.cc b/chrome/browser/safe_browsing/module_integrity_verifier_unittest.cc
index 479cdba16ebd5b4b0297284c11059d13edd8bf14..b8774db2bcf1705f919b84f6d63ba928add44488 100644
--- a/chrome/browser/safe_browsing/module_integrity_verifier_unittest.cc
+++ b/chrome/browser/safe_browsing/module_integrity_verifier_unittest.cc
@@ -15,6 +15,7 @@
namespace safe_browsing {
const wchar_t kTestDllName[] = L"verifier_test_dll.dll";
+const char kTestExportName[] = "DummyExport";
class SafeBrowsingModuleVerifierTest : public testing::Test {
protected:
@@ -67,50 +68,51 @@ class SafeBrowsingModuleVerifierTest : public testing::Test {
reinterpret_cast<HMODULE>(const_cast<uint8*>(disk_dll_handle_.data()));
}
- private:
- DISALLOW_COPY_AND_ASSIGN(SafeBrowsingModuleVerifierTest);
-};
-
-TEST_F(SafeBrowsingModuleVerifierTest, CountBytesDiffInPtr) {
- // Construct test pointers and try with CountBytesDiffInPtr.
- // The first Bytes differ.
- uintptr_t num_a = 0xFF;
- uintptr_t num_b = 0x00;
-
- // Any inbetween Bytes are identical.
- int num_bytes_to_add = sizeof(num_a) - 2;
- for (int i = 0; i < num_bytes_to_add; ++i) {
- num_a <<= 8;
- num_b <<= 8;
- num_a += 0xFF;
- num_b += 0xFF;
- }
-
- // The last Bytes differ.
- num_a <<= 8;
- num_b <<= 8;
- num_a += 0x0F;
- num_b += 0xFF;
-
- EXPECT_EQ(2, CountBytesDiffInPtr(num_a, num_b));
- EXPECT_EQ(2, CountBytesDiffInPtr(num_b, num_a));
- EXPECT_EQ(0, CountBytesDiffInPtr(num_a, num_a));
+ void EditExport(const char* export_name) {
+ HMODULE mem_handle;
+ GetMemModuleHandle(&mem_handle);
+ uint8_t* export_addr =
+ reinterpret_cast<uint8_t*>(GetProcAddress(mem_handle, export_name));
+ EXPECT_TRUE(NULL != export_addr);
+
+ export_addr = export_addr;
+
+ // Edit the first byte of the function.
+ uint8_t new_val = (*export_addr) + 1;
+ SIZE_T bytes_written = 0;
+ WriteProcessMemory(GetCurrentProcess(),
+ export_addr,
+ reinterpret_cast<void*>(&new_val),
+ 1,
+ &bytes_written);
+ EXPECT_EQ(1, bytes_written);
}
+private:
+DISALLOW_COPY_AND_ASSIGN(SafeBrowsingModuleVerifierTest);
+};
+
TEST_F(SafeBrowsingModuleVerifierTest, VerifyModuleUnmodified) {
+ std::set<std::string> modified_exports;
// Call VerifyModule before the module has been loaded, should fail.
- EXPECT_EQ(MODULE_STATE_UNKNOWN, VerifyModule(kTestDllName));
+ EXPECT_EQ(MODULE_STATE_UNKNOWN,
+ VerifyModule(kTestDllName, &modified_exports));
+ EXPECT_EQ(0, modified_exports.size());
// On loading, the module should be identical (up to relocations) in memory as
// on disk.
SetUpTestDllAndPEImages();
- EXPECT_EQ(MODULE_STATE_UNMODIFIED, VerifyModule(kTestDllName));
+ EXPECT_EQ(MODULE_STATE_UNMODIFIED,
+ VerifyModule(kTestDllName, &modified_exports));
+ EXPECT_EQ(0, modified_exports.size());
}
TEST_F(SafeBrowsingModuleVerifierTest, VerifyModuleModified) {
+ std::set<std::string> modified_exports;
// Confirm the module is identical in memory as on disk before we begin.
SetUpTestDllAndPEImages();
- EXPECT_EQ(MODULE_STATE_UNMODIFIED, VerifyModule(kTestDllName));
+ EXPECT_EQ(MODULE_STATE_UNMODIFIED,
+ VerifyModule(kTestDllName, &modified_exports));
uint8_t* mem_code_addr = NULL;
uint8_t* disk_code_addr = NULL;
@@ -132,7 +134,22 @@ TEST_F(SafeBrowsingModuleVerifierTest, VerifyModuleModified) {
EXPECT_EQ(1, bytes_written);
// VerifyModule should detect the change.
- EXPECT_EQ(MODULE_STATE_MODIFIED, VerifyModule(kTestDllName));
+ EXPECT_EQ(MODULE_STATE_MODIFIED,
+ VerifyModule(kTestDllName, &modified_exports));
+}
+
+TEST_F(SafeBrowsingModuleVerifierTest, VerifyModuleExportModified) {
+ std::set<std::string> modified_exports;
+ // Confirm the module is identical in memory as on disk before we begin.
+ SetUpTestDllAndPEImages();
+ EXPECT_EQ(MODULE_STATE_UNMODIFIED,
+ VerifyModule(kTestDllName, &modified_exports));
+ modified_exports.clear();
+
+ EditExport(kTestExportName);
+ EXPECT_EQ(MODULE_STATE_MODIFIED,
+ VerifyModule(kTestDllName, &modified_exports));
+ EXPECT_EQ(1, modified_exports.size());
}
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698