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/disassembler.h" | 5 #include "courgette/disassembler.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <algorithm> | 10 #include <algorithm> |
8 #include <string> | 11 #include <string> |
9 #include <vector> | 12 #include <vector> |
10 | 13 |
11 #include "base/basictypes.h" | |
12 #include "base/logging.h" | 14 #include "base/logging.h" |
13 | 15 |
14 #include "courgette/assembly_program.h" | 16 #include "courgette/assembly_program.h" |
15 #include "courgette/courgette.h" | 17 #include "courgette/courgette.h" |
16 #include "courgette/disassembler_elf_32_arm.h" | 18 #include "courgette/disassembler_elf_32_arm.h" |
17 #include "courgette/disassembler_elf_32_x86.h" | 19 #include "courgette/disassembler_elf_32_x86.h" |
18 #include "courgette/disassembler_win32_x64.h" | 20 #include "courgette/disassembler_win32_x64.h" |
19 #include "courgette/disassembler_win32_x86.h" | 21 #include "courgette/disassembler_win32_x86.h" |
20 #include "courgette/encoded_program.h" | 22 #include "courgette/encoded_program.h" |
21 | 23 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 *output = program; | 96 *output = program; |
95 return C_OK; | 97 return C_OK; |
96 } | 98 } |
97 | 99 |
98 void DeleteAssemblyProgram(AssemblyProgram* program) { | 100 void DeleteAssemblyProgram(AssemblyProgram* program) { |
99 delete program; | 101 delete program; |
100 } | 102 } |
101 | 103 |
102 Disassembler::Disassembler(const void* start, size_t length) | 104 Disassembler::Disassembler(const void* start, size_t length) |
103 : failure_reason_("uninitialized") { | 105 : failure_reason_("uninitialized") { |
104 | 106 start_ = reinterpret_cast<const uint8_t*>(start); |
105 start_ = reinterpret_cast<const uint8*>(start); | |
106 length_ = length; | 107 length_ = length; |
107 end_ = start_ + length_; | 108 end_ = start_ + length_; |
108 }; | 109 }; |
109 | 110 |
110 Disassembler::~Disassembler() {}; | 111 Disassembler::~Disassembler() {}; |
111 | 112 |
112 const uint8* Disassembler::OffsetToPointer(size_t offset) const { | 113 const uint8_t* Disassembler::OffsetToPointer(size_t offset) const { |
113 assert(start_ + offset <= end_); | 114 assert(start_ + offset <= end_); |
114 return start_ + offset; | 115 return start_ + offset; |
115 } | 116 } |
116 | 117 |
117 bool Disassembler::Good() { | 118 bool Disassembler::Good() { |
118 failure_reason_ = NULL; | 119 failure_reason_ = NULL; |
119 return true; | 120 return true; |
120 } | 121 } |
121 | 122 |
122 bool Disassembler::Bad(const char* reason) { | 123 bool Disassembler::Bad(const char* reason) { |
123 failure_reason_ = reason; | 124 failure_reason_ = reason; |
124 return false; | 125 return false; |
125 } | 126 } |
126 | 127 |
127 void Disassembler::ReduceLength(size_t reduced_length) { | 128 void Disassembler::ReduceLength(size_t reduced_length) { |
128 CHECK_LE(reduced_length, length_); | 129 CHECK_LE(reduced_length, length_); |
129 length_ = reduced_length; | 130 length_ = reduced_length; |
130 end_ = start_ + length_; | 131 end_ = start_ + length_; |
131 } | 132 } |
132 | 133 |
133 } // namespace courgette | 134 } // namespace courgette |
OLD | NEW |