Chromium Code Reviews| Index: courgette/rel32_finder_win32_x86.cc |
| diff --git a/courgette/rel32_finder_win32_x86.cc b/courgette/rel32_finder_win32_x86.cc |
| index 171b781ba707f2e8dc389d1c0ea7b17a6cc74ea2..44e991dd6c917e0c73d181f2fbe6d9c33f736bbd 100644 |
| --- a/courgette/rel32_finder_win32_x86.cc |
| +++ b/courgette/rel32_finder_win32_x86.cc |
| @@ -9,10 +9,9 @@ |
| namespace courgette { |
| Rel32FinderWin32X86::Rel32FinderWin32X86( |
| - RVA relocs_start_rva, RVA relocs_end_rva, RVA image_end_rva) |
| + RVA relocs_start_rva, RVA relocs_end_rva) |
| : relocs_start_rva_(relocs_start_rva), |
| - relocs_end_rva_(relocs_end_rva), |
| - image_end_rva_(image_end_rva) { |
| + relocs_end_rva_(relocs_end_rva) { |
| } |
| Rel32FinderWin32X86::~Rel32FinderWin32X86() { |
| @@ -30,7 +29,8 @@ void Rel32FinderWin32X86::SwapRel32TargetRVAs(std::map<RVA, int>* dest) { |
| Rel32FinderWin32X86_Basic::Rel32FinderWin32X86_Basic( |
| RVA relocs_start_rva, RVA relocs_end_rva, RVA image_end_rva) |
| - : Rel32FinderWin32X86(relocs_start_rva, relocs_end_rva, image_end_rva) { |
| + : Rel32FinderWin32X86(relocs_start_rva, relocs_end_rva), |
| + image_end_rva_(image_end_rva) { |
| } |
| Rel32FinderWin32X86_Basic::~Rel32FinderWin32X86_Basic() { |
| @@ -51,6 +51,10 @@ void Rel32FinderWin32X86_Basic::Find(const uint8_t* start_pointer, |
| const uint8_t* p = start_pointer; |
| while (p < end_pointer) { |
| RVA current_rva = static_cast<RVA>(p - adjust_pointer_to_rva); |
| + |
| + // Skip the base reloation table if we encounter it. |
| + // Note: We're not bothering to handle the edge case where a Rel32 pointer |
| + // collides with |relocs_start_rva_| by being {1, 2, 3}-bytes before it. |
| if (current_rva == relocs_start_rva_) { |
| if (relocs_start_rva_ < relocs_end_rva_) { |
| p += relocs_end_rva_ - relocs_start_rva_; |
| @@ -58,13 +62,10 @@ void Rel32FinderWin32X86_Basic::Find(const uint8_t* start_pointer, |
| } |
| } |
| - //while (abs32_pos != abs32_locations.end() && *abs32_pos < current_rva) |
| - // ++abs32_pos; |
| - |
| // Heuristic discovery of rel32 locations in instruction stream: are the |
| // next few bytes the start of an instruction containing a rel32 |
| // addressing mode? |
| - const uint8_t* rel32 = NULL; |
| + const uint8_t* rel32 = nullptr; |
| if (p + 5 <= end_pointer) { |
| if (*p == 0xE8 || *p == 0xE9) { // jmp rel32 and call rel32 |
| @@ -95,9 +96,8 @@ void Rel32FinderWin32X86_Basic::Find(const uint8_t* start_pointer, |
| } |
| RVA target_rva = rel32_rva + 4 + Read32LittleEndian(rel32); |
| - // To be valid, rel32 target must be within image, and within this |
| - // section. |
| - if (IsValidRVA(target_rva) && |
| + // Valid, rel32 target must be within image, and within this section. |
| + if (target_rva < image_end_rva_ && // Subsumes rva != kUnassignedRVA. |
| start_rva <= target_rva && target_rva < end_rva) { |
|
grt (UTC plus 2)
2016/02/11 16:55:34
is it valid for end_rva to be > image_end_rva_? ca
huangs
2016/02/12 01:08:42
The original code intends to separate the "is RVA
|
| rel32_locations_.push_back(rel32_rva); |
| #if COURGETTE_HISTOGRAM_TARGETS |