LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
ResourceVersion.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_PE_RESOURCE_VERSION_H
16#define LIEF_PE_RESOURCE_VERSION_H
17#include <cstdint>
18#include <ostream>
19#include <string>
20
21#include "LIEF/Object.hpp"
22#include "LIEF/errors.hpp"
23#include "LIEF/visibility.h"
24#include <optional>
25
28
29namespace LIEF {
30class BinaryStream;
31
32namespace PE {
33class ResourceData;
34
40 public:
42 static result<ResourceVersion> parse(const uint8_t* p, size_t sz);
44
48 enum class VERSION_OS : uint32_t {
51 UNKNOWN = 0x00000000,
52
54 DOS = 0x00010000,
55
57 OS216 = 0x00020000,
58
60 OS232 = 0x00030000,
61
63 NT = 0x00040000,
64
66 WINCE = 0x00050000,
67
69 WINDOWS16 = 0x00000001,
70
72 PM16 = 0x00000002,
73
75 PM32 = 0x00000003,
76
78 WINDOWS32 = 0x00000004,
79
81 DOS_WINDOWS16 = DOS | WINDOWS16,
82
84 DOS_WINDOWS32 = DOS | WINDOWS32,
85
88 OS216_PM16 = OS216 | PM16,
89
92 OS232_PM32 = OS232 | PM32,
93
95 NT_WINDOWS32 = NT | WINDOWS32,
96 };
97
98 enum class FILE_TYPE : uint32_t {
100 UNKNOWN = 0x00000000,
101
103 APP = 0x00000001,
104
106 DLL = 0x00000002,
107
110 DRV = 0x00000003,
111
114 FONT = 0x00000004,
115
117 VXD = 0x00000005,
118
120 STATIC_LIB = 0x00000007,
121 };
122
123 static constexpr auto DRV_K = uint64_t(1) << 33;
124 static constexpr auto FONT_K = uint64_t(1) << 34;
125
126 enum class FILE_TYPE_DETAILS : uint64_t {
128 UNKNOWN = 0x00000000,
130 DRV_PRINTER = 0x00000001 | DRV_K,
132 DRV_KEYBOARD = 0x00000002 | DRV_K,
134 DRV_LANGUAGE = 0x00000003 | DRV_K,
136 DRV_DISPLAY = 0x00000004 | DRV_K,
138 DRV_MOUSE = 0x00000005 | DRV_K,
140 DRV_NETWORK = 0x00000006 | DRV_K,
142 DRV_SYSTEM = 0x00000007 | DRV_K,
144 DRV_INSTALLABLE = 0x00000008 | DRV_K,
146 DRV_SOUND = 0x00000009 | DRV_K,
148 DRV_COMM = 0x0000000A | DRV_K,
149
150 DRV_INPUTMETHOD = 0x0000000B | DRV_K,
151
153 DRV_VERSIONED_PRINTER = 0x0000000C,
154
156 FONT_RASTER = 0x00000001 | FONT_K,
157
159 FONT_VECTOR = 0x00000002 | FONT_K,
160
162 FONT_TRUETYPE = 0x00000003 | FONT_K,
163 };
164
165 enum class FILE_FLAGS : uint32_t {
168 DEBUG = 0x00000001,
169
173 INFO_INFERRED = 0x00000010,
174
177 PATCHED = 0x00000004,
178
180 PRERELEASE = 0x00000002,
181
184 PRIVATEBUILD = 0x00000008,
185
190 SPECIALBUILD = 0x00000020,
191 };
192
193 static constexpr auto SIGNATURE_VALUE = 0xFEEF04BD;
197 uint32_t signature = 0;
198
202 uint32_t struct_version = 0;
203
207 uint32_t file_version_ms = 0;
208
212 uint32_t file_version_ls = 0;
213
217 uint32_t product_version_ms = 0;
218
222 uint32_t product_version_ls = 0;
223
226 uint32_t file_flags_mask = 0;
227
230 uint32_t file_flags = 0;
231
234 uint32_t file_os = 0;
235
238 uint32_t file_type = 0;
239
242 uint32_t file_subtype = 0;
243
246 uint32_t file_date_ms = 0;
247
250 uint32_t file_date_ls = 0;
251
253 bool has(FILE_FLAGS f) const {
254 return ((file_flags & file_flags_mask) & (uint32_t)f) != 0;
255 }
256
258 std::vector<FILE_FLAGS> flags() const;
259
261 if (file_subtype == 0) {
263 }
264
265 auto ty = FILE_TYPE(file_type);
266 if (ty == FILE_TYPE::DRV) {
268 }
269
270 if (ty == FILE_TYPE::FONT) {
272 }
273
275 }
276
277 std::string to_string() const;
278
279 LIEF_API friend std::ostream& operator<<(std::ostream& os,
280 const fixed_file_info_t& info) {
281 os << info.to_string();
282 return os;
283 }
284 };
285
288
291
292 ~ResourceVersion() override = default;
293
296 return fixed_file_info_;
297 }
298
300 return fixed_file_info_;
301 }
302
305 if (auto& info = string_file_info_) {
306 return &info.value();
307 }
308 return nullptr;
309 }
310
312 return const_cast<ResourceVersion*>(this)->string_file_info();
313 }
314
317 if (auto& info = var_file_info_) {
318 return &info.value();
319 }
320 return nullptr;
321 }
322
326 uint16_t type() const {
327 return type_;
328 }
329
331 const std::u16string& key() const {
332 return key_;
333 }
334
336 std::string key_u8() const;
337
338 ResourceVersion& type(uint16_t value) {
339 type_ = value;
340 return *this;
341 }
342
343 ResourceVersion& key(std::u16string value) {
344 key_ = std::move(value);
345 return *this;
346 }
347
349 return const_cast<ResourceVersion*>(this)->var_file_info();
350 }
351
353 var_file_info_ = std::move(info);
354 return *this;
355 }
356
358 string_file_info_ = std::move(info);
359 return *this;
360 }
361
362 void accept(Visitor& visitor) const override;
363
364 LIEF_API friend std::ostream& operator<<(std::ostream& os,
365 const ResourceVersion& version);
366
367 private:
368 ResourceVersion() = default;
369
370 static ok_error_t parse_children(ResourceVersion& version, BinaryStream& stream);
371 static ok_error_t parse_child(ResourceVersion& version, BinaryStream& stream);
372 static ok_error_t parse_fixed_file_info(ResourceVersion& version,
373 BinaryStream& stream);
374 static ok_error_t parse_str_file_info(ResourceVersion& version,
375 BinaryStream& stream);
376 static ok_error_t parse_var_file_info(ResourceVersion& version,
377 BinaryStream& stream);
378
379 uint16_t type_ = 0;
380 std::u16string key_;
381 fixed_file_info_t fixed_file_info_;
382
383 std::optional<ResourceStringFileInfo> string_file_info_;
384 std::optional<ResourceVarFileInfo> var_file_info_;
385};
386
390LIEF_API const char*
392
393}
394}
395
396#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:34
Class which represents a Data Node in the PE resources tree.
Definition ResourceData.hpp:35
Representation of the StringFileInfo structure.
Definition ResourceStringFileInfo.hpp:39
Representation of the VarFileInfo structure.
Definition ResourceVarFileInfo.hpp:38
const fixed_file_info_t & file_info() const
Return the fixed file info (VS_FIXEDFILEINFO).
Definition ResourceVersion.hpp:295
ResourceVersion(ResourceVersion &&)=default
ResourceVersion & operator=(const ResourceVersion &)=default
const ResourceVarFileInfo * var_file_info() const
Definition ResourceVersion.hpp:348
fixed_file_info_t & file_info()
Definition ResourceVersion.hpp:299
const ResourceStringFileInfo * string_file_info() const
Definition ResourceVersion.hpp:311
~ResourceVersion() override=default
ResourceVersion & string_file_info(ResourceStringFileInfo info)
Definition ResourceVersion.hpp:357
std::string key_u8() const
The key as an utf8 string.
ResourceVersion(const ResourceVersion &)=default
static result< ResourceVersion > parse(const ResourceData &node)
ResourceVersion & key(std::u16string value)
Definition ResourceVersion.hpp:343
ResourceVarFileInfo * var_file_info()
Return the VarFileInfo element.
Definition ResourceVersion.hpp:316
ResourceStringFileInfo * string_file_info()
Return the StringFileInfo element.
Definition ResourceVersion.hpp:304
ResourceVersion & operator=(ResourceVersion &&)=default
ResourceVersion & var_file_info(ResourceVarFileInfo info)
Definition ResourceVersion.hpp:352
friend std::ostream & operator<<(std::ostream &os, const ResourceVersion &version)
uint16_t type() const
The type of data in the version resource.
Definition ResourceVersion.hpp:326
ResourceVersion & type(uint16_t value)
Definition ResourceVersion.hpp:338
static result< ResourceVersion > parse(BinaryStream &stream)
const std::u16string & key() const
The Unicode string L"VS_VERSION_INFO".
Definition ResourceVersion.hpp:331
static result< ResourceVersion > parse(const uint8_t *p, size_t sz)
void accept(Visitor &visitor) const override
Definition Visitor.hpp:211
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:118
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:78
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:31
const char * to_string(CODE_PAGES e)
LIEF namespace.
Definition Abstract/Binary.hpp:41
lief_version_t version()
Return the current version.
This structure represents the VS_FIXEDFILEINFO structure defined in verrsrc.h.
Definition ResourceVersion.hpp:47
FILE_FLAGS
Definition ResourceVersion.hpp:165
VERSION_OS
Definition ResourceVersion.hpp:48
uint32_t file_date_ms
The most significant 32 bits of the file's 64-bit binary creation date and time stamp.
Definition ResourceVersion.hpp:246
uint32_t file_subtype
The function of the file. The possible values depend on the value of file_type.
Definition ResourceVersion.hpp:242
FILE_TYPE_DETAILS file_type_details() const
Definition ResourceVersion.hpp:260
uint32_t product_version_ms
The most significant 32 bits of the binary version number of the product with which this file was dis...
Definition ResourceVersion.hpp:217
uint32_t file_flags
Contains a bitmask that specifies the Boolean attributes of the file. This member can include one or ...
Definition ResourceVersion.hpp:230
uint32_t signature
Contains the value 0xFEEF04BD. This is used with the szKey member of the VS_VERSIONINFO structure whe...
Definition ResourceVersion.hpp:197
uint32_t file_version_ls
The least significant 32 bits of the file's binary version number. This member is used with file_vers...
Definition ResourceVersion.hpp:212
friend std::ostream & operator<<(std::ostream &os, const fixed_file_info_t &info)
Definition ResourceVersion.hpp:279
uint32_t file_version_ms
The most significant 32 bits of the file's binary version number. This member is used with file_versi...
Definition ResourceVersion.hpp:207
static constexpr auto DRV_K
Definition ResourceVersion.hpp:123
FILE_TYPE
Definition ResourceVersion.hpp:98
@ FONT
The file contains a font. If dwFileType is VFT_FONT, dwFileSubtype contains a more specific descripti...
Definition ResourceVersion.hpp:114
@ DRV
The file contains a device driver. If dwFileType is VFT_DRV, dwFileSubtype contains a more specific d...
Definition ResourceVersion.hpp:110
std::vector< FILE_FLAGS > flags() const
List of FILE_FLAGS.
uint32_t product_version_ls
The least significant 32 bits of the binary version number of the product with which this file was di...
Definition ResourceVersion.hpp:222
uint32_t file_type
The general type of file. This member can be one of the values specified in FILE_TYPE....
Definition ResourceVersion.hpp:238
uint32_t struct_version
The binary version number of this structure. The high-order word of this member contains the major ve...
Definition ResourceVersion.hpp:202
FILE_TYPE_DETAILS
Definition ResourceVersion.hpp:126
@ UNKNOWN
The type is unknown by the system.
Definition ResourceVersion.hpp:128
uint32_t file_os
The operating system for which this file was designed. This member can be one of the values specified...
Definition ResourceVersion.hpp:234
uint32_t file_date_ls
The least significant 32 bits of the file's 64-bit binary creation date and time stamp.
Definition ResourceVersion.hpp:250
static constexpr auto FONT_K
Definition ResourceVersion.hpp:124
bool has(FILE_FLAGS f) const
Check if the given FILE_FLAGS is present.
Definition ResourceVersion.hpp:253
static constexpr auto SIGNATURE_VALUE
Definition ResourceVersion.hpp:193
uint32_t file_flags_mask
Contains a bitmask that specifies the valid bits in file_flags. A bit is valid only if it was defined...
Definition ResourceVersion.hpp:226
#define LIEF_API
Definition visibility.h:44