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,
60
typename
=
typename
std::enable_if<std::is_enum<T>::value>::type>
61
Hash
&
process
(T v) {
62
return
process
(
static_cast<
value_type
>
(v));
63
}
64
65
template
<
class
It>
66
Hash
&
process
(
typename
It::iterator v) {
67
return
process
(std::begin(v), std::end(v));
68
}
69
70
71
template
<
class
T,
size_t
N>
72
Hash
&
process
(
const
std::array<T, N>& array) {
73
process
(std::begin(array), std::end(array));
74
return
*
this
;
75
}
76
77
template
<
class
T>
78
Hash
&
process
(
const
std::vector<T>& vector) {
79
process
(std::begin(vector), std::end(vector));
80
return
*
this
;
81
}
82
83
template
<
class
T>
84
Hash
&
process
(
const
std::set<T>& set) {
85
process
(std::begin(set), std::end(set));
86
return
*
this
;
87
}
88
89
template
<
class
T>
90
Hash
&
process
(
const
optional<T>
& opt) {
91
if
(opt) {
92
return
process
(*opt);
93
}
94
return
*
this
;
95
}
96
97
template
<
class
U,
class
V>
98
Hash
&
process
(
const
std::pair<U, V>& p) {
99
process
(p.first);
100
process
(p.second);
101
return
*
this
;
102
}
103
104
template
<
class
InputIt>
105
Hash
&
process
(InputIt begin, InputIt end) {
106
for
(
auto
&& it = begin; it != end; ++it) {
107
process
(*it);
108
}
109
return
*
this
;
110
}
111
112
value_type
value
()
const
{
113
return
value_;
114
}
115
116
~Hash
()
override
;
117
118
protected
:
119
value_type
value_ = 0;
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::hash
static value_type hash(const Object &obj)
Definition
hash.hpp:127
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:72
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:105
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::process
Hash & process(const std::vector< T > &vector)
Definition
hash.hpp:78
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:90
LIEF::Hash::process
Hash & process(const std::pair< U, V > &p)
Definition
hash.hpp:98
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:112
LIEF::Hash::process
Hash & process(T v)
Definition
hash.hpp:61
LIEF::Hash::process
Hash & process(typename It::iterator v)
Definition
hash.hpp:66
LIEF::Hash::process
virtual Hash & process(const Object &obj)
LIEF::Hash::process
Hash & process(const std::set< T > &set)
Definition
hash.hpp:84
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:43
Generated by
1.17.0