| OLD | NEW |
| 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 <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 8 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 9 | 11 |
| 10 #include "courgette/region.h" | 12 #include "courgette/region.h" |
| 11 #include "courgette/simple_delta.h" | 13 #include "courgette/simple_delta.h" |
| 12 #include "courgette/streams.h" | 14 #include "courgette/streams.h" |
| 13 | 15 |
| 14 namespace courgette { | 16 namespace courgette { |
| 15 | 17 |
| 16 Element::Element(ExecutableType kind, | 18 Element::Element(ExecutableType kind, |
| 17 Ensemble* ensemble, | 19 Ensemble* ensemble, |
| 18 const Region& region) | 20 const Region& region) |
| 19 : kind_(kind), ensemble_(ensemble), region_(region) { | 21 : kind_(kind), ensemble_(ensemble), region_(region) { |
| 20 } | 22 } |
| 21 | 23 |
| 22 Element::~Element() {} | 24 Element::~Element() {} |
| 23 | 25 |
| 24 std::string Element::Name() const { | 26 std::string Element::Name() const { |
| 25 return ensemble_->name() + "(" | 27 return ensemble_->name() + "(" |
| 26 + base::IntToString(kind()) + "," | 28 + base::IntToString(kind()) + "," |
| 27 + base::Uint64ToString(offset_in_ensemble()) + "," | 29 + base::Uint64ToString(offset_in_ensemble()) + "," |
| 28 + base::Uint64ToString(region().length()) + ")"; | 30 + base::Uint64ToString(region().length()) + ")"; |
| 29 } | 31 } |
| 30 | 32 |
| 31 // Scans the Ensemble's region, sniffing out Elements. We assume that the | 33 // Scans the Ensemble's region, sniffing out Elements. We assume that the |
| 32 // elements do not overlap. | 34 // elements do not overlap. |
| 33 Status Ensemble::FindEmbeddedElements() { | 35 Status Ensemble::FindEmbeddedElements() { |
| 34 | 36 |
| 35 size_t length = region_.length(); | 37 size_t length = region_.length(); |
| 36 const uint8* start = region_.start(); | 38 const uint8_t* start = region_.start(); |
| 37 | 39 |
| 38 size_t position = 0; | 40 size_t position = 0; |
| 39 while (position < length) { | 41 while (position < length) { |
| 40 ExecutableType type; | 42 ExecutableType type; |
| 41 size_t detected_length; | 43 size_t detected_length; |
| 42 | 44 |
| 43 Status result = DetectExecutableType(start + position, | 45 Status result = DetectExecutableType(start + position, |
| 44 length - position, | 46 length - position, |
| 45 &type, &detected_length); | 47 &type, &detected_length); |
| 46 | 48 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 } | 59 } |
| 58 return C_OK; | 60 return C_OK; |
| 59 } | 61 } |
| 60 | 62 |
| 61 Ensemble::~Ensemble() { | 63 Ensemble::~Ensemble() { |
| 62 for (size_t i = 0; i < owned_elements_.size(); ++i) | 64 for (size_t i = 0; i < owned_elements_.size(); ++i) |
| 63 delete owned_elements_[i]; | 65 delete owned_elements_[i]; |
| 64 } | 66 } |
| 65 | 67 |
| 66 } // namespace | 68 } // namespace |
| OLD | NEW |