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_win32_x64.h" | 5 #include "courgette/disassembler_win32_x64.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 p += relocs_size; | 566 p += relocs_size; |
567 continue; | 567 continue; |
568 } | 568 } |
569 } | 569 } |
570 | 570 |
571 while (abs32_pos != abs32_locations_.end() && *abs32_pos < current_rva) | 571 while (abs32_pos != abs32_locations_.end() && *abs32_pos < current_rva) |
572 ++abs32_pos; | 572 ++abs32_pos; |
573 | 573 |
574 if (abs32_pos != abs32_locations_.end() && *abs32_pos == current_rva) { | 574 if (abs32_pos != abs32_locations_.end() && *abs32_pos == current_rva) { |
575 uint32 target_address = Read32LittleEndian(p); | 575 uint32 target_address = Read32LittleEndian(p); |
576 RVA target_rva = target_address - image_base(); | 576 // TODO(wfh): image_base() can be larger than 32 bits, so this math can |
| 577 // underflow. Figure out the right solution here. |
| 578 RVA target_rva = target_address - static_cast<uint32>(image_base()); |
577 // TODO(sra): target could be Label+offset. It is not clear how to guess | 579 // TODO(sra): target could be Label+offset. It is not clear how to guess |
578 // which it might be. We assume offset==0. | 580 // which it might be. We assume offset==0. |
579 if (!program->EmitAbs32(program->FindOrMakeAbs32Label(target_rva))) | 581 if (!program->EmitAbs32(program->FindOrMakeAbs32Label(target_rva))) |
580 return false; | 582 return false; |
581 p += 4; | 583 p += 4; |
582 continue; | 584 continue; |
583 } | 585 } |
584 | 586 |
585 while (rel32_pos != rel32_locations_.end() && *rel32_pos < current_rva) | 587 while (rel32_pos != rel32_locations_.end() && *rel32_pos < current_rva) |
586 ++rel32_pos; | 588 ++rel32_pos; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 directory->size_ = static_cast<uint32>(size); | 725 directory->size_ = static_cast<uint32>(size); |
724 return true; | 726 return true; |
725 } else { | 727 } else { |
726 directory->address_ = 0; | 728 directory->address_ = 0; |
727 directory->size_ = 0; | 729 directory->size_ = 0; |
728 return true; | 730 return true; |
729 } | 731 } |
730 } | 732 } |
731 | 733 |
732 } // namespace courgette | 734 } // namespace courgette |
OLD | NEW |