1 : // Copyright 2013 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 : // CoffPrepareHeadersTransform is the COFF-equivalent of
16 : // PEPrepareHeadersTransform. The transform adjusts the contents of the
17 : // headers block to match block graph metadata, so it can be written back as
18 : // a COFF file.
19 :
20 : #ifndef SYZYGY_PE_TRANSFORMS_COFF_PREPARE_HEADERS_TRANSFORM_H_
21 : #define SYZYGY_PE_TRANSFORMS_COFF_PREPARE_HEADERS_TRANSFORM_H_
22 :
23 : #include "syzygy/block_graph/transforms/named_transform.h"
24 :
25 m : namespace pe {
26 m : namespace transforms {
27 :
28 : // A block graph transform that resizes the headers block to fit the number
29 : // of sections of the block graph, and updates the file header
30 : // accordingly. All references are also wiped from the headers block, so as
31 : // to make removing dependent (referenced) blocks, such as relocation
32 : // tables, possible.
33 m : class CoffPrepareHeadersTransform
34 m : : public block_graph::transforms::NamedBlockGraphTransformImpl<
35 m : CoffPrepareHeadersTransform> {
36 m : public:
37 m : typedef block_graph::BlockGraph BlockGraph;
38 m : typedef block_graph::TransformPolicyInterface TransformPolicyInterface;
39 :
40 : // Apply this transform to the specified COFF block graph.
41 : //
42 : // @param policy The policy object restricting how the transform is applied.
43 : // @param block_graph The block graph to transform.
44 : // @param headers_block The COFF headers block of the block graph.
45 : // @returns true on success, false otherwise.
46 m : virtual bool TransformBlockGraph(const TransformPolicyInterface* policy,
47 m : BlockGraph* block_graph,
48 m : BlockGraph::Block* headers_block) override;
49 :
50 : // The name of this transform.
51 m : static const char kTransformName[];
52 m : };
53 :
54 m : } // namespace transforms
55 m : } // namespace pe
56 :
57 : #endif // SYZYGY_PE_TRANSFORMS_COFF_PREPARE_HEADERS_TRANSFORM_H_
|