1 : // Copyright 2015 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/refinery/process_state/layer_data.h"
16 :
17 : #include "gtest/gtest.h"
18 : #include "syzygy/pe/pe_file.h"
19 :
20 : namespace refinery {
21 :
22 E : TEST(PESignatureHasherTest, BasicTest) {
23 : PESignatureHasher hasher;
24 :
25 E : pe::PEFile::Signature s1(L"PathA", core::AbsoluteAddress(0U), 1, 2, 3);
26 E : pe::PEFile::Signature s2(s1);
27 E : pe::PEFile::Signature s3(L"PathA", core::AbsoluteAddress(3U), 2, 1, 0);
28 :
29 E : ASSERT_EQ(hasher(s1), hasher(s2));
30 E : ASSERT_NE(hasher(s1), hasher(s3));
31 E : }
32 :
33 E : TEST(ModuleLayerDataTest, BasicTest) {
34 E : ModuleLayerData data;
35 :
36 : // Should not find something when searching in empty data.
37 E : pe::PEFile::Signature retrieved_sig;
38 E : ASSERT_FALSE(data.Find(0, &retrieved_sig));
39 :
40 E : pe::PEFile::Signature sig(L"Path", core::AbsoluteAddress(0U), 1, 2, 3);
41 E : ASSERT_EQ(kNoModuleId, data.Find(sig));
42 :
43 : // FindOrIndex with a new signature should succeed.
44 E : ModuleId retrieved_id = data.FindOrIndex(sig);
45 E : ASSERT_NE(kNoModuleId, retrieved_id);
46 :
47 : // Ensure indexed modules can be found.
48 E : ASSERT_EQ(retrieved_id, data.Find(sig));
49 E : ASSERT_TRUE(data.Find(retrieved_id, &retrieved_sig));
50 E : ASSERT_EQ(sig, retrieved_sig);
51 :
52 : // Second call to FindOrIndex should also work.
53 E : ASSERT_EQ(retrieved_id, data.FindOrIndex(sig));
54 E : }
55 :
56 : } // namespace refinery
|