mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-29 08:39:44 +08:00
15103742e0
I opted to leave casts to types that were definitely the same size alone. reinterpret_cast<uintptr_t>(pointer) and reinterpret_cast<intptr_t>(pointer) should always be safe, for example. Casts to other integral types have been replaced with FromPointerCast<>(), which does zero-extension or sign-extension based on the target type. To make it possible to use FromPointerCast<>() with some use sites that were already using checked_cast<>(), FromPointerCast<>() now uses check_cast<>() when converting to a narrower type. Test: crashpad_util_test FromPointerCast*, others Change-Id: I4a71b4aa2d87f545c75524290a702f5f3138d675 Reviewed-on: https://chromium-review.googlesource.com/489701 Reviewed-by: Scott Graham <scottmg@chromium.org>
55 lines
1.8 KiB
C++
55 lines
1.8 KiB
C++
// Copyright 2016 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.
|
|
|
|
#include "snapshot/api/module_annotations_win.h"
|
|
|
|
#include "snapshot/win/pe_image_annotations_reader.h"
|
|
#include "snapshot/win/pe_image_reader.h"
|
|
#include "snapshot/win/process_reader_win.h"
|
|
#include "util/misc/from_pointer_cast.h"
|
|
#include "util/win/get_module_information.h"
|
|
|
|
namespace crashpad {
|
|
|
|
bool ReadModuleAnnotations(HANDLE process,
|
|
HMODULE module,
|
|
std::map<std::string, std::string>* annotations) {
|
|
ProcessReaderWin process_reader;
|
|
if (!process_reader.Initialize(process, ProcessSuspensionState::kRunning))
|
|
return false;
|
|
|
|
MODULEINFO module_info;
|
|
if (!CrashpadGetModuleInformation(
|
|
process, module, &module_info, sizeof(module_info))) {
|
|
PLOG(ERROR) << "CrashpadGetModuleInformation";
|
|
return false;
|
|
}
|
|
|
|
PEImageReader image_reader;
|
|
if (!image_reader.Initialize(
|
|
&process_reader,
|
|
FromPointerCast<WinVMAddress>(module_info.lpBaseOfDll),
|
|
module_info.SizeOfImage,
|
|
""))
|
|
return false;
|
|
|
|
PEImageAnnotationsReader annotations_reader(
|
|
&process_reader, &image_reader, L"");
|
|
|
|
*annotations = annotations_reader.SimpleMap();
|
|
return true;
|
|
}
|
|
|
|
} // namespace crashpad
|