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.
5 // This is the transformation for Windows X86 executables.
7 #ifndef COURGETTE_WIN32_X86_PATCHER_H_
8 #define COURGETTE_WIN32_X86_PATCHER_H_
10 #include "courgette/ensemble.h"
14 // Courgette32X86Patcher is a TransformationPatcher for Windows 32-bit
17 class PatcherX86_32
: public TransformationPatcher
{
19 explicit PatcherX86_32(const Region
& region
)
20 : ensemble_region_(region
) {
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
;
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
;
37 Status
PredictTransformParameters(SinkStreamSet
* predicted_parameters
) {
38 // No code needed to write an 'empty' predicted parameter set.
42 Status
Transform(SourceStreamSet
* corrected_parameters
,
43 SinkStreamSet
* transformed_element
) {
45 if (!corrected_parameters
->Empty())
46 return C_GENERAL_ERROR
; // Don't expect any corrected parameters.
48 AssemblyProgram
* program
= NULL
;
49 status
= ParseDetectedExecutable(ensemble_region_
.start() + base_offset_
,
55 EncodedProgram
* encoded
= NULL
;
56 status
= Encode(program
, &encoded
);
57 DeleteAssemblyProgram(program
);
61 status
= WriteEncodedProgram(encoded
, transformed_element
);
62 DeleteEncodedProgram(encoded
);
67 Status
Reform(SourceStreamSet
* transformed_element
,
68 SinkStream
* reformed_element
) {
70 EncodedProgram
* encoded_program
= NULL
;
71 status
= ReadEncodedProgram(transformed_element
, &encoded_program
);
75 status
= Assemble(encoded_program
, reformed_element
);
76 DeleteEncodedProgram(encoded_program
);
84 Region ensemble_region_
;
89 DISALLOW_COPY_AND_ASSIGN(PatcherX86_32
);
93 #endif // COURGETTE_WIN32_X86_PATCHER_H_