mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-29 00:32:35 +08:00
0758dbde9a
This makes the basics of !peb work in windbg, however, pointed-to things are not yet retrieved. For full functionality, a variety of pointers in the PEB also needs to be walked and captured. e.g. Previously: 0:000> .ecxr eax=00000007 ebx=7e383000 ecx=c3f9a943 edx=00000000 esi=006d62d0 edi=003c9280 eip=00384828 esp=005bf634 ebp=005bf638 iopl=0 nv up ei pl zr na pe nc cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010246 crashy_program!crashpad::`anonymous namespace'::SomeCrashyFunction+0x28: 00384828 c7002a000000 mov dword ptr [eax],2Ah ds:002b:00000007=???????? 0:000> !peb PEB at 7e383000 error 1 InitTypeRead( nt!_PEB at 7e383000)... Now: 0:000> .ecxr eax=00000007 ebx=7f958000 ecx=02102f4d edx=00000000 esi=00e162d0 edi=01389280 eip=01344828 esp=00c2fb64 ebp=00c2fb68 iopl=0 nv up ei pl zr na pe nc cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010246 crashy_program!crashpad::`anonymous namespace'::SomeCrashyFunction+0x28: 01344828 c7002a000000 mov dword ptr [eax],2Ah ds:002b:00000007=???????? 0:000> !peb PEB at 7f958000 InheritedAddressSpace: No ReadImageFileExecOptions: No BeingDebugged: No ImageBaseAddress: 01340000 Ldr 77ec8b40 *** unable to read Ldr table at 77ec8b40 SubSystemData: 00000000 ProcessHeap: 00e10000 ProcessParameters: 00e114e0 CurrentDirectory: '< Name not readable >' WindowTitle: '< Name not readable >' ImageFile: '< Name not readable >' CommandLine: '< Name not readable >' DllPath: '< Name not readable >' Environment: 00000000 Unable to read Environment string. R=mark@chromium.org BUG=crashpad:46 Review URL: https://codereview.chromium.org/1364053002 .
123 lines
3.9 KiB
C++
123 lines
3.9 KiB
C++
// Copyright 2015 The Crashpad Authors. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#ifndef CRASHPAD_UTIL_WIN_PROCESS_INFO_H_
|
|
#define CRASHPAD_UTIL_WIN_PROCESS_INFO_H_
|
|
|
|
#include <sys/types.h>
|
|
#include <windows.h>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "base/basictypes.h"
|
|
#include "util/misc/initialization_state_dcheck.h"
|
|
#include "util/win/address_types.h"
|
|
|
|
namespace crashpad {
|
|
|
|
//! \brief Gathers information about a process given its `HANDLE`. This consists
|
|
//! primarily of information stored in the Process Environment Block.
|
|
class ProcessInfo {
|
|
public:
|
|
//! \brief Contains information about a module loaded into a process.
|
|
struct Module {
|
|
Module();
|
|
~Module();
|
|
|
|
//! \brief The pathname used to load the module from disk.
|
|
std::wstring name;
|
|
|
|
//! \brief The base address of the loaded DLL.
|
|
WinVMAddress dll_base;
|
|
|
|
//! \brief The size of the module.
|
|
WinVMSize size;
|
|
|
|
//! \brief The module's timestamp.
|
|
time_t timestamp;
|
|
};
|
|
|
|
ProcessInfo();
|
|
~ProcessInfo();
|
|
|
|
//! \brief Initializes this object with information about the given
|
|
//! \a process.
|
|
//!
|
|
//! This method must be called successfully prior to calling any other
|
|
//! method in this class. This method may only be called once.
|
|
//!
|
|
//! \return `true` on success, `false` on failure with a message logged.
|
|
bool Initialize(HANDLE process);
|
|
|
|
//! \return `true` if the target process is a 64-bit process.
|
|
bool Is64Bit() const;
|
|
|
|
//! \return `true` if the target process is running on the Win32-on-Win64
|
|
//! subsystem.
|
|
bool IsWow64() const;
|
|
|
|
//! \return The target process's process ID.
|
|
pid_t ProcessID() const;
|
|
|
|
//! \return The target process's parent process ID.
|
|
pid_t ParentProcessID() const;
|
|
|
|
//! \return The command line from the target process's Process Environment
|
|
//! Block.
|
|
bool CommandLine(std::wstring* command_line) const;
|
|
|
|
//! \brief Gets the address and size of the process's Process Environment
|
|
//! Block.
|
|
//!
|
|
//! \param[out] peb_address The address of the Process Environment Block.
|
|
//! \param[out] peb_size The size of the Process Environment Block.
|
|
void Peb(WinVMAddress* peb_address, WinVMSize* peb_size) const;
|
|
|
|
//! \brief Retrieves the modules loaded into the target process.
|
|
//!
|
|
//! The modules are enumerated in initialization order as detailed in the
|
|
//! Process Environment Block. The main executable will always be the
|
|
//! first element.
|
|
bool Modules(std::vector<Module>* modules) const;
|
|
|
|
private:
|
|
template <class Traits>
|
|
friend bool GetProcessBasicInformation(HANDLE process,
|
|
bool is_wow64,
|
|
ProcessInfo* process_info,
|
|
WinVMAddress* peb_address,
|
|
WinVMSize* peb_size);
|
|
template <class Traits>
|
|
friend bool ReadProcessData(HANDLE process,
|
|
WinVMAddress peb_address_vmaddr,
|
|
ProcessInfo* process_info);
|
|
|
|
pid_t process_id_;
|
|
pid_t inherited_from_process_id_;
|
|
std::wstring command_line_;
|
|
WinVMAddress peb_address_;
|
|
WinVMSize peb_size_;
|
|
std::vector<Module> modules_;
|
|
bool is_64_bit_;
|
|
bool is_wow64_;
|
|
InitializationStateDcheck initialized_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ProcessInfo);
|
|
};
|
|
|
|
} // namespace crashpad
|
|
|
|
#endif // CRASHPAD_UTIL_WIN_PROCESS_INFO_H_
|