LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
CoreFile.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_ELF_CORE_FILE_H
17#define LIEF_ELF_CORE_FILE_H
18
19#include <vector>
20#include <ostream>
21
22#include "LIEF/visibility.h"
23
24#include "LIEF/ELF/Note.hpp"
25
26namespace LIEF {
27namespace ELF {
28
31class LIEF_API CoreFile : public Note {
32 public:
34 struct entry_t {
35 uint64_t start = 0;
36 uint64_t end = 0;
37 uint64_t file_ofs = 0;
38 std::string path;
39
40 LIEF_API friend
41 std::ostream& operator<<(std::ostream& os, const entry_t& entry);
42 };
43
44 using files_t = std::vector<entry_t>;
45 using iterator = files_t::iterator;
46 using const_iterator = files_t::const_iterator;
47
48 public:
49 CoreFile(ARCH arch, Header::CLASS cls, std::string name,
50 uint32_t type, Note::description_t description);
51
52 std::unique_ptr<Note> clone() const override {
53 return std::unique_ptr<Note>(new CoreFile(*this));
54 }
55
57 uint64_t count() const {
58 return files_.size();
59 }
60
62 const files_t& files() const {
63 return files_;
64 }
65
67 return files_.begin();
68 }
69
71 return files_.end();
72 }
73
75 return files_.begin();
76 }
77
79 return files_.end();
80 }
81
82 void files(const files_t& file);
83
84 void dump(std::ostream& os) const override;
85 void accept(Visitor& visitor) const override;
86
87 static bool classof(const Note* note) {
88 return note->type() == Note::TYPE::CORE_FILE;
89 }
90
91 ~CoreFile() override = default;
92
93 LIEF_API friend
94 std::ostream& operator<<(std::ostream& os, const CoreFile& note) {
95 note.dump(os);
96 return os;
97 }
98
99 protected:
100 template<class T>
101 LIEF_LOCAL void read_files();
102
103 template<class T>
104 LIEF_LOCAL void write_files();
105
106 files_t files_;
107 uint64_t page_size_ = 0;
108 ARCH arch_ = ARCH::NONE;
109 Header::CLASS class_ = Header::CLASS::NONE;
110};
111
112} // namepsace ELF
113} // namespace LIEF
114
115#endif
Class representing a core NT_FILE which describes the mapped files of the process.
Definition CoreFile.hpp:31
iterator begin()
Definition CoreFile.hpp:66
void dump(std::ostream &os) const override
files_t::iterator iterator
Definition CoreFile.hpp:45
void accept(Visitor &visitor) const override
std::unique_ptr< Note > clone() const override
Clone the current note and keep its polymorphic type.
Definition CoreFile.hpp:52
CoreFile(ARCH arch, Header::CLASS cls, std::string name, uint32_t type, Note::description_t description)
files_t::const_iterator const_iterator
Definition CoreFile.hpp:46
std::vector< entry_t > files_t
Definition CoreFile.hpp:44
const_iterator end() const
Definition CoreFile.hpp:78
void files(const files_t &file)
friend std::ostream & operator<<(std::ostream &os, const CoreFile &note)
Definition CoreFile.hpp:94
static bool classof(const Note *note)
Definition CoreFile.hpp:87
const_iterator begin() const
Definition CoreFile.hpp:74
const files_t & files() const
Coredump file entries.
Definition CoreFile.hpp:62
iterator end()
Definition CoreFile.hpp:70
~CoreFile() override=default
uint64_t count() const
Number of coredump file entries.
Definition CoreFile.hpp:57
CLASS
Match the result of Elfxx_Ehdr.e_ident[EI_CLASS]
Definition ELF/Header.hpp:76
Class which represents an ELF note. This class can be instantiated using the static Note::create func...
Definition Note.hpp:39
std::vector< uint8_t > description_t
Container used to handle the description data.
Definition Note.hpp:46
TYPE type() const
Return the type of the note. This type does not match the NT_ type value. For accessing the original ...
Definition Note.hpp:195
Definition Visitor.hpp:224
ARCH
Machine architectures See current registered ELF machine architectures at: http://www....
Definition ELF/enums.hpp:30
LIEF namespace.
Definition Abstract/Binary.hpp:32
Core file entry.
Definition CoreFile.hpp:34
std::string path
Path of mapped file.
Definition CoreFile.hpp:38
friend std::ostream & operator<<(std::ostream &os, const entry_t &entry)
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42