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
3 // found in the LICENSE file.
5 #ifndef COURGETTE_REL32_FINDER_H_
6 #define COURGETTE_REL32_FINDER_H_
13 #include "courgette/image_utils.h"
17 // A helper class to scan through a section of code to extract RVAs.
20 Rel32Finder(RVA relocs_start_rva, RVA relocs_end_rva);
21 virtual ~Rel32Finder() = default;
23 // Swaps data in |rel32_locations_| with |dest|.
24 void SwapRel32Locations(std::vector<RVA>* dest);
26 #if COURGETTE_HISTOGRAM_TARGETS
27 // Swaps data in |rel32_target_rvas_| with |dest|.
28 void SwapRel32TargetRVAs(std::map<RVA, int>* dest);
31 // Scans through [|start_pointer|, |end_pointer|) for rel32 addresses. Seeks
32 // RVAs that satisfy the following:
33 // - Do not overlap with |abs32_locations| (assumed sorted).
34 // - Do not overlap with [relocs_start_rva, relocs_end_rva).
35 // - Whose targets are in [|start_rva|, |end_rva|).
36 // The sorted results are written to |rel32_locations_|.
37 virtual void Find(const uint8_t* start_pointer,
38 const uint8_t* end_pointer,
41 const std::vector<RVA>& abs32_locations) = 0;
44 const RVA relocs_start_rva_;
45 const RVA relocs_end_rva_;
47 std::vector<RVA> rel32_locations_;
49 #if COURGETTE_HISTOGRAM_TARGETS
50 std::map<RVA, int> rel32_target_rvas_;
54 } // namespace courgette
56 #endif // COURGETTE_REL32_FINDER_H_