OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The main idea in Courgette is to do patching *under a tranformation*. The | 5 // The main idea in Courgette is to do patching *under a tranformation*. The |
6 // input is transformed into a new representation, patching occurs in the new | 6 // input is transformed into a new representation, patching occurs in the new |
7 // repesentation, and then the tranform is reversed to get the patched data. | 7 // repesentation, and then the tranform is reversed to get the patched data. |
8 // | 8 // |
9 // The idea is applied to pieces (or 'Elements') of the whole (or 'Ensemble'). | 9 // The idea is applied to pieces (or 'Elements') of the whole (or 'Ensemble'). |
10 // Each of the elements has to go through the same set of steps in lock-step, | 10 // Each of the elements has to go through the same set of steps in lock-step, |
(...skipping 18 matching lines...) Expand all Loading... |
29 namespace courgette { | 29 namespace courgette { |
30 | 30 |
31 // Forward declarations: | 31 // Forward declarations: |
32 class Ensemble; | 32 class Ensemble; |
33 class PEInfo; | 33 class PEInfo; |
34 | 34 |
35 // An Element is a region of an Ensemble with an identifyable kind. | 35 // An Element is a region of an Ensemble with an identifyable kind. |
36 // | 36 // |
37 class Element { | 37 class Element { |
38 public: | 38 public: |
39 enum Kind { WIN32_X86_WITH_CODE, WIN32_NOCODE }; | 39 Element(ExecutableType kind, |
| 40 Ensemble* ensemble, |
| 41 const Region& region, |
| 42 PEInfo*info); |
40 | 43 |
41 virtual ~Element() {} | 44 virtual ~Element(); |
42 | 45 |
43 Kind kind() const { return kind_; } | 46 ExecutableType kind() const { return kind_; } |
44 const Region& region() const { return region_; } | 47 const Region& region() const { return region_; } |
45 | 48 |
46 // The name is used only for debugging and logging. | 49 // The name is used only for debugging and logging. |
47 virtual std::string Name() const; | 50 virtual std::string Name() const; |
48 | 51 |
49 // Returns the byte position of this Element relative to the start of | 52 // Returns the byte position of this Element relative to the start of |
50 // containing Ensemble. | 53 // containing Ensemble. |
51 size_t offset_in_ensemble() const; | 54 size_t offset_in_ensemble() const; |
52 | 55 |
53 // Some subclasses of Element might have a PEInfo. | 56 // The ImageInfo for this executable |
54 virtual PEInfo* GetPEInfo() const { return NULL; } | 57 virtual PEInfo* GetImageInfo() const { return info_; } |
55 | |
56 protected: | |
57 Element(Kind kind, Ensemble* ensemble, const Region& region); | |
58 | 58 |
59 private: | 59 private: |
60 Kind kind_; | 60 ExecutableType kind_; |
61 Ensemble* ensemble_; | 61 Ensemble* ensemble_; |
62 Region region_; | 62 Region region_; |
| 63 PEInfo *info_; |
63 | 64 |
64 DISALLOW_COPY_AND_ASSIGN(Element); | 65 DISALLOW_COPY_AND_ASSIGN(Element); |
65 }; | 66 }; |
66 | 67 |
67 | 68 |
68 class Ensemble { | 69 class Ensemble { |
69 public: | 70 public: |
70 Ensemble(const Region& region, const char* name) | 71 Ensemble(const Region& region, const char* name) |
71 : region_(region), name_(name) {} | 72 : region_(region), name_(name) {} |
72 ~Ensemble(); | 73 ~Ensemble(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // correction: | 133 // correction: |
133 // base-file | 134 // base-file |
134 // element-1 | 135 // element-1 |
135 // element-2 | 136 // element-2 |
136 // ... | 137 // ... |
137 | 138 |
138 static const uint32 kMagic = 'C' | ('o' << 8) | ('u' << 16); | 139 static const uint32 kMagic = 'C' | ('o' << 8) | ('u' << 16); |
139 | 140 |
140 static const uint32 kVersion = 20110216; | 141 static const uint32 kVersion = 20110216; |
141 | 142 |
142 // Transformation method IDs. | 143 // Transformation method IDs. These are embedded in generated files, so |
| 144 // never remove or change an existing id. |
143 enum TransformationMethodId { | 145 enum TransformationMethodId { |
144 T_COURGETTE_WIN32_X86 = 1, // Windows 32 bit 'Portable Executable' x86. | 146 T_COURGETTE_WIN32_X86 = 1, // Windows 32 bit 'Portable Executable' x86. |
145 }; | 147 }; |
146 }; | 148 }; |
147 | 149 |
148 // For any transform you would implement both a TransformationPatcher and a | 150 // For any transform you would implement both a TransformationPatcher and a |
149 // TransformationPatchGenerator. | 151 // TransformationPatchGenerator. |
150 // | 152 // |
151 // TransformationPatcher is the interface which abstracts out the actual | 153 // TransformationPatcher is the interface which abstracts out the actual |
152 // transformation used on an Element. The patching itself happens outside the | 154 // transformation used on an Element. The patching itself happens outside the |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 SinkStream* reformed_element); | 251 SinkStream* reformed_element); |
250 | 252 |
251 protected: | 253 protected: |
252 Element* old_element_; | 254 Element* old_element_; |
253 Element* new_element_; | 255 Element* new_element_; |
254 TransformationPatcher* patcher_; | 256 TransformationPatcher* patcher_; |
255 }; | 257 }; |
256 | 258 |
257 } // namespace | 259 } // namespace |
258 #endif // COURGETTE_ENSEMBLE_H_ | 260 #endif // COURGETTE_ENSEMBLE_H_ |
OLD | NEW |