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.h" | 5 #include "courgette/disassembler_elf_32.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 402 } |
403 | 403 |
404 CheckBool DisassemblerElf32::ParseSimpleRegion( | 404 CheckBool DisassemblerElf32::ParseSimpleRegion( |
405 size_t start_file_offset, | 405 size_t start_file_offset, |
406 size_t end_file_offset, | 406 size_t end_file_offset, |
407 AssemblyProgram* program) { | 407 AssemblyProgram* program) { |
408 | 408 |
409 const uint8* start = OffsetToPointer(start_file_offset); | 409 const uint8* start = OffsetToPointer(start_file_offset); |
410 const uint8* end = OffsetToPointer(end_file_offset); | 410 const uint8* end = OffsetToPointer(end_file_offset); |
411 | 411 |
412 const uint8* p = start; | 412 // Callers don't guarantee start < end |
| 413 if (start >= end) return true; |
413 | 414 |
414 while (p < end) { | 415 const ptrdiff_t len = end - start; // Works because vars are byte pointers |
415 if (!program->EmitByteInstruction(*p)) | 416 |
416 return false; | 417 if (!program->EmitBytesInstruction(start, len)) |
417 ++p; | 418 return false; |
418 } | |
419 | 419 |
420 return true; | 420 return true; |
421 } | 421 } |
422 | 422 |
423 CheckBool DisassemblerElf32::ParseAbs32Relocs() { | 423 CheckBool DisassemblerElf32::ParseAbs32Relocs() { |
424 abs32_locations_.clear(); | 424 abs32_locations_.clear(); |
425 | 425 |
426 // Loop through sections for relocation sections | 426 // Loop through sections for relocation sections |
427 for (int section_id = 0; section_id < SectionHeaderCount(); section_id++) { | 427 for (int section_id = 0; section_id < SectionHeaderCount(); section_id++) { |
428 const Elf32_Shdr *section_header = SectionHeader(section_id); | 428 const Elf32_Shdr *section_header = SectionHeader(section_id); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 return false; | 497 return false; |
498 } | 498 } |
499 | 499 |
500 std::sort(rel32_locations_.begin(), | 500 std::sort(rel32_locations_.begin(), |
501 rel32_locations_.end(), | 501 rel32_locations_.end(), |
502 TypedRVA::IsLessThan); | 502 TypedRVA::IsLessThan); |
503 return true; | 503 return true; |
504 } | 504 } |
505 | 505 |
506 } // namespace courgette | 506 } // namespace courgette |
OLD | NEW |