17#ifndef LIEF_PE_RESOURCES_MANAGER_H
18#define LIEF_PE_RESOURCES_MANAGER_H
21#include "LIEF/errors.hpp"
22#include "LIEF/visibility.h"
23#include "LIEF/Object.hpp"
25#include "LIEF/PE/resources/ResourceVersion.hpp"
26#include "LIEF/PE/resources/ResourceIcon.hpp"
27#include "LIEF/PE/resources/ResourceDialog.hpp"
28#include "LIEF/PE/resources/ResourceStringTable.hpp"
29#include "LIEF/PE/resources/ResourceAccelerator.hpp"
67 static constexpr uint32_t lang_from_id(
size_t id) {
71 static constexpr uint32_t sublang_from_id(
size_t id) {
76 using dialogs_t = std::vector<ResourceDialog>;
77 using it_const_dialogs = const_ref_iterator<dialogs_t>;
79 using icons_t = std::vector<ResourceIcon>;
80 using it_const_icons = const_ref_iterator<icons_t>;
82 using strings_table_t = std::vector<ResourceStringTable>;
83 using it_const_strings_table = const_ref_iterator<strings_table_t>;
85 using accelerators_t = std::vector<ResourceAccelerator>;
86 using it_const_accelerators = const_ref_iterator<accelerators_t>;
88 ResourcesManager() =
delete;
89 ResourcesManager(ResourceNode& rsrc) :
93 ResourcesManager(
const ResourcesManager&) =
default;
94 ResourcesManager& operator=(
const ResourcesManager&) =
default;
96 ResourcesManager(ResourcesManager&&) =
default;
97 ResourcesManager& operator=(ResourcesManager&&) =
default;
99 ~ResourcesManager()
override =
default;
111 return get_node_type(type) !=
nullptr;
116 return get_node_type(TYPE::MANIFEST) !=
nullptr;
128 return get_node_type(TYPE::VERSION) !=
nullptr;
136 return get_node_type(TYPE::ICON) !=
nullptr &&
137 get_node_type(TYPE::GROUP_ICON) !=
nullptr;
150 return get_node_type(TYPE::DIALOG) !=
nullptr;
158 return get_node_type(TYPE::STRING) !=
nullptr;
166 return get_node_type(TYPE::HTML) !=
nullptr;
170 std::vector<std::string>
html()
const;
174 return get_node_type(TYPE::ACCELERATOR) !=
nullptr;
181 std::string
print(uint32_t depth = 0)
const;
183 void accept(
Visitor& visitor)
const override;
185 LIEF_API
friend std::ostream& operator<<(std::ostream& os,
const ResourcesManager& m);
188 void print_tree(
const ResourceNode& node, std::ostringstream& stream,
189 uint32_t current_depth, uint32_t max_depth)
const;
Definition ResourceIcon.hpp:39
Class which represents a Node in the resource tree.
Definition ResourceNode.hpp:38
The Resource Manager provides an enhanced API to manipulate the resource tree.
Definition ResourcesManager.hpp:38
void add_icon(const ResourceIcon &icon)
Add an icon to the resources.
bool has_version() const
true if resources contain a LIEF::PE::ResourceVersion
Definition ResourcesManager.hpp:127
bool has_html() const
true if the resources contain html
Definition ResourcesManager.hpp:165
it_const_accelerators accelerator() const
Return the list of the accelerator in the resource.
it_const_dialogs dialogs() const
Return the list of the dialogs present in the resource.
ResourceNode * get_node_type(TYPE type)
Return the ResourceNode associated with the given KIND or a nullptr if not found;.
bool has_type(TYPE type) const
true if the resource has the given LIEF::PE::KIND
Definition ResourcesManager.hpp:110
result< ResourceVersion > version() const
Return the ResourceVersion if any.
bool has_icons() const
true if resources contain a LIEF::PE::ResourceIcon
Definition ResourcesManager.hpp:135
bool has_manifest() const
true if resources contain the Manifest element
Definition ResourcesManager.hpp:115
std::string print(uint32_t depth=0) const
Print the resource tree to the given depth.
std::vector< TYPE > get_types() const
List of TYPE present in the resources.
it_const_icons icons() const
Return the list of the icons present in the resources.
TYPE
The different types of resources Ref: From https://docs.microsoft.com/en-us/windows/win32/menurc/reso...
Definition ResourcesManager.hpp:43
it_const_strings_table string_table() const
Return the list of the string table in the resource.
bool has_string_table() const
true if the resources contain a LIEF::PE::ResourceStringTable
Definition ResourcesManager.hpp:157
std::string manifest() const
Return the manifest as a std::string or an empty string if not found or corrupted.
bool has_accelerator() const
true if the resources contain LIEF::PE::ResourceAccelerator
Definition ResourcesManager.hpp:173
bool has_dialogs() const
true if resources contain dialogs
Definition ResourcesManager.hpp:149
std::vector< std::string > html() const
Return the list of the html resources.
void manifest(const std::string &manifest)
Update the manifest with the given string.
Definition Visitor.hpp:219
Iterator which returns reference on container's values.
Definition iterators.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:32
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:72