Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_win32.h" | 5 #include "courgette/disassembler_win32.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 directory->address_ = rva; | 646 directory->address_ = rva; |
| 647 directory->size_ = static_cast<uint32_t>(size); | 647 directory->size_ = static_cast<uint32_t>(size); |
| 648 return true; | 648 return true; |
| 649 } else { | 649 } else { |
| 650 directory->address_ = 0; | 650 directory->address_ = 0; |
| 651 directory->size_ = 0; | 651 directory->size_ = 0; |
| 652 return true; | 652 return true; |
| 653 } | 653 } |
| 654 } | 654 } |
| 655 | 655 |
| 656 bool DisassemblerWin32::QuickDetects(const uint8_t* start, | |
|
huangs
2016/06/10 21:10:22
Move to line 341 for consistent ordering with head
etiennep
2016/06/13 17:50:21
Done.
| |
| 657 size_t length, | |
| 658 uint16_t magic) { | |
| 659 if (length < kOffsetOfFileAddressOfNewExeHeader + 4 /* size */) | |
| 660 return false; | |
| 661 | |
| 662 // Have 'MZ' magic for a DOS header? | |
| 663 if (start[0] != 'M' || start[1] != 'Z') | |
| 664 return false; | |
| 665 | |
| 666 FileOffset file_offset = static_cast<FileOffset>( | |
| 667 ReadU32(start, kOffsetOfFileAddressOfNewExeHeader)); | |
| 668 if (file_offset >= length) | |
| 669 return false; | |
| 670 const uint8_t* const pe_header = start + file_offset; | |
| 671 const size_t kMinPEHeaderSize = 4 /*signature*/ + kSizeOfCoffHeader; | |
| 672 if (pe_header <= start || pe_header >= start + length - kMinPEHeaderSize) | |
|
huangs
2016/06/10 21:10:22
NIT: I'd prefer
pe_header + kMinPEHeaderSize >= st
etiennep
2016/06/13 17:50:21
Done.
| |
| 673 return false; | |
| 674 if (file_offset % 8 != 0) | |
|
huangs
2016/06/10 21:10:22
Can combine this condition via || with "file_offse
etiennep
2016/06/13 17:50:21
Done.
| |
| 675 return false; | |
| 676 | |
| 677 const uint8_t* optional_header = pe_header + 4 + kSizeOfCoffHeader; | |
| 678 | |
| 679 // Check we can read the magic. | |
| 680 if (optional_header + 2 >= start + length) | |
| 681 return false; | |
| 682 if (magic != ReadU16(optional_header, 0)) | |
| 683 return false; | |
| 684 | |
| 685 return true; | |
| 686 } | |
| 687 | |
| 656 } // namespace courgette | 688 } // namespace courgette |
| OLD | NEW |