| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_elf_32_arm.h" | 5 #include "courgette/disassembler_elf_32_arm.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "courgette/assembly_program.h" | 11 #include "courgette/assembly_program.h" |
| 12 #include "courgette/courgette.h" | 12 #include "courgette/courgette.h" |
| 13 | 13 |
| 14 namespace courgette { | 14 namespace courgette { |
| 15 | 15 |
| 16 CheckBool DisassemblerElf32ARM::Compress(ARM_RVA type, | 16 CheckBool DisassemblerElf32ARM::Compress(ARM_RVA type, |
| 17 uint32_t arm_op, | 17 uint32_t arm_op, |
| 18 RVA rva, | 18 RVA rva, |
| 19 uint16_t* c_op, | 19 uint16_t* c_op, |
| 20 uint32_t* addr) { | 20 uint32_t* addr) { |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 const uint8_t* const adjust_pointer_to_rva = | 420 const uint8_t* const adjust_pointer_to_rva = |
| 421 start_pointer - section_header->sh_addr; | 421 start_pointer - section_header->sh_addr; |
| 422 | 422 |
| 423 // Find the rel32 relocations. | 423 // Find the rel32 relocations. |
| 424 const uint8_t* p = start_pointer; | 424 const uint8_t* p = start_pointer; |
| 425 bool on_32bit = 1; // 32-bit ARM ops appear on 32-bit boundaries, so track it | 425 bool on_32bit = 1; // 32-bit ARM ops appear on 32-bit boundaries, so track it |
| 426 while (p < end_pointer) { | 426 while (p < end_pointer) { |
| 427 // Heuristic discovery of rel32 locations in instruction stream: are the | 427 // Heuristic discovery of rel32 locations in instruction stream: are the |
| 428 // next few bytes the start of an instruction containing a rel32 | 428 // next few bytes the start of an instruction containing a rel32 |
| 429 // addressing mode? | 429 // addressing mode? |
| 430 scoped_ptr<TypedRVAARM> rel32_rva; | 430 std::unique_ptr<TypedRVAARM> rel32_rva; |
| 431 RVA target_rva = 0; | 431 RVA target_rva = 0; |
| 432 bool found = false; | 432 bool found = false; |
| 433 | 433 |
| 434 // 16-bit thumb ops | 434 // 16-bit thumb ops |
| 435 if (!found && p + 3 <= end_pointer) { | 435 if (!found && p + 3 <= end_pointer) { |
| 436 uint16_t pval = Read16LittleEndian(p); | 436 uint16_t pval = Read16LittleEndian(p); |
| 437 if ((pval & 0xF000) == 0xD000) { | 437 if ((pval & 0xF000) == 0xD000) { |
| 438 RVA rva = static_cast<RVA>(p - adjust_pointer_to_rva); | 438 RVA rva = static_cast<RVA>(p - adjust_pointer_to_rva); |
| 439 | 439 |
| 440 rel32_rva.reset(new TypedRVAARM(ARM_OFF8, rva)); | 440 rel32_rva.reset(new TypedRVAARM(ARM_OFF8, rva)); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 // Move 2 bytes at a time, but track 32-bit boundaries | 523 // Move 2 bytes at a time, but track 32-bit boundaries |
| 524 p += 2; | 524 p += 2; |
| 525 on_32bit = ((on_32bit + 1) % 2) != 0; | 525 on_32bit = ((on_32bit + 1) % 2) != 0; |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 | 528 |
| 529 return true; | 529 return true; |
| 530 } | 530 } |
| 531 | 531 |
| 532 } // namespace courgette | 532 } // namespace courgette |
| OLD | NEW |