1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/*************************************************************************/
/* Copyright (c) 2015 dx, http://kaimi.ru */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following conditions: */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#pragma once
#include <string>
#include <map>
#include "stdint_defs.h"
#include "pe_structures.h"
namespace pe_bliss
{
//Structure representing fixed file version info
class file_version_info
{
public:
//Enumeration of file operating system types
enum file_os_type
{
file_os_unknown,
file_os_dos,
file_os_os216,
file_os_os232,
file_os_nt,
file_os_wince,
file_os_win16,
file_os_pm16,
file_os_pm32,
file_os_win32,
file_os_dos_win16,
file_os_dos_win32,
file_os_os216_pm16,
file_os_os232_pm32,
file_os_nt_win32
};
//Enumeration of file types
enum file_type
{
file_type_unknown,
file_type_application,
file_type_dll,
file_type_driver,
file_type_font,
file_type_vxd,
file_type_static_lib
};
public:
//Default constructor
file_version_info();
//Constructor from Windows fixed version info structure
explicit file_version_info(const pe_win::vs_fixedfileinfo& info);
public: //Getters
//Returns true if file is debug-built
bool is_debug() const;
//Returns true if file is prerelease
bool is_prerelease() const;
//Returns true if file is patched
bool is_patched() const;
//Returns true if private build
bool is_private_build() const;
//Returns true if special build
bool is_special_build() const;
//Returns true if info inferred
bool is_info_inferred() const;
//Retuens file flags (raw DWORD)
uint32_t get_file_flags() const;
//Returns file version most significant DWORD
uint32_t get_file_version_ms() const;
//Returns file version least significant DWORD
uint32_t get_file_version_ls() const;
//Returns product version most significant DWORD
uint32_t get_product_version_ms() const;
//Returns product version least significant DWORD
uint32_t get_product_version_ls() const;
//Returns file OS type (raw DWORD)
uint32_t get_file_os_raw() const;
//Returns file OS type
file_os_type get_file_os() const;
//Returns file type (raw DWORD)
uint32_t get_file_type_raw() const;
//Returns file type
file_type get_file_type() const;
//Returns file subtype (usually non-zero for drivers and fonts)
uint32_t get_file_subtype() const;
//Returns file date most significant DWORD
uint32_t get_file_date_ms() const;
//Returns file date least significant DWORD
uint32_t get_file_date_ls() const;
//Returns file version string
template<typename T>
const std::basic_string<T> get_file_version_string() const
{
return get_version_string<T>(file_version_ms_, file_version_ls_);
}
//Returns product version string
template<typename T>
const std::basic_string<T> get_product_version_string() const
{
return get_version_string<T>(product_version_ms_, product_version_ls_);
}
public: //Setters
//Sets if file is debug-built
void set_debug(bool debug);
//Sets if file is prerelease
void set_prerelease(bool prerelease);
//Sets if file is patched
void set_patched(bool patched);
//Sets if private build
void set_private_build(bool private_build);
//Sets if special build
void set_special_build(bool special_build);
//Sets if info inferred
void set_info_inferred(bool info_inferred);
//Sets flags (raw DWORD)
void set_file_flags(uint32_t file_flags);
//Sets file version most significant DWORD
void set_file_version_ms(uint32_t file_version_ms);
//Sets file version least significant DWORD
void set_file_version_ls(uint32_t file_version_ls);
//Sets product version most significant DWORD
void set_product_version_ms(uint32_t product_version_ms);
//Sets product version least significant DWORD
void set_product_version_ls(uint32_t product_version_ls);
//Sets file OS type (raw DWORD)
void set_file_os_raw(uint32_t file_os);
//Sets file OS type
void set_file_os(file_os_type file_os);
//Sets file type (raw DWORD)
void set_file_type_raw(uint32_t file_type);
//Sets file type
void set_file_type(file_type file_type);
//Sets file subtype (usually non-zero for drivers and fonts)
void set_file_subtype(uint32_t file_subtype);
//Sets file date most significant DWORD
void set_file_date_ms(uint32_t file_date_ms);
//Sets file date least significant DWORD
void set_file_date_ls(uint32_t file_date_ls);
private:
//Helper to convert version DWORDs to string
template<typename T>
static const std::basic_string<T> get_version_string(uint32_t ms, uint32_t ls)
{
std::basic_stringstream<T> ss;
ss << (ms >> 16) << static_cast<T>(L'.')
<< (ms & 0xFFFF) << static_cast<T>(L'.')
<< (ls >> 16) << static_cast<T>(L'.')
<< (ls & 0xFFFF);
return ss.str();
}
//Helper to set file flag
void set_file_flag(uint32_t flag);
//Helper to clear file flag
void clear_file_flag(uint32_t flag);
//Helper to set or clear file flag
void set_file_flag(uint32_t flag, bool set_flag);
uint32_t file_version_ms_, file_version_ls_,
product_version_ms_, product_version_ls_;
uint32_t file_flags_;
uint32_t file_os_;
uint32_t file_type_, file_subtype_;
uint32_t file_date_ms_, file_date_ls_;
};
}
|