Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: snapshot/win/pe_image_reader.h

Issue 1052813002: win: make CrashpadInfo retrievable (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_READER_H_
16 #define CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_READER_H_
17
18 #include <windows.h>
19
20 #include <string>
21
22 #include "base/basictypes.h"
23 #include "util/misc/initialization_state_dcheck.h"
24 #include "util/numeric/checked_address_range.h"
25
26 namespace crashpad {
27
28 class ProcessReaderWin;
29
30 namespace process_types {
31
32 // TODO(scottmg): Genericize and/or? move process_types out of mac/.
33 struct CrashpadInfo {
34 uint32_t signature;
35 uint32_t size;
36 uint32_t version;
37 uint8_t crashpad_handler_behavior; // TriState.
38 uint8_t system_crash_reporter_forwarding; // TriState.
39 uint16_t padding_0;
40 uint64_t simple_annotations; // TODO(scottmg): x86/64.
41 };
42
43 struct Section {
44 };
45
46 } // namespace process_types
47
48 //! \brief A reader for PE images mapped into another process.
49 //!
50 //! This class is capable of reading both 32-bit and 64-bit images based on the
51 //! bitness of the remote process.
52 //!
53 //! \sa PEImageAnnotationsReader
54 class PEImageReader {
55 public:
56 PEImageReader();
57 ~PEImageReader();
58
59 //! \brief Initializes the reader.
60 //!
61 //! This method must be called only once on an object. This method must be
62 //! called successfully before any other method in this class may be called.
63 //!
64 //! \param[in] process_reader The reader for the remote process.
65 //! \param[in] address The address, in the remote process' address space,
66 //! where the `IMAGE_DOS_HEADER` is located.
67 //! \param[in] size The size of the image.
68 //! \param[in] name The module's name, a string to be used in logged messages.
69 //! This string is for diagnostic purposes.
70 //!
71 //! \return `true` if the image was read successfully, `false` otherwise, with
72 //! an appropriate message logged.
73 bool Initialize(ProcessReaderWin* process_reader,
74 uintptr_t address,
75 uintptr_t size,
Mark Mentovai 2015/04/30 20:58:35 I don’t love uintptr_t for sizes. size_t is better
scottmg 2015/04/30 22:09:44 I started making an address_types.h, but then reca
scottmg 2015/04/30 22:12:23 Although now that I say that... e.g. ModuleSnapsho
scottmg 2015/04/30 22:28:23 Lacking a better name, I used win_vm_address_t and
76 const std::string& module_name);
77
78 //! \brief Obtains the module's CrashpadInfo structure.
79 //!
80 //! \return `true` on success, `false` on failure. If the module does not have
81 //! a `CPADinfo` section, this will return `false` without logging any
82 //! messages. Other failures will result in messages being logged.
83 bool GetCrashpadInfo(process_types::CrashpadInfo* crashpad_info) const;
84
85 private:
86 //! \brief Finds a given section by name in the image.
87 bool GetSectionByName(const std::string& name,
88 IMAGE_SECTION_HEADER* section) const;
89
90 //! \brief Reads memory from target process, first checking whether the range
91 //! requested falls inside module_range_.
92 //!
93 //! \return `true` on success, with \a into filled out, otherwise `false` and
94 //! a message will be logged.
95 bool CheckedReadMemory(uintptr_t address, uintptr_t size, void* into) const;
96
97 ProcessReaderWin* process_reader_; // weak
98 uintptr_t address_;
99 uintptr_t size_;
100 CheckedAddressRange module_range_;
101 std::string module_name_;
102 InitializationStateDcheck initialized_;
103
104 DISALLOW_COPY_AND_ASSIGN(PEImageReader);
105 };
106
107 } // namespace crashpad
108
109 #endif // CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698