Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: syzygy/instrument/transforms/security_cookie_check_hook_transform.cc

Issue 2871863002: adds the security cookie check hook transform. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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
16 #include "syzygy/instrument/transforms/security_cookie_check_hook_transform.h"
17
18 #include "syzygy/pe/pe_utils.h"
19
20 namespace instrument {
21 namespace transforms {
22
23 using block_graph::Displacement;
24 using block_graph::Operand;
25
26 const char SecurityCookieCheckHookTransform::kTransformName[] =
27 "SecurityCookieCheckHookTransform";
28
29 bool SecurityCookieCheckHookTransform::TransformBlockGraph(
30 const TransformPolicyInterface* policy,
31 BlockGraph* block_graph,
32 BlockGraph::Block* header_block
chrisha 2017/05/09 19:18:39 Indent parameters another +2 (4 from start of line
33 ) {
chrisha 2017/05/09 19:18:39 Move to the previous line.
34 BlockGraph::Block *__report_gsfailure = nullptr;
chrisha 2017/05/09 19:18:40 Move * to left (BlockGraph::Block* __report_gsfail
35 const BlockGraph::BlockMap &blocks = block_graph->blocks();
chrisha 2017/05/09 19:18:39 Move & to left.
36 for (const auto &block : blocks) {
chrisha 2017/05/09 19:18:39 Move & to left (auto& block)
37 std::string name(block.second.name());
38 if (name == "__report_gsfailure") {
chrisha 2017/05/09 19:18:39 Make an anonymous namespaced static global at the
39 __report_gsfailure = block_graph->GetBlockById(block.first);
chrisha 2017/05/09 19:18:39 You've already got the block, no need to go throug
40 break;
41 }
42 }
43
44 if (__report_gsfailure == nullptr) {
45 LOG(ERROR) << "Could not find __report_gsfailure.";
46 return false;
47 }
48
49 LOG(INFO) << "Found a __report_gsfailure implementation, hooking it now..";
chrisha 2017/05/09 19:18:40 Remove extra period.
50 BlockGraph::Section* section_text = block_graph->FindOrAddSection(
51 pe::kCodeSectionName,
52 pe::kCodeCharacteristics
chrisha 2017/05/09 19:18:39 Both of these parameters fit on one line, indented
53 );
chrisha 2017/05/09 19:18:39 Move to end of previous line.
54
55 // All of the below is needed to build the instrumentation via the assembler
chrisha 2017/05/09 19:18:39 Missing period on comment.
56 BasicBlockSubGraph bbsg;
57 BasicBlockSubGraph::BlockDescription* block_desc = bbsg.AddBlockDescription(
58 "__my_report_gsfailure",
59 nullptr,
60 BlockGraph::CODE_BLOCK,
61 section_text->id(),
62 1,
63 0
chrisha 2017/05/09 19:18:39 These likely all fit on one line.
64 );
chrisha 2017/05/09 19:18:39 Move to end of previous line.
65
66 BasicCodeBlock* bb = bbsg.AddBasicCodeBlock("__my_report_gsfailure");
chrisha 2017/05/09 19:18:39 Prefix with __syzygy_ maybe? Slightly more consist
67 block_desc->basic_block_order.push_back(bb);
68 BasicBlockAssembler assm(bb->instructions().begin(), &bb->instructions());
69 assm.mov(
70 Operand(Displacement(0xdeadbeef)),
71 assm::eax
chrisha 2017/05/09 19:18:39 Indent another 2 spaces.
72 );
chrisha 2017/05/09 19:18:39 Move to previous line.
73
74 // Condense into a block
chrisha 2017/05/09 19:18:39 Missing period on comment.
75 BlockBuilder block_builder(block_graph);
76 if (!block_builder.Merge(&bbsg)) {
77 LOG(ERROR) << "Failed to build __my_report_gsfailure block.";
chrisha 2017/05/09 19:18:39 Create another string constant with this name and
78 return false;
79 }
80
81 // Exactly one new block should have been created
chrisha 2017/05/09 19:18:39 This should be a DCHECK (kind of like an assertion
82 if (block_builder.new_blocks().size() != 1) {
83 LOG(ERROR) << "Only one block should have been built.";
84 return false;
85 }
86
87 if (__report_gsfailure->references().size() != 1) {
chrisha 2017/05/09 19:18:39 Ditto with this as a DCHECK assertion.
88 VLOG(1) << "Only a single reference is expected.";
89 }
90
91 // Transfer the referrers to the new block, and delete the old one
92 BlockGraph::Block* __my_report_gsfailure = block_builder.new_blocks().front();
93 __report_gsfailure->TransferReferrers(
94 0,
95 __my_report_gsfailure,
96 BlockGraph::Block::kTransferInternalReferences
chrisha 2017/05/09 19:18:39 Indent all of these another 2 spaces, try to fit a
97 );
chrisha 2017/05/09 19:18:39 Move to end of previous line.
98
99 __report_gsfailure->RemoveAllReferences();
100 if (!block_graph->RemoveBlock(__report_gsfailure)) {
101 LOG(ERROR) << "Removing __report_gsfailure failed.";
102 return false;
103 }
104
105 return true;
106 }
107
108 } // namespace transforms
109 } // namespace instrument
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698