OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sandbox/win/src/service_resolver.h" | 5 #include "sandbox/win/src/service_resolver.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "sandbox/win/src/sandbox_nt_util.h" | 8 #include "sandbox/win/src/sandbox_nt_util.h" |
9 #include "sandbox/win/src/win_utils.h" | 9 #include "sandbox/win/src/win_utils.h" |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 if (NULL != storage_used) | 109 if (NULL != storage_used) |
110 *storage_used = thunk_bytes; | 110 *storage_used = thunk_bytes; |
111 | 111 |
112 return ret; | 112 return ret; |
113 } | 113 } |
114 | 114 |
115 size_t ServiceResolverThunk::GetThunkSize() const { | 115 size_t ServiceResolverThunk::GetThunkSize() const { |
116 return sizeof(ServiceFullThunk); | 116 return sizeof(ServiceFullThunk); |
117 } | 117 } |
118 | 118 |
119 NTSTATUS ServiceResolverThunk::CopyThunk(const void* target_module, | |
120 const char* target_name, | |
121 void* thunk_storage, | |
122 size_t storage_bytes, | |
123 size_t* storage_used) { | |
124 NTSTATUS ret = ResolveTarget(target_module, target_name, &target_); | |
125 if(!NT_SUCCESS(ret)) | |
robertshield
2014/02/28 21:02:22
space after if
Cait (Slow)
2014/03/03 20:55:11
Done.
| |
126 return ret; | |
127 | |
128 size_t thunk_bytes = GetThunkSize(); | |
129 scoped_ptr<char[]> thunk_buffer(new char[thunk_bytes]); | |
robertshield
2014/02/28 21:02:22
we use BYTE below for storage and chars here. Shou
Cait (Slow)
2014/03/03 20:55:11
Done.
| |
130 ServiceFullThunk* thunk = reinterpret_cast<ServiceFullThunk*>( | |
131 thunk_buffer.get()); | |
132 | |
133 if (!IsFunctionAService(&thunk->original)) | |
134 return STATUS_UNSUCCESSFUL; | |
135 | |
136 BYTE* thunk_storage_bytes = reinterpret_cast<BYTE*>(thunk_storage); | |
137 | |
138 // Mark the thunk storage as readable and writeable, since we | |
139 // ready to write to it. | |
140 DWORD old_protect = 0; | |
141 if(!VirtualProtect(thunk_storage, | |
robertshield
2014/02/28 21:02:22
space after if
Cait (Slow)
2014/03/03 20:55:11
Done.
| |
142 sizeof(thunk_storage), | |
143 PAGE_EXECUTE_READWRITE, | |
144 &old_protect)) { | |
145 return STATUS_UNSUCCESSFUL; | |
146 } | |
147 | |
148 // copy the local thunk buffer to the child | |
149 SIZE_T written; | |
robertshield
2014/02/28 21:02:22
= 0
Cait (Slow)
2014/03/03 20:55:11
Done.
| |
150 ret = ::WriteProcessMemory(process_, | |
151 thunk_storage_bytes, | |
152 reinterpret_cast<void*>(&thunk->original), | |
153 thunk_bytes, | |
154 &written); | |
155 | |
156 if (!NT_SUCCESS(ret)) | |
157 return ret; | |
158 | |
159 if (thunk_bytes != written) | |
160 return STATUS_UNSUCCESSFUL; | |
161 | |
162 if (VirtualProtect(thunk_storage, | |
163 sizeof(thunk_storage), | |
164 PAGE_EXECUTE_READ, | |
165 &old_protect)) { | |
166 return STATUS_UNSUCCESSFUL; | |
167 } | |
168 | |
169 if (NULL != storage_used) | |
170 *storage_used = thunk_bytes; | |
171 | |
172 return ret; | |
173 } | |
174 | |
119 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const { | 175 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const { |
120 ServiceFullThunk function_code; | 176 ServiceFullThunk function_code; |
121 SIZE_T read; | 177 SIZE_T read; |
122 if (!::ReadProcessMemory(process_, target_, &function_code, | 178 if (!::ReadProcessMemory(process_, target_, &function_code, |
123 sizeof(function_code), &read)) | 179 sizeof(function_code), &read)) |
124 return false; | 180 return false; |
125 | 181 |
126 if (sizeof(function_code) != read) | 182 if (sizeof(function_code) != read) |
127 return false; | 183 return false; |
128 | 184 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 NOTREACHED_NT(); | 240 NOTREACHED_NT(); |
185 return false; | 241 return false; |
186 } | 242 } |
187 | 243 |
188 bool Win2kResolverThunk::IsFunctionAService(void* local_thunk) const { | 244 bool Win2kResolverThunk::IsFunctionAService(void* local_thunk) const { |
189 NOTREACHED_NT(); | 245 NOTREACHED_NT(); |
190 return false; | 246 return false; |
191 } | 247 } |
192 | 248 |
193 } // namespace sandbox | 249 } // namespace sandbox |
OLD | NEW |