LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ResourceDialogExtended.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_DIALOG_EXTENDED_H
17#define LIEF_PE_RESOURCE_DIALOG_EXTENDED_H
18
19#include "LIEF/visibility.h"
21#include "LIEF/errors.hpp"
22#include "LIEF/iterators.hpp"
23
24namespace LIEF {
25class BinaryStream;
26
27namespace PE {
33 public:
34 class LIEF_API Item : public ResourceDialog::Item {
39 public:
40 Item() = default;
41 Item(const Item&) = default;
42 Item& operator=(const Item&) = default;
43
44 Item(Item&&) = default;
45 Item& operator=(Item&&) = default;
46
47 static result<Item> parse(BinaryStream& stream);
48
49 std::string to_string() const override;
50 uint32_t help_id() const {
55 return help_id_;
56 }
57
58 Item& help_id(uint32_t value) {
59 help_id_ = value;
60 return *this;
61 }
62
63 ~Item() override = default;
64
65 protected:
66 uint32_t help_id_ = 0;
67 };
68 struct font_t { uint16_t point_size = 0;
74 uint16_t weight = 0;
77 bool italic = false;
80 uint8_t charset = false;
83 std::u16string typeface;
86
87 bool is_defined() const {
88 return point_size != 0 || weight != 0;
89 }
90
91 operator bool() const {
92 return is_defined();
93 }
94
95 std::string to_string() const;
96
97 LIEF_API friend std::ostream& operator<<(std::ostream& os, const font_t& font) {
98 os << font.to_string();
99 return os;
100 }
101 };
102
103 using items_t = std::vector<Item>;
104 using it_items = ref_iterator<items_t&>;
105 using it_const_items = const_ref_iterator<const items_t&>;
106
107 ResourceDialogExtended() :
108 ResourceDialog(ResourceDialog::TYPE::EXTENDED)
109 {}
110
111 ResourceDialogExtended(const ResourceDialogExtended&) = default;
112 ResourceDialogExtended& operator=(const ResourceDialogExtended&) = default;
113
114 ResourceDialogExtended(ResourceDialogExtended&&) = default;
115 ResourceDialogExtended& operator=(ResourceDialogExtended&&) = default;
116
117 static std::unique_ptr<ResourceDialogExtended> create(BinaryStream& stream);
118
119 std::unique_ptr<ResourceDialog> clone() const override {
120 return std::unique_ptr<ResourceDialogExtended>(new ResourceDialogExtended(*this));
121 }
122
123 static bool classof(const ResourceDialog* dialog) {
124 return dialog->type() == ResourceDialog::TYPE::EXTENDED;
125 }
126
127 void accept(Visitor& visitor) const override;
128
129 std::string to_string() const override;
130
131 ~ResourceDialogExtended() override = default;
132 uint16_t version() const {
136 return version_;
137 }
138 uint16_t signature() const {
143 return signature_;
144 }
145 uint32_t help_id() const {
150 return help_id_;
151 }
152 it_items items() {
155 return items_;
156 }
157
158 it_const_items items() const {
159 return items_;
160 }
161 void add_item(const Item& item) {
164 items_.push_back(item);
165 }
166
167 ResourceDialogExtended& version(uint16_t value) {
168 version_ = value;
169 return *this;
170 }
171
172 ResourceDialogExtended& signature(uint16_t value) {
173 signature_ = value;
174 return *this;
175 }
176
177 ResourceDialogExtended& help_id(uint32_t value) {
178 help_id_ = value;
179 return *this;
180 }
181 const font_t& font() const {
184 return font_;
185 }
186
187 ResourceDialogExtended& font(uint16_t point_size, uint16_t weight, bool italic,
188 uint8_t charset, std::u16string typeface)
189 {
190 font_.point_size = point_size;
191 font_.weight = weight;
192 font_.italic = italic;
193 font_.charset = charset;
194 font_.typeface = std::move(typeface);
195 return *this;
196 }
197
198 ResourceDialogExtended& font(font_t f) {
199 font_ = std::move(f);
200 return *this;
201 }
202
203 protected:
204 uint16_t version_ = 0;
205 uint16_t signature_ = 0;
206 uint32_t help_id_ = 0;
207 font_t font_;
208 items_t items_;
209};
210
211}
212}
213
214
215#endif
ResourceDialog.hpp
LIEF::BinaryStream
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
LIEF::PE::ResourceDialogExtended::Item::operator=
Item & operator=(const Item &)=default
LIEF::PE::ResourceDialogExtended::Item::parse
static result< Item > parse(BinaryStream &stream)
LIEF::PE::ResourceDialogExtended::Item::Item
Item(const Item &)=default
LIEF::PE::ResourceDialogExtended::Item::to_string
std::string to_string() const override
LIEF::PE::ResourceDialogExtended::Item::Item
Item()=default
LIEF::PE::ResourceDialogExtended::Item::Item
Item(Item &&)=default
LIEF::PE::ResourceDialogExtended::Item::~Item
~Item() override=default
LIEF::PE::ResourceDialogExtended::Item::help_id
uint32_t help_id() const
The help context identifier for the control. When the system sends a WM_HELP message,...
Definition ResourceDialogExtended.hpp:54
LIEF::PE::ResourceDialogExtended::Item::operator=
Item & operator=(Item &&)=default
LIEF::PE::ResourceDialogExtended::Item::help_id
Item & help_id(uint32_t value)
Definition ResourceDialogExtended.hpp:58
LIEF::PE::ResourceDialogExtended
Implementation for the new extended dialogbox format.
Definition ResourceDialogExtended.hpp:32
LIEF::PE::ResourceDialogExtended::ResourceDialogExtended
ResourceDialogExtended(ResourceDialogExtended &&)=default
LIEF::PE::ResourceDialogExtended::version
uint16_t version() const
The version number of the extended dialog box template. This member must be set to 1.
Definition ResourceDialogExtended.hpp:135
LIEF::PE::ResourceDialogExtended::add_item
void add_item(const Item &item)
Add a new control item to the dialog.
Definition ResourceDialogExtended.hpp:163
LIEF::PE::ResourceDialogExtended::font
ResourceDialogExtended & font(font_t f)
Definition ResourceDialogExtended.hpp:198
LIEF::PE::ResourceDialogExtended::signature
uint16_t signature() const
Indicates whether a template is an extended dialog box template. If signature is 0xFFFF,...
Definition ResourceDialogExtended.hpp:142
LIEF::PE::ResourceDialogExtended::help_id
ResourceDialogExtended & help_id(uint32_t value)
Definition ResourceDialogExtended.hpp:177
LIEF::PE::ResourceDialogExtended::create
static std::unique_ptr< ResourceDialogExtended > create(BinaryStream &stream)
LIEF::PE::ResourceDialogExtended::signature
ResourceDialogExtended & signature(uint16_t value)
Definition ResourceDialogExtended.hpp:172
LIEF::PE::ResourceDialogExtended::~ResourceDialogExtended
~ResourceDialogExtended() override=default
LIEF::PE::ResourceDialogExtended::font
ResourceDialogExtended & font(uint16_t point_size, uint16_t weight, bool italic, uint8_t charset, std::u16string typeface)
Definition ResourceDialogExtended.hpp:187
LIEF::PE::ResourceDialogExtended::font
const font_t & font() const
Additional font information.
Definition ResourceDialogExtended.hpp:183
LIEF::PE::ResourceDialogExtended::version
ResourceDialogExtended & version(uint16_t value)
Definition ResourceDialogExtended.hpp:167
LIEF::PE::ResourceDialogExtended::clone
std::unique_ptr< ResourceDialog > clone() const override
Definition ResourceDialogExtended.hpp:119
LIEF::PE::ResourceDialogExtended::accept
void accept(Visitor &visitor) const override
LIEF::PE::ResourceDialogExtended::ResourceDialogExtended
ResourceDialogExtended(const ResourceDialogExtended &)=default
LIEF::PE::ResourceDialogExtended::classof
static bool classof(const ResourceDialog *dialog)
Definition ResourceDialogExtended.hpp:123
LIEF::PE::ResourceDialogExtended::operator=
ResourceDialogExtended & operator=(const ResourceDialogExtended &)=default
LIEF::PE::ResourceDialogExtended::items
it_const_items items() const
Definition ResourceDialogExtended.hpp:158
LIEF::PE::ResourceDialogExtended::to_string
std::string to_string() const override
LIEF::PE::ResourceDialogExtended::items
it_items items()
Iterator over the control items of this dialog box.
Definition ResourceDialogExtended.hpp:154
LIEF::PE::ResourceDialogExtended::help_id
uint32_t help_id() const
The help context identifier for the dialog box window. When the system sends a WM_HELP message,...
Definition ResourceDialogExtended.hpp:149
LIEF::PE::ResourceDialogExtended::ResourceDialogExtended
ResourceDialogExtended()
Definition ResourceDialogExtended.hpp:107
LIEF::PE::ResourceDialogExtended::operator=
ResourceDialogExtended & operator=(ResourceDialogExtended &&)=default
LIEF::PE::ResourceDialog
This class is the base class for either a regular (legacy) Dialog or an extended Dialog....
Definition ResourceDialog.hpp:41
LIEF::PE::ResourceDialog::type
TYPE type() const
Definition ResourceDialog.hpp:333
errors.hpp
iterators.hpp
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
LIEF::PE::ResourceDialogExtended::font_t::is_defined
bool is_defined() const
Definition ResourceDialogExtended.hpp:87
LIEF::PE::ResourceDialogExtended::font_t::to_string
std::string to_string() const
LIEF::PE::ResourceDialogExtended::font_t::operator<<
friend std::ostream & operator<<(std::ostream &os, const font_t &font)
Definition ResourceDialogExtended.hpp:97
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41