OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/src/target_process.h" | 5 #include "sandbox/src/target_process.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/pe_image.h" |
8 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
9 #include "sandbox/src/crosscall_server.h" | 10 #include "sandbox/src/crosscall_server.h" |
10 #include "sandbox/src/crosscall_client.h" | 11 #include "sandbox/src/crosscall_client.h" |
11 #include "sandbox/src/pe_image.h" | |
12 #include "sandbox/src/policy_low_level.h" | 12 #include "sandbox/src/policy_low_level.h" |
13 #include "sandbox/src/sandbox_types.h" | 13 #include "sandbox/src/sandbox_types.h" |
14 #include "sandbox/src/sharedmem_ipc_server.h" | 14 #include "sandbox/src/sharedmem_ipc_server.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 void TerminateTarget(PROCESS_INFORMATION* pi) { | 18 void TerminateTarget(PROCESS_INFORMATION* pi) { |
19 ::CloseHandle(pi->hThread); | 19 ::CloseHandle(pi->hThread); |
20 ::TerminateProcess(pi->hProcess, 0); | 20 ::TerminateProcess(pi->hProcess, 0); |
21 ::CloseHandle(pi->hProcess); | 21 ::CloseHandle(pi->hProcess); |
(...skipping 25 matching lines...) Expand all Loading... |
47 SANDBOX_INTERCEPT size_t g_shared_IPC_size; | 47 SANDBOX_INTERCEPT size_t g_shared_IPC_size; |
48 SANDBOX_INTERCEPT size_t g_shared_policy_size; | 48 SANDBOX_INTERCEPT size_t g_shared_policy_size; |
49 | 49 |
50 // Returns the address of the main exe module in memory taking in account | 50 // Returns the address of the main exe module in memory taking in account |
51 // address space layout randomization. | 51 // address space layout randomization. |
52 void* GetBaseAddress(const wchar_t* exe_name, void* entry_point) { | 52 void* GetBaseAddress(const wchar_t* exe_name, void* entry_point) { |
53 HMODULE exe = ::LoadLibrary(exe_name); | 53 HMODULE exe = ::LoadLibrary(exe_name); |
54 if (NULL == exe) | 54 if (NULL == exe) |
55 return exe; | 55 return exe; |
56 | 56 |
57 sandbox::PEImage pe(exe); | 57 PEImage pe(exe); |
58 if (!pe.VerifyMagic()) { | 58 if (!pe.VerifyMagic()) { |
59 ::FreeLibrary(exe); | 59 ::FreeLibrary(exe); |
60 return exe; | 60 return exe; |
61 } | 61 } |
62 PIMAGE_NT_HEADERS nt_header = pe.GetNTHeaders(); | 62 PIMAGE_NT_HEADERS nt_header = pe.GetNTHeaders(); |
63 char* base = reinterpret_cast<char*>(entry_point) - | 63 char* base = reinterpret_cast<char*>(entry_point) - |
64 nt_header->OptionalHeader.AddressOfEntryPoint; | 64 nt_header->OptionalHeader.AddressOfEntryPoint; |
65 | 65 |
66 ::FreeLibrary(exe); | 66 ::FreeLibrary(exe); |
67 return base; | 67 return base; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 317 |
318 | 318 |
319 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address) { | 319 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address) { |
320 TargetProcess* target = new TargetProcess(NULL, NULL, NULL, NULL); | 320 TargetProcess* target = new TargetProcess(NULL, NULL, NULL, NULL); |
321 target->sandbox_process_ = process; | 321 target->sandbox_process_ = process; |
322 target->base_address_ = base_address; | 322 target->base_address_ = base_address; |
323 return target; | 323 return target; |
324 } | 324 } |
325 | 325 |
326 } // namespace sandbox | 326 } // namespace sandbox |
OLD | NEW |