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