| 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_PATCHER_X86_32_H_ | 5 #ifndef COURGETTE_PATCHER_X86_32_H_ |
| 6 #define COURGETTE_PATCHER_X86_32_H_ | 6 #define COURGETTE_PATCHER_X86_32_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include "base/logging.h" |
| 11 | |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "courgette/assembly_program.h" | |
| 14 #include "courgette/courgette_flow.h" | 12 #include "courgette/courgette_flow.h" |
| 15 #include "courgette/encoded_program.h" | |
| 16 #include "courgette/ensemble.h" | 13 #include "courgette/ensemble.h" |
| 17 #include "courgette/program_detector.h" | 14 #include "courgette/region.h" |
| 15 #include "courgette/streams.h" |
| 18 | 16 |
| 19 namespace courgette { | 17 namespace courgette { |
| 20 | 18 |
| 21 // PatcherX86_32 is the universal patcher for all executables. The executable | 19 // PatcherX86_32 is the universal patcher for all executables. The executable |
| 22 // type is determined by the program detector. | 20 // type is determined by the program detector. |
| 23 class PatcherX86_32 : public TransformationPatcher { | 21 class PatcherX86_32 : public TransformationPatcher { |
| 24 public: | 22 public: |
| 25 explicit PatcherX86_32(const Region& region) | 23 explicit PatcherX86_32(const Region& region) |
| 26 : ensemble_region_(region), | 24 : ensemble_region_(region), |
| 27 base_offset_(0), | 25 base_offset_(0), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 42 return C_OK; | 40 return C_OK; |
| 43 } | 41 } |
| 44 | 42 |
| 45 Status PredictTransformParameters(SinkStreamSet* predicted_parameters) { | 43 Status PredictTransformParameters(SinkStreamSet* predicted_parameters) { |
| 46 // No code needed to write an 'empty' predicted parameter set. | 44 // No code needed to write an 'empty' predicted parameter set. |
| 47 return C_OK; | 45 return C_OK; |
| 48 } | 46 } |
| 49 | 47 |
| 50 Status Transform(SourceStreamSet* corrected_parameters, | 48 Status Transform(SourceStreamSet* corrected_parameters, |
| 51 SinkStreamSet* transformed_element) { | 49 SinkStreamSet* transformed_element) { |
| 50 if (!corrected_parameters->Empty()) |
| 51 return C_GENERAL_ERROR; // Don't expect any corrected parameters. |
| 52 |
| 52 CourgetteFlow flow; | 53 CourgetteFlow flow; |
| 53 RegionBuffer only_buffer( | 54 RegionBuffer only_buffer( |
| 54 Region(ensemble_region_.start() + base_offset_, base_length_)); | 55 Region(ensemble_region_.start() + base_offset_, base_length_)); |
| 55 flow.ReadAssemblyProgramFromBuffer(flow.ONLY, only_buffer, false); | 56 flow.ReadDisassemblerFromBuffer(flow.ONLY, only_buffer); |
| 56 flow.CreateEncodedProgramFromAssemblyProgram(flow.ONLY); | 57 flow.CreateAssemblyProgramFromDisassembler(flow.ONLY, false); |
| 58 flow.CreateEncodedProgramFromDisassemblerAndAssemblyProgram(flow.ONLY); |
| 57 flow.DestroyAssemblyProgram(flow.ONLY); | 59 flow.DestroyAssemblyProgram(flow.ONLY); |
| 60 flow.DestroyDisassembler(flow.ONLY); |
| 58 flow.WriteSinkStreamSetFromEncodedProgram(flow.ONLY, transformed_element); | 61 flow.WriteSinkStreamSetFromEncodedProgram(flow.ONLY, transformed_element); |
| 59 if (flow.failed()) | 62 if (flow.failed()) |
| 60 LOG(ERROR) << flow.message(); | 63 LOG(ERROR) << flow.message(); |
| 61 return flow.status(); | 64 return flow.status(); |
| 62 } | 65 } |
| 63 | 66 |
| 64 Status Reform(SourceStreamSet* transformed_element, | 67 Status Reform(SourceStreamSet* transformed_element, |
| 65 SinkStream* reformed_element) { | 68 SinkStream* reformed_element) { |
| 66 CourgetteFlow flow; | 69 CourgetteFlow flow; |
| 67 flow.ReadEncodedProgramFromSourceStreamSet(flow.ONLY, transformed_element); | 70 flow.ReadEncodedProgramFromSourceStreamSet(flow.ONLY, transformed_element); |
| 68 flow.WriteExecutableFromEncodedProgram(flow.ONLY, reformed_element); | 71 flow.WriteExecutableFromEncodedProgram(flow.ONLY, reformed_element); |
| 69 if (flow.failed()) | 72 if (flow.failed()) |
| 70 LOG(ERROR) << flow.message(); | 73 LOG(ERROR) << flow.message(); |
| 71 return flow.status(); | 74 return flow.status(); |
| 72 } | 75 } |
| 73 | 76 |
| 74 private: | 77 private: |
| 75 Region ensemble_region_; | 78 Region ensemble_region_; |
| 76 | 79 |
| 77 uint32_t base_offset_; | 80 uint32_t base_offset_; |
| 78 uint32_t base_length_; | 81 uint32_t base_length_; |
| 79 | 82 |
| 80 DISALLOW_COPY_AND_ASSIGN(PatcherX86_32); | 83 DISALLOW_COPY_AND_ASSIGN(PatcherX86_32); |
| 81 }; | 84 }; |
| 82 | 85 |
| 83 } // namespace courgette | 86 } // namespace courgette |
| 84 | 87 |
| 85 #endif // COURGETTE_PATCHER_X86_32_H_ | 88 #endif // COURGETTE_PATCHER_X86_32_H_ |
| OLD | NEW |