LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ResourceVersion.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_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
38 public:
40 static result<ResourceVersion> parse(const uint8_t* p, size_t sz);
42
46 enum class VERSION_OS : uint32_t {
48 UNKNOWN = 0x00000000,
49
51 DOS = 0x00010000,
52
54 OS216 = 0x00020000,
55
57 OS232 = 0x00030000,
58
60 NT = 0x00040000,
61
63 WINCE = 0x00050000,
64
66 WINDOWS16 = 0x00000001,
67
69 PM16 = 0x00000002,
70
72 PM32 = 0x00000003,
73
75 WINDOWS32 = 0x00000004,
76
79
82
86
90
93 };
94
95 enum class FILE_TYPE : uint32_t {
97 UNKNOWN = 0x00000000,
98
100 APP = 0x00000001,
101
103 DLL = 0x00000002,
104
107 DRV = 0x00000003,
108
111 FONT = 0x00000004,
112
114 VXD = 0x00000005,
115
117 STATIC_LIB = 0x00000007,
118 };
119
120 static constexpr auto DRV_K = uint64_t(1) << 33;
121 static constexpr auto FONT_K = uint64_t(1) << 34;
122
123 enum class FILE_TYPE_DETAILS : uint64_t {
125 UNKNOWN = 0x00000000,
127 DRV_PRINTER = 0x00000001 | DRV_K,
129 DRV_KEYBOARD = 0x00000002 | DRV_K,
131 DRV_LANGUAGE = 0x00000003 | DRV_K,
133 DRV_DISPLAY = 0x00000004 | DRV_K,
135 DRV_MOUSE = 0x00000005 | DRV_K,
137 DRV_NETWORK = 0x00000006 | DRV_K,
139 DRV_SYSTEM = 0x00000007 | DRV_K,
141 DRV_INSTALLABLE = 0x00000008 | DRV_K,
143 DRV_SOUND = 0x00000009 | DRV_K,
145 DRV_COMM = 0x0000000A | DRV_K,
146
147 DRV_INPUTMETHOD = 0x0000000B | DRV_K,
148
151
153 FONT_RASTER = 0x00000001 | FONT_K,
154
156 FONT_VECTOR = 0x00000002 | FONT_K,
157
159 FONT_TRUETYPE = 0x00000003 | FONT_K,
160 };
161
162 enum class FILE_FLAGS : uint32_t {
165 DEBUG = 0x00000001,
166
170 INFO_INFERRED = 0x00000010,
171
174 PATCHED = 0x00000004,
175
177 PRERELEASE = 0x00000002,
178
181 PRIVATEBUILD = 0x00000008,
182
187 SPECIALBUILD = 0x00000020,
188 };
189
190 static constexpr auto SIGNATURE_VALUE = 0xFEEF04BD;
194 uint32_t signature = 0;
195
199 uint32_t struct_version = 0;
200
204 uint32_t file_version_ms = 0;
205
209 uint32_t file_version_ls = 0;
210
214 uint32_t product_version_ms = 0;
215
219 uint32_t product_version_ls = 0;
220
223 uint32_t file_flags_mask = 0;
224
227 uint32_t file_flags = 0;
228
231 uint32_t file_os = 0;
232
235 uint32_t file_type = 0;
236
239 uint32_t file_subtype = 0;
240
243 uint32_t file_date_ms = 0;
244
247 uint32_t file_date_ls = 0;
248
250 bool has(FILE_FLAGS f) const {
251 return ((file_flags & file_flags_mask) & (uint32_t)f) != 0;
252 }
253
255 std::vector<FILE_FLAGS> flags() const;
256
258 if (file_subtype == 0) {
260 }
261
262 auto ty = FILE_TYPE(file_type);
263 if (ty == FILE_TYPE::DRV) {
265 }
266
267 if (ty == FILE_TYPE::FONT) {
269 }
270
272 }
273
274 std::string to_string() const;
275
276 LIEF_API friend
277 std::ostream& operator<<(std::ostream& os, const fixed_file_info_t& info)
278 {
279 os << info.to_string();
280 return os;
281 }
282 };
283
286
289
290 ~ResourceVersion() override = default;
291
294 return fixed_file_info_;
295 }
296
298 return fixed_file_info_;
299 }
300
303 if (auto& info = string_file_info_) {
304 return &info.value();
305 }
306 return nullptr;
307 }
308
310 return const_cast<ResourceVersion*>(this)->string_file_info();
311 }
312
315 if (auto& info = var_file_info_) {
316 return &info.value();
317 }
318 return nullptr;
319 }
320
324 uint16_t type() const {
325 return type_;
326 }
327
329 const std::u16string& key() const {
330 return key_;
331 }
332
334 std::string key_u8() const;
335
336 ResourceVersion& type(uint16_t value) {
337 type_ = value;
338 return *this;
339 }
340
341 ResourceVersion& key(std::u16string value) {
342 key_ = std::move(value);
343 return *this;
344 }
346 return const_cast<ResourceVersion*>(this)->var_file_info();
347 }
348
350 var_file_info_ = std::move(info);
351 return *this;
352 }
353
355 string_file_info_ = std::move(info);
356 return *this;
357 }
358
359 void accept(Visitor& visitor) const override;
360
361 LIEF_API friend
362 std::ostream& operator<<(std::ostream& os, const ResourceVersion& version);
363
364 private:
365 ResourceVersion() = default;
366
367 static ok_error_t parse_children(ResourceVersion& version, BinaryStream& stream);
368 static ok_error_t parse_child(ResourceVersion& version, BinaryStream& stream);
369 static ok_error_t parse_fixed_file_info(ResourceVersion& version, BinaryStream& stream);
370 static ok_error_t parse_str_file_info(ResourceVersion& version, BinaryStream& stream);
371 static ok_error_t parse_var_file_info(ResourceVersion& version, BinaryStream& stream);
372
373 uint16_t type_ = 0;
374 std::u16string key_;
375 fixed_file_info_t fixed_file_info_;
376
377 optional<ResourceStringFileInfo> string_file_info_;
378 optional<ResourceVarFileInfo> var_file_info_;
379};
380
385
386}
387}
388
389#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:293
ResourceVersion(ResourceVersion &&)=default
ResourceVersion & operator=(const ResourceVersion &)=default
const ResourceVarFileInfo * var_file_info() const
Definition ResourceVersion.hpp:345
fixed_file_info_t & file_info()
Definition ResourceVersion.hpp:297
const ResourceStringFileInfo * string_file_info() const
Definition ResourceVersion.hpp:309
~ResourceVersion() override=default
ResourceVersion & string_file_info(ResourceStringFileInfo info)
Definition ResourceVersion.hpp:354
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:341
ResourceVarFileInfo * var_file_info()
Return the VarFileInfo element.
Definition ResourceVersion.hpp:314
ResourceStringFileInfo * string_file_info()
Return the StringFileInfo element.
Definition ResourceVersion.hpp:302
ResourceVersion & operator=(ResourceVersion &&)=default
ResourceVersion & var_file_info(ResourceVarFileInfo info)
Definition ResourceVersion.hpp:349
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:324
ResourceVersion & type(uint16_t value)
Definition ResourceVersion.hpp:336
static result< ResourceVersion > parse(BinaryStream &stream)
const std::u16string & key() const
The Unicode string L"VS_VERSION_INFO".
Definition ResourceVersion.hpp:329
static result< ResourceVersion > parse(const uint8_t *p, size_t sz)
void accept(Visitor &visitor) const override
Definition Visitor.hpp:210
Definition optional.hpp:23
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
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:109
lief_version_t version()
Return the current version.
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:75
This structure represents the VS_FIXEDFILEINFO structure defined in verrsrc.h.
Definition ResourceVersion.hpp:45
FILE_FLAGS
Definition ResourceVersion.hpp:162
@ PRERELEASE
The file is a development version, not a commercially released product.
Definition ResourceVersion.hpp:177
@ PATCHED
The file has been modified and is not identical to the original shipping file of the same version num...
Definition ResourceVersion.hpp:174
@ INFO_INFERRED
The file's version structure was created dynamically; therefore, some of the members in this structur...
Definition ResourceVersion.hpp:170
@ PRIVATEBUILD
The file was not built using standard release procedures. If this flag is set, the StringFileInfo str...
Definition ResourceVersion.hpp:181
@ SPECIALBUILD
The file was built by the original company using standard release procedures but is a variation of th...
Definition ResourceVersion.hpp:187
@ DEBUG
The file contains debugging information or is compiled with debugging features enabled.
Definition ResourceVersion.hpp:165
VERSION_OS
Definition ResourceVersion.hpp:46
@ NT_WINDOWS32
The file was designed for Windows NT.
Definition ResourceVersion.hpp:92
@ PM32
The file was designed for 32-bit Presentation Manager.
Definition ResourceVersion.hpp:72
@ DOS_WINDOWS32
The file was designed for 32-bit Windows running on MS-DOS.
Definition ResourceVersion.hpp:81
@ OS216_PM16
The file was designed for 16-bit Presentation Manager running on 16-bit OS/2.
Definition ResourceVersion.hpp:85
@ UNKNOWN
The operating system for which the file was designed is unknown to the system.
Definition ResourceVersion.hpp:48
@ OS232_PM32
The file was designed for 32-bit Presentation Manager running on 32-bit OS/2.
Definition ResourceVersion.hpp:89
@ OS232
The file was designed for 32-bit OS/2.
Definition ResourceVersion.hpp:57
@ DOS_WINDOWS16
The file was designed for 16-bit Windows running on MS-DOS.
Definition ResourceVersion.hpp:78
@ DOS
The file was designed for MS-DOS.
Definition ResourceVersion.hpp:51
@ WINCE
The file was designed for Windows CE (Windows Embedded Compact).
Definition ResourceVersion.hpp:63
@ OS216
The file was designed for 16-bit OS/2.
Definition ResourceVersion.hpp:54
@ NT
The file was designed for Windows NT.
Definition ResourceVersion.hpp:60
@ WINDOWS16
The file was designed for 16-bit Windows.
Definition ResourceVersion.hpp:66
@ WINDOWS32
The file was designed for 32-bit Windows.
Definition ResourceVersion.hpp:75
@ PM16
The file was designed for 16-bit Presentation Manager.
Definition ResourceVersion.hpp:69
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:243
uint32_t file_subtype
The function of the file. The possible values depend on the value of file_type.
Definition ResourceVersion.hpp:239
FILE_TYPE_DETAILS file_type_details() const
Definition ResourceVersion.hpp:257
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:214
uint32_t file_flags
Contains a bitmask that specifies the Boolean attributes of the file. This member can include one or ...
Definition ResourceVersion.hpp:227
uint32_t signature
Contains the value 0xFEEF04BD. This is used with the szKey member of the VS_VERSIONINFO structure whe...
Definition ResourceVersion.hpp:194
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:209
friend std::ostream & operator<<(std::ostream &os, const fixed_file_info_t &info)
Definition ResourceVersion.hpp:277
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:204
static constexpr auto DRV_K
Definition ResourceVersion.hpp:120
FILE_TYPE
Definition ResourceVersion.hpp:95
@ APP
The file contains an application.
Definition ResourceVersion.hpp:100
@ FONT
The file contains a font. If dwFileType is VFT_FONT, dwFileSubtype contains a more specific descripti...
Definition ResourceVersion.hpp:111
@ DLL
The file contains a DLL.
Definition ResourceVersion.hpp:103
@ STATIC_LIB
The file contains a static-link library.
Definition ResourceVersion.hpp:117
@ DRV
The file contains a device driver. If dwFileType is VFT_DRV, dwFileSubtype contains a more specific d...
Definition ResourceVersion.hpp:107
@ VXD
The file contains a virtual device.
Definition ResourceVersion.hpp:114
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:219
uint32_t file_type
The general type of file. This member can be one of the values specified in FILE_TYPE....
Definition ResourceVersion.hpp:235
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:199
FILE_TYPE_DETAILS
Definition ResourceVersion.hpp:123
@ DRV_INSTALLABLE
The file contains an installable driver.
Definition ResourceVersion.hpp:141
@ DRV_LANGUAGE
The file contains a language driver.
Definition ResourceVersion.hpp:131
@ DRV_DISPLAY
The file contains a display driver.
Definition ResourceVersion.hpp:133
@ DRV_SOUND
The file contains a sound driver.
Definition ResourceVersion.hpp:143
@ UNKNOWN
The type is unknown by the system.
Definition ResourceVersion.hpp:125
@ DRV_MOUSE
The file contains a mouse driver.
Definition ResourceVersion.hpp:135
@ DRV_KEYBOARD
The file contains a keyboard driver.
Definition ResourceVersion.hpp:129
@ DRV_PRINTER
The file contains a printer driver.
Definition ResourceVersion.hpp:127
@ FONT_TRUETYPE
The file contains a TrueType font.
Definition ResourceVersion.hpp:159
@ FONT_VECTOR
The file contains a vector font.
Definition ResourceVersion.hpp:156
@ DRV_VERSIONED_PRINTER
The file contains a versioned printer driver.
Definition ResourceVersion.hpp:150
@ FONT_RASTER
The file contains a raster font.
Definition ResourceVersion.hpp:153
@ DRV_NETWORK
The file contains a network driver.
Definition ResourceVersion.hpp:137
@ DRV_SYSTEM
The file contains a system driver.
Definition ResourceVersion.hpp:139
@ DRV_COMM
The file contains a communications driver.
Definition ResourceVersion.hpp:145
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:231
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:247
static constexpr auto FONT_K
Definition ResourceVersion.hpp:121
bool has(FILE_FLAGS f) const
Check if the given FILE_FLAGS is present.
Definition ResourceVersion.hpp:250
static constexpr auto SIGNATURE_VALUE
Definition ResourceVersion.hpp:190
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:223
#define LIEF_API
Definition visibility.h:41