OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef COURGETTE_WIN32_X86_PATCHER_H_ | 5 #ifndef COURGETTE_WIN32_X86_PATCHER_H_ |
6 #define COURGETTE_WIN32_X86_PATCHER_H_ | 6 #define COURGETTE_WIN32_X86_PATCHER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "courgette/assembly_program.h" | |
13 #include "courgette/encoded_program.h" | |
14 #include "courgette/ensemble.h" | 11 #include "courgette/ensemble.h" |
15 #include "courgette/program_detector.h" | |
16 | 12 |
17 namespace courgette { | 13 namespace courgette { |
18 | 14 |
19 // PatcherX86_32 is the universal patcher for all executables. The executable | 15 // PatcherX86_32 is the universal patcher for all executables. The executable |
20 // type is determined by ParseDetectedExecutable function. | 16 // type is determined by ParseDetectedExecutable function. |
21 // | 17 // |
22 class PatcherX86_32 : public TransformationPatcher { | 18 class PatcherX86_32 : public TransformationPatcher { |
23 public: | 19 public: |
24 explicit PatcherX86_32(const Region& region) | 20 explicit PatcherX86_32(const Region& region) |
25 : ensemble_region_(region), | 21 : ensemble_region_(region), |
(...skipping 19 matching lines...) Expand all Loading... |
45 // No code needed to write an 'empty' predicted parameter set. | 41 // No code needed to write an 'empty' predicted parameter set. |
46 return C_OK; | 42 return C_OK; |
47 } | 43 } |
48 | 44 |
49 Status Transform(SourceStreamSet* corrected_parameters, | 45 Status Transform(SourceStreamSet* corrected_parameters, |
50 SinkStreamSet* transformed_element) { | 46 SinkStreamSet* transformed_element) { |
51 Status status; | 47 Status status; |
52 if (!corrected_parameters->Empty()) | 48 if (!corrected_parameters->Empty()) |
53 return C_GENERAL_ERROR; // Don't expect any corrected parameters. | 49 return C_GENERAL_ERROR; // Don't expect any corrected parameters. |
54 | 50 |
55 scoped_ptr<AssemblyProgram> program; | 51 AssemblyProgram* program = NULL; |
56 status = ParseDetectedExecutable(ensemble_region_.start() + base_offset_, | 52 status = ParseDetectedExecutable(ensemble_region_.start() + base_offset_, |
57 base_length_, | 53 base_length_, |
58 &program); | 54 &program); |
59 if (status != C_OK) | 55 if (status != C_OK) |
60 return status; | 56 return status; |
61 | 57 |
62 scoped_ptr<EncodedProgram> encoded; | 58 EncodedProgram* encoded = NULL; |
63 status = Encode(*program, &encoded); | 59 status = Encode(program, &encoded); |
| 60 DeleteAssemblyProgram(program); |
64 if (status != C_OK) | 61 if (status != C_OK) |
65 return status; | 62 return status; |
66 | 63 |
67 program.reset(); | 64 status = WriteEncodedProgram(encoded, transformed_element); |
| 65 DeleteEncodedProgram(encoded); |
68 | 66 |
69 return WriteEncodedProgram(encoded.get(), transformed_element); | 67 return status; |
70 } | 68 } |
71 | 69 |
72 Status Reform(SourceStreamSet* transformed_element, | 70 Status Reform(SourceStreamSet* transformed_element, |
73 SinkStream* reformed_element) { | 71 SinkStream* reformed_element) { |
74 Status status; | 72 Status status; |
75 scoped_ptr<EncodedProgram> encoded_program; | 73 EncodedProgram* encoded_program = NULL; |
76 status = ReadEncodedProgram(transformed_element, &encoded_program); | 74 status = ReadEncodedProgram(transformed_element, &encoded_program); |
77 if (status != C_OK) | 75 if (status != C_OK) |
78 return status; | 76 return status; |
79 | 77 |
80 return Assemble(encoded_program.get(), reformed_element); | 78 status = Assemble(encoded_program, reformed_element); |
| 79 DeleteEncodedProgram(encoded_program); |
| 80 if (status != C_OK) |
| 81 return status; |
| 82 |
| 83 return C_OK; |
81 } | 84 } |
82 | 85 |
83 private: | 86 private: |
84 Region ensemble_region_; | 87 Region ensemble_region_; |
85 | 88 |
86 uint32_t base_offset_; | 89 uint32_t base_offset_; |
87 uint32_t base_length_; | 90 uint32_t base_length_; |
88 | 91 |
89 DISALLOW_COPY_AND_ASSIGN(PatcherX86_32); | 92 DISALLOW_COPY_AND_ASSIGN(PatcherX86_32); |
90 }; | 93 }; |
91 | 94 |
92 } // namespace | 95 } // namespace |
93 | |
94 #endif // COURGETTE_WIN32_X86_PATCHER_H_ | 96 #endif // COURGETTE_WIN32_X86_PATCHER_H_ |
OLD | NEW |