LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ResourceIcon.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_RESOURCE_ICON_H
17#define LIEF_PE_RESOURCE_ICON_H
18#include <ostream>
19#include <climits>
20#include <vector>
21
22#include "LIEF/visibility.h"
23#include "LIEF/errors.hpp"
24
25#include "LIEF/span.hpp"
26#include "LIEF/Object.hpp"
27
28namespace LIEF {
29namespace PE {
31
32namespace details {
33struct pe_resource_icon_group;
34struct pe_icon_header;
35}
36
38 friend class ResourcesManager;
39
40 public:
42 from_serialization(const uint8_t* buffer, size_t size);
43
44 static result<ResourceIcon> from_serialization(const std::vector<uint8_t>& bytes) {
45 return from_serialization(bytes.data(), bytes.size());
46 }
47
49 return from_serialization(bytes.data(), bytes.size_bytes());
50 }
51
52 ResourceIcon() = default;
53 ResourceIcon(const details::pe_resource_icon_group& header);
54 ResourceIcon(const details::pe_icon_header& header);
55
56 ResourceIcon(const ResourceIcon&) = default;
58
61
62 ~ResourceIcon() override = default;
63
65 uint32_t id() const {
66 return id_;
67 }
68
70 uint32_t lang() const {
71 return lang_;
72 }
73
75 uint32_t sublang() const {
76 return sublang_;
77 }
78
80 uint8_t width() const {
81 return width_;
82 }
83
85 uint8_t height() const {
86 return height_;
87 }
88
90 uint8_t color_count() const {
91 return color_count_;
92 }
93
95 uint8_t reserved() const {
96 return reserved_;
97 }
98
100 uint16_t planes() const {
101 return planes_;
102 }
103
105 uint16_t bit_count() const {
106 return bit_count_;
107 }
108
110 uint32_t size() const {
111 return pixels_.size();
112 }
113
116 return pixels_;
117 }
118
119 void id(uint32_t id) {
120 id_ = id;
121 }
122
123 void lang(uint32_t lang) {
124 lang_ = lang;
125 }
126
127 void sublang(uint32_t sublang) {
128 sublang_ = sublang;
129 }
130
131 void width(uint8_t width) {
132 width_ = width;
133 }
134
135 void height(uint8_t height) {
136 height_ = height;
137 }
138
139 void color_count(uint8_t color_count) {
140 color_count_ = color_count;
141 }
142
143 void reserved(uint8_t reserved) {
144 reserved_ = reserved;
145 }
146
147 void planes(uint16_t planes) {
148 planes_ = planes;
149 }
150
151 void bit_count(uint16_t bit_count) {
152 bit_count_ = bit_count;
153 }
154
155 void pixels(std::vector<uint8_t> pixels) {
156 pixels_ = std::move(pixels);
157 }
158
162 void save(const std::string& filename) const;
163
164 std::vector<uint8_t> serialize() const;
165
166 void accept(Visitor& visitor) const override;
167
168 LIEF_API friend std::ostream& operator<<(std::ostream& os, const ResourceIcon& entry);
169
170 private:
171 uint8_t width_ = 0;
172 uint8_t height_ = 0;
173 uint8_t color_count_ = 0;
174 uint8_t reserved_ = 0;
175 uint16_t planes_ = 0;
176 uint16_t bit_count_ = 0;
177 uint32_t id_ = uint32_t(-1);
178 uint32_t lang_ = /* LANG_NEUTRAL */0;
179 uint32_t sublang_ = 0 /* SUBLANG_NEUTRAL */;
180 std::vector<uint8_t> pixels_;
181};
182
183}
184}
185
186
187#endif
ResourceIcon(const details::pe_resource_icon_group &header)
void pixels(std::vector< uint8_t > pixels)
Definition ResourceIcon.hpp:155
void height(uint8_t height)
Definition ResourceIcon.hpp:135
static result< ResourceIcon > from_bytes(LIEF::span< const uint8_t > bytes)
Definition ResourceIcon.hpp:48
uint32_t lang() const
Language associated with the icon.
Definition ResourceIcon.hpp:70
void id(uint32_t id)
Definition ResourceIcon.hpp:119
static result< ResourceIcon > from_serialization(const uint8_t *buffer, size_t size)
uint32_t sublang() const
Sub language associated with the icon.
Definition ResourceIcon.hpp:75
void width(uint8_t width)
Definition ResourceIcon.hpp:131
static result< ResourceIcon > from_serialization(const std::vector< uint8_t > &bytes)
Definition ResourceIcon.hpp:44
ResourceIcon(const ResourceIcon &)=default
friend std::ostream & operator<<(std::ostream &os, const ResourceIcon &entry)
ResourceIcon & operator=(ResourceIcon &&)=default
void bit_count(uint16_t bit_count)
Definition ResourceIcon.hpp:151
uint8_t height() const
Height in pixels of the image.
Definition ResourceIcon.hpp:85
uint16_t planes() const
Color Planes.
Definition ResourceIcon.hpp:100
void color_count(uint8_t color_count)
Definition ResourceIcon.hpp:139
void planes(uint16_t planes)
Definition ResourceIcon.hpp:147
uint32_t id() const
Id associated with the icon.
Definition ResourceIcon.hpp:65
std::vector< uint8_t > serialize() const
span< const uint8_t > pixels() const
Pixels of the image (as bytes).
Definition ResourceIcon.hpp:115
ResourceIcon(const details::pe_icon_header &header)
ResourceIcon(ResourceIcon &&)=default
void sublang(uint32_t sublang)
Definition ResourceIcon.hpp:127
uint8_t reserved() const
Reserved (must be 0).
Definition ResourceIcon.hpp:95
uint8_t color_count() const
Number of colors in image (0 if >=8bpp).
Definition ResourceIcon.hpp:90
void accept(Visitor &visitor) const override
uint32_t size() const
Size in bytes of the image.
Definition ResourceIcon.hpp:110
~ResourceIcon() override=default
friend class ResourcesManager
Definition ResourceIcon.hpp:38
uint16_t bit_count() const
Bits per pixel.
Definition ResourceIcon.hpp:105
void save(const std::string &filename) const
Save the icon to the given filename.
void lang(uint32_t lang)
Definition ResourceIcon.hpp:123
void reserved(uint8_t reserved)
Definition ResourceIcon.hpp:143
ResourceIcon & operator=(const ResourceIcon &)=default
uint8_t width() const
Width in pixels of the image.
Definition ResourceIcon.hpp:80
The Resource Manager provides an enhanced API to manipulate the resource tree.
Definition ResourcesManager.hpp:38
Definition Visitor.hpp:210
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF namespace.
Definition Abstract/Binary.hpp:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:75
#define LIEF_API
Definition visibility.h:41