LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
RichHeader.hpp
Go to the documentation of this file.
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 <ostream>
19
20#include "LIEF/Object.hpp"
21#include "LIEF/visibility.h"
22
23#include "LIEF/iterators.hpp"
24
25#include "LIEF/PE/RichEntry.hpp"
26#include "LIEF/PE/enums.hpp"
27
28namespace LIEF {
29namespace PE {
30
37class LIEF_API RichHeader : public Object {
38 public:
39
40 using entries_t = std::vector<RichEntry>;
43
44 RichHeader() = default;
45 RichHeader(const RichHeader&) = default;
46 RichHeader& operator=(const RichHeader&) = default;
47 ~RichHeader() override = default;
48
50 uint32_t key() const {
51 return key_;
52 }
53
56 return entries_;
57 }
58
60 return entries_;
61 }
62
63 void key(uint32_t key) {
64 key_ = key;
65 }
66
68 void add_entry(RichEntry entry) {
69 entries_.push_back(std::move(entry));
70 }
71
73 void add_entry(uint16_t id, uint16_t build_id, uint32_t count) {
74 entries_.emplace_back(id, build_id, count);
75 }
76
80 std::vector<uint8_t> raw() const {
81 return raw(/*xor_key=*/0);
82 }
83
90 std::vector<uint8_t> raw(uint32_t xor_key) const;
91
94 std::vector<uint8_t> hash(ALGORITHMS algo) const {
95 return hash(algo, /*xor_key=*/0);
96 }
97
99 std::vector<uint8_t> hash(ALGORITHMS algo, uint32_t xor_key) const;
100
101 void accept(Visitor& visitor) const override;
102
103 LIEF_API friend std::ostream& operator<<(std::ostream& os, const RichHeader& rich_header);
104
105 private:
106 uint32_t key_ = 0;
107 entries_t entries_;
108
109};
110}
111}
112
113#endif
114
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:37
std::vector< uint8_t > raw() const
The raw structure of the Rich header without xor-encoding.
Definition RichHeader.hpp:80
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...
void accept(Visitor &visitor) const override
it_const_entries entries() const
Definition RichHeader.hpp:59
std::vector< RichEntry > entries_t
Definition RichHeader.hpp:40
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:55
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:73
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:94
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:68
void key(uint32_t key)
Definition RichHeader.hpp:63
uint32_t key() const
Key used to encode the header (xor operation)
Definition RichHeader.hpp:50
Definition Visitor.hpp:224
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
Hash::value_type hash(const Object &v)
#define LIEF_API
Definition visibility.h:41