LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
PDBChecksum.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 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_PE_PDBCHECKSUM_H
17#define LIEF_PE_PDBCHECKSUM_H
18#include <vector>
19
20#include "LIEF/visibility.h"
22
23namespace LIEF {
24namespace PE {
25class LIEF_API PDBChecksum : public Debug {
29 public:
30 static std::unique_ptr<PDBChecksum>
31 parse(const details::pe_debug& hdr, Section* section, span<uint8_t> payload);
32
33 enum class HASH_ALGO : uint32_t {
34 UNKNOWN = 0,
35 SHA256,
36 };
37
38 PDBChecksum(HASH_ALGO algo, std::vector<uint8_t> hash) :
39 Debug(Debug::TYPES::PDBCHECKSUM),
40 algo_(algo),
41 hash_(std::move(hash))
42 {}
43
44 PDBChecksum(const details::pe_debug& dbg, Section* sec,
45 HASH_ALGO algo, std::vector<uint8_t> hash) :
46 Debug(dbg, sec),
47 algo_(algo),
48 hash_(std::move(hash))
49 {}
50
51 PDBChecksum(const PDBChecksum& other) = default;
52 PDBChecksum& operator=(const PDBChecksum& other) = default;
53
54 PDBChecksum(PDBChecksum&&) = default;
55 PDBChecksum& operator=(PDBChecksum&& other) = default;
56
57 std::unique_ptr<Debug> clone() const override {
58 return std::unique_ptr<Debug>(new PDBChecksum(*this));
59 }
60 span<const uint8_t> hash() const {
63 return hash_;
64 }
65
66 span<uint8_t> hash() {
67 return hash_;
68 }
69
70 void hash(std::vector<uint8_t> h) {
71 hash_ = std::move(h);
72 }
73 HASH_ALGO algorithm() const {
76 return algo_;
77 }
78
79 void algorithm(HASH_ALGO algo) {
80 algo_ = algo;
81 }
82
83 static bool classof(const Debug* debug) {
84 return debug->type() == Debug::TYPES::PDBCHECKSUM;
85 }
86
87 ~PDBChecksum() override = default;
88
89 std::string to_string() const override;
90
91 private:
92 HASH_ALGO algo_ = HASH_ALGO::UNKNOWN;
93 std::vector<uint8_t> hash_;
94};
95
96LIEF_API const char* to_string(PDBChecksum::HASH_ALGO e);
97
98}
99}
100
101#endif
LIEF::PE::Debug
This class represents a generic entry in the debug data directory. For known types,...
Definition debug/Debug.hpp:40
LIEF::PE::PDBChecksum
This class represents the PDB Checksum debug entry which is essentially an array of bytes representin...
Definition PDBChecksum.hpp:28
LIEF::PE::PDBChecksum::PDBChecksum
PDBChecksum(HASH_ALGO algo, std::vector< uint8_t > hash)
Definition PDBChecksum.hpp:38
LIEF::PE::PDBChecksum::operator=
PDBChecksum & operator=(const PDBChecksum &other)=default
LIEF::PE::PDBChecksum::operator=
PDBChecksum & operator=(PDBChecksum &&other)=default
LIEF::PE::PDBChecksum::algorithm
HASH_ALGO algorithm() const
Algorithm used for hashing the PDB content.
Definition PDBChecksum.hpp:75
LIEF::PE::PDBChecksum::clone
std::unique_ptr< Debug > clone() const override
Definition PDBChecksum.hpp:57
LIEF::PE::PDBChecksum::to_string
std::string to_string() const override
LIEF::PE::PDBChecksum::algorithm
void algorithm(HASH_ALGO algo)
Definition PDBChecksum.hpp:79
LIEF::PE::PDBChecksum::hash
span< uint8_t > hash()
Definition PDBChecksum.hpp:66
LIEF::PE::PDBChecksum::PDBChecksum
PDBChecksum(PDBChecksum &&)=default
LIEF::PE::PDBChecksum::PDBChecksum
PDBChecksum(const details::pe_debug &dbg, Section *sec, HASH_ALGO algo, std::vector< uint8_t > hash)
Definition PDBChecksum.hpp:44
LIEF::PE::PDBChecksum::hash
span< const uint8_t > hash() const
Hash of the PDB content.
Definition PDBChecksum.hpp:62
LIEF::PE::PDBChecksum::~PDBChecksum
~PDBChecksum() override=default
LIEF::PE::PDBChecksum::classof
static bool classof(const Debug *debug)
Definition PDBChecksum.hpp:83
LIEF::PE::PDBChecksum::hash
void hash(std::vector< uint8_t > h)
Definition PDBChecksum.hpp:70
LIEF::PE::PDBChecksum::HASH_ALGO
HASH_ALGO
Definition PDBChecksum.hpp:33
LIEF::PE::PDBChecksum::PDBChecksum
PDBChecksum(const PDBChecksum &other)=default
LIEF::PE::PDBChecksum::parse
static std::unique_ptr< PDBChecksum > parse(const details::pe_debug &hdr, Section *section, span< uint8_t > payload)
Debug.hpp
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::to_string
const char * to_string(AuxiliaryWeakExternal::CHARACTERISTICS e)
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