LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
RichHeader.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_PE_RICH_HEADER_H
16#define LIEF_PE_RICH_HEADER_H
17#include <ostream>
18
19#include "LIEF/Object.hpp"
20#include "LIEF/visibility.h"
21
22#include "LIEF/iterators.hpp"
23
24#include "LIEF/PE/RichEntry.hpp"
25#include "LIEF/PE/enums.hpp"
26
27
28namespace LIEF::PE {
29
36class LIEF_API RichHeader : public Object {
37 public:
38 using entries_t = std::vector<RichEntry>;
41
42 static constexpr uint8_t RICH_MAGIC[] = {'R', 'i', 'c', 'h'};
43 static constexpr uint32_t RICH_MAGIC_INT = 0x68636952; // 'Rich'
44 static constexpr uint32_t DANS_MAGIC_NUMBER = 0x536E6144; // 'DanS'
45
46 RichHeader() = default;
47 RichHeader(const RichHeader&) = default;
48 RichHeader& operator=(const RichHeader&) = default;
49 ~RichHeader() override = default;
50
52 uint32_t key() const {
53 return key_;
54 }
55
58 return entries_;
59 }
60
62 return entries_;
63 }
64
65 void key(uint32_t key) {
66 key_ = key;
67 }
68
70 void add_entry(RichEntry entry) {
71 entries_.push_back(std::move(entry));
72 }
73
75 void add_entry(uint16_t id, uint16_t build_id, uint32_t count) {
76 entries_.emplace_back(id, build_id, count);
77 }
78
83 std::vector<uint8_t> raw() const {
84 return raw(/*xor_key=*/0);
85 }
86
93 std::vector<uint8_t> raw(uint32_t xor_key) const;
94
97 std::vector<uint8_t> hash(ALGORITHMS algo) const {
98 return hash(algo, /*xor_key=*/0);
99 }
100
102 std::vector<uint8_t> hash(ALGORITHMS algo, uint32_t xor_key) const;
103
104 void accept(Visitor& visitor) const override;
105
106 LIEF_API friend std::ostream& operator<<(std::ostream& os,
107 const RichHeader& rich_header);
108
109 private:
110 uint32_t key_ = 0;
111 entries_t entries_;
112};
113}
114
115
116#endif
Class which represents an entry associated to the RichHeader.
Definition RichEntry.hpp:27
std::vector< uint8_t > raw() const
The raw structure of the Rich header without xor-encoding.
Definition RichHeader.hpp:83
std::vector< uint8_t > raw(uint32_t xor_key) const
Given this rich header, this function re-computes the raw bytes of the structure with the provided xo...
ref_iterator< entries_t & > it_entries
Definition RichHeader.hpp:39
static constexpr uint32_t RICH_MAGIC_INT
Definition RichHeader.hpp:43
static constexpr uint8_t RICH_MAGIC[]
Definition RichHeader.hpp:42
void accept(Visitor &visitor) const override
it_const_entries entries() const
Definition RichHeader.hpp:61
std::vector< RichEntry > entries_t
Definition RichHeader.hpp:38
RichHeader(const RichHeader &)=default
RichHeader & operator=(const RichHeader &)=default
friend std::ostream & operator<<(std::ostream &os, const RichHeader &rich_header)
it_entries entries()
Return an iterator over the PE::RichEntry within the header.
Definition RichHeader.hpp:57
void add_entry(uint16_t id, uint16_t build_id, uint32_t count)
Add a new entry given the id, build_id and count.
Definition RichHeader.hpp:75
std::vector< uint8_t > hash(ALGORITHMS algo) const
Compute the hash of the decoded rich header structure with the given hash algorithm.
Definition RichHeader.hpp:97
std::vector< uint8_t > hash(ALGORITHMS algo, uint32_t xor_key) const
Compute the hash of the rich header structure encoded with the provided key.
~RichHeader() override=default
void add_entry(RichEntry entry)
Add a new PE::RichEntry.
Definition RichHeader.hpp:70
static constexpr uint32_t DANS_MAGIC_NUMBER
Definition RichHeader.hpp:44
const_ref_iterator< const entries_t & > it_const_entries
Definition RichHeader.hpp:40
void key(uint32_t key)
Definition RichHeader.hpp:65
uint32_t key() const
Key used to encode the header (xor operation).
Definition RichHeader.hpp:52
Definition Visitor.hpp:211
Iterator which returns reference on container's values.
Definition iterators.hpp:120
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:31
ALGORITHMS
Cryptography algorithms.
Definition PE/enums.hpp:28
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which returns a const ref on container's values.
Definition iterators.hpp:385
#define LIEF_API
Definition visibility.h:44