Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: courgette/ensemble.cc

Issue 8166013: Further refactoring, move ImageInfo into Disassembler/DisassemblerWin32X86. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebase over other changes, fix nit. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « courgette/ensemble.h ('k') | courgette/ensemble_apply.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "courgette/ensemble.h" 5 #include "courgette/ensemble.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 9
10 #include "courgette/image_info.h"
11 #include "courgette/region.h" 10 #include "courgette/region.h"
12 #include "courgette/streams.h" 11 #include "courgette/streams.h"
13 #include "courgette/simple_delta.h" 12 #include "courgette/simple_delta.h"
14 13
15 namespace courgette { 14 namespace courgette {
16 15
17 Element::Element(ExecutableType kind, 16 Element::Element(ExecutableType kind,
18 Ensemble* ensemble, 17 Ensemble* ensemble,
19 const Region& region, 18 const Region& region)
20 PEInfo* info) 19 : kind_(kind), ensemble_(ensemble), region_(region) {
21 : kind_(kind), ensemble_(ensemble), region_(region), info_(info) {
22 } 20 }
23 21
24 Element::~Element() { 22 Element::~Element() {}
25 delete info_;
26 }
27 23
28 std::string Element::Name() const { 24 std::string Element::Name() const {
29 return ensemble_->name() + "(" 25 return ensemble_->name() + "("
30 + base::IntToString(kind()) + "," 26 + base::IntToString(kind()) + ","
31 + base::Uint64ToString(offset_in_ensemble()) + "," 27 + base::Uint64ToString(offset_in_ensemble()) + ","
32 + base::Uint64ToString(region().length()) + ")"; 28 + base::Uint64ToString(region().length()) + ")";
33 } 29 }
34 30
35 // Scans the Ensemble's region, sniffing out Elements. We assume that the 31 // Scans the Ensemble's region, sniffing out Elements. We assume that the
36 // elements do not overlap. 32 // elements do not overlap.
37 Status Ensemble::FindEmbeddedElements() { 33 Status Ensemble::FindEmbeddedElements() {
38 34
39 size_t length = region_.length(); 35 size_t length = region_.length();
40 const uint8* start = region_.start(); 36 const uint8* start = region_.start();
41 37
42 size_t position = 0; 38 size_t position = 0;
43 while (position < length) { 39 while (position < length) {
44 ExecutableType type = DetectExecutableType(start + position, 40 ExecutableType type;
45 length - position); 41 size_t detected_length;
46 42
47 // 43 Status result = DetectExecutableType(start + position,
48 // TODO(dgarrett) This switch can go away totally after two things. 44 length - position,
49 // 45 &type, &detected_length);
50 // Make ImageInfo generic for all executable types.
51 // Find a generic way to handle length detection for executables.
52 //
53 // When this switch is gone, that's one less piece of code that is
54 // executable type aware.
55 //
56 switch (type) {
57 case UNKNOWN: {
58 // No Element found at current position.
59 ++position;
60 break;
61 }
62 case WIN32_X86: {
63 // The Info is only created to detect the length of the executable
64 courgette::PEInfo* info(new courgette::PEInfo());
65 info->Init(start + position, length - position);
66 if (!info->ParseHeader()) {
67 delete info;
68 position++;
69 break;
70 }
71 Region region(start + position, info->length());
72 46
73 Element* element = new Element(type, this, region, info); 47 if (result == C_OK) {
74 owned_elements_.push_back(element); 48 Region region(start + position, detected_length);
75 elements_.push_back(element); 49
76 position += region.length(); 50 Element* element = new Element(type, this, region);
77 break; 51 owned_elements_.push_back(element);
78 } 52 elements_.push_back(element);
53 position += region.length();
54 } else {
55 position++;
79 } 56 }
80 } 57 }
81 return C_OK; 58 return C_OK;
82 } 59 }
83 60
84 Ensemble::~Ensemble() { 61 Ensemble::~Ensemble() {
85 for (size_t i = 0; i < owned_elements_.size(); ++i) 62 for (size_t i = 0; i < owned_elements_.size(); ++i)
86 delete owned_elements_[i]; 63 delete owned_elements_[i];
87 } 64 }
88 65
89 } // namespace 66 } // namespace
OLDNEW
« no previous file with comments | « courgette/ensemble.h ('k') | courgette/ensemble_apply.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698