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 : // Defines RelinkerInterface.
16 :
17 : #ifndef SYZYGY_PE_RELINKER_H_
18 : #define SYZYGY_PE_RELINKER_H_
19 :
20 : #include <vector>
21 :
22 : #include "base/logging.h"
23 : #include "syzygy/block_graph/orderer.h"
24 : #include "syzygy/block_graph/transform.h"
25 : #include "syzygy/pdb/pdb_mutator.h"
26 :
27 : namespace pe {
28 :
29 : // Interface for full file-to-file transformations of PE or COFF files.
30 : class RelinkerInterface {
31 : public:
32 : typedef block_graph::BlockGraph BlockGraph;
33 : typedef block_graph::BlockGraph::ImageFormat ImageFormat;
34 : typedef block_graph::BlockGraphOrdererInterface Orderer;
35 : typedef block_graph::BlockGraphTransformInterface Transform;
36 : typedef pdb::PdbMutatorInterface PdbMutator;
37 :
38 : // Virtual destructor for derived classes.
39 E : virtual ~RelinkerInterface() {}
40 :
41 : // @returns the image format handled by the relinker.
42 : virtual ImageFormat image_format() const = 0;
43 :
44 : // Add a transform to be applied. Transform objects must outlive the
45 : // relinker. Each transform will be applied in the order added to the
46 : // relinker, assuming all earlier transforms have succeeded.
47 : //
48 : // @param transform a transform to be applied.
49 : // @returns true on success, or false if adding transforms is not
50 : // supported.
51 i : virtual bool AppendTransform(Transform* transform) {
52 i : LOG(ERROR) << "Relinker does not support transforms.";
53 i : return false;
54 i : }
55 :
56 : // Add transforms to be applied. Transform objects must outlive the
57 : // relinker. Each transform will be applied in the order added to the
58 : // relinker, assuming all earlier transforms have succeeded.
59 : //
60 : // @param transforms transforms to be applied, in order.
61 : // @returns true on success, or false if adding transforms is not
62 : // supported.
63 i : virtual bool AppendTransforms(const std::vector<Transform*>& transforms) {
64 i : LOG(ERROR) << "Relinker does not support transforms.";
65 i : return false;
66 i : }
67 :
68 : // Add an orderer to be applied. Orderer objects must outlive the
69 : // relinker. Each orderer will be applied in the order added to the
70 : // relinker, assuming all earlier orderers have succeeded.
71 : //
72 : // @param orderer an orderer to be applied.
73 : // @returns true on success, or false if adding orderers is not
74 : // supported.
75 i : virtual bool AppendOrderer(Orderer* orderer) {
76 i : LOG(ERROR) << "Relinker does not support orderers.";
77 i : return false;
78 i : }
79 :
80 : // Add orderers to be applied. Orderer objects must outlive the
81 : // relinker. Each orderer will be applied in the order added to the
82 : // relinker, assuming all earlier orderers have succeeded.
83 : //
84 : // @param orderers orderers to be applied, in order.
85 : // @returns true on success, or false if adding orderers is not
86 : // supported.
87 i : virtual bool AppendOrderers(const std::vector<Orderer*>& orderers) {
88 i : LOG(ERROR) << "Relinker does not support orderers.";
89 i : return false;
90 i : }
91 :
92 : // Add a PDB mutator to be applied. PDB mutater objects must outlive the
93 : // relinker. Each mutator will be applied in the order added to the
94 : // relinker, assuming all earlier mutators have succeeded.
95 : //
96 : // @param pdb_mutator a PDB mutator to be applied.
97 : // @returns true on success, or false if adding PDB mutators is not
98 : // supported.
99 i : virtual bool AppendPdbMutator(PdbMutator* pdb_mutator) {
100 i : LOG(ERROR) << "Relinker does not support PDB mutators.";
101 i : return false;
102 i : }
103 :
104 : // Add PDB mutators to be applied by this relinker. Each mutator will be
105 : // applied in the order added to the relinker, assuming all earlier mutators
106 : // have succeeded.
107 : //
108 : // @param pdb_mutators a vector of mutators to be applied to the input image.
109 : // The pointers must remain valid for the lifespan of the relinker.
110 i : virtual bool AppendPdbMutators(const std::vector<PdbMutator*>& pdb_mutators) {
111 i : LOG(ERROR) << "Relinker does not support PDB mutators.";
112 i : return false;
113 i : }
114 :
115 : // Initialize the relinker from its input data.
116 : //
117 : // @returns true on success, false otherwise.
118 : virtual bool Init() = 0;
119 :
120 : // After a successful call to Init(), apply transforms, orderers, and PDB
121 : // mutators, as appropriate, then generate the output files.
122 : //
123 : // @returns true on success, false otherwise.
124 : virtual bool Relink() = 0;
125 :
126 : protected:
127 : // Protected default constructor for derived classes.
128 E : RelinkerInterface() {}
129 :
130 : private:
131 : DISALLOW_COPY_AND_ASSIGN(RelinkerInterface);
132 : };
133 :
134 : } // namespace pe
135 :
136 : #endif // SYZYGY_PE_RELINKER_H_
|