LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
ResourceVersion.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_VERSION_H
17#define LIEF_PE_RESOURCE_VERSION_H
18#include <ostream>
19
20#include "LIEF/visibility.h"
21#include "LIEF/Object.hpp"
22#include "LIEF/errors.hpp"
23#include "LIEF/optional.hpp"
24
27
28namespace LIEF {
29class BinaryStream;
30
31namespace PE {
32class ResourceData;
33
39 public:
41 static result<ResourceVersion> parse(const uint8_t* p, size_t sz);
43
47 enum class VERSION_OS : uint32_t {
50 UNKNOWN = 0x00000000,
51
53 DOS = 0x00010000,
54
56 OS216 = 0x00020000,
57
59 OS232 = 0x00030000,
60
62 NT = 0x00040000,
63
65 WINCE = 0x00050000,
66
68 WINDOWS16 = 0x00000001,
69
71 PM16 = 0x00000002,
72
74 PM32 = 0x00000003,
75
77 WINDOWS32 = 0x00000004,
78
80 DOS_WINDOWS16 = DOS | WINDOWS16,
81
83 DOS_WINDOWS32 = DOS | WINDOWS32,
84
87 OS216_PM16 = OS216 | PM16,
88
91 OS232_PM32 = OS232 | PM32,
92
94 NT_WINDOWS32 = NT | WINDOWS32,
95 };
96
97 enum class FILE_TYPE : uint32_t {
99 UNKNOWN = 0x00000000,
100
102 APP = 0x00000001,
103
105 DLL = 0x00000002,
106
109 DRV = 0x00000003,
110
113 FONT = 0x00000004,
114
116 VXD = 0x00000005,
117
119 STATIC_LIB = 0x00000007,
120 };
121
122 static constexpr auto DRV_K = uint64_t(1) << 33;
123 static constexpr auto FONT_K = uint64_t(1) << 34;
124
125 enum class FILE_TYPE_DETAILS : uint64_t {
127 UNKNOWN = 0x00000000,
129 DRV_PRINTER = 0x00000001 | DRV_K,
131 DRV_KEYBOARD = 0x00000002 | DRV_K,
133 DRV_LANGUAGE = 0x00000003 | DRV_K,
135 DRV_DISPLAY = 0x00000004 | DRV_K,
137 DRV_MOUSE = 0x00000005 | DRV_K,
139 DRV_NETWORK = 0x00000006 | DRV_K,
141 DRV_SYSTEM = 0x00000007 | DRV_K,
143 DRV_INSTALLABLE = 0x00000008 | DRV_K,
145 DRV_SOUND = 0x00000009 | DRV_K,
147 DRV_COMM = 0x0000000A | DRV_K,
148
149 DRV_INPUTMETHOD = 0x0000000B | DRV_K,
150
152 DRV_VERSIONED_PRINTER = 0x0000000C,
153
155 FONT_RASTER = 0x00000001 | FONT_K,
156
158 FONT_VECTOR = 0x00000002 | FONT_K,
159
161 FONT_TRUETYPE = 0x00000003 | FONT_K,
162 };
163
164 enum class FILE_FLAGS : uint32_t {
167 DEBUG = 0x00000001,
168
172 INFO_INFERRED = 0x00000010,
173
176 PATCHED = 0x00000004,
177
179 PRERELEASE = 0x00000002,
180
183 PRIVATEBUILD = 0x00000008,
184
189 SPECIALBUILD = 0x00000020,
190 };
191
192 static constexpr auto SIGNATURE_VALUE = 0xFEEF04BD;
196 uint32_t signature = 0;
197
201 uint32_t struct_version = 0;
202
206 uint32_t file_version_ms = 0;
207
211 uint32_t file_version_ls = 0;
212
216 uint32_t product_version_ms = 0;
217
221 uint32_t product_version_ls = 0;
222
225 uint32_t file_flags_mask = 0;
226
229 uint32_t file_flags = 0;
230
233 uint32_t file_os = 0;
234
237 uint32_t file_type = 0;
238
241 uint32_t file_subtype = 0;
242
245 uint32_t file_date_ms = 0;
246
249 uint32_t file_date_ls = 0;
250
252 bool has(FILE_FLAGS f) const {
253 return ((file_flags & file_flags_mask) & (uint32_t)f) != 0;
254 }
255
257 std::vector<FILE_FLAGS> flags() const;
258
260 if (file_subtype == 0) {
262 }
263
264 auto ty = FILE_TYPE(file_type);
265 if (ty == FILE_TYPE::DRV) {
267 }
268
269 if (ty == FILE_TYPE::FONT) {
271 }
272
274 }
275
276 std::string to_string() const;
277
278 LIEF_API friend std::ostream& operator<<(std::ostream& os,
279 const fixed_file_info_t& info) {
280 os << info.to_string();
281 return os;
282 }
283 };
284
287
290
291 ~ResourceVersion() override = default;
292
295 return fixed_file_info_;
296 }
297
299 return fixed_file_info_;
300 }
301
304 if (auto& info = string_file_info_) {
305 return &info.value();
306 }
307 return nullptr;
308 }
309
311 return const_cast<ResourceVersion*>(this)->string_file_info();
312 }
313
316 if (auto& info = var_file_info_) {
317 return &info.value();
318 }
319 return nullptr;
320 }
321
325 uint16_t type() const {
326 return type_;
327 }
328
330 const std::u16string& key() const {
331 return key_;
332 }
333
335 std::string key_u8() const;
336
337 ResourceVersion& type(uint16_t value) {
338 type_ = value;
339 return *this;
340 }
341
342 ResourceVersion& key(std::u16string value) {
343 key_ = std::move(value);
344 return *this;
345 }
347 return const_cast<ResourceVersion*>(this)->var_file_info();
348 }
349
351 var_file_info_ = std::move(info);
352 return *this;
353 }
354
356 string_file_info_ = std::move(info);
357 return *this;
358 }
359
360 void accept(Visitor& visitor) const override;
361
362 LIEF_API friend std::ostream& operator<<(std::ostream& os,
363 const ResourceVersion& version);
364
365 private:
366 ResourceVersion() = default;
367
368 static ok_error_t parse_children(ResourceVersion& version, BinaryStream& stream);
369 static ok_error_t parse_child(ResourceVersion& version, BinaryStream& stream);
370 static ok_error_t parse_fixed_file_info(ResourceVersion& version,
371 BinaryStream& stream);
372 static ok_error_t parse_str_file_info(ResourceVersion& version,
373 BinaryStream& stream);
374 static ok_error_t parse_var_file_info(ResourceVersion& version,
375 BinaryStream& stream);
376
377 uint16_t type_ = 0;
378 std::u16string key_;
379 fixed_file_info_t fixed_file_info_;
380
381 optional<ResourceStringFileInfo> string_file_info_;
382 optional<ResourceVarFileInfo> var_file_info_;
383};
384
388LIEF_API const char*
390
391}
392}
393
394#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
Class which represents a Data Node in the PE resources tree.
Definition ResourceData.hpp:33
Representation of the StringFileInfo structure.
Definition ResourceStringFileInfo.hpp:40
Representation of the VarFileInfo structure.
Definition ResourceVarFileInfo.hpp:39
const fixed_file_info_t & file_info() const
Return the fixed file info (VS_FIXEDFILEINFO).
Definition ResourceVersion.hpp:294
ResourceVersion(ResourceVersion &&)=default
ResourceVersion & operator=(const ResourceVersion &)=default
const ResourceVarFileInfo * var_file_info() const
Definition ResourceVersion.hpp:346
fixed_file_info_t & file_info()
Definition ResourceVersion.hpp:298
const ResourceStringFileInfo * string_file_info() const
Definition ResourceVersion.hpp:310
~ResourceVersion() override=default
ResourceVersion & string_file_info(ResourceStringFileInfo info)
Definition ResourceVersion.hpp:355
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:342
ResourceVarFileInfo * var_file_info()
Return the VarFileInfo element.
Definition ResourceVersion.hpp:315
ResourceStringFileInfo * string_file_info()
Return the StringFileInfo element.
Definition ResourceVersion.hpp:303
ResourceVersion & operator=(ResourceVersion &&)=default
ResourceVersion & var_file_info(ResourceVarFileInfo info)
Definition ResourceVersion.hpp:350
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:325
ResourceVersion & type(uint16_t value)
Definition ResourceVersion.hpp:337
static result< ResourceVersion > parse(BinaryStream &stream)
const std::u16string & key() const
The Unicode string L"VS_VERSION_INFO".
Definition ResourceVersion.hpp:330
static result< ResourceVersion > parse(const uint8_t *p, size_t sz)
void accept(Visitor &visitor) const override
Definition Visitor.hpp:212
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:114
Definition optional.hpp:23
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:77
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
const char * to_string(CODE_PAGES e)
LIEF namespace.
Definition Abstract/Binary.hpp:40
lief_version_t version()
Return the current version.
This structure represents the VS_FIXEDFILEINFO structure defined in verrsrc.h.
Definition ResourceVersion.hpp:46
FILE_FLAGS
Definition ResourceVersion.hpp:164
VERSION_OS
Definition ResourceVersion.hpp:47
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:245
uint32_t file_subtype
The function of the file. The possible values depend on the value of file_type.
Definition ResourceVersion.hpp:241
FILE_TYPE_DETAILS file_type_details() const
Definition ResourceVersion.hpp:259
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:216
uint32_t file_flags
Contains a bitmask that specifies the Boolean attributes of the file. This member can include one or ...
Definition ResourceVersion.hpp:229
uint32_t signature
Contains the value 0xFEEF04BD. This is used with the szKey member of the VS_VERSIONINFO structure whe...
Definition ResourceVersion.hpp:196
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:211
friend std::ostream & operator<<(std::ostream &os, const fixed_file_info_t &info)
Definition ResourceVersion.hpp:278
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:206
static constexpr auto DRV_K
Definition ResourceVersion.hpp:122
FILE_TYPE
Definition ResourceVersion.hpp:97
@ FONT
The file contains a font. If dwFileType is VFT_FONT, dwFileSubtype contains a more specific descripti...
Definition ResourceVersion.hpp:113
@ DRV
The file contains a device driver. If dwFileType is VFT_DRV, dwFileSubtype contains a more specific d...
Definition ResourceVersion.hpp:109
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:221
uint32_t file_type
The general type of file. This member can be one of the values specified in FILE_TYPE....
Definition ResourceVersion.hpp:237
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:201
FILE_TYPE_DETAILS
Definition ResourceVersion.hpp:125
@ UNKNOWN
The type is unknown by the system.
Definition ResourceVersion.hpp:127
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:233
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:249
static constexpr auto FONT_K
Definition ResourceVersion.hpp:123
bool has(FILE_FLAGS f) const
Check if the given FILE_FLAGS is present.
Definition ResourceVersion.hpp:252
static constexpr auto SIGNATURE_VALUE
Definition ResourceVersion.hpp:192
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:225
#define LIEF_API
Definition visibility.h:43