toolkit/crashreporter/InjectCrashReporter.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "InjectCrashReporter.h"
michael@0 7 #include "nsDirectoryServiceUtils.h"
michael@0 8 #include "nsDirectoryServiceDefs.h"
michael@0 9 #include "client/windows/crash_generation/crash_generation_client.h"
michael@0 10 #include "nsExceptionHandler.h"
michael@0 11 #include "LoadLibraryRemote.h"
michael@0 12 #include "nsWindowsHelpers.h"
michael@0 13
michael@0 14 using google_breakpad::CrashGenerationClient;
michael@0 15 using CrashReporter::GetChildNotificationPipe;
michael@0 16
michael@0 17 namespace mozilla {
michael@0 18
michael@0 19 InjectCrashRunnable::InjectCrashRunnable(DWORD pid)
michael@0 20 : mPID(pid)
michael@0 21 {
michael@0 22 nsCOMPtr<nsIFile> dll;
michael@0 23 nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(dll));
michael@0 24 if (NS_SUCCEEDED(rv)) {
michael@0 25 dll->Append(NS_LITERAL_STRING("breakpadinjector.dll"));
michael@0 26 dll->GetPath(mInjectorPath);
michael@0 27 }
michael@0 28 }
michael@0 29
michael@0 30 NS_IMETHODIMP
michael@0 31 InjectCrashRunnable::Run()
michael@0 32 {
michael@0 33 if (mInjectorPath.IsEmpty())
michael@0 34 return NS_OK;
michael@0 35
michael@0 36 nsAutoHandle hProcess(
michael@0 37 OpenProcess(PROCESS_CREATE_THREAD |
michael@0 38 PROCESS_QUERY_INFORMATION |
michael@0 39 PROCESS_DUP_HANDLE |
michael@0 40 PROCESS_VM_OPERATION |
michael@0 41 PROCESS_VM_WRITE |
michael@0 42 PROCESS_VM_READ, FALSE, mPID));
michael@0 43 if (!hProcess) {
michael@0 44 NS_WARNING("Unable to open remote process handle for crashreporter injection.");
michael@0 45 return NS_OK;
michael@0 46 }
michael@0 47
michael@0 48 void* proc = LoadRemoteLibraryAndGetAddress(hProcess, mInjectorPath.get(),
michael@0 49 "Start");
michael@0 50 if (!proc) {
michael@0 51 NS_WARNING("Unable to inject crashreporter DLL.");
michael@0 52 return NS_OK;
michael@0 53 }
michael@0 54
michael@0 55 HANDLE hRemotePipe =
michael@0 56 CrashGenerationClient::DuplicatePipeToClientProcess(
michael@0 57 NS_ConvertASCIItoUTF16(GetChildNotificationPipe()).get(),
michael@0 58 hProcess);
michael@0 59 if (INVALID_HANDLE_VALUE == hRemotePipe) {
michael@0 60 NS_WARNING("Unable to duplicate crash reporter pipe to process.");
michael@0 61 return NS_OK;
michael@0 62 }
michael@0 63
michael@0 64 nsAutoHandle hThread(CreateRemoteThread(hProcess, nullptr, 0,
michael@0 65 (LPTHREAD_START_ROUTINE) proc,
michael@0 66 (void*) hRemotePipe, 0, nullptr));
michael@0 67 if (!hThread) {
michael@0 68 NS_WARNING("Unable to CreateRemoteThread");
michael@0 69
michael@0 70 // We have to close the remote pipe or else our crash generation client
michael@0 71 // will be stuck unable to accept other remote requests.
michael@0 72 HANDLE toClose = INVALID_HANDLE_VALUE;
michael@0 73 if (DuplicateHandle(hProcess, hRemotePipe, ::GetCurrentProcess(),
michael@0 74 &toClose, 0, FALSE,
michael@0 75 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
michael@0 76 CloseHandle(toClose);
michael@0 77 return NS_OK;
michael@0 78 }
michael@0 79 }
michael@0 80
michael@0 81 return NS_OK;
michael@0 82 }
michael@0 83
michael@0 84 } // namespace mozilla

mercurial