LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
GnuHash.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_ELF_GNU_HASH_H
17#define LIEF_ELF_GNU_HASH_H
18
19#include <vector>
20#include <ostream>
21#include <cstdint>
22
23#include "LIEF/Object.hpp"
24#include "LIEF/visibility.h"
25
26namespace LIEF {
27namespace ELF {
28
29class Parser;
30class Builder;
31class Binary;
32class LIEF_API GnuHash : public Object {
37
38 friend class Parser;
39 friend class Builder;
40 friend class Binary;
41
42 public:
43 GnuHash() = default;
44 GnuHash(uint32_t symbol_idx, uint32_t shift2,
45 std::vector<uint64_t> bloom_filters, std::vector<uint32_t> buckets,
46 std::vector<uint32_t> hash_values = {});
47
48
49 GnuHash& operator=(const GnuHash& copy) = default;
50 GnuHash(const GnuHash& copy) = default;
51
52 GnuHash(GnuHash&&) = default;
53 GnuHash& operator=(GnuHash&&) = default;
54
55 ~GnuHash() override = default;
56 uint32_t nb_buckets() const {
60 return buckets_.size();
61 }
62 uint32_t symbol_index() const {
66 return symbol_index_;
67 }
68 uint32_t shift2() const {
71 return shift2_;
72 }
73 uint32_t maskwords() const {
77 return bloom_filters_.size();
78 }
79 const std::vector<uint64_t>& bloom_filters() const {
82 return bloom_filters_;
83 }
84 const std::vector<uint32_t>& buckets() const {
87 return buckets_;
88 }
89 const std::vector<uint32_t>& hash_values() const {
92 return hash_values_;
93 }
94 bool check_bloom_filter(uint32_t hash) const;
97 bool check_bucket(uint32_t hash) const {
100 return buckets_[hash % nb_buckets()] > 0;
101 }
102 bool check(const std::string& symbol_name) const;
108 bool check(uint32_t hash) const;
114
115
116 void accept(Visitor& visitor) const override;
117
118 LIEF_API friend std::ostream& operator<<(std::ostream& os, const GnuHash& gnuhash);
119
120 private:
121 uint32_t symbol_index_ = 0;
122 uint32_t shift2_ = 0;
123
124 std::vector<uint64_t> bloom_filters_;
125 std::vector<uint32_t> buckets_;
126 std::vector<uint32_t> hash_values_;
127
128 size_t c_ = 0;
129};
130
131
132} // namepsace ELF
133} // namespace LIEF
134
135#endif
Object.hpp
LIEF::ELF::Binary
Class which represents an ELF binary.
Definition ELF/Binary.hpp:59
LIEF::ELF::Builder
Class which takes an ELF::Binary object and reconstructs a valid binary.
Definition ELF/Builder.hpp:48
LIEF::ELF::GnuHash
Class which provides a view over the GNU Hash implementation. Most of the fields are read-only since ...
Definition GnuHash.hpp:36
LIEF::ELF::GnuHash::check_bucket
bool check_bucket(uint32_t hash) const
Check if the given hash passes the bucket filter.
Definition GnuHash.hpp:99
LIEF::ELF::GnuHash::GnuHash
GnuHash(uint32_t symbol_idx, uint32_t shift2, std::vector< uint64_t > bloom_filters, std::vector< uint32_t > buckets, std::vector< uint32_t > hash_values={})
LIEF::ELF::GnuHash::operator=
GnuHash & operator=(const GnuHash &copy)=default
LIEF::ELF::GnuHash::operator=
GnuHash & operator=(GnuHash &&)=default
LIEF::ELF::GnuHash::check
bool check(uint32_t hash) const
Check if the symbol associated with the given hash probably exists. If the returned value is false yo...
LIEF::ELF::GnuHash::symbol_index
uint32_t symbol_index() const
Index of the first symbol in the dynamic symbols table which accessible with the hash table.
Definition GnuHash.hpp:65
LIEF::ELF::GnuHash::hash_values
const std::vector< uint32_t > & hash_values() const
Hash values.
Definition GnuHash.hpp:91
LIEF::ELF::GnuHash::accept
void accept(Visitor &visitor) const override
LIEF::ELF::GnuHash::maskwords
uint32_t maskwords() const
Number of bloom filters used. It must be a power of 2.
Definition GnuHash.hpp:76
LIEF::ELF::GnuHash::GnuHash
GnuHash(const GnuHash &copy)=default
LIEF::ELF::GnuHash::~GnuHash
~GnuHash() override=default
LIEF::ELF::GnuHash::GnuHash
GnuHash()=default
LIEF::ELF::GnuHash::check
bool check(const std::string &symbol_name) const
Check if the symbol probably exists. If the returned value is false you can assume at 100% that the s...
LIEF::ELF::GnuHash::GnuHash
GnuHash(GnuHash &&)=default
LIEF::ELF::GnuHash::nb_buckets
uint32_t nb_buckets() const
Return the number of buckets.
Definition GnuHash.hpp:59
LIEF::ELF::GnuHash::bloom_filters
const std::vector< uint64_t > & bloom_filters() const
Bloom filters.
Definition GnuHash.hpp:81
LIEF::ELF::GnuHash::check_bloom_filter
bool check_bloom_filter(uint32_t hash) const
Check if the given hash passes the bloom filter.
LIEF::ELF::GnuHash::operator<<
friend std::ostream & operator<<(std::ostream &os, const GnuHash &gnuhash)
LIEF::ELF::GnuHash::buckets
const std::vector< uint32_t > & buckets() const
Hash buckets.
Definition GnuHash.hpp:86
LIEF::ELF::GnuHash::shift2
uint32_t shift2() const
Shift count used in the bloom filter.
Definition GnuHash.hpp:70
LIEF::ELF::Parser
Class which parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:45
LIEF::ELF
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
LIEF::hash
Hash::value_type hash(const Object &v)
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41