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