LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
RichHeader.hpp
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_PE_RICH_HEADER_H
17#define LIEF_PE_RICH_HEADER_H
18#include <array>
19#include <ostream>
20
21#include "LIEF/Object.hpp"
22#include "LIEF/visibility.h"
23
24#include "LIEF/iterators.hpp"
25
26#include "LIEF/PE/RichEntry.hpp"
27#include "LIEF/PE/enums.hpp"
28
29namespace LIEF {
30namespace PE {
31
38class LIEF_API RichHeader : public Object {
39 public:
40
41 using entries_t = std::vector<RichEntry>;
44
45 RichHeader();
46 RichHeader(const RichHeader&);
47 RichHeader& operator=(const RichHeader&);
48 ~RichHeader() override;
49
51 uint32_t key() const {
52 return key_;
53 }
54
57 return entries_;
58 }
59
60 it_const_entries entries() const {
61 return entries_;
62 }
63
64 void key(uint32_t key) {
65 key_ = key;
66 }
67
69 void add_entry(const RichEntry& entry);
70
72 void add_entry(uint16_t id, uint16_t build_id, uint32_t count);
73
77 std::vector<uint8_t> raw() const {
78 return raw(/*xor_key=*/0);
79 }
80
87 std::vector<uint8_t> raw(uint32_t xor_key) const;
88
91 std::vector<uint8_t> hash(ALGORITHMS algo) const {
92 return hash(algo, /*xor_key=*/0);
93 }
94
96 std::vector<uint8_t> hash(ALGORITHMS algo, uint32_t xor_key) const;
97
98 void accept(Visitor& visitor) const override;
99
100 LIEF_API friend std::ostream& operator<<(std::ostream& os, const RichHeader& rich_header);
101
102 private:
103 uint32_t key_ = 0;
104 entries_t entries_;
105
106};
107}
108}
109
110#endif
111
Definition Object.hpp:25
Class which represents an entry associated to the RichHeader.
Definition RichEntry.hpp:28
Class which represents the not-so-documented rich header.
Definition RichHeader.hpp:38
std::vector< uint8_t > raw() const
The raw structure of the Rich header without xor-encoding.
Definition RichHeader.hpp:77
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...
it_entries entries()
Return an iterator over the PE::RichEntry within the header.
Definition RichHeader.hpp:56
void add_entry(uint16_t id, uint16_t build_id, uint32_t count)
Add a new entry given the id, build_id and count.
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:91
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.
void add_entry(const RichEntry &entry)
Add a new PE::RichEntry.
uint32_t key() const
Key used to encode the header (xor operation)
Definition RichHeader.hpp:51
Definition Visitor.hpp:219
Iterator which returns reference on container's values.
Definition iterators.hpp:48
ALGORITHMS
Cryptography algorithms.
Definition PE/enums.hpp:686
LIEF namespace.
Definition Abstract/Binary.hpp:32