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_SYMBOLS_SYMBOL_PROVIDER_H_
16 : #define SYZYGY_REFINERY_SYMBOLS_SYMBOL_PROVIDER_H_
17 :
18 : #include <memory>
19 :
20 : #include "base/macros.h"
21 : #include "base/containers/hash_tables.h"
22 : #include "base/memory/ref_counted.h"
23 : #include "base/strings/string16.h"
24 : #include "syzygy/pe/pe_file.h"
25 : #include "syzygy/refinery/core/address.h"
26 : #include "syzygy/refinery/symbols/simple_cache.h"
27 : #include "syzygy/refinery/types/type_repository.h"
28 :
29 m : namespace refinery {
30 :
31 : // The SymbolProvider provides symbol information. See DiaSymbolProvider for an
32 : // alternative.
33 m : class SymbolProvider : public base::RefCounted<SymbolProvider> {
34 m : public:
35 m : SymbolProvider();
36 : // @note virtual to enable mocking.
37 m : virtual ~SymbolProvider();
38 :
39 : // Retrieves or creates a TypeRepository for the module corresponding to @p
40 : // signature.
41 : // @note virtual to enable mocking.
42 : // @param signature the signature of the module for which to get a type
43 : // repository.
44 : // @param type_repo on success, returns a type repository for the module. On
45 : // failure, contains nullptr.
46 : // @returns true on success, false on failure.
47 m : virtual bool FindOrCreateTypeRepository(
48 m : const pe::PEFile::Signature& signature,
49 m : scoped_refptr<TypeRepository>* type_repo);
50 :
51 : // Retrieves or creates a TypeNameIndex for the module corresponding to @p
52 : // signature.
53 : // @param signature the signature of the module for which to get a type
54 : // repository.
55 : // @param type_repo on success, returns a typename index for the module. On
56 : // failure, contains nullptr.
57 : // @returns true on success, false on failure.
58 m : bool FindOrCreateTypeNameIndex(const pe::PEFile::Signature& signature,
59 m : scoped_refptr<TypeNameIndex>* typename_index);
60 :
61 : // Retrieves the relative virtual addresses of all virtual function tables in
62 : // the module identified by @p signature.
63 : // @param signature the signature of the module.
64 : // @param vftable_rvas on success contains zero or more relative addresses.
65 : // @returns true on success, false on failure.
66 m : virtual bool GetVFTableRVAs(const pe::PEFile::Signature& signature,
67 m : base::hash_set<RelativeAddress>* vftable_rvas);
68 :
69 m : private:
70 m : static void GetCacheKey(const pe::PEFile::Signature& signature,
71 m : base::string16* cache_key);
72 :
73 : // Creates a type repository (without caching it).
74 m : bool CreateTypeRepository(const pe::PEFile::Signature& signature,
75 m : scoped_refptr<TypeRepository>* type_repo);
76 :
77 : // Creates a type name index (without caching it).
78 m : bool CreateTypeNameIndex(const pe::PEFile::Signature& signature,
79 m : scoped_refptr<TypeNameIndex>* index);
80 :
81 : // Caching for type repositories and typename indices. The cache key is
82 : // "<basename>:<size>:<checksum>:<timestamp>". The caches may contain
83 : // negative entries (indicating a failed attempt at creating a session) in the
84 : // form of null pointers.
85 m : SimpleCache<TypeRepository> type_repos_;
86 m : SimpleCache<TypeNameIndex> typename_indices_;
87 :
88 m : DISALLOW_COPY_AND_ASSIGN(SymbolProvider);
89 m : };
90 :
91 m : } // namespace refinery
92 :
93 : #endif // SYZYGY_REFINERY_SYMBOLS_SYMBOL_PROVIDER_H_
|