1 : // Copyright 2013 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 : // Declares ImageFilter, a structure for imposing a filter on an image. The
16 : // filter itself is a core::AddressFilter built on relative addresses.
17 :
18 : #ifndef SYZYGY_PE_IMAGE_FILTER_H_
19 : #define SYZYGY_PE_IMAGE_FILTER_H_
20 :
21 : #include "base/values.h"
22 : #include "base/files/file_path.h"
23 : #include "syzygy/core/address.h"
24 : #include "syzygy/core/address_filter.h"
25 : #include "syzygy/core/json_file_writer.h"
26 : #include "syzygy/pe/pe_file.h"
27 :
28 m : namespace pe {
29 :
30 m : struct ImageFilter {
31 m : typedef core::RelativeAddress RelativeAddress;
32 m : typedef core::AddressFilter<RelativeAddress, size_t> RelativeAddressFilter;
33 m : typedef RelativeAddressFilter::Range Range;
34 :
35 : // The signature of the module to which this filter applies.
36 m : PEFile::Signature signature;
37 :
38 : // The filtered relative address space.
39 m : RelativeAddressFilter filter;
40 :
41 : // Initializes this ImageFilter to the given PE file. Sets the signature,
42 : // the extent of the filter, and clears the marked ranges.
43 : // @param pe_signature The signature to use.
44 : // @param pe_file The module whose signature should be used.
45 : // @param path The path to the module whose signature should be used.
46 : // @returns true on success, false otherwise.
47 m : void Init(const PEFile::Signature& pe_signature);
48 m : void Init(const PEFile& pe_file);
49 m : bool Init(const base::FilePath& path);
50 :
51 : // Determines if this filter is for the given module.
52 : // @param pe_signature The signature to compare against.
53 : // @param pe_file The module to compare against.
54 : // @param path The path to the module to compare against.
55 : // @returns true if this filter matches the provided module, false otherwise.
56 m : bool IsForModule(const PEFile::Signature& pe_signature) const;
57 m : bool IsForModule(const PEFile& pe_file) const;
58 m : bool IsForModule(const base::FilePath& path) const;
59 :
60 : // Saves this image filter to file.
61 : // @param json The JSON writer to be written to.
62 : // @param pretty_print If true the file will be pretty-printed.
63 : // @param file The file to be written to.
64 : // @param path The path of the file to be written to.
65 : // @returns true on success, false otherwise.
66 : // @note Logs on error.
67 m : bool SaveToJSON(core::JSONFileWriter* json) const;
68 m : bool SaveToJSON(bool pretty_print, FILE* file) const;
69 m : bool SaveToJSON(bool pretty_print, const base::FilePath& path) const;
70 :
71 : // Loads an image filter from a file in JSON format.
72 : // @param dict The JSON dictionary to be loaded from.
73 : // @param file The file to be read from.
74 : // @param path The path of the file to be read.
75 : // @returns true on success, false otherwise.
76 : // @note Logs on error.
77 m : bool LoadFromJSON(const base::DictionaryValue& dict);
78 m : bool LoadFromJSON(FILE* file);
79 m : bool LoadFromJSON(const base::FilePath& path);
80 m : };
81 :
82 m : } // namespace pe
83 :
84 : #endif // SYZYGY_PE_IMAGE_FILTER_H_
|