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_AGENT_ASAN_IAT_PATCHER_H_
16 : #define SYZYGY_AGENT_ASAN_IAT_PATCHER_H_
17 :
18 : #include <windows.h>
19 :
20 : #include <map>
21 : #include "base/strings/string_piece.h"
22 :
23 m : namespace agent {
24 m : namespace asan {
25 :
26 m : typedef void (*FunctionPointer)();
27 : // Note this map doesn't copy the strings supplied, it's the caller's
28 : // responsibility to ensure their lifetime.
29 m : using IATPatchMap = std::map<base::StringPiece, FunctionPointer>;
30 :
31 : // Modifies the IAT of @p module such that each function named in @p patch_map
32 : // points to the associated function.
33 : // @param module the module to patch up.
34 : // @param patch_map a map from name to the desired function.
35 : // @note this function is BYOL - bring your own locking.
36 : // @note IAT patching is inherently racy. It's wise to call this function from
37 : // under a lock that prevents concurrent patching on the same module, and
38 : // the caller must guarantee that the module is not unloaded during
39 : // patching.
40 : // TODO(siggi): Should this be scoped to module name also?
41 m : bool PatchIATForModule(HMODULE module, const IATPatchMap& patch_map);
42 :
43 m : } // namespace asan
44 m : } // namespace agent
45 :
46 : #endif // SYZYGY_AGENT_ASAN_IAT_PATCHER_H_
|