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
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:
41 static result<ResourceIcon> from_serialization(const uint8_t* buffer,
42 size_t size);
43
45 from_serialization(const std::vector<uint8_t>& bytes) {
46 return from_serialization(bytes.data(), bytes.size());
47 }
48
50 return from_serialization(bytes.data(), bytes.size_bytes());
51 }
52
53 ResourceIcon() = default;
54 ResourceIcon(const details::pe_resource_icon_group& header);
55 ResourceIcon(const details::pe_icon_header& header);
56
57 ResourceIcon(const ResourceIcon&) = default;
59
62
63 ~ResourceIcon() override = default;
64
66 uint32_t id() const {
67 return id_;
68 }
69
71 uint32_t lang() const {
72 return lang_;
73 }
74
76 uint32_t sublang() const {
77 return sublang_;
78 }
79
81 uint8_t width() const {
82 return width_;
83 }
84
86 uint8_t height() const {
87 return height_;
88 }
89
91 uint8_t color_count() const {
92 return color_count_;
93 }
94
96 uint8_t reserved() const {
97 return reserved_;
98 }
99
101 uint16_t planes() const {
102 return planes_;
103 }
104
106 uint16_t bit_count() const {
107 return bit_count_;
108 }
109
111 uint32_t size() const {
112 return pixels_.size();
113 }
114
117 return pixels_;
118 }
119
120 void id(uint32_t id) {
121 id_ = id;
122 }
123
124 void lang(uint32_t lang) {
125 lang_ = lang;
126 }
127
128 void sublang(uint32_t sublang) {
129 sublang_ = sublang;
130 }
131
132 void width(uint8_t width) {
133 width_ = width;
134 }
135
136 void height(uint8_t height) {
137 height_ = height;
138 }
139
140 void color_count(uint8_t color_count) {
141 color_count_ = color_count;
142 }
143
144 void reserved(uint8_t reserved) {
145 reserved_ = reserved;
146 }
147
148 void planes(uint16_t planes) {
149 planes_ = planes;
150 }
151
152 void bit_count(uint16_t bit_count) {
153 bit_count_ = bit_count;
154 }
155
156 void pixels(std::vector<uint8_t> pixels) {
157 pixels_ = std::move(pixels);
158 }
159
163 void save(const std::string& filename) const;
164
165 std::vector<uint8_t> serialize() const;
166
167 void accept(Visitor& visitor) const override;
168
169 LIEF_API friend std::ostream& operator<<(std::ostream& os,
170 const ResourceIcon& entry);
171
172 private:
173 uint8_t width_ = 0;
174 uint8_t height_ = 0;
175 uint8_t color_count_ = 0;
176 uint8_t reserved_ = 0;
177 uint16_t planes_ = 0;
178 uint16_t bit_count_ = 0;
179 uint32_t id_ = uint32_t(-1);
180 uint32_t lang_ = /* LANG_NEUTRAL */ 0;
181 uint32_t sublang_ = 0 /* SUBLANG_NEUTRAL */;
182 std::vector<uint8_t> pixels_;
183};
184
185}
186}
187
188
189#endif
ResourceIcon(const details::pe_resource_icon_group &header)
void pixels(std::vector< uint8_t > pixels)
Definition ResourceIcon.hpp:156
void height(uint8_t height)
Definition ResourceIcon.hpp:136
static result< ResourceIcon > from_bytes(LIEF::span< const uint8_t > bytes)
Definition ResourceIcon.hpp:49
uint32_t lang() const
Language associated with the icon.
Definition ResourceIcon.hpp:71
void id(uint32_t id)
Definition ResourceIcon.hpp:120
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:76
void width(uint8_t width)
Definition ResourceIcon.hpp:132
static result< ResourceIcon > from_serialization(const std::vector< uint8_t > &bytes)
Definition ResourceIcon.hpp:45
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:152
uint8_t height() const
Height in pixels of the image.
Definition ResourceIcon.hpp:86
uint16_t planes() const
Color Planes.
Definition ResourceIcon.hpp:101
void color_count(uint8_t color_count)
Definition ResourceIcon.hpp:140
void planes(uint16_t planes)
Definition ResourceIcon.hpp:148
uint32_t id() const
Id associated with the icon.
Definition ResourceIcon.hpp:66
std::vector< uint8_t > serialize() const
span< const uint8_t > pixels() const
Pixels of the image (as bytes).
Definition ResourceIcon.hpp:116
ResourceIcon(const details::pe_icon_header &header)
ResourceIcon(ResourceIcon &&)=default
void sublang(uint32_t sublang)
Definition ResourceIcon.hpp:128
uint8_t reserved() const
Reserved (must be 0).
Definition ResourceIcon.hpp:96
uint8_t color_count() const
Number of colors in image (0 if >=8bpp).
Definition ResourceIcon.hpp:91
void accept(Visitor &visitor) const override
uint32_t size() const
Size in bytes of the image.
Definition ResourceIcon.hpp:111
~ResourceIcon() override=default
friend class ResourcesManager
Definition ResourceIcon.hpp:38
uint16_t bit_count() const
Bits per pixel.
Definition ResourceIcon.hpp:106
void save(const std::string &filename) const
Save the icon to the given filename.
void lang(uint32_t lang)
Definition ResourceIcon.hpp:124
void reserved(uint8_t reserved)
Definition ResourceIcon.hpp:144
ResourceIcon & operator=(const ResourceIcon &)=default
uint8_t width() const
Width in pixels of the image.
Definition ResourceIcon.hpp:81
The Resource Manager provides an enhanced API to manipulate the resource tree.
Definition ResourcesManager.hpp:38
Definition Visitor.hpp:212
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:77
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
#define LIEF_API
Definition visibility.h:43