Skip to content

Commit

Permalink
Start refactoring to reduce executable type knowledge.
Browse files Browse the repository at this point in the history
This creates executable detection functions, a globally shared enum for
describing an executable type, and reduces the number of classes and
locations with executable specific knowledge.

These changes, along with moving architecture specific classes into their
own files should make it easier to produce special purpose clients that
only contain the code required to apply their own form of patch.

DisassemblerWin32EXE, ImagePE, CourgetteWin32X86PatchGenerator, and
CourgetteWin32X86Patcher, and ensemble handling are all heavily affected here.

This should have no effect on the behavior of the system yet, and is instead
all prep-work.

BUG=None
TEST=Unittests


Review URL: http://codereview.chromium.org/7920004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103879 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dgarrett@chromium.org committed Oct 4, 2011
1 parent 13daae6 commit 14df9e6
Show file tree
Hide file tree
Showing 15 changed files with 579 additions and 512 deletions.
4 changes: 3 additions & 1 deletion courgette/courgette.gyp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Copyright (c) 2011 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.

Expand All @@ -22,6 +22,8 @@
'difference_estimator.h',
'disassembler.cc',
'disassembler.h',
'disassembler_win32_x86.cc',
'disassembler_win32_x86.h',
'encoded_program.cc',
'encoded_program.h',
'ensemble.cc',
Expand Down
19 changes: 16 additions & 3 deletions courgette/courgette.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.

Expand Down Expand Up @@ -50,6 +50,13 @@ enum Status {
C_ADJUSTMENT_FAILED = 27, //
};

// What type of executable is something
// Generally corresponds to CourgettePatchFile::TransformationMethodId
enum ExecutableType {
UNKNOWN,
WIN32_X86
};

class SinkStream;
class SinkStreamSet;
class SourceStream;
Expand Down Expand Up @@ -84,8 +91,14 @@ Status GenerateEnsemblePatch(SourceStream* old, SourceStream* target,
// storing the pointer to the AssemblyProgram in |*output|.
// Returns C_OK if successful, otherwise returns an error status and sets
// |*output| to NULL.
Status ParseWin32X86PE(const void* buffer, size_t length,
AssemblyProgram** output);
ExecutableType DetectExecutableType(const void* buffer, size_t length);

// Attempts to detect the type of executable, and parse it with the
// appropriate tools, storing the pointer to the AssemblyProgram in |*output|.
// Returns C_OK if successful, otherwise returns an error status and sets
// |*output| to NULL.
Status ParseDetectedExecutable(const void* buffer, size_t length,
AssemblyProgram** output);

// Converts |program| into encoded form, returning it as |*output|.
// Returns C_OK if succeeded, otherwise returns an error status and
Expand Down
27 changes: 14 additions & 13 deletions courgette/courgette_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ void Disassemble(const std::wstring& input_file,

courgette::AssemblyProgram* program = NULL;
const courgette::Status parse_status =
courgette::ParseWin32X86PE(buffer.c_str(), buffer.length(), &program);
courgette::ParseDetectedExecutable(buffer.c_str(), buffer.length(),
&program);

if (parse_status != courgette::C_OK)
Problem("Can't parse input.");
Expand Down Expand Up @@ -122,17 +123,17 @@ void DisassembleAndAdjust(const std::wstring& program_file,

courgette::AssemblyProgram* program = NULL;
const courgette::Status parse_program_status =
courgette::ParseWin32X86PE(program_buffer.c_str(),
program_buffer.length(),
&program);
courgette::ParseDetectedExecutable(program_buffer.c_str(),
program_buffer.length(),
&program);
if (parse_program_status != courgette::C_OK)
Problem("Can't parse program input.");

courgette::AssemblyProgram* model = NULL;
const courgette::Status parse_model_status =
courgette::ParseWin32X86PE(model_buffer.c_str(),
model_buffer.length(),
&model);
courgette::ParseDetectedExecutable(model_buffer.c_str(),
model_buffer.length(),
&model);
if (parse_model_status != courgette::C_OK)
Problem("Can't parse model input.");

Expand Down Expand Up @@ -178,17 +179,17 @@ void DisassembleAdjustDiff(const std::wstring& model_file,

courgette::AssemblyProgram* model = NULL;
const courgette::Status parse_model_status =
courgette::ParseWin32X86PE(model_buffer.c_str(),
model_buffer.length(),
&model);
courgette::ParseDetectedExecutable(model_buffer.c_str(),
model_buffer.length(),
&model);
if (parse_model_status != courgette::C_OK)
Problem("Can't parse model input.");

courgette::AssemblyProgram* program = NULL;
const courgette::Status parse_program_status =
courgette::ParseWin32X86PE(program_buffer.c_str(),
program_buffer.length(),
&program);
courgette::ParseDetectedExecutable(program_buffer.c_str(),
program_buffer.length(),
&program);
if (parse_program_status != courgette::C_OK)
Problem("Can't parse program input.");

Expand Down
Loading

0 comments on commit 14df9e6

Please sign in to comment.