1 : // Copyright 2014 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 BlockGraphTransform that removes empty sections (e.g sections
16 : // without blocks). Empty sections cannot contribute any bytes to the final
17 : // image. It is safe to remove them.
18 :
19 : #ifndef SYZYGY_PE_TRANSFORMS_PE_REMOVE_EMPTY_SECTIONS_TRANSFORM_H_
20 : #define SYZYGY_PE_TRANSFORMS_PE_REMOVE_EMPTY_SECTIONS_TRANSFORM_H_
21 :
22 : #include "syzygy/block_graph/transforms/named_transform.h"
23 :
24 m : namespace pe {
25 m : namespace transforms {
26 :
27 m : using block_graph::transforms::NamedBlockGraphTransformImpl;
28 :
29 : // A transform for removing empty sections in a given block graph.
30 m : class PERemoveEmptySectionsTransform
31 m : : public NamedBlockGraphTransformImpl<PERemoveEmptySectionsTransform> {
32 m : public:
33 m : typedef block_graph::BlockGraph BlockGraph;
34 m : typedef block_graph::TransformPolicyInterface TransformPolicyInterface;
35 :
36 m : PERemoveEmptySectionsTransform();
37 :
38 : // Performs the transform which removes every empty section.
39 : //
40 : // @param policy The policy object restricting how the transform is applied.
41 : // @param block_graph The block graph to transform.
42 : // @param dos_header_block the block containing the module's DOS header.
43 : // @returns true on success, false otherwise.
44 m : virtual bool TransformBlockGraph(
45 m : const TransformPolicyInterface* policy,
46 m : BlockGraph* block_graph,
47 m : BlockGraph::Block* dos_header_block) override;
48 :
49 : // The name of this transform.
50 m : static const char kTransformName[];
51 m : };
52 :
53 m : } // namespace transforms
54 m : } // namespace pe
55 :
56 : #endif // SYZYGY_PE_TRANSFORMS_PE_REMOVE_EMPTY_SECTIONS_TRANSFORM_H_
|