LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
Abstract/Section.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_ABSTRACT_SECTION_H
17#define LIEF_ABSTRACT_SECTION_H
18
19#include <string>
20#include <vector>
21#include <ostream>
22
23#include "LIEF/span.hpp"
24#include "LIEF/Object.hpp"
25#include "LIEF/visibility.h"
26
27namespace LIEF {class LIEF_API Section : public Object {
30 public:
31 static constexpr size_t npos = -1;
32
33 Section() = default;
34 Section(std::string name) :
35 name_(std::move(name))
36 {}
37
38 ~Section() override = default;
39
40 Section& operator=(const Section&) = default;
41 Section(const Section&) = default;
42 virtual std::string name() const {
45 return name_.c_str();
46 }
47 virtual const std::string& fullname() const {
51 return name_;
52 }
53 virtual span<const uint8_t> content() const {
56 return {};
57 }
58 virtual void size(uint64_t size) {
61 size_ = size;
62 }
63 virtual uint64_t size() const {
66 return size_;
67 }
68 virtual uint64_t offset() const {
71 return offset_;
72 }
73 virtual uint64_t virtual_address() const {
76 return virtual_address_;
77 }
78
79 virtual void virtual_address(uint64_t virtual_address) {
80 virtual_address_ = virtual_address;
81 }
82 virtual void name(std::string name) {
85 name_ = std::move(name);
86 }
87 virtual void content(const std::vector<uint8_t>&) {}
90
91 virtual void offset(uint64_t offset) {
92 offset_ = offset;
93 }
94 double entropy() const;
97
98 // Search functions
99 // ================
100 size_t search(uint64_t integer, size_t pos, size_t size) const;
101 size_t search(const std::vector<uint8_t>& pattern, size_t pos = 0) const;
102 size_t search(const std::string& pattern, size_t pos = 0) const;
103 size_t search(uint64_t integer, size_t pos = 0) const;
104
105 // Search all functions
106 // ====================
107 std::vector<size_t> search_all(uint64_t v, size_t size) const;
108
109 std::vector<size_t> search_all(uint64_t v) const;
110
111 std::vector<size_t> search_all(const std::string& v) const;
112 void accept(Visitor& visitor) const override;
115
116
117 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Section& entry);
118
119 protected:
120 std::string name_;
121 uint64_t virtual_address_ = 0;
122 uint64_t size_ = 0;
123 uint64_t offset_ = 0;
124
125 private:
126 template<typename T>
127 std::vector<size_t> search_all_(const T& v) const;
128};
129}
130
131#endif
Object.hpp
LIEF::Object
Definition Object.hpp:25
LIEF::Section
Class which represents an abstracted section.
Definition Abstract/Section.hpp:29
LIEF::Section::offset
virtual void offset(uint64_t offset)
Definition Abstract/Section.hpp:91
LIEF::Section::content
virtual void content(const std::vector< uint8_t > &)
Change section content.
Definition Abstract/Section.hpp:89
LIEF::Section::size
virtual void size(uint64_t size)
Change the section size.
Definition Abstract/Section.hpp:60
LIEF::Section::size
virtual uint64_t size() const
section's size (size in the binary, not the virtual size)
Definition Abstract/Section.hpp:65
LIEF::Section::search_all
std::vector< size_t > search_all(const std::string &v) const
LIEF::Section::virtual_address
virtual void virtual_address(uint64_t virtual_address)
Definition Abstract/Section.hpp:79
LIEF::Section::search
size_t search(uint64_t integer, size_t pos, size_t size) const
LIEF::Section::Section
Section()=default
LIEF::Section::Section
Section(const Section &)=default
LIEF::Section::fullname
virtual const std::string & fullname() const
Return the complete section's name which might trailing (0) bytes.
Definition Abstract/Section.hpp:50
LIEF::Section::search
size_t search(const std::vector< uint8_t > &pattern, size_t pos=0) const
LIEF::Section::search_all
std::vector< size_t > search_all(uint64_t v) const
LIEF::Section::Section
Section(std::string name)
Definition Abstract/Section.hpp:34
LIEF::Section::search
size_t search(uint64_t integer, size_t pos=0) const
LIEF::Section::entropy
double entropy() const
Section's entropy.
LIEF::Section::name
virtual void name(std::string name)
Change the section's name.
Definition Abstract/Section.hpp:84
LIEF::Section::name
virtual std::string name() const
section's name
Definition Abstract/Section.hpp:44
LIEF::Section::operator<<
friend std::ostream & operator<<(std::ostream &os, const Section &entry)
LIEF::Section::content
virtual span< const uint8_t > content() const
section's content
Definition Abstract/Section.hpp:55
LIEF::Section::~Section
~Section() override=default
LIEF::Section::offset
virtual uint64_t offset() const
Offset in the binary.
Definition Abstract/Section.hpp:70
LIEF::Section::search
size_t search(const std::string &pattern, size_t pos=0) const
LIEF::Section::search_all
std::vector< size_t > search_all(uint64_t v, size_t size) const
LIEF::Section::accept
void accept(Visitor &visitor) const override
Method so that the visitor can visit us.
LIEF::Section::operator=
Section & operator=(const Section &)=default
LIEF::Section::virtual_address
virtual uint64_t virtual_address() const
Address where the section should be mapped.
Definition Abstract/Section.hpp:75
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
span.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41