OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "courgette/rel32_finder_win32_x86.h" | 7 #include "courgette/rel32_finder_win32_x86.h" |
8 | 8 |
9 namespace courgette { | 9 namespace courgette { |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 RVA rel32_rva = static_cast<RVA>(rel32 - adjust_pointer_to_rva); | 80 RVA rel32_rva = static_cast<RVA>(rel32 - adjust_pointer_to_rva); |
81 | 81 |
82 // Is there an abs32 reloc overlapping the candidate? | 82 // Is there an abs32 reloc overlapping the candidate? |
83 while (abs32_pos != abs32_locations.end() && *abs32_pos < rel32_rva - 3) | 83 while (abs32_pos != abs32_locations.end() && *abs32_pos < rel32_rva - 3) |
84 ++abs32_pos; | 84 ++abs32_pos; |
85 // Now: (*abs32_pos > rel32_rva - 4) i.e. the lowest addressed 4-byte | 85 // Now: (*abs32_pos > rel32_rva - 4) i.e. the lowest addressed 4-byte |
86 // region that could overlap rel32_rva. | 86 // region that could overlap rel32_rva. |
87 if (abs32_pos != abs32_locations.end()) { | 87 if (abs32_pos != abs32_locations.end()) { |
88 if (*abs32_pos < rel32_rva + 4) { | 88 if (*abs32_pos < rel32_rva + 4) { |
89 // Beginning of abs32 reloc is before end of rel32 reloc so they | 89 // Beginning of abs32 reloc is before end of rel32 reloc so they |
90 // overlap. Skip four bytes past the abs32 reloc. | 90 // overlap. Skip four bytes past the abs32 reloc. |
91 p += (*abs32_pos + 4) - current_rva; | 91 p += (*abs32_pos + 4) - current_rva; |
92 continue; | 92 continue; |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
| 96 // + 4 since offset is relative to start of next instruction. |
96 RVA target_rva = rel32_rva + 4 + Read32LittleEndian(rel32); | 97 RVA target_rva = rel32_rva + 4 + Read32LittleEndian(rel32); |
97 // Valid, rel32 target must be within image, and within this section. | 98 // Valid, rel32 target must be within image, and within this section. |
98 // Subsumes |target_rva| != |kUnassignedRVA|. | 99 // Subsumes |target_rva| != |kUnassignedRVA|. |
99 if (start_rva <= target_rva && target_rva < end_rva) { | 100 if (start_rva <= target_rva && target_rva < end_rva) { |
100 rel32_locations_.push_back(rel32_rva); | 101 rel32_locations_.push_back(rel32_rva); |
101 #if COURGETTE_HISTOGRAM_TARGETS | 102 #if COURGETTE_HISTOGRAM_TARGETS |
102 ++rel32_target_rvas_[target_rva]; | 103 ++rel32_target_rvas_[target_rva]; |
103 #endif | 104 #endif |
104 p = rel32 + 4; | 105 p = rel32 + 4; |
105 continue; | 106 continue; |
106 } | 107 } |
107 } | 108 } |
108 p += 1; | 109 p += 1; |
109 } | 110 } |
110 } | 111 } |
111 | 112 |
112 } // namespace courgette | 113 } // namespace courgette |
OLD | NEW |