summaryrefslogtreecommitdiffstats
path: root/courgette/win32_x86_generator.h
diff options
context:
space:
mode:
authorsra@chromium.org <sra@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 23:00:29 +0000
committersra@chromium.org <sra@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 23:00:29 +0000
commit04ca1bc65afb76ea30698c25f24599d20119e3d2 (patch)
tree2bb65e974d478f4d607b83f6a84a56c01f501ac0 /courgette/win32_x86_generator.h
parent9adf1dcf3281408560267787eddcc767566b425f (diff)
downloadchromium_src-04ca1bc65afb76ea30698c25f24599d20119e3d2.zip
chromium_src-04ca1bc65afb76ea30698c25f24599d20119e3d2.tar.gz
chromium_src-04ca1bc65afb76ea30698c25f24599d20119e3d2.tar.bz2
Move Courgette
from src\third_party\courgette to src\courgette and src\courgette\third_party Fixed #includes Added properties to ignore generated files: C:\c5\src>svn pg svn:ignore courgette courgette.xcodeproj courgette.sln courgette_fuzz.vcproj courgette_lib.vcproj courgette_minimal_tool.vcproj courgette_tool.vcproj courgette.vcproj courgette_unittests.vcproj SConstruct courgette_fuzz.scons courgette_lib.scons courgette_main.scons courgette_minimal_tool.scons courgette.scons courgette_tool.scons courgette_unittests.scons Review URL: http://codereview.chromium.org/115062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15692 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/win32_x86_generator.h')
-rw-r--r--courgette/win32_x86_generator.h126
1 files changed, 126 insertions, 0 deletions
diff --git a/courgette/win32_x86_generator.h b/courgette/win32_x86_generator.h
new file mode 100644
index 0000000..3aabe9f
--- /dev/null
+++ b/courgette/win32_x86_generator.h
@@ -0,0 +1,126 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This is the transformation and adjustment for Windows X86 executables.
+
+#ifndef COURGETTE_WIN32_X86_GENERATOR_H_
+#define COURGETTE_WIN32_X86_GENERATOR_H_
+
+#include "base/scoped_ptr.h"
+
+#include "courgette/ensemble.h"
+
+namespace courgette {
+
+class CourgetteWin32X86PatchGenerator : public TransformationPatchGenerator {
+ public:
+ CourgetteWin32X86PatchGenerator(Element* old_element,
+ Element* new_element,
+ CourgetteWin32X86Patcher* patcher)
+ : TransformationPatchGenerator(old_element, new_element, patcher) {
+ }
+
+ CourgettePatchFile::TransformationMethodId Kind() {
+ return CourgettePatchFile::T_COURGETTE_WIN32_X86;
+ }
+
+ Status WriteInitialParameters(SinkStream* parameter_stream) {
+ parameter_stream->WriteVarint32(old_element_->offset_in_ensemble());
+ parameter_stream->WriteVarint32(old_element_->region().length());
+ return C_OK;
+ // TODO(sra): Initialize |patcher_| with these parameters.
+ }
+
+ Status PredictTransformParameters(SinkStreamSet* prediction) {
+ return TransformationPatchGenerator::PredictTransformParameters(prediction);
+ }
+
+ Status CorrectedTransformParameters(SinkStreamSet* parameters) {
+ // No code needed to write an 'empty' parameter set.
+ return C_OK;
+ }
+
+ // The format of a transformed_element is a serialized EncodedProgram. We
+ // first disassemble the original old and new Elements into AssemblyPrograms.
+ // Then we adjust the new AssemblyProgram to make it as much like the old one
+ // as possible, before converting the AssemblyPrograms to EncodedPrograms and
+ // serializing them.
+ Status Transform(SourceStreamSet* corrected_parameters,
+ SinkStreamSet* old_transformed_element,
+ SinkStreamSet* new_transformed_element) {
+ // Don't expect any corrected parameters.
+ if (!corrected_parameters->Empty())
+ return C_GENERAL_ERROR;
+
+ // Generate old version of program using |corrected_parameters|.
+ // TODO(sra): refactor to use same code from patcher_.
+ AssemblyProgram* old_program = NULL;
+ Status old_parse_status =
+ ParseWin32X86PE(old_element_->region().start(),
+ old_element_->region().length(),
+ &old_program);
+ if (old_parse_status != C_OK)
+ return old_parse_status;
+
+ AssemblyProgram* new_program = NULL;
+ Status new_parse_status =
+ ParseWin32X86PE(new_element_->region().start(),
+ new_element_->region().length(),
+ &new_program);
+ if (new_parse_status != C_OK) {
+ DeleteAssemblyProgram(old_program);
+ return new_parse_status;
+ }
+
+ EncodedProgram* old_encoded = NULL;
+ Status old_encode_status = Encode(old_program, &old_encoded);
+ if (old_encode_status != C_OK) {
+ DeleteAssemblyProgram(old_program);
+ return old_encode_status;
+ }
+
+ Status old_write_status =
+ WriteEncodedProgram(old_encoded, old_transformed_element);
+ DeleteEncodedProgram(old_encoded);
+ if (old_write_status != C_OK) {
+ DeleteAssemblyProgram(old_program);
+ return old_write_status;
+ }
+
+ Status adjust_status = Adjust(*old_program, new_program);
+ DeleteAssemblyProgram(old_program);
+ if (adjust_status != C_OK) {
+ DeleteAssemblyProgram(new_program);
+ return adjust_status;
+ }
+
+ EncodedProgram* new_encoded = NULL;
+ Status new_encode_status = Encode(new_program, &new_encoded);
+ DeleteAssemblyProgram(new_program);
+ if (new_encode_status != C_OK)
+ return new_encode_status;
+
+ Status new_write_status =
+ WriteEncodedProgram(new_encoded, new_transformed_element);
+ DeleteEncodedProgram(new_encoded);
+ if (new_write_status != C_OK)
+ return new_write_status;
+
+ return C_OK;
+ }
+
+ Status Reform(SourceStreamSet* transformed_element,
+ SinkStream* reformed_element) {
+ return TransformationPatchGenerator::Reform(transformed_element,
+ reformed_element);
+ }
+
+ private:
+ ~CourgetteWin32X86PatchGenerator() { }
+
+ DISALLOW_COPY_AND_ASSIGN(CourgetteWin32X86PatchGenerator);
+};
+
+} // namespace courgette
+#endif // COURGETTE_WIN32_X86_GENERATOR_H_