LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DumpStream.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
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 LIEF_DUMP_STREAM_H
16#define LIEF_DUMP_STREAM_H
17
18#include <cstdint>
19#include <memory>
20
23#include "LIEF/errors.hpp"
24#include "LIEF/visibility.h"
25
26namespace LIEF {
27class Binary;
28
36 public:
37 DumpStream() = delete;
40 baseaddr_(base_address),
41 ref_(&ref) {}
42
43 DumpStream(uintptr_t base_address, std::unique_ptr<BinaryStream> owned) :
45 baseaddr_(base_address),
46 owned_(std::move(owned)),
47 ref_(owned_.get()) {}
48
49 DumpStream(const DumpStream&) = delete;
50 DumpStream& operator=(const DumpStream&) = delete;
51
52 DumpStream(DumpStream&&) noexcept = default;
53 DumpStream& operator=(DumpStream&&) noexcept = default;
54
55 uintptr_t base_address() const {
56 return baseaddr_;
57 }
58
60 return binary_;
61 }
62
63 uint64_t size() const override {
64 return ref_->size();
65 }
66
67 bool bind_binary(Binary& bin) override {
68 binary_ = &bin;
69 return true;
70 }
71
72 std::vector<uint8_t> content() const;
73
74 result<const void*> read_at(uint64_t /*offset*/, uint64_t /*size*/,
75 uint64_t /*virtual_address*/ = 0) const override {
77 }
78
79 ok_error_t peek_in(void* dst, uint64_t offset, uint64_t size,
80 uint64_t virtual_address = 0) const override;
81
82 ~DumpStream() override = default;
83
84 static bool classof(const BinaryStream& stream) {
85 return stream.type() == BinaryStream::STREAM_TYPE::DUMP;
86 }
87
88 protected:
89 uintptr_t baseaddr_ = 0;
90 Binary* binary_ = nullptr;
91 std::unique_ptr<BinaryStream> owned_;
92 BinaryStream* ref_ = nullptr;
93};
94}
95
96#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:34
STREAM_TYPE
Definition BinaryStream.hpp:38
@ DUMP
Definition BinaryStream.hpp:44
BinaryStream(STREAM_TYPE type)
Definition BinaryStream.hpp:49
STREAM_TYPE type() const
Definition BinaryStream.hpp:54
Generic interface representing a binary executable.
Definition Abstract/Binary.hpp:60
uintptr_t base_address() const
Definition DumpStream.hpp:55
uint64_t size() const override
Definition DumpStream.hpp:63
DumpStream(const DumpStream &)=delete
ok_error_t peek_in(void *dst, uint64_t offset, uint64_t size, uint64_t virtual_address=0) const override
DumpStream & operator=(const DumpStream &)=delete
DumpStream(DumpStream &&) noexcept=default
~DumpStream() override=default
bool bind_binary(Binary &bin) override
Definition DumpStream.hpp:67
Binary * binary()
Definition DumpStream.hpp:59
std::vector< uint8_t > content() const
DumpStream(uintptr_t base_address, std::unique_ptr< BinaryStream > owned)
Definition DumpStream.hpp:43
DumpStream()=delete
DumpStream(uintptr_t base_address, BinaryStream &ref)
Definition DumpStream.hpp:38
static bool classof(const BinaryStream &stream)
Definition DumpStream.hpp:84
result< const void * > read_at(uint64_t, uint64_t, uint64_t=0) const override
Definition DumpStream.hpp:74
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:118
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:78
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
@ not_supported
Definition errors.hpp:27
tl::unexpected< lief_errors > make_error_code(lief_errors e)
Create a standard error code from lief_errors.
Definition errors.hpp:54
LIEF namespace.
Definition Abstract/Binary.hpp:41
#define LIEF_API
Definition visibility.h:44