1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #ifndef SYZYGY_PDB_OMAP_H_
16 : #define SYZYGY_PDB_OMAP_H_
17 :
18 : #include <windows.h> // NOLINT
19 : #include <dbghelp.h>
20 : #include <vector>
21 :
22 : #include "syzygy/core/address.h"
23 : #include "syzygy/pdb/pdb_file.h"
24 : #include "syzygy/pdb/pdb_reader.h"
25 :
26 m : namespace pdb {
27 :
28 : // Builds an anonymous intialized OMAP object.
29 : //
30 : // @param rva the relative address this entry maps.
31 : // @param rvaTo the relative address that @p rva is mapped to.
32 m : OMAP CreateOmap(ULONG rva, ULONG rvaTo);
33 :
34 : // A comparison functor, for comparing two OMAP entries based on 'rva'.
35 : //
36 : // @param omap1 the first omap object to compare.
37 : // @param omap2 the second omap object to comapre.
38 : // @returns true if omap1.rva < omap2.rva, false otherwise.
39 m : bool OmapLess(const OMAP& omap1, const OMAP& omap2);
40 :
41 : // Determines if the given OMAP vector is valid. That is, for every i in
42 : // [1, omaps.size() - 1], OmapLess(omaps[i - 1], omaps[i]) is true.
43 : //
44 : // @param omaps the vector of OMAPs to validate.
45 : // @returns true if omaps is valid, false otherwise.
46 m : bool OmapVectorIsValid(const std::vector<OMAP>& omaps);
47 :
48 : // Maps an address through the given OMAP information.
49 : //
50 : // @param omaps the vector of OMAPs to apply.
51 : // @param address the address to map.
52 : // @returns the mapped address.
53 : // @pre OmapIsValid(omaps) is true.
54 m : core::RelativeAddress TranslateAddressViaOmap(const std::vector<OMAP>& omaps,
55 m : core::RelativeAddress address);
56 :
57 : // Reads OMAP tables from a PdbFile. The destination vectors may be NULL if
58 : // they are not required to be read. Even if neither stream is read they will be
59 : // checked for existence.
60 : //
61 : // @param pdb_reader the PdbReader to read from.
62 : // @param omap_to the vector to populate with OMAPTO entries. May be NULL.
63 : // @param omap_from the vector to populate with OMAPFROM entries. May be NULL.
64 : // @returns true if the PDB file contains OMAP data and if the OMAP entries have
65 : // been successfully read, false otherwise.
66 m : bool ReadOmapsFromPdbFile(const PdbFile& pdb_file,
67 m : std::vector<OMAP>* omap_to,
68 m : std::vector<OMAP>* omap_from);
69 :
70 : // Reads OMAP tables from a PDB file. The destination vectors may be NULL if
71 : // they are not required to be read. Even if neither stream is read they will be
72 : // checked for existence.
73 : //
74 : // @param pdb_path the path of the PDB file from which to read OMAP data.
75 : // @param omap_to the vector to populate with OMAPTO entries. May be NULL.
76 : // @param omap_from the vector to populate with OMAPFROM entries. May be NULL.
77 : // @returns true if the PDB file contains OMAP data and if the OMAP entries have
78 : // been successfully read, false otherwise.
79 m : bool ReadOmapsFromPdbFile(const base::FilePath& pdb_path,
80 m : std::vector<OMAP>* omap_to,
81 m : std::vector<OMAP>* omap_from);
82 :
83 m : } // namespace pdb
84 :
85 : #endif // SYZYGY_PDB_OMAP_H_
|