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_reader.h"
24 :
25 m : namespace pdb {
26 :
27 : // Builds an anonymous intialized OMAP object.
28 : //
29 : // @param rva the relative address this entry maps.
30 : // @param rvaTo the relative address that @p rva is mapped to.
31 m : OMAP CreateOmap(ULONG rva, ULONG rvaTo);
32 :
33 : // A comparison functor, for comparing two OMAP entries based on 'rva'.
34 : //
35 : // @param omap1 the first omap object to compare.
36 : // @param omap2 the second omap object to comapre.
37 : // @returns true if omap1.rva < omap2.rva, false otherwise.
38 m : bool OmapLess(const OMAP& omap1, const OMAP& omap2);
39 :
40 : // Determines if the given OMAP vector is valid. That is, for every i in
41 : // [1, omaps.size() - 1], OmapLess(omaps[i - 1], omaps[i]) is true.
42 : //
43 : // @param omaps the vector of OMAPs to validate.
44 : // @returns true if omaps is valid, false otherwise.
45 m : bool OmapVectorIsValid(const std::vector<OMAP>& omaps);
46 :
47 : // Maps an address through the given OMAP information.
48 : //
49 : // @param omaps the vector of OMAPs to apply.
50 : // @param address the address to map.
51 : // @returns the mapped address.
52 : // @pre OmapIsValid(omaps) is true.
53 m : core::RelativeAddress TranslateAddressViaOmap(const std::vector<OMAP>& omaps,
54 m : core::RelativeAddress address);
55 :
56 : // Reads OMAP tables from a PdbFile. The destination vectors may be NULL if
57 : // they are not required to be read. Even if neither stream is read they will be
58 : // checked for existence.
59 : //
60 : // @param pdb_reader the PdbReader to read from.
61 : // @param omap_to the vector to populate with OMAPTO entries. May be NULL.
62 : // @param omap_from the vector to populate with OMAPFROM entries. May be NULL.
63 : // @returns true if the PDB file contains OMAP data and if the OMAP entries have
64 : // been successfully read, false otherwise.
65 m : bool ReadOmapsFromPdbFile(const PdbFile& pdb_file,
66 m : std::vector<OMAP>* omap_to,
67 m : std::vector<OMAP>* omap_from);
68 :
69 : // Reads OMAP tables from a PDB file. The destination vectors may be NULL if
70 : // they are not required to be read. Even if neither stream is read they will be
71 : // checked for existence.
72 : //
73 : // @param pdb_path the path of the PDB file from which to read OMAP data.
74 : // @param omap_to the vector to populate with OMAPTO entries. May be NULL.
75 : // @param omap_from the vector to populate with OMAPFROM entries. May be NULL.
76 : // @returns true if the PDB file contains OMAP data and if the OMAP entries have
77 : // been successfully read, false otherwise.
78 m : bool ReadOmapsFromPdbFile(const base::FilePath& pdb_path,
79 m : std::vector<OMAP>* omap_to,
80 m : std::vector<OMAP>* omap_from);
81 :
82 m : } // namespace pdb
83 :
84 : #endif // SYZYGY_PDB_OMAP_H_
|