1 : // Copyright 2012 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 : // Implements TestDllTransformTest functions.
16 :
17 : #include "syzygy/instrument/transforms/unittest_util.h"
18 :
19 : #include "syzygy/pe/coff_decomposer.h"
20 : #include "syzygy/pe/coff_utils.h"
21 : #include "syzygy/pe/decomposer.h"
22 : #include "syzygy/pe/pe_utils.h"
23 :
24 : namespace testing {
25 :
26 : TestDllTransformTest::TestDllTransformTest()
27 E : : policy_(NULL), header_block_(NULL) {
28 E : }
29 :
30 E : void TestDllTransformTest::DecomposeTestDll() {
31 : base::FilePath test_dll_path = ::testing::GetOutputRelativePath(
32 E : testing::kTestDllName);
33 :
34 E : ASSERT_TRUE(pe_file_.Init(test_dll_path));
35 :
36 E : pe::ImageLayout layout(&block_graph_);
37 E : pe::Decomposer decomposer(pe_file_);
38 E : ASSERT_TRUE(decomposer.Decompose(&layout));
39 :
40 : header_block_ = layout.blocks.GetBlockByAddress(
41 E : core::RelativeAddress(0));
42 E : ASSERT_TRUE(header_block_ != NULL);
43 :
44 E : policy_ = &pe_policy_;
45 E : }
46 :
47 E : void TestDllTransformTest::DecomposeTestDllObj() {
48 : base::FilePath test_dll_obj_path = ::testing::GetExeTestDataRelativePath(
49 E : testing::kTestDllCoffObjName);
50 :
51 E : ASSERT_TRUE(coff_file_.Init(test_dll_obj_path));
52 :
53 E : pe::ImageLayout layout(&block_graph_);
54 E : pe::CoffDecomposer decomposer(coff_file_);
55 E : ASSERT_TRUE(decomposer.Decompose(&layout));
56 :
57 : ASSERT_TRUE(pe::FindCoffSpecialBlocks(
58 E : &block_graph_, &header_block_, NULL, NULL));
59 E : ASSERT_TRUE(header_block_ != NULL);
60 :
61 E : policy_ = &coff_policy_;
62 E : }
63 :
64 : } // namespace testing
|