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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "courgette/assembly_program.h" | 10 #include "courgette/assembly_program.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 const std::vector<RVA>& rva_locations, | 26 const std::vector<RVA>& rva_locations, |
27 const AddressTranslator& translator) | 27 const AddressTranslator& translator) |
28 : VectorRvaVisitor<RVA>(rva_locations), translator_(translator) { | 28 : VectorRvaVisitor<RVA>(rva_locations), translator_(translator) { |
29 } | 29 } |
30 | 30 |
31 RVA Disassembler::RvaVisitor_Rel32::Get() const { | 31 RVA Disassembler::RvaVisitor_Rel32::Get() const { |
32 // For Rel32 targets, only handle 32-bit offsets. | 32 // For Rel32 targets, only handle 32-bit offsets. |
33 return *it_ + 4 + Read32LittleEndian(translator_.RVAToPointer(*it_)); | 33 return *it_ + 4 + Read32LittleEndian(translator_.RVAToPointer(*it_)); |
34 } | 34 } |
35 | 35 |
36 Disassembler::Disassembler(const void* start, size_t length) | 36 Disassembler::Disassembler(const uint8_t* start, size_t length) |
37 : failure_reason_("uninitialized") { | 37 : failure_reason_("uninitialized") { |
38 start_ = reinterpret_cast<const uint8_t*>(start); | 38 start_ = start; |
39 length_ = length; | 39 length_ = length; |
40 end_ = start_ + length_; | 40 end_ = start_ + length_; |
41 }; | 41 }; |
42 | 42 |
43 Disassembler::~Disassembler() {}; | 43 Disassembler::~Disassembler() {}; |
44 | 44 |
45 const uint8_t* Disassembler::FileOffsetToPointer(FileOffset file_offset) const { | 45 const uint8_t* Disassembler::FileOffsetToPointer(FileOffset file_offset) const { |
46 CHECK_LE(file_offset, static_cast<FileOffset>(end_ - start_)); | 46 CHECK_LE(file_offset, static_cast<FileOffset>(end_ - start_)); |
47 return start_ + file_offset; | 47 return start_ + file_offset; |
48 } | 48 } |
(...skipping 22 matching lines...) Expand all Loading... |
71 program->PrecomputeLabels(abs32_visitor.get(), rel32_visitor.get()); | 71 program->PrecomputeLabels(abs32_visitor.get(), rel32_visitor.get()); |
72 } | 72 } |
73 | 73 |
74 void Disassembler::ReduceLength(size_t reduced_length) { | 74 void Disassembler::ReduceLength(size_t reduced_length) { |
75 CHECK_LE(reduced_length, length_); | 75 CHECK_LE(reduced_length, length_); |
76 length_ = reduced_length; | 76 length_ = reduced_length; |
77 end_ = start_ + length_; | 77 end_ = start_ + length_; |
78 } | 78 } |
79 | 79 |
80 } // namespace courgette | 80 } // namespace courgette |
OLD | NEW |