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/logging.h" | |
8 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
9 #include "sandbox/win/src/win_utils.h" | 8 #include "sandbox/win/src/sandbox_nt_util.h" |
10 | 9 |
11 namespace { | 10 namespace { |
12 #pragma pack(push, 1) | 11 #pragma pack(push, 1) |
13 | 12 |
14 const ULONG kMmovR10EcxMovEax = 0xB8D18B4C; | 13 const ULONG kMmovR10EcxMovEax = 0xB8D18B4C; |
15 const USHORT kSyscall = 0x050F; | 14 const USHORT kSyscall = 0x050F; |
16 const BYTE kRetNp = 0xC3; | 15 const BYTE kRetNp = 0xC3; |
17 const ULONG64 kMov1 = 0x54894808244C8948; | 16 const ULONG64 kMov1 = 0x54894808244C8948; |
18 const ULONG64 kMov2 = 0x4C182444894C1024; | 17 const ULONG64 kMov2 = 0x4C182444894C1024; |
19 const ULONG kMov3 = 0x20244C89; | 18 const ULONG kMov3 = 0x20244C89; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 143 |
145 NTSTATUS ServiceResolverThunk::PerformPatch(void* local_thunk, | 144 NTSTATUS ServiceResolverThunk::PerformPatch(void* local_thunk, |
146 void* remote_thunk) { | 145 void* remote_thunk) { |
147 ServiceFullThunk* full_local_thunk = reinterpret_cast<ServiceFullThunk*>( | 146 ServiceFullThunk* full_local_thunk = reinterpret_cast<ServiceFullThunk*>( |
148 local_thunk); | 147 local_thunk); |
149 ServiceFullThunk* full_remote_thunk = reinterpret_cast<ServiceFullThunk*>( | 148 ServiceFullThunk* full_remote_thunk = reinterpret_cast<ServiceFullThunk*>( |
150 remote_thunk); | 149 remote_thunk); |
151 | 150 |
152 // Patch the original code. | 151 // Patch the original code. |
153 ServiceEntry local_service; | 152 ServiceEntry local_service; |
154 DCHECK_GE(GetInternalThunkSize(), sizeof(local_service)); | |
155 if (!SetInternalThunk(&local_service, sizeof(local_service), NULL, | 153 if (!SetInternalThunk(&local_service, sizeof(local_service), NULL, |
156 interceptor_)) | 154 interceptor_)) |
157 return STATUS_UNSUCCESSFUL; | 155 return STATUS_UNSUCCESSFUL; |
158 | 156 |
159 // Copy the local thunk buffer to the child. | 157 // Copy the local thunk buffer to the child. |
160 SIZE_T actual; | 158 SIZE_T actual; |
161 if (!::WriteProcessMemory(process_, remote_thunk, local_thunk, | 159 if (!::WriteProcessMemory(process_, remote_thunk, local_thunk, |
162 sizeof(ServiceFullThunk), &actual)) | 160 sizeof(ServiceFullThunk), &actual)) |
163 return STATUS_UNSUCCESSFUL; | 161 return STATUS_UNSUCCESSFUL; |
164 | 162 |
165 if (sizeof(ServiceFullThunk) != actual) | 163 if (sizeof(ServiceFullThunk) != actual) |
166 return STATUS_UNSUCCESSFUL; | 164 return STATUS_UNSUCCESSFUL; |
167 | 165 |
168 // And now change the function to intercept, on the child. | 166 // And now change the function to intercept, on the child. |
169 if (NULL != ntdll_base_) { | 167 if (NULL != ntdll_base_) { |
170 // Running a unit test. | 168 // Running a unit test. |
171 if (!::WriteProcessMemory(process_, target_, &local_service, | 169 if (!::WriteProcessMemory(process_, target_, &local_service, |
172 sizeof(local_service), &actual)) | 170 sizeof(local_service), &actual)) |
173 return STATUS_UNSUCCESSFUL; | 171 return STATUS_UNSUCCESSFUL; |
174 } else { | 172 } else { |
175 if (!WriteProtectedChildMemory(process_, target_, &local_service, | 173 if (!WriteProtectedChildMemory(process_, target_, &local_service, |
176 sizeof(local_service))) | 174 sizeof(local_service))) |
177 return STATUS_UNSUCCESSFUL; | 175 return STATUS_UNSUCCESSFUL; |
178 } | 176 } |
179 | 177 |
180 return STATUS_SUCCESS; | 178 return STATUS_SUCCESS; |
181 } | 179 } |
182 | 180 |
183 bool Wow64ResolverThunk::IsFunctionAService(void* local_thunk) const { | 181 bool Wow64ResolverThunk::IsFunctionAService(void* local_thunk) const { |
184 NOTREACHED(); | |
185 return false; | 182 return false; |
186 } | 183 } |
187 | 184 |
188 bool Win2kResolverThunk::IsFunctionAService(void* local_thunk) const { | 185 bool Win2kResolverThunk::IsFunctionAService(void* local_thunk) const { |
189 NOTREACHED(); | |
190 return false; | 186 return false; |
191 } | 187 } |
192 | 188 |
193 } // namespace sandbox | 189 } // namespace sandbox |
OLD | NEW |