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 #ifndef COURGETTE_DISASSEMBLER_H_ | 5 #ifndef COURGETTE_DISASSEMBLER_H_ |
6 #define COURGETTE_DISASSEMBLER_H_ | 6 #define COURGETTE_DISASSEMBLER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 | 9 |
10 #include "courgette/courgette.h" | 10 #include "courgette/courgette.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // Returns a pointer into the memory copy of the file format. | 47 // Returns a pointer into the memory copy of the file format. |
48 // FileOffsetToPointer(0) returns a pointer to the start of the file format. | 48 // FileOffsetToPointer(0) returns a pointer to the start of the file format. |
49 const uint8* OffsetToPointer(size_t offset) const; | 49 const uint8* OffsetToPointer(size_t offset) const; |
50 | 50 |
51 protected: | 51 protected: |
52 Disassembler(const void* start, size_t length); | 52 Disassembler(const void* start, size_t length); |
53 | 53 |
54 bool Good(); | 54 bool Good(); |
55 bool Bad(const char *reason); | 55 bool Bad(const char *reason); |
56 | 56 |
| 57 // Returns true if the array lies within our memory region. |
| 58 bool IsArrayInBounds(size_t offset, size_t elements, size_t element_size) { |
| 59 return offset <= length() && elements <= (length() - offset) / element_size; |
| 60 } |
| 61 |
57 // These helper functions avoid the need for casts in the main code. | 62 // These helper functions avoid the need for casts in the main code. |
58 uint16 ReadU16(const uint8* address, size_t offset) { | 63 uint16 ReadU16(const uint8* address, size_t offset) { |
59 return *reinterpret_cast<const uint16*>(address + offset); | 64 return *reinterpret_cast<const uint16*>(address + offset); |
60 } | 65 } |
61 | 66 |
62 uint32 ReadU32(const uint8* address, size_t offset) { | 67 uint32 ReadU32(const uint8* address, size_t offset) { |
63 return *reinterpret_cast<const uint32*>(address + offset); | 68 return *reinterpret_cast<const uint32*>(address + offset); |
64 } | 69 } |
65 | 70 |
66 uint64 ReadU64(const uint8* address, size_t offset) { | 71 uint64 ReadU64(const uint8* address, size_t offset) { |
(...skipping 26 matching lines...) Expand all Loading... |
93 // | 98 // |
94 size_t length_; // In current memory. | 99 size_t length_; // In current memory. |
95 const uint8* start_; // In current memory, base for 'file offsets'. | 100 const uint8* start_; // In current memory, base for 'file offsets'. |
96 const uint8* end_; // In current memory. | 101 const uint8* end_; // In current memory. |
97 | 102 |
98 DISALLOW_COPY_AND_ASSIGN(Disassembler); | 103 DISALLOW_COPY_AND_ASSIGN(Disassembler); |
99 }; | 104 }; |
100 | 105 |
101 } // namespace courgette | 106 } // namespace courgette |
102 #endif // COURGETTE_DISASSEMBLER_H_ | 107 #endif // COURGETTE_DISASSEMBLER_H_ |
OLD | NEW |