15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sandbox/win/wow_helper/target_code.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace sandbox { 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Hooks NtMapViewOfSection to detect the load of dlls. 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NTSTATUS WINAPI TargetNtMapViewOfSection( 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PatchInfo *patch_info, HANDLE process, PVOID *base, ULONG_PTR zero_bits, 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SIZE_T commit_size, PLARGE_INTEGER offset, PSIZE_T view_size, 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SECTION_INHERIT inherit, ULONG allocation_type, ULONG protect) { 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NTSTATUS ret = patch_info->orig_MapViewOfSection(patch_info->section, process, 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base, zero_bits, commit_size, 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) offset, view_size, inherit, 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) allocation_type, protect); 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LARGE_INTEGER timeout; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) timeout.QuadPart = -(5 * 10000000); // 5 seconds. 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The wait is alertable. 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) patch_info->signal_and_wait(patch_info->dll_load, patch_info->continue_load, 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TRUE, &timeout); 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ret; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Marks the end of the code to copy to the target process. 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NTSTATUS WINAPI TargetEnd() { 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return STATUS_SUCCESS; 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace sandbox 35