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 : #include "syzygy/refinery/validators/vftable_ptr_validator.h"
16 :
17 : #include "syzygy/refinery/process_state/process_state_util.h"
18 :
19 : namespace refinery {
20 :
21 : Validator::ValidationResult VftablePtrValidator::Validate(
22 : ProcessState* process_state,
23 : ValidationReport* report) {
24 : DCHECK(process_state); DCHECK(report);
25 :
26 : // TODO(manzagop): implement.
27 : // Get the set of valid vftable ptrs.
28 : // Go through the typed block layer for validation.
29 :
30 : return VALIDATION_COMPLETE;
31 : }
32 :
33 : bool VftablePtrValidator::GetVFTableVAs(
34 : ProcessState* process_state,
35 : scoped_refptr<DiaSymbolProvider> dia_symbol_provider,
36 E : base::hash_set<Address>* vftable_vas) {
37 E : DCHECK(process_state); DCHECK(dia_symbol_provider.get()); DCHECK(vftable_vas);
38 :
39 E : ModuleLayerPtr layer;
40 E : if (!process_state->FindLayer(&layer))
41 i : return false; // We expect to find a module layer (though possibly empty).
42 E : ModuleLayerAccessor accessor(process_state);
43 :
44 : // Note: no optimisation for multiples instances of the same module.
45 E : for (ModuleRecordPtr record : *layer) {
46 E : pe::PEFile::Signature signature;
47 E : if (!accessor.GetModuleSignature(record->data().module_id(), &signature))
48 i : return false;
49 :
50 E : base::hash_set<Address> vftable_rvas;
51 E : if (!dia_symbol_provider->GetVFTableRVAs(signature, &vftable_rvas))
52 i : return false;
53 :
54 E : Address module_base = record->range().start();
55 E : for (Address rva : vftable_rvas) {
56 E : base::CheckedNumeric<Address> virtual_address = module_base;
57 E : virtual_address += rva;
58 E : if (!virtual_address.IsValid())
59 i : return false;
60 :
61 E : vftable_vas->insert(virtual_address.ValueOrDie());
62 : }
63 E : }
64 :
65 E : return true;
66 E : }
67 :
68 : } // namespace refinery
|