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