| 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> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "courgette/assembly_program.h" |
| 8 | 11 |
| 9 namespace courgette { | 12 namespace courgette { |
| 10 | 13 |
| 14 Disassembler::RvaVisitor_Abs32::RvaVisitor_Abs32( |
| 15 const std::vector<RVA>& rva_locations, |
| 16 const AddressTranslator& translator) |
| 17 : VectorRvaVisitor<RVA>(rva_locations), translator_(translator) { |
| 18 } |
| 19 |
| 20 RVA Disassembler::RvaVisitor_Abs32::Get() const { |
| 21 // For Abs32 targets, get target RVA from architecture-dependent functions. |
| 22 return translator_.PointerToTargetRVA(translator_.RVAToPointer(*it_)); |
| 23 } |
| 24 |
| 25 Disassembler::RvaVisitor_Rel32::RvaVisitor_Rel32( |
| 26 const std::vector<RVA>& rva_locations, |
| 27 const AddressTranslator& translator) |
| 28 : VectorRvaVisitor<RVA>(rva_locations), translator_(translator) { |
| 29 } |
| 30 |
| 31 RVA Disassembler::RvaVisitor_Rel32::Get() const { |
| 32 // For Rel32 targets, only handle 32-bit offsets. |
| 33 return *it_ + 4 + Read32LittleEndian(translator_.RVAToPointer(*it_)); |
| 34 } |
| 35 |
| 11 Disassembler::Disassembler(const void* start, size_t length) | 36 Disassembler::Disassembler(const void* start, size_t length) |
| 12 : failure_reason_("uninitialized") { | 37 : failure_reason_("uninitialized") { |
| 13 start_ = reinterpret_cast<const uint8_t*>(start); | 38 start_ = reinterpret_cast<const uint8_t*>(start); |
| 14 length_ = length; | 39 length_ = length; |
| 15 end_ = start_ + length_; | 40 end_ = start_ + length_; |
| 16 }; | 41 }; |
| 17 | 42 |
| 18 Disassembler::~Disassembler() {}; | 43 Disassembler::~Disassembler() {}; |
| 19 | 44 |
| 20 const uint8_t* Disassembler::FileOffsetToPointer(FileOffset file_offset) const { | 45 const uint8_t* Disassembler::FileOffsetToPointer(FileOffset file_offset) const { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 bool Disassembler::Good() { | 58 bool Disassembler::Good() { |
| 34 failure_reason_ = nullptr; | 59 failure_reason_ = nullptr; |
| 35 return true; | 60 return true; |
| 36 } | 61 } |
| 37 | 62 |
| 38 bool Disassembler::Bad(const char* reason) { | 63 bool Disassembler::Bad(const char* reason) { |
| 39 failure_reason_ = reason; | 64 failure_reason_ = reason; |
| 40 return false; | 65 return false; |
| 41 } | 66 } |
| 42 | 67 |
| 68 void Disassembler::PrecomputeLabels(AssemblyProgram* program) { |
| 69 std::unique_ptr<RvaVisitor> abs32_visitor(CreateAbs32TargetRvaVisitor()); |
| 70 std::unique_ptr<RvaVisitor> rel32_visitor(CreateRel32TargetRvaVisitor()); |
| 71 program->PrecomputeLabels(abs32_visitor.get(), rel32_visitor.get()); |
| 72 } |
| 73 |
| 43 void Disassembler::ReduceLength(size_t reduced_length) { | 74 void Disassembler::ReduceLength(size_t reduced_length) { |
| 44 CHECK_LE(reduced_length, length_); | 75 CHECK_LE(reduced_length, length_); |
| 45 length_ = reduced_length; | 76 length_ = reduced_length; |
| 46 end_ = start_ + length_; | 77 end_ = start_ + length_; |
| 47 } | 78 } |
| 48 | 79 |
| 49 } // namespace courgette | 80 } // namespace courgette |
| OLD | NEW |