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 : // Declares a basic BlockGraphTransform for adding a Syzygy-toolchain metadata
16 : // section to a PE image.
17 :
18 : #ifndef SYZYGY_PE_TRANSFORMS_ADD_METADATA_TRANSFORM_H_
19 : #define SYZYGY_PE_TRANSFORMS_ADD_METADATA_TRANSFORM_H_
20 :
21 : #include "base/files/file_path.h"
22 : #include "syzygy/block_graph/transforms/named_transform.h"
23 :
24 : namespace pe {
25 : namespace transforms {
26 :
27 : using block_graph::BlockGraph;
28 : using block_graph::TransformPolicyInterface;
29 : using block_graph::transforms::NamedBlockGraphTransformImpl;
30 :
31 : class AddMetadataTransform
32 : : public NamedBlockGraphTransformImpl<AddMetadataTransform> {
33 : public:
34 : // @param module_path the path to the module that the metadata will refer to.
35 : // This should be the original module from which the block-graph was
36 : // generated.
37 : explicit AddMetadataTransform(const base::FilePath& module_path);
38 :
39 : // Applies this transform to the provided PE image block graph.
40 : //
41 : // @param policy The policy object restricting how the transform is applied.
42 : // @param block_graph The block graph to transform.
43 : // @param dos_header_block The DOS header block of the block graph. This is
44 : // unused in this transform.
45 : // @returns true on success, false otherwise.
46 : virtual bool TransformBlockGraph(
47 : const TransformPolicyInterface* policy,
48 : BlockGraph* block_graph,
49 : BlockGraph::Block* /*dos_header_block*/) override;
50 :
51 E : BlockGraph::Block* metadata_block() const { return metadata_block_; }
52 :
53 : // The name of this transform.
54 : static const char kTransformName[];
55 :
56 : private:
57 : // The path to the module which the metadata refers to.
58 : base::FilePath module_path_;
59 :
60 : // The block that has been created or reused to hold metadata.
61 : BlockGraph::Block* metadata_block_;
62 :
63 : DISALLOW_COPY_AND_ASSIGN(AddMetadataTransform);
64 : };
65 :
66 : } // namespace transforms
67 : } // namespace pe
68 :
69 : #endif // SYZYGY_PE_TRANSFORMS_ADD_METADATA_TRANSFORM_H_
|