LIEF: Library to Instrument Executable Formats
Version 1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
lief-install
x86_64
static
include
LIEF
hash.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_HASH_H
17
#define LIEF_HASH_H
18
19
#include <vector>
20
#include <string>
21
22
#include "
LIEF/visibility.h
"
23
#include "
LIEF/Object.hpp
"
24
#include "
LIEF/Visitor.hpp
"
25
#include "
LIEF/span.hpp
"
26
#include "
LIEF/optional.hpp
"
27
28
namespace
LIEF
{
29
30
31
class
LIEF_API
Hash
:
public
Visitor
{
32
public
:
33
using
value_type
= size_t;
34
template
<
class
H = Hash>
35
static
value_type
hash
(
const
Object
& obj);
36
37
static
value_type
hash
(
const
std::vector<uint8_t>& raw);
38
static
value_type
hash
(
span<const uint8_t>
raw);
39
static
value_type
hash
(
const
void
* raw,
size_t
size);
40
41
// combine two elements to produce a size_t.
42
template
<
typename
U = value_type>
43
static
value_type
combine
(
value_type
lhs, U rhs) {
44
return
(lhs ^ rhs) + 0x9e3779b9 + (lhs << 6) + (rhs >> 2);
45
}
46
47
public
:
48
using
Visitor::visit
;
49
Hash
();
50
Hash
(
value_type
init_value);
51
52
virtual
Hash
&
process
(
const
Object
& obj);
53
virtual
Hash
&
process
(
size_t
integer);
54
virtual
Hash
&
process
(
const
std::string& str);
55
virtual
Hash
&
process
(
const
std::u16string& str);
56
virtual
Hash
&
process
(
const
std::vector<uint8_t>& raw);
57
virtual
Hash
&
process
(
span<const uint8_t>
raw);
58
59
template<class T, typename = typename std::enable_if<std::is_enum<T>::value>::type>
60
Hash
&
process
(T v) {
61
return
process
(
static_cast<
value_type
>
(v));
62
}
63
64
template
<
class
It>
65
Hash
&
process
(
typename
It::iterator v) {
66
return
process
(std::begin(v), std::end(v));
67
}
68
69
70
template
<
class
T,
size_t
N>
71
Hash
&
process
(
const
std::array<T, N>& array) {
72
process
(std::begin(array), std::end(array));
73
return
*
this
;
74
}
75
76
template
<
class
T>
77
Hash
&
process
(
const
std::vector<T>& vector) {
78
process
(std::begin(vector), std::end(vector));
79
return
*
this
;
80
}
81
82
template
<
class
T>
83
Hash
&
process
(
const
std::set<T>& set) {
84
process
(std::begin(set), std::end(set));
85
return
*
this
;
86
}
87
88
template
<
class
T>
89
Hash
&
process
(
const
optional<T>
& opt) {
90
if
(opt) {
91
return
process
(*opt);
92
}
93
return
*
this
;
94
}
95
96
template
<
class
U,
class
V>
97
Hash
&
process
(
const
std::pair<U, V>& p) {
98
process
(p.first);
99
process
(p.second);
100
return
*
this
;
101
}
102
103
template
<
class
InputIt>
104
Hash
&
process
(InputIt begin, InputIt end) {
105
for
(
auto
&& it = begin; it != end; ++it) {
106
process
(*it);
107
}
108
return
*
this
;
109
}
110
111
value_type
value
()
const
{
112
return
value_;
113
}
114
115
~Hash
()
override
;
116
117
protected
:
118
value_type
value_ = 0;
119
120
};
121
122
LIEF_API
Hash::value_type
hash
(
const
Object
& v);
123
LIEF_API
Hash::value_type
hash
(
const
std::vector<uint8_t>& raw);
124
LIEF_API
Hash::value_type
hash
(
span<const uint8_t>
raw);
125
126
template
<
class
Hasher>
127
Hash::value_type
Hash::hash
(
const
Object
& obj) {
128
Hasher hasher;
129
obj.
accept
(hasher);
130
return
hasher.value();
131
}
132
133
}
134
135
136
#endif
Object.hpp
Visitor.hpp
LIEF::Hash::hash
static value_type hash(span< const uint8_t > raw)
LIEF::Hash::process
virtual Hash & process(const std::u16string &str)
LIEF::Hash::process
virtual Hash & process(span< const uint8_t > raw)
LIEF::Hash::process
Hash & process(const std::array< T, N > &array)
Definition
hash.hpp:71
LIEF::Hash::Hash
Hash()
LIEF::Hash::~Hash
~Hash() override
LIEF::Hash::combine
static value_type combine(value_type lhs, U rhs)
Definition
hash.hpp:43
LIEF::Hash::process
Hash & process(InputIt begin, InputIt end)
Definition
hash.hpp:104
LIEF::Hash::process
virtual Hash & process(const std::string &str)
LIEF::Hash::process
virtual Hash & process(size_t integer)
LIEF::Hash::value_type
size_t value_type
Definition
hash.hpp:33
LIEF::Hash::hash
static value_type hash(const Object &obj)
Definition
hash.hpp:127
LIEF::Hash::process
Hash & process(const std::vector< T > &vector)
Definition
hash.hpp:77
LIEF::Hash::Hash
Hash(value_type init_value)
LIEF::Hash::process
virtual Hash & process(const std::vector< uint8_t > &raw)
LIEF::Hash::process
Hash & process(const optional< T > &opt)
Definition
hash.hpp:89
LIEF::Hash::process
Hash & process(const std::pair< U, V > &p)
Definition
hash.hpp:97
LIEF::Hash::hash
static value_type hash(const void *raw, size_t size)
LIEF::Hash::hash
static value_type hash(const std::vector< uint8_t > &raw)
LIEF::Hash::value
value_type value() const
Definition
hash.hpp:111
LIEF::Hash::process
Hash & process(T v)
Definition
hash.hpp:60
LIEF::Hash::process
Hash & process(typename It::iterator v)
Definition
hash.hpp:65
LIEF::Hash::process
virtual Hash & process(const Object &obj)
LIEF::Hash::process
Hash & process(const std::set< T > &set)
Definition
hash.hpp:83
LIEF::Object
Definition
Object.hpp:25
LIEF::Object::accept
virtual void accept(Visitor &visitor) const =0
LIEF::Visitor::visit
virtual void visit(const Object &)
LIEF::Visitor::Visitor
Visitor()
LIEF::optional
Definition
optional.hpp:23
LIEF
LIEF namespace.
Definition
Abstract/Binary.hpp:40
LIEF::span
tcb::span< ElementType, Extent > span
Definition
span.hpp:22
LIEF::hash
Hash::value_type hash(const Object &v)
optional.hpp
span.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition
visibility.h:41
Generated by
1.17.0