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 #include "courgette/ensemble.h"
7 #include "base/basictypes.h"
8 #include "base/string_number_conversions.h"
10 #include "courgette/region.h"
11 #include "courgette/streams.h"
12 #include "courgette/simple_delta.h"
16 Element::Element(ExecutableType kind
,
19 : kind_(kind
), ensemble_(ensemble
), region_(region
) {
22 Element::~Element() {}
24 std::string
Element::Name() const {
25 return ensemble_
->name() + "("
26 + base::IntToString(kind()) + ","
27 + base::Uint64ToString(offset_in_ensemble()) + ","
28 + base::Uint64ToString(region().length()) + ")";
31 // Scans the Ensemble's region, sniffing out Elements. We assume that the
32 // elements do not overlap.
33 Status
Ensemble::FindEmbeddedElements() {
35 size_t length
= region_
.length();
36 const uint8
* start
= region_
.start();
39 while (position
< length
) {
41 size_t detected_length
;
43 Status result
= DetectExecutableType(start
+ position
,
45 &type
, &detected_length
);
48 Region
region(start
+ position
, detected_length
);
50 Element
* element
= new Element(type
, this, region
);
51 owned_elements_
.push_back(element
);
52 elements_
.push_back(element
);
53 position
+= region
.length();
61 Ensemble::~Ensemble() {
62 for (size_t i
= 0; i
< owned_elements_
.size(); ++i
)
63 delete owned_elements_
[i
];