LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_PE_RESOURCE_DIALOG_H
17#define LIEF_PE_RESOURCE_DIALOG_H
43 using dialogs_t = std::vector<std::unique_ptr<ResourceDialog>>;
44 struct ordinal_or_str_t {
50 std::u16string string;
53 return ordinal || !
string.empty();
56 operator bool()
const {
68 enum class DIALOG_STYLES : uint32_t {
77 SETFOREGROUND = 0x0200,
80 NOFAILCREATE = 0x0010,
85 SHELLFONT = SETFONT | FIXEDSYS,
87 enum class WINDOW_STYLES : uint32_t {
90 OVERLAPPED = 0x00000000,
93 MINIMIZE = 0x20000000,
95 DISABLED = 0x08000000,
96 CLIPSIBLINGS = 0x04000000,
97 CLIPCHILDREN = 0x02000000,
98 MAXIMIZE = 0x01000000,
101 DLGFRAME = 0x00400000,
102 VSCROLL = 0x00200000,
103 HSCROLL = 0x00100000,
104 SYSMENU = 0x00080000,
105 THICKFRAME = 0x00040000,
107 TABSTOP = 0x00010000,
109 enum class WINDOW_EXTENDED_STYLES : uint32_t {
112 DLGMODALFRAME = 0x00000001,
113 NOPARENTNOTIFY = 0x00000004,
114 TOPMOST = 0x00000008,
115 ACCEPTFILES = 0x00000010,
116 TRANSPARENT_STY = 0x00000020,
117 MDICHILD = 0x00000040,
118 TOOLWINDOW = 0x00000080,
119 WINDOWEDGE = 0x00000100,
120 CLIENTEDGE = 0x00000200,
121 CONTEXTHELP = 0x00000400,
125 RTLREADING = 0x00002000,
126 LEFTSCROLLBAR = 0x00004000,
128 CONTROLPARENT = 0x00010000,
129 STATICEDGE = 0x00020000,
130 APPWINDOW = 0x00040000,
132 enum class CONTROL_STYLES : uint32_t {
136 NOMOVEY = 0x00000002,
138 NORESIZE = 0x00000004,
139 NOPARENTALIGN = 0x00000008,
140 ADJUSTABLE = 0x00000020,
141 NODIVIDER = 0x00000040,
145 NOMOVEX = VERT | NOMOVEY
163 enum class WINDOW_CLASS : uint32_t {
171 uint32_t
style()
const {
184 return extended_style_;
191 bool has(WINDOW_STYLES style)
const {
194 return (style_ & (uint32_t)style) != 0;
196 bool has(CONTROL_STYLES style)
const {
199 return (style_ & (uint32_t)style) != 0;
207 int16_t
x()
const {
return x_; }
212 int16_t
y()
const {
return y_; }
217 int16_t
cx()
const {
return cx_; }
220 int16_t
cy()
const {
return cy_; }
230 extended_style_ = value;
234 Item&
x(int16_t value) { x_ = value;
return *
this; }
235 Item&
y(int16_t value) { y_ = value;
return *
this; }
236 Item&
cx(int16_t value) { cx_ = value;
return *
this; }
237 Item&
cy(int16_t value) { cy_ = value;
return *
this; }
239 Item&
id(int32_t value) { id_ = value;
return *
this; }
241 Item&
data(std::vector<uint8_t> creation_data) {
242 creation_data_ = std::move(creation_data);
247 class_.string = std::move(title);
253 class_.ordinal = ord;
258 title_.string = std::move(value);
264 title_.ordinal = ord;
267 const ordinal_or_str_t&
clazz()
const {
274 const ordinal_or_str_t&
title()
const {
284 return creation_data_;
288 return creation_data_;
302 uint32_t extended_style_ = 0;
311 ordinal_or_str_t class_;
312 ordinal_or_str_t title_;
313 std::vector<uint8_t> creation_data_;
315 static dialogs_t
parse(
const ResourceData& node);
318 static dialogs_t
parse(
const uint8_t* buffer,
size_t size);
322 ResourceDialog&
operator=(
const ResourceDialog&) =
default;
331 virtual std::unique_ptr<ResourceDialog>
clone()
const = 0;
336 uint32_t
style()
const {
348 return extended_style_;
350 int16_t
x()
const {
return x_; }
354 int16_t
y()
const {
return y_; }
358 int16_t
cx()
const {
return cx_; }
361 int16_t
cy()
const {
return cy_; }
365 ResourceDialog&
style(uint32_t value) {
371 extended_style_ = value;
375 ResourceDialog&
x(int16_t value) { x_ = value;
return *
this; }
376 ResourceDialog&
y(int16_t value) { y_ = value;
return *
this; }
377 ResourceDialog&
cx(int16_t value) { cx_ = value;
return *
this; }
378 ResourceDialog&
cy(int16_t value) { cy_ = value;
return *
this; }
380 ResourceDialog&
menu(std::u16string title) {
381 menu_.string = std::move(title);
386 ResourceDialog&
menu(uint16_t ord) {
392 window_class_.string = std::move(title);
398 window_class_.ordinal = ord;
402 ResourceDialog&
title(std::u16string value) {
403 title_ = std::move(value);
407 ResourceDialog&
title(
const std::string& title);
408 bool has(DIALOG_STYLES style)
const {
411 return (style_ & (uint32_t)style) != 0;
413 bool has(WINDOW_STYLES style)
const {
416 return (style_ & (uint32_t)style) != 0;
418 bool has(WINDOW_EXTENDED_STYLES style)
const {
421 return (extended_style_ & (uint32_t)style) != 0;
432 const std::u16string&
title()
const {
440 const ordinal_or_str_t&
menu()
const {
449 return window_class_;
461 static_assert(std::is_base_of<ResourceDialog, T>::value,
462 "Require ResourceDialog inheritance");
463 if (T::classof(
this)) {
464 return static_cast<const T*
>(
this);
475 static ok_error_t parse_menu(ResourceDialog& dialog, BinaryStream& stream);
476 static ok_error_t parse_class(ResourceDialog& dialog, BinaryStream& stream);
477 static ok_error_t parse_class(ResourceDialog::Item& dialog, BinaryStream& stream);
478 static ok_error_t parse_title(ResourceDialog& dialog, BinaryStream& stream);
479 static ok_error_t parse_title(ResourceDialog::Item& dialog, BinaryStream& stream);
480 static ok_error_t parse_creation_data(ResourceDialog::Item& item, BinaryStream& stream);
481 TYPE type_ = TYPE::UNKNOWN;
484 uint32_t extended_style_ = 0;
491 ordinal_or_str_t menu_;
492 ordinal_or_str_t window_class_;
494 std::u16string title_;
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
const ordinal_or_str_t & clazz() const
Window class of the control. This can be either: a string that specifies the name of a registered win...
Definition ResourceDialog.hpp:271
Item & cy(int16_t value)
Definition ResourceDialog.hpp:237
Item & y(int16_t value)
Definition ResourceDialog.hpp:235
friend std::ostream & operator<<(std::ostream &os, const Item &item)
Definition ResourceDialog.hpp:295
Item & cx(int16_t value)
Definition ResourceDialog.hpp:236
bool has(WINDOW_STYLES style) const
Check if this item has the given WINDOW_STYLES.
Definition ResourceDialog.hpp:193
const ordinal_or_str_t & title() const
Title of the item which can be either: a string that specifies the initial text or an ordinal value o...
Definition ResourceDialog.hpp:278
Item & extended_style(uint32_t value)
Definition ResourceDialog.hpp:229
span< uint8_t > creation_data()
Definition ResourceDialog.hpp:287
virtual std::string to_string() const =0
Item & title(uint16_t ord)
Definition ResourceDialog.hpp:263
Item & operator=(Item &&)=default
int32_t id() const
The control identifier.
Definition ResourceDialog.hpp:188
Item(const Item &)=default
span< const uint8_t > creation_data() const
Creation data that is passed to the control's window procedure.
Definition ResourceDialog.hpp:283
uint32_t style() const
The style of the control. This can be a combination of WINDOW_STYLES or CONTROL_STYLES.
Definition ResourceDialog.hpp:174
std::vector< WINDOW_STYLES > window_styles() const
List of WINDOW_STYLES used by this item.
Item & clazz(uint16_t ord)
Definition ResourceDialog.hpp:252
int16_t cx() const
The width, in dialog box units, of the control.
Definition ResourceDialog.hpp:219
bool has(CONTROL_STYLES style) const
Check if this item has the given CONTROL_STYLES.
Definition ResourceDialog.hpp:198
uint32_t extended_style() const
The extended styles for a window. This member is not used to create controls in dialog boxes,...
Definition ResourceDialog.hpp:183
Item & style(uint32_t value)
Definition ResourceDialog.hpp:224
int16_t cy() const
The height, in dialog box units, of the control.
Definition ResourceDialog.hpp:222
Item & operator=(const Item &)=default
Item & x(int16_t value)
Definition ResourceDialog.hpp:234
Item & data(std::vector< uint8_t > creation_data)
Definition ResourceDialog.hpp:241
std::vector< CONTROL_STYLES > control_styles() const
List of CONTROL_STYLES used by this item.
Item & id(int32_t value)
Definition ResourceDialog.hpp:239
int16_t y() const
The y-coordinate, in dialog box units, of the upper-left corner of the control. This coordinate is al...
Definition ResourceDialog.hpp:216
Item & title(std::u16string value)
Definition ResourceDialog.hpp:257
int16_t x() const
The x-coordinate, in dialog box units, of the upper-left corner of the control. This coordinate is al...
Definition ResourceDialog.hpp:211
Item & clazz(std::u16string title)
Definition ResourceDialog.hpp:246
This class is the base class for either a regular (legacy) Dialog or an extended Dialog....
Definition ResourceDialog.hpp:41
ResourceDialog & window_class(std::u16string title)
Definition ResourceDialog.hpp:391
virtual std::string to_string() const =0
std::vector< WINDOW_STYLES > windows_styles_list() const
List of WINDOW_STYLES used by this dialog.
CONTROL_STYLES
From: https://learn.microsoft.com/en-us/windows/win32/controls/common-control-styles.
Definition ResourceDialog.hpp:134
WINDOW_EXTENDED_STYLES
From https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles.
Definition ResourceDialog.hpp:111
ResourceDialog(ResourceDialog &&)=default
static dialogs_t parse(const ResourceData &node)
Parse dialogs from the given resource data node.
ResourceDialog & window_class(uint16_t ord)
Definition ResourceDialog.hpp:397
ResourceDialog(const ResourceDialog &)=default
const T * as() const
Helper to downcast a ResourceDialog into a ResourceDialogRegular or a ResourceDialogExtended.
Definition ResourceDialog.hpp:460
ResourceDialog & title(std::u16string value)
Definition ResourceDialog.hpp:402
ResourceDialog & title(const std::string &title)
friend std::ostream & operator<<(std::ostream &os, const ResourceDialog &dialog)
Definition ResourceDialog.hpp:469
ResourceDialog & menu(std::u16string title)
Definition ResourceDialog.hpp:380
DIALOG_STYLES
From: https://learn.microsoft.com/en-us/windows/win32/dlgbox/dialog-box-styles.
Definition ResourceDialog.hpp:70
int16_t cx() const
The width, in dialog box units, of the dialog box.
Definition ResourceDialog.hpp:360
bool has(WINDOW_EXTENDED_STYLES style) const
Check if the dialog used to given extended window style.
Definition ResourceDialog.hpp:420
uint32_t style() const
The style of the dialog box. This member can be a combination of window style values (such as WINDOW_...
Definition ResourceDialog.hpp:340
virtual std::unique_ptr< ResourceDialog > clone() const =0
bool has(WINDOW_STYLES style) const
Check if the dialog used to given window style.
Definition ResourceDialog.hpp:415
ResourceDialog & menu(uint16_t ord)
Definition ResourceDialog.hpp:386
ResourceDialog & extended_style(uint32_t value)
Definition ResourceDialog.hpp:370
ResourceDialog & operator=(ResourceDialog &&)=default
ResourceDialog & y(int16_t value)
Definition ResourceDialog.hpp:376
ResourceDialog & cx(int16_t value)
Definition ResourceDialog.hpp:377
const ordinal_or_str_t & menu() const
ordinal or name value of a menu resource.
Definition ResourceDialog.hpp:442
ResourceDialog & style(uint32_t value)
Definition ResourceDialog.hpp:365
uint32_t extended_style() const
The extended styles for a window. This member is not used to create dialog boxes, but applications th...
Definition ResourceDialog.hpp:347
bool has(DIALOG_STYLES style) const
Check if the dialog used to given dialog style.
Definition ResourceDialog.hpp:410
WINDOW_STYLES
From: https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles.
Definition ResourceDialog.hpp:89
int16_t x() const
The x-coordinate, in dialog box units, of the upper-left corner of the dialog box.
Definition ResourceDialog.hpp:353
ResourceDialog & x(int16_t value)
Definition ResourceDialog.hpp:375
ResourceDialog & operator=(const ResourceDialog &)=default
std::vector< WINDOW_EXTENDED_STYLES > windows_ext_styles_list() const
List of WINDOW_EXTENDED_STYLES used by this dialog.
std::string title_utf8() const
title of the dialog box
ResourceDialog & cy(int16_t value)
Definition ResourceDialog.hpp:378
virtual ~ResourceDialog()=default
int16_t y() const
The y-coordinate, in dialog box units, of the upper-left corner of the dialog box.
Definition ResourceDialog.hpp:357
int16_t cy() const
The height, in dialog box units, of the dialog box.
Definition ResourceDialog.hpp:363
static dialogs_t parse(const uint8_t *buffer, size_t size)
const ordinal_or_str_t & window_class() const
ordinal of a predefined system window class or name of a registered window class
Definition ResourceDialog.hpp:448
const std::u16string & title() const
title of the dialog box
Definition ResourceDialog.hpp:434
TYPE type() const
Definition ResourceDialog.hpp:333
std::vector< DIALOG_STYLES > styles_list() const
List of DIALOG_STYLES used by this dialog.
ResourceDialog(TYPE ty)
Definition ResourceDialog.hpp:327
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
@ not_found
Definition errors.hpp:25
tl::unexpected< lief_errors > make_error_code(lief_errors e)
Create an standard error code from lief_errors.
Definition errors.hpp:52
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
@ RIGHT
Definition AcceleratorCodes.hpp:59
@ LEFT
Definition AcceleratorCodes.hpp:57
@ T
Definition AcceleratorCodes.hpp:97
@ CONTROL
Definition AcceleratorCodes.hpp:37
const char * to_string(AuxiliaryWeakExternal::CHARACTERISTICS e)
LIEF namespace.
Definition Abstract/Binary.hpp:36
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:109
std::string to_string() const
bool is_defined() const
Definition ResourceDialog.hpp:52
#define LIEF_API
Definition visibility.h:41