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