summaryrefslogtreecommitdiffstats
path: root/courgette/ensemble.cc
diff options
context:
space:
mode:
authordgarrett@chromium.org <dgarrett@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-26 00:50:20 +0000
committerdgarrett@chromium.org <dgarrett@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-26 00:50:20 +0000
commit423a381f4fd3efd99dfd7bc932777ea596cf7b17 (patch)
treefdbf4a4bc5f2b8d73b90020da470c40a22f4cc2a /courgette/ensemble.cc
parentda1543a1a526aefd1114853cf737846eb5c29640 (diff)
downloadchromium_src-423a381f4fd3efd99dfd7bc932777ea596cf7b17.zip
chromium_src-423a381f4fd3efd99dfd7bc932777ea596cf7b17.tar.gz
chromium_src-423a381f4fd3efd99dfd7bc932777ea596cf7b17.tar.bz2
Further refactoring, move ImageInfo into Disassembler/DisassemblerWin32X86.
This means that all PE specific knowledge is now contained in a single class which leaves us in pretty good shape for supporting ELF 32. There are still widespread assumptions about being 32 bit, but those can be addressed at a much later date. BUG=None TEST=Unittests Review URL: http://codereview.chromium.org/8166013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107260 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/ensemble.cc')
-rw-r--r--courgette/ensemble.cc57
1 files changed, 17 insertions, 40 deletions
diff --git a/courgette/ensemble.cc b/courgette/ensemble.cc
index a2bea8f..fb9b25b 100644
--- a/courgette/ensemble.cc
+++ b/courgette/ensemble.cc
@@ -7,7 +7,6 @@
#include "base/basictypes.h"
#include "base/string_number_conversions.h"
-#include "courgette/image_info.h"
#include "courgette/region.h"
#include "courgette/streams.h"
#include "courgette/simple_delta.h"
@@ -16,14 +15,11 @@ namespace courgette {
Element::Element(ExecutableType kind,
Ensemble* ensemble,
- const Region& region,
- PEInfo* info)
- : kind_(kind), ensemble_(ensemble), region_(region), info_(info) {
+ const Region& region)
+ : kind_(kind), ensemble_(ensemble), region_(region) {
}
-Element::~Element() {
- delete info_;
-}
+Element::~Element() {}
std::string Element::Name() const {
return ensemble_->name() + "("
@@ -41,41 +37,22 @@ Status Ensemble::FindEmbeddedElements() {
size_t position = 0;
while (position < length) {
- ExecutableType type = DetectExecutableType(start + position,
- length - position);
+ ExecutableType type;
+ size_t detected_length;
+
+ Status result = DetectExecutableType(start + position,
+ length - position,
+ &type, &detected_length);
- //
- // TODO(dgarrett) This switch can go away totally after two things.
- //
- // Make ImageInfo generic for all executable types.
- // Find a generic way to handle length detection for executables.
- //
- // When this switch is gone, that's one less piece of code that is
- // executable type aware.
- //
- switch (type) {
- case UNKNOWN: {
- // No Element found at current position.
- ++position;
- break;
- }
- case WIN32_X86: {
- // The Info is only created to detect the length of the executable
- courgette::PEInfo* info(new courgette::PEInfo());
- info->Init(start + position, length - position);
- if (!info->ParseHeader()) {
- delete info;
- position++;
- break;
- }
- Region region(start + position, info->length());
+ if (result == C_OK) {
+ Region region(start + position, detected_length);
- Element* element = new Element(type, this, region, info);
- owned_elements_.push_back(element);
- elements_.push_back(element);
- position += region.length();
- break;
- }
+ Element* element = new Element(type, this, region);
+ owned_elements_.push_back(element);
+ elements_.push_back(element);
+ position += region.length();
+ } else {
+ position++;
}
}
return C_OK;