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_VALIDATORS_VFTABLE_PTR_VALIDATOR_H_
16 : #define SYZYGY_REFINERY_VALIDATORS_VFTABLE_PTR_VALIDATOR_H_
17 :
18 : #include "base/macros.h"
19 : #include "base/containers/hash_tables.h"
20 : #include "base/memory/ref_counted.h"
21 : #include "syzygy/refinery/core/address.h"
22 : #include "syzygy/refinery/symbols/symbol_provider.h"
23 : #include "syzygy/refinery/types/typed_data.h"
24 : #include "syzygy/refinery/validators/validator.h"
25 :
26 m : namespace refinery {
27 :
28 : // A validator for vftable ptr values. This simple implementation validates
29 : // that an object's vftable ptr is within the valid set for the process.
30 : // TODO(manzagop): tighter checking of a vftable ptr's possible values.
31 m : class VftablePtrValidator : public Validator {
32 m : public:
33 : // TODO(manzagop): Is this a validator? Take in a symbol provider?
34 m : explicit VftablePtrValidator(scoped_refptr<SymbolProvider> symbol_provider);
35 :
36 m : ValidationResult Validate(ProcessState* process_state,
37 m : ValidationReport* report) override;
38 :
39 m : protected:
40 : // Retrieves the set of vftable virtual addresses for @p process_state.
41 : // @param process_state the process_state.
42 : // @param vftable_vas on success, contains zero or more addresses.
43 : // @returns true on success, false on failure.
44 m : static bool GetVFTableVAs(
45 m : ProcessState* process_state,
46 m : SymbolProvider* symbol_provider,
47 m : base::hash_set<Address>* vftable_vas);
48 :
49 m : private:
50 m : bool ValidateTypedData(const TypedData& typed_data,
51 m : const base::hash_set<RelativeAddress>& vftable_vas,
52 m : ValidationReport* report);
53 :
54 m : scoped_refptr<SymbolProvider> symbol_provider_;
55 :
56 m : DISALLOW_COPY_AND_ASSIGN(VftablePtrValidator);
57 m : };
58 :
59 m : } // namespace refinery
60 :
61 : #endif // SYZYGY_REFINERY_VALIDATORS_VFTABLE_PTR_VALIDATOR_H_
|