| OLD | NEW |
| 1 // Copyright 2015 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 #ifndef COURGETTE_REL32_FINDER_WIN32_X86_H_ | 5 #ifndef COURGETTE_REL32_FINDER_H_ |
| 6 #define COURGETTE_REL32_FINDER_WIN32_X86_H_ | 6 #define COURGETTE_REL32_FINDER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "courgette/image_utils.h" | 13 #include "courgette/image_utils.h" |
| 14 | 14 |
| 15 namespace courgette { | 15 namespace courgette { |
| 16 | 16 |
| 17 // A helper class to scan through a section of code to extract RVAs. | 17 // A helper class to scan through a section of code to extract RVAs. |
| 18 class Rel32FinderWin32X86 { | 18 class Rel32Finder { |
| 19 public: | 19 public: |
| 20 Rel32FinderWin32X86(RVA relocs_start_rva, RVA relocs_end_rva); | 20 Rel32Finder(RVA relocs_start_rva, RVA relocs_end_rva); |
| 21 virtual ~Rel32FinderWin32X86(); | 21 virtual ~Rel32Finder() = default; |
| 22 | 22 |
| 23 // Swaps data in |rel32_locations_| with |dest|. | 23 // Swaps data in |rel32_locations_| with |dest|. |
| 24 void SwapRel32Locations(std::vector<RVA>* dest); | 24 void SwapRel32Locations(std::vector<RVA>* dest); |
| 25 | 25 |
| 26 #if COURGETTE_HISTOGRAM_TARGETS | 26 #if COURGETTE_HISTOGRAM_TARGETS |
| 27 // Swaps data in |rel32_target_rvas_| with |dest|. | 27 // Swaps data in |rel32_target_rvas_| with |dest|. |
| 28 void SwapRel32TargetRVAs(std::map<RVA, int>* dest); | 28 void SwapRel32TargetRVAs(std::map<RVA, int>* dest); |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 // Scans through [|start_pointer|, |end_pointer|) for rel32 addresses. Seeks | 31 // Scans through [|start_pointer|, |end_pointer|) for rel32 addresses. Seeks |
| (...skipping 12 matching lines...) Expand all Loading... |
| 44 const RVA relocs_start_rva_; | 44 const RVA relocs_start_rva_; |
| 45 const RVA relocs_end_rva_; | 45 const RVA relocs_end_rva_; |
| 46 | 46 |
| 47 std::vector<RVA> rel32_locations_; | 47 std::vector<RVA> rel32_locations_; |
| 48 | 48 |
| 49 #if COURGETTE_HISTOGRAM_TARGETS | 49 #if COURGETTE_HISTOGRAM_TARGETS |
| 50 std::map<RVA, int> rel32_target_rvas_; | 50 std::map<RVA, int> rel32_target_rvas_; |
| 51 #endif | 51 #endif |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 // The basic implementation performs naive scan for rel32 JMP and Jcc opcodes | |
| 55 // (excluding JPO/JPE) disregarding instruction alignment. | |
| 56 class Rel32FinderWin32X86_Basic : public Rel32FinderWin32X86 { | |
| 57 public: | |
| 58 Rel32FinderWin32X86_Basic(RVA relocs_start_rva, RVA relocs_end_rva); | |
| 59 virtual ~Rel32FinderWin32X86_Basic(); | |
| 60 | |
| 61 // Rel32FinderWin32X86 implementation. | |
| 62 void Find(const uint8_t* start_pointer, | |
| 63 const uint8_t* end_pointer, | |
| 64 RVA start_rva, | |
| 65 RVA end_rva, | |
| 66 const std::vector<RVA>& abs32_locations) override; | |
| 67 }; | |
| 68 | |
| 69 } // namespace courgette | 54 } // namespace courgette |
| 70 | 55 |
| 71 #endif // COURGETTE_REL32_FINDER_WIN32_X86_H_ | 56 #endif // COURGETTE_REL32_FINDER_H_ |
| OLD | NEW |