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

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: Address comments, add scoped ptr 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
« no previous file with comments | « sandbox/win/src/service_resolver.h ('k') | sandbox/win/src/service_resolver_64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
192 if (storage_bytes < thunk_bytes)
193 return STATUS_UNSUCCESSFUL;
194
195 ServiceFullThunk* thunk = reinterpret_cast<ServiceFullThunk*>(thunk_storage);
196
197 if (!IsFunctionAService(&thunk->original) &&
198 (!relaxed_ || !SaveOriginalFunction(&thunk->original, thunk_storage))) {
199 return STATUS_UNSUCCESSFUL;
200 }
201
202 if (NULL != storage_used)
203 *storage_used = thunk_bytes;
204
205 return ret;
206 }
207
182 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const { 208 bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const {
183 ServiceEntry function_code; 209 ServiceEntry function_code;
184 SIZE_T read; 210 SIZE_T read;
185 if (!::ReadProcessMemory(process_, target_, &function_code, 211 if (!::ReadProcessMemory(process_, target_, &function_code,
186 sizeof(function_code), &read)) 212 sizeof(function_code), &read))
187 return false; 213 return false;
188 214
189 if (sizeof(function_code) != read) 215 if (sizeof(function_code) != read)
190 return false; 216 return false;
191 217
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 return false; 437 return false;
412 } 438 }
413 439
414 // Save the verified code 440 // Save the verified code
415 memcpy(local_thunk, &function_code, sizeof(function_code)); 441 memcpy(local_thunk, &function_code, sizeof(function_code));
416 442
417 return true; 443 return true;
418 } 444 }
419 445
420 } // namespace sandbox 446 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/service_resolver.h ('k') | sandbox/win/src/service_resolver_64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698