LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
MemoryStream.hpp
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_MEMORY_STREAM_H
17#define LIEF_MEMORY_STREAM_H
18
19#include <vector>
20#include <string>
21
22#include "LIEF/BinaryStream/BinaryStream.hpp"
23
24namespace LIEF {
25class Binary;
26class MemoryStream : public BinaryStream {
27 public:
28 using BinaryStream::p;
29 using BinaryStream::end;
30 using BinaryStream::start;
31
32 MemoryStream() = delete;
33 MemoryStream(uintptr_t base_address);
34 MemoryStream(uintptr_t base_address, uint64_t size);
35
36 MemoryStream(const MemoryStream&) = delete;
37 MemoryStream& operator=(const MemoryStream&) = delete;
38
40 MemoryStream& operator=(MemoryStream&&);
41
42 uintptr_t base_address() const {
43 return this->baseaddr_;
44 }
45
46 const uint8_t* p() const override {
47 return start() + pos();
48 }
49
50 const uint8_t* start() const override {
51 return reinterpret_cast<const uint8_t*>(baseaddr_);
52 }
53
54 const uint8_t* end() const override {
55 return start() + size_;
56 }
57
58 void binary(Binary& bin) {
59 this->binary_ = &bin;
60 }
61
62 Binary* binary() {
63 return this->binary_;
64 }
65
66 uint64_t size() const override;
67 ~MemoryStream() override;
68
69 static bool classof(const BinaryStream& stream);
70
71 protected:
72 result<const void*> read_at(uint64_t offset, uint64_t size) const override;
73 uintptr_t baseaddr_ = 0;
74 uint64_t size_ = 0;
75 Binary* binary_ = nullptr;
76};
77}
78
79#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:34
Abstract binary that exposes an uniform API for the different executable file formats.
Definition Abstract/Binary.hpp:39
Definition MemoryStream.hpp:26
LIEF namespace.
Definition Abstract/Binary.hpp:32
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:72