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_DIA_CRAWLER_H_
16 : #define SYZYGY_REFINERY_TYPES_DIA_CRAWLER_H_
17 :
18 : #include <dia2.h>
19 : #include <vector>
20 :
21 : #include "base/containers/hash_tables.h"
22 : #include "base/files/file_path.h"
23 : #include "base/strings/string_piece.h"
24 : #include "base/win/scoped_comptr.h"
25 : #include "syzygy/refinery/core/address.h"
26 : #include "syzygy/refinery/types/type.h"
27 :
28 m : namespace refinery {
29 :
30 : // fwd.
31 m : class TypeRepository;
32 :
33 : // A worker class to scrape types from PDB symbols using DIA.
34 m : class DiaCrawler {
35 m : public:
36 m : DiaCrawler();
37 m : ~DiaCrawler();
38 :
39 : // Initializes this crawler for the file at @p path.
40 : // @param path the image file whose symbols to crawl for types.
41 : // @returns true on success, false on failure.
42 m : bool InitializeForFile(const base::FilePath& path);
43 :
44 : // Initializes this crawler using @p source and @p session.
45 : // @param source the dia source to initialize with.
46 : // @param session the dia session to initialize with.
47 : // @returns true on success, false on failure.
48 m : bool InitializeForSession(base::win::ScopedComPtr<IDiaDataSource> source,
49 m : base::win::ScopedComPtr<IDiaSession> session);
50 :
51 : // Retrieves all types associated with the file this instance
52 : // is initialized to.
53 : // @param types on success contains zero or more types.
54 : // @returns true on success, false on failure.
55 m : bool GetTypes(TypeRepository* types);
56 :
57 : // Retrieves the relative virtual addresses of all virtual function tables.
58 : // @param vftable_rvas on success contains zero or more addresses.
59 : // @returns true on success, false on failure.
60 m : bool GetVFTableRVAs(base::hash_set<Address>* vftable_rvas);
61 :
62 m : private:
63 m : base::win::ScopedComPtr<IDiaDataSource> source_;
64 m : base::win::ScopedComPtr<IDiaSession> session_;
65 m : base::win::ScopedComPtr<IDiaSymbol> global_;
66 m : };
67 :
68 m : } // namespace refinery
69 :
70 : #endif // SYZYGY_REFINERY_TYPES_DIA_CRAWLER_H_
|