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

Side by Side Diff: sandbox/win/src/service_resolver_32.cc

Issue 183833004: Make chrome_elf use thunks instead of function pointers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
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/win_utils.h" 8 #include "sandbox/win/src/win_utils.h"
9 9
10 namespace { 10 namespace {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (NULL != storage_used) 172 if (NULL != storage_used)
173 *storage_used = thunk_bytes; 173 *storage_used = thunk_bytes;
174 174
175 return ret; 175 return ret;
176 } 176 }
177 177
178 size_t ServiceResolverThunk::GetThunkSize() const { 178 size_t ServiceResolverThunk::GetThunkSize() const {
179 return offsetof(ServiceFullThunk, internal_thunk) + GetInternalThunkSize(); 179 return offsetof(ServiceFullThunk, internal_thunk) + GetInternalThunkSize();
180 } 180 }
181 181
182 NTSTATUS ServiceResolverThunk::CopyThunk(const void* target_module,
183 const char* target_name,
184 void* thunk_storage,
185 size_t storage_bytes,
186 size_t* storage_used) {
187 NTSTATUS ret = ResolveTarget(target_module, target_name, &target_);
188 if(!NT_SUCCESS(ret))
robertshield 2014/02/28 21:02:22 space after if
Cait (Slow) 2014/03/03 20:55:11 Done.
189 return ret;
190
191 size_t thunk_bytes = GetThunkSize();
rvargas (doing something else) 2014/02/28 19:40:09 I'm fine with this code as is, but I would also be
192 scoped_ptr<char[]> thunk_buffer(new char[thunk_bytes]);
193 ServiceFullThunk* thunk = reinterpret_cast<ServiceFullThunk*>(
194 thunk_buffer.get());
195
196 if (!IsFunctionAService(&thunk->original) &&
197 (!relaxed_ || !SaveOriginalFunction(&thunk->original, thunk_storage))) {
198 return STATUS_UNSUCCESSFUL;
199 }
200
201 BYTE* thunk_storage_bytes = reinterpret_cast<BYTE*>(thunk_storage);
rvargas (doing something else) 2014/02/28 19:40:09 Why have the rest of this code here? We can assume
robertshield 2014/02/28 21:02:22 I agree with this, I think the memory protection c
Cait (Slow) 2014/03/03 20:55:11 Done.
202
203 // Mark the thunk storage as readable and writeable, since we
204 // ready to write to it.
205 DWORD old_protect = 0;
206 if(!VirtualProtect(thunk_storage,
robertshield 2014/02/28 21:02:22 space after if
Cait (Slow) 2014/03/03 20:55:11 Done.
207 sizeof(thunk_storage),
208 PAGE_EXECUTE_READWRITE,
209 &old_protect)) {
210 return STATUS_UNSUCCESSFUL;
211 }
212
213 // copy the local thunk buffer to the child
214 SIZE_T written;
robertshield 2014/02/28 21:02:22 = 0
Cait (Slow) 2014/03/03 20:55:11 Done.
215 ret = ::WriteProcessMemory(process_,
216 thunk_storage_bytes,
217 reinterpret_cast<void*>(&thunk->original),
218 thunk_bytes,
219 &written);
220
221 if (!NT_SUCCESS(ret))
222 return ret;
223
224 if (thunk_bytes != written)
225 return STATUS_UNSUCCESSFUL;
226
227 if (! VirtualProtect(thunk_storage,
robertshield 2014/02/28 21:02:22 nit: no space after !
Cait (Slow) 2014/03/03 20:55:11 Done.
228 sizeof(thunk_storage),
229 PAGE_EXECUTE_READ,
230 &old_protect)) {
231 return STATUS_UNSUCCESSFUL;
232 }
233
234 if (NULL != storage_used)
235 *storage_used = thunk_bytes;
236
237 return ret;
238 }
239
182 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const { 240 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const {
183 ServiceEntry function_code; 241 ServiceEntry function_code;
184 SIZE_T read; 242 SIZE_T read;
185 if (!::ReadProcessMemory(process_, target_, &function_code, 243 if (!::ReadProcessMemory(process_, target_, &function_code,
186 sizeof(function_code), &read)) 244 sizeof(function_code), &read))
187 return false; 245 return false;
188 246
189 if (sizeof(function_code) != read) 247 if (sizeof(function_code) != read)
190 return false; 248 return false;
191 249
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 return false; 469 return false;
412 } 470 }
413 471
414 // Save the verified code 472 // Save the verified code
415 memcpy(local_thunk, &function_code, sizeof(function_code)); 473 memcpy(local_thunk, &function_code, sizeof(function_code));
416 474
417 return true; 475 return true;
418 } 476 }
419 477
420 } // namespace sandbox 478 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698