| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // This is the transformation for Windows X86 executables. | |
| 6 | |
| 7 #ifndef COURGETTE_WIN32_X86_PATCHER_H_ | |
| 8 #define COURGETTE_WIN32_X86_PATCHER_H_ | |
| 9 | |
| 10 #include "courgette/ensemble.h" | |
| 11 | |
| 12 namespace courgette { | |
| 13 | |
| 14 // CourgetteWin32X86Patcher is a TransformationPatcher for Windows 32-bit | |
| 15 // executables. | |
| 16 // | |
| 17 class CourgetteWin32X86Patcher : public TransformationPatcher { | |
| 18 public: | |
| 19 explicit CourgetteWin32X86Patcher(const Region& region) | |
| 20 : ensemble_region_(region) { | |
| 21 } | |
| 22 | |
| 23 Status Init(SourceStream* parameter_stream) { | |
| 24 if (!parameter_stream->ReadVarint32(&base_offset_)) | |
| 25 return C_BAD_TRANSFORM; | |
| 26 if (!parameter_stream->ReadVarint32(&base_length_)) | |
| 27 return C_BAD_TRANSFORM; | |
| 28 | |
| 29 if (base_offset_ > ensemble_region_.length()) | |
| 30 return C_BAD_TRANSFORM; | |
| 31 if (base_length_ > ensemble_region_.length() - base_offset_) | |
| 32 return C_BAD_TRANSFORM; | |
| 33 | |
| 34 return C_OK; | |
| 35 } | |
| 36 | |
| 37 Status PredictTransformParameters(SinkStreamSet* predicted_parameters) { | |
| 38 // No code needed to write an 'empty' predicted parameter set. | |
| 39 return C_OK; | |
| 40 } | |
| 41 | |
| 42 Status Transform(SourceStreamSet* corrected_parameters, | |
| 43 SinkStreamSet* transformed_element) { | |
| 44 Status status; | |
| 45 if (!corrected_parameters->Empty()) | |
| 46 return C_GENERAL_ERROR; // Don't expect any corrected parameters. | |
| 47 | |
| 48 AssemblyProgram* program = NULL; | |
| 49 status = ParseDetectedExecutable(ensemble_region_.start() + base_offset_, | |
| 50 base_length_, | |
| 51 &program); | |
| 52 if (status != C_OK) | |
| 53 return status; | |
| 54 | |
| 55 EncodedProgram* encoded = NULL; | |
| 56 status = Encode(program, &encoded); | |
| 57 DeleteAssemblyProgram(program); | |
| 58 if (status != C_OK) | |
| 59 return status; | |
| 60 | |
| 61 status = WriteEncodedProgram(encoded, transformed_element); | |
| 62 DeleteEncodedProgram(encoded); | |
| 63 | |
| 64 return status; | |
| 65 } | |
| 66 | |
| 67 Status Reform(SourceStreamSet* transformed_element, | |
| 68 SinkStream* reformed_element) { | |
| 69 Status status; | |
| 70 EncodedProgram* encoded_program = NULL; | |
| 71 status = ReadEncodedProgram(transformed_element, &encoded_program); | |
| 72 if (status != C_OK) | |
| 73 return status; | |
| 74 | |
| 75 status = Assemble(encoded_program, reformed_element); | |
| 76 DeleteEncodedProgram(encoded_program); | |
| 77 if (status != C_OK) | |
| 78 return status; | |
| 79 | |
| 80 return C_OK; | |
| 81 } | |
| 82 | |
| 83 private: | |
| 84 Region ensemble_region_; | |
| 85 | |
| 86 uint32 base_offset_; | |
| 87 uint32 base_length_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(CourgetteWin32X86Patcher); | |
| 90 }; | |
| 91 | |
| 92 } // namespace | |
| 93 #endif // COURGETTE_WIN32_X86_PATCHER_H_ | |
| OLD | NEW |