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/logging.h"
18 : #include "base/files/file_util.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::InstrumentPrepare() {
33 E : return true;
34 E : }
35 :
36 E : bool EntryCallInstrumenter::InstrumentImpl() {
37 : entry_thunk_transform_.reset(
38 E : new instrument::transforms::EntryCallTransform(debug_friendly_));
39 E : entry_thunk_transform_->set_instrument_dll_name(agent_dll_);
40 E : relinker_->AppendTransform(entry_thunk_transform_.get());
41 :
42 : // If we are thunking imports then add the appropriate transform.
43 E : if (thunk_imports_) {
44 : import_thunk_tx_.reset(
45 E : new instrument::transforms::ThunkImportReferencesTransform);
46 : // Use the selected client DLL.
47 E : import_thunk_tx_->set_instrument_dll_name(agent_dll_);
48 E : relinker_->AppendTransform(import_thunk_tx_.get());
49 : }
50 :
51 E : return true;
52 E : }
53 :
54 : bool EntryCallInstrumenter::DoCommandLineParse(
55 E : const base::CommandLine* command_line) {
56 E : if (!Super::DoCommandLineParse(command_line))
57 i : return false;
58 :
59 E : thunk_imports_ = command_line->HasSwitch("instrument-imports");
60 :
61 E : return true;
62 E : }
63 :
64 i : const char* EntryCallInstrumenter::InstrumentationMode() {
65 i : return "profile";
66 i : }
67 :
68 : } // namespace instrumenters
69 : } // namespace instrument
|