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

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: Move all memory mgmt out of CopyThunk 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 BYTE* 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))
189 return ret;
190
191 size_t thunk_bytes = GetThunkSize();
rvargas (doing something else) 2014/03/03 22:36:46 Did you mean to compare this against storage_bytes
Cait (Slow) 2014/03/04 15:43:56 Done.
192 ServiceFullThunk* thunk = reinterpret_cast<ServiceFullThunk*>(thunk_storage);
193
194 if (!IsFunctionAService(&thunk->original) &&
195 (!relaxed_ || !SaveOriginalFunction(&thunk->original, thunk_storage))) {
196 return STATUS_UNSUCCESSFUL;
197 }
198
199 return ret;
200 }
201
182 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const { 202 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const {
183 ServiceEntry function_code; 203 ServiceEntry function_code;
184 SIZE_T read; 204 SIZE_T read;
185 if (!::ReadProcessMemory(process_, target_, &function_code, 205 if (!::ReadProcessMemory(process_, target_, &function_code,
186 sizeof(function_code), &read)) 206 sizeof(function_code), &read))
187 return false; 207 return false;
188 208
189 if (sizeof(function_code) != read) 209 if (sizeof(function_code) != read)
190 return false; 210 return false;
191 211
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 return false; 431 return false;
412 } 432 }
413 433
414 // Save the verified code 434 // Save the verified code
415 memcpy(local_thunk, &function_code, sizeof(function_code)); 435 memcpy(local_thunk, &function_code, sizeof(function_code));
416 436
417 return true; 437 return true;
418 } 438 }
419 439
420 } // namespace sandbox 440 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698