1 : // Copyright 2015 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_REFINERY_TYPES_PDB_CRAWLER_H_
16 : #define SYZYGY_REFINERY_TYPES_PDB_CRAWLER_H_
17 :
18 : #include <windows.h> // NOLINT
19 : #include <dbghelp.h>
20 : #include <memory>
21 : #include <vector>
22 :
23 : #include "base/containers/hash_tables.h"
24 : #include "base/files/file_path.h"
25 : #include "syzygy/common/binary_stream.h"
26 : #include "syzygy/pdb/pdb_dbi_stream.h"
27 : #include "syzygy/pdb/pdb_stream.h"
28 : #include "syzygy/refinery/core/address.h"
29 :
30 m : namespace refinery {
31 : // Forward declaration.
32 m : class TypeRepository;
33 :
34 : // A worker class to scrape types from PDB symbols using type info enumerator.
35 : // TODO(manzagop): ensure duplicate types are properly dealt with. The current
36 : // implementation generates equivalent types due to:
37 : // - basic types that are mapped to the same type (eg T_LONG and T_INT4)
38 : // - UDTs that are identical up to extra LF_NESTTYPE (which do not make it to
39 : // our type representation)
40 : // - pointers: Foo* and Foo*const will lead to the creation of 2 Foo* types.
41 m : class PdbCrawler {
42 m : public:
43 m : PdbCrawler();
44 m : ~PdbCrawler();
45 :
46 : // Initializes this crawler for the file at @p path.
47 : // @param path the image file whose symbols to crawl for types.
48 m : bool InitializeForFile(const base::FilePath& path);
49 :
50 : // Retrieves all @p types associated with the file this instance
51 : // is initialized to.
52 : // @param types on success contains zero or more types.
53 : // @returns true on success, false on failure.
54 m : bool GetTypes(TypeRepository* types);
55 :
56 : // Retrieves the relative virtual addresses of all virtual function tables.
57 : // @param vftable_rvas on success contains zero or more relative addresses.
58 : // @returns true on success, false on failure.
59 m : bool GetVFTableRVAs(base::hash_set<RelativeAddress>* vftable_rvas);
60 :
61 m : private:
62 m : bool GetVFTableRVAForSymbol(base::hash_set<RelativeAddress>* vftable_rvas,
63 m : uint16_t symbol_length,
64 m : uint16_t symbol_type,
65 m : common::BinaryStreamReader* symbol_reader);
66 :
67 : // Pointers to the PDB type and symbol streams.
68 m : scoped_refptr<pdb::PdbStream> tpi_stream_;
69 m : scoped_refptr<pdb::PdbStream> sym_stream_;
70 :
71 : // The PE section headers extracted from the pdb.
72 : // Note: we use these as it seems the DbiStream's section map does not contain
73 : // information about section offsets (rva_offset is 0).
74 m : std::vector<IMAGE_SECTION_HEADER> section_headers_;
75 :
76 : // OMAP data to map from original space to transformed space. Empty if there
77 : // is no OMAP data.
78 m : std::vector<OMAP> omap_from_;
79 m : };
80 :
81 m : } // namespace refinery
82 :
83 : #endif // SYZYGY_REFINERY_TYPES_PDB_CRAWLER_H_
|