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 : #include "syzygy/instrument/instrumenters/entry_call_instrumenter.h"
16 :
17 : #include "base/file_util.h"
18 : #include "base/logging.h"
19 : #include "syzygy/application/application.h"
20 : #include "syzygy/pe/image_filter.h"
21 :
22 : namespace instrument {
23 : namespace instrumenters {
24 :
25 : const char EntryCallInstrumenter::kAgentDllProfile[] = "profile_client.dll";
26 :
27 : EntryCallInstrumenter::EntryCallInstrumenter()
28 E : : thunk_imports_(false) {
29 E : agent_dll_ = kAgentDllProfile;
30 E : }
31 :
32 E : bool EntryCallInstrumenter::InstrumentImpl() {
33 : entry_thunk_transform_.reset(
34 E : new instrument::transforms::EntryCallTransform(debug_friendly_));
35 E : entry_thunk_transform_->set_instrument_dll_name(agent_dll_);
36 E : relinker_->AppendTransform(entry_thunk_transform_.get());
37 :
38 : // If we are thunking imports then add the appropriate transform.
39 E : if (thunk_imports_) {
40 : import_thunk_tx_.reset(
41 E : new instrument::transforms::ThunkImportReferencesTransform);
42 : // Use the selected client DLL.
43 E : import_thunk_tx_->set_instrument_dll_name(agent_dll_);
44 E : relinker_->AppendTransform(import_thunk_tx_.get());
45 : }
46 :
47 E : return true;
48 E : }
49 :
50 : bool EntryCallInstrumenter::ParseAdditionalCommandLineArguments(
51 E : const CommandLine* command_line) {
52 E : thunk_imports_ = command_line->HasSwitch("instrument-imports");
53 :
54 E : return true;
55 E : }
56 :
57 i : const char* EntryCallInstrumenter::InstrumentationMode() {
58 i : return "profile";
59 i : }
60 :
61 : } // namespace instrumenters
62 : } // namespace instrument
|