Skip to content

Commit

Permalink
Update PE's ResourcesManager
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Jan 7, 2024
1 parent 66fcfcc commit c01dc6a
Show file tree
Hide file tree
Showing 31 changed files with 605 additions and 2,316 deletions.
318 changes: 38 additions & 280 deletions api/python/lief/PE.pyi

Large diffs are not rendered by default.

361 changes: 0 additions & 361 deletions api/python/src/PE/enums.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/python/src/PE/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "LIEF/PE/debug/Pogo.hpp"
#include "LIEF/PE/debug/PogoEntry.hpp"
#include "LIEF/PE/resources/LangCodeItem.hpp"
#include "LIEF/PE/resources/langs.hpp"
#include "LIEF/PE/signature/attributes.hpp"
#include "LIEF/PE/signature/SpcIndirectData.hpp"
#include "LIEF/PE/signature/GenericContent.hpp"
Expand All @@ -55,6 +56,7 @@ void init_resources(nb::module_& m) {
CREATE(ResourceDialogItem, m);
CREATE(ResourceStringTable, m);
CREATE(ResourceAccelerator, m);
CREATE(RESOURCE_LANGS, m);
}

void init_load_configs(nb::module_& m) {
Expand Down
1 change: 1 addition & 0 deletions api/python/src/PE/objects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ target_sources(pyLIEF PRIVATE
pyDelayImportEntry.cpp
pySymbol.cpp
pyTLS.cpp
pyLang.cpp
)

add_subdirectory(resources)
Expand Down
133 changes: 133 additions & 0 deletions api/python/src/PE/objects/pyLang.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* Copyright 2017 - 2023 R. Thomas
* Copyright 2017 - 2023 Quarkslab
* Copyright 2017 - 2021 K. Nakagawa
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "PE/pyPE.hpp"

#include "LIEF/PE/resources/langs.hpp"
#include "enums_wrapper.hpp"

namespace LIEF::PE::py {

template<>
void create<RESOURCE_LANGS>(nb::module_& m) {
enum_<RESOURCE_LANGS>(m, "RESOURCE_LANGS")
.value("NEUTRAL", RESOURCE_LANGS::NEUTRAL)
.value("INVARIANT", RESOURCE_LANGS::INVARIANT)
.value("AFRIKAANS", RESOURCE_LANGS::AFRIKAANS)
.value("ALBANIAN", RESOURCE_LANGS::ALBANIAN)
.value("ARABIC", RESOURCE_LANGS::ARABIC)
.value("ARMENIAN", RESOURCE_LANGS::ARMENIAN)
.value("ASSAMESE", RESOURCE_LANGS::ASSAMESE)
.value("AZERI", RESOURCE_LANGS::AZERI)
.value("BASQUE", RESOURCE_LANGS::BASQUE)
.value("BELARUSIAN", RESOURCE_LANGS::BELARUSIAN)
.value("BANGLA", RESOURCE_LANGS::BANGLA)
.value("BULGARIAN", RESOURCE_LANGS::BULGARIAN)
.value("CATALAN", RESOURCE_LANGS::CATALAN)
.value("CHINESE", RESOURCE_LANGS::CHINESE)
.value("CROATIAN", RESOURCE_LANGS::CROATIAN)
.value("BOSNIAN", RESOURCE_LANGS::BOSNIAN)
.value("CZECH", RESOURCE_LANGS::CZECH)
.value("DANISH", RESOURCE_LANGS::DANISH)
.value("DIVEHI", RESOURCE_LANGS::DIVEHI)
.value("DUTCH", RESOURCE_LANGS::DUTCH)
.value("ENGLISH", RESOURCE_LANGS::ENGLISH)
.value("ESTONIAN", RESOURCE_LANGS::ESTONIAN)
.value("FAEROESE", RESOURCE_LANGS::FAEROESE)
.value("FARSI", RESOURCE_LANGS::FARSI)
.value("FINNISH", RESOURCE_LANGS::FINNISH)
.value("FRENCH", RESOURCE_LANGS::FRENCH)
.value("GALICIAN", RESOURCE_LANGS::GALICIAN)
.value("GEORGIAN", RESOURCE_LANGS::GEORGIAN)
.value("GERMAN", RESOURCE_LANGS::GERMAN)
.value("GREEK", RESOURCE_LANGS::GREEK)
.value("GUJARATI", RESOURCE_LANGS::GUJARATI)
.value("HEBREW", RESOURCE_LANGS::HEBREW)
.value("HINDI", RESOURCE_LANGS::HINDI)
.value("HUNGARIAN", RESOURCE_LANGS::HUNGARIAN)
.value("ICELANDIC", RESOURCE_LANGS::ICELANDIC)
.value("INDONESIAN", RESOURCE_LANGS::INDONESIAN)
.value("ITALIAN", RESOURCE_LANGS::ITALIAN)
.value("JAPANESE", RESOURCE_LANGS::JAPANESE)
.value("KANNADA", RESOURCE_LANGS::KANNADA)
.value("KASHMIRI", RESOURCE_LANGS::KASHMIRI)
.value("KAZAK", RESOURCE_LANGS::KAZAK)
.value("KONKANI", RESOURCE_LANGS::KONKANI)
.value("KOREAN", RESOURCE_LANGS::KOREAN)
.value("KYRGYZ", RESOURCE_LANGS::KYRGYZ)
.value("LATVIAN", RESOURCE_LANGS::LATVIAN)
.value("LITHUANIAN", RESOURCE_LANGS::LITHUANIAN)
.value("MACEDONIAN", RESOURCE_LANGS::MACEDONIAN)
.value("MALAY", RESOURCE_LANGS::MALAY)
.value("MALAYALAM", RESOURCE_LANGS::MALAYALAM)
.value("MANIPURI", RESOURCE_LANGS::MANIPURI)
.value("MARATHI", RESOURCE_LANGS::MARATHI)
.value("MONGOLIAN", RESOURCE_LANGS::MONGOLIAN)
.value("NEPALI", RESOURCE_LANGS::NEPALI)
.value("NORWEGIAN", RESOURCE_LANGS::NORWEGIAN)
.value("ORIYA", RESOURCE_LANGS::ORIYA)
.value("POLISH", RESOURCE_LANGS::POLISH)
.value("PORTUGUESE", RESOURCE_LANGS::PORTUGUESE)
.value("PUNJABI", RESOURCE_LANGS::PUNJABI)
.value("ROMANIAN", RESOURCE_LANGS::ROMANIAN)
.value("RUSSIAN", RESOURCE_LANGS::RUSSIAN)
.value("SANSKRIT", RESOURCE_LANGS::SANSKRIT)
.value("SERBIAN", RESOURCE_LANGS::SERBIAN)
.value("SINDHI", RESOURCE_LANGS::SINDHI)
.value("SLOVAK", RESOURCE_LANGS::SLOVAK)
.value("SLOVENIAN", RESOURCE_LANGS::SLOVENIAN)
.value("SPANISH", RESOURCE_LANGS::SPANISH)
.value("SWAHILI", RESOURCE_LANGS::SWAHILI)
.value("SWEDISH", RESOURCE_LANGS::SWEDISH)
.value("SYRIAC", RESOURCE_LANGS::SYRIAC)
.value("TAMIL", RESOURCE_LANGS::TAMIL)
.value("TATAR", RESOURCE_LANGS::TATAR)
.value("TELUGU", RESOURCE_LANGS::TELUGU)
.value("THAI", RESOURCE_LANGS::THAI)
.value("TURKISH", RESOURCE_LANGS::TURKISH)
.value("UKRAINIAN", RESOURCE_LANGS::UKRAINIAN)
.value("URDU", RESOURCE_LANGS::URDU)
.value("UZBEK", RESOURCE_LANGS::UZBEK)
.value("VIETNAMESE", RESOURCE_LANGS::VIETNAMESE)
.value("GAELIC", RESOURCE_LANGS::GAELIC)
.value("MALTESE", RESOURCE_LANGS::MALTESE)
.value("MAORI", RESOURCE_LANGS::MAORI)
.value("RHAETO_ROMANCE", RESOURCE_LANGS::RHAETO_ROMANCE)
.value("SAMI", RESOURCE_LANGS::SAMI)
.value("SORBIAN", RESOURCE_LANGS::SORBIAN)
.value("SUTU", RESOURCE_LANGS::SUTU)
.value("TSONGA", RESOURCE_LANGS::TSONGA)
.value("TSWANA", RESOURCE_LANGS::TSWANA)
.value("VENDA", RESOURCE_LANGS::VENDA)
.value("XHOSA", RESOURCE_LANGS::XHOSA)
.value("ZULU", RESOURCE_LANGS::ZULU)
.value("ESPERANTO", RESOURCE_LANGS::ESPERANTO)
.value("WALON", RESOURCE_LANGS::WALON)
.value("CORNISH", RESOURCE_LANGS::CORNISH)
.value("WELSH", RESOURCE_LANGS::WELSH)
.value("BRETON", RESOURCE_LANGS::BRETON)
.value("INUKTITUT", RESOURCE_LANGS::INUKTITUT)
.value("IRISH", RESOURCE_LANGS::IRISH)
.value("LOWER_SORBIAN", RESOURCE_LANGS::LOWER_SORBIAN)
.value("PULAR", RESOURCE_LANGS::PULAR)
.value("QUECHUA", RESOURCE_LANGS::QUECHUA)
.value("TAMAZIGHT", RESOURCE_LANGS::TAMAZIGHT)
.value("TIGRINYA", RESOURCE_LANGS::TIGRINYA)
.value("VALENCIAN", RESOURCE_LANGS::VALENCIAN);

}

}
46 changes: 32 additions & 14 deletions api/python/src/PE/objects/pyResourcesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "LIEF/PE/ResourcesManager.hpp"
#include "LIEF/PE/ResourceNode.hpp"
#include "enums_wrapper.hpp"

#include <string>
#include <sstream>
Expand All @@ -41,6 +42,31 @@ void create<ResourcesManager>(nb::module_& m) {
init_ref_iterator<ResourcesManager::it_const_icons>(manager, "it_const_icons");
init_ref_iterator<ResourcesManager::it_const_strings_table>(manager, "it_const_strings_table");
init_ref_iterator<ResourcesManager::it_const_accelerators>(manager, "it_const_accelerators");
#define ENTRY(X) .value(to_string(ResourcesManager::TYPE::X), ResourcesManager::TYPE::X)
enum_<ResourcesManager::TYPE>(manager, "TYPE")
ENTRY(CURSOR)
ENTRY(BITMAP)
ENTRY(ICON)
ENTRY(MENU)
ENTRY(DIALOG)
ENTRY(STRING)
ENTRY(FONTDIR)
ENTRY(FONT)
ENTRY(ACCELERATOR)
ENTRY(RCDATA)
ENTRY(MESSAGETABLE)
ENTRY(GROUP_CURSOR)
ENTRY(GROUP_ICON)
ENTRY(VERSION)
ENTRY(DLGINCLUDE)
ENTRY(PLUGPLAY)
ENTRY(VXD)
ENTRY(ANICURSOR)
ENTRY(ANIICON)
ENTRY(HTML)
ENTRY(MANIFEST)
;
#undef ENTRY

manager
.def(nb::init<ResourceNode&>(), nb::keep_alive<0, 1>())
Expand Down Expand Up @@ -88,17 +114,9 @@ void create<ResourcesManager>(nb::module_& m) {
"Return the list of the " RST_CLASS_REF(lief.PE.ResourceDialog) " present in the resource"_doc,
nb::keep_alive<0, 1>())

.def_prop_ro("types_available",
&ResourcesManager::get_types_available,
"Return list of " RST_CLASS_REF(lief.PE.RESOURCE_TYPES) " present in the resources"_doc)

.def_prop_ro("langs_available",
&ResourcesManager::get_langs_available,
"Return list of " RST_CLASS_REF(lief.PE.RESOURCE_LANGS) " present in the resources"_doc)

.def_prop_ro("sublangs_available",
&ResourcesManager::get_sublangs_available,
"Return list of " RST_CLASS_REF(lief.PE.RESOURCE_SUBLANGS) " present in the resources"_doc)
.def_prop_ro("types",
&ResourcesManager::get_types,
"Return list of :class:`~.TYPE` present in the resources"_doc)

.def("add_icon",
&ResourcesManager::add_icon,
Expand All @@ -107,7 +125,7 @@ void create<ResourcesManager>(nb::module_& m) {

.def("has_type",
&ResourcesManager::has_type,
"``True`` if the resource has the given " RST_CLASS_REF(lief.PE.RESOURCE_TYPES) ""_doc,
"``True`` if the resource has the given :class:`~.TYPE`"_doc,
"type"_a)

.def_prop_ro("has_string_table",
Expand Down Expand Up @@ -135,9 +153,9 @@ void create<ResourcesManager>(nb::module_& m) {
nb::keep_alive<1, 0>())

.def("get_node_type",
nb::overload_cast<RESOURCE_TYPES>(&ResourcesManager::get_node_type),
nb::overload_cast<ResourcesManager::TYPE>(&ResourcesManager::get_node_type),
R"delim(
Return :class:`~lief.PE.ResourceNode` with the given :class:`~lief.PE.RESOURCE_TYPES`
Return :class:`~lief.PE.ResourceNode` with the given :class:`~.TYPE`
or None if not found.
)delim"_doc,
"type"_a,
Expand Down
8 changes: 4 additions & 4 deletions api/python/src/PE/objects/resources/pyLangCodeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ void create<LangCodeItem>(nb::module_& m) {

.def_prop_rw("lang",
nb::overload_cast<>(&LangCodeItem::lang, nb::const_),
nb::overload_cast<RESOURCE_LANGS>(&LangCodeItem::lang),
"Lang (" RST_CLASS_REF(lief.PE.RESOURCE_LANGS) ") for which "
nb::overload_cast<uint32_t>(&LangCodeItem::lang),
"Language for which "
":attr:`~lief.PE.LangCodeItem.items` are defined"_doc)

.def_prop_rw("sublang",
nb::overload_cast<>(&LangCodeItem::sublang, nb::const_),
nb::overload_cast<RESOURCE_SUBLANGS>(&LangCodeItem::sublang),
"Sub-lang (" RST_CLASS_REF(lief.PE.RESOURCE_SUBLANGS) ") for which "
nb::overload_cast<uint32_t>(&LangCodeItem::sublang),
"Sublanguage for which "
":attr:`~lief.PE.LangCodeItem.items` are defined"_doc)

.def_prop_rw("code_page",
Expand Down
8 changes: 4 additions & 4 deletions api/python/src/PE/objects/resources/pyResourceDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ void create<ResourceDialog>(nb::module_& m) {

.def_prop_rw("lang",
nb::overload_cast<>(&ResourceDialog::lang, nb::const_),
nb::overload_cast<RESOURCE_LANGS>(&ResourceDialog::lang),
"Primary " RST_CLASS_REF(lief.PE.RESOURCE_LANGS) " associated with the dialog"_doc)
nb::overload_cast<uint32_t>(&ResourceDialog::lang),
"Primary language associated with the dialog"_doc)

.def_prop_rw("sub_lang",
nb::overload_cast<>(&ResourceDialog::sub_lang, nb::const_),
nb::overload_cast<RESOURCE_SUBLANGS>(&ResourceDialog::sub_lang),
"Secondary " RST_CLASS_REF(lief.PE.RESOURCE_SUBLANGS) " associated with the dialog"_doc)
nb::overload_cast<uint32_t>(&ResourceDialog::sub_lang),
"Secondary language associated with the dialog"_doc)

LIEF_DEFAULT_STR(ResourceDialog);
}
Expand Down
8 changes: 4 additions & 4 deletions api/python/src/PE/objects/resources/pyResourceIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ void create<ResourceIcon>(nb::module_& m) {

.def_prop_rw("lang",
nb::overload_cast<>(&ResourceIcon::lang, nb::const_),
nb::overload_cast<RESOURCE_LANGS>(&ResourceIcon::lang),
"Language (" RST_CLASS_REF(lief.PE.RESOURCE_LANGS) ") associated with the icon"_doc)
nb::overload_cast<uint32_t>(&ResourceIcon::lang),
"Language associated with the icon"_doc)

.def_prop_rw("sublang",
nb::overload_cast<>(&ResourceIcon::sublang, nb::const_),
nb::overload_cast<RESOURCE_SUBLANGS>(&ResourceIcon::sublang),
"Sub language (" RST_CLASS_REF(lief.PE.RESOURCE_SUBLANGS) ") associated with the icon"_doc)
nb::overload_cast<uint32_t>(&ResourceIcon::sublang),
"Sublanguage associated with the icon"_doc)

.def_prop_rw("width",
nb::overload_cast<>(&ResourceIcon::width, nb::const_),
Expand Down
9 changes: 0 additions & 9 deletions doc/sphinx/api/cpp/pe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,6 @@ Enums
.. doxygenenum:: LIEF::PE::RELOCATIONS_ARM
:project: lief

.. doxygenenum:: LIEF::PE::RESOURCE_TYPES
:project: lief

.. doxygenenum:: LIEF::PE::RESOURCE_LANGS
:project: lief

.. doxygenenum:: LIEF::PE::RESOURCE_SUBLANGS
:project: lief

.. doxygenenum:: LIEF::PE::CODE_PAGES
:project: lief

Expand Down
28 changes: 7 additions & 21 deletions doc/sphinx/api/python/pe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -551,27 +551,6 @@ RELOCATIONS_BASE_TYPES

----------

RESOURCE_TYPES
~~~~~~~~~~~~~~

.. autoclass:: lief.PE.RESOURCE_TYPES

----------

RESOURCE_LANGS
~~~~~~~~~~~~~~

.. autoclass:: lief.PE.RESOURCE_LANGS

----------

RESOURCE_SUBLANGS
~~~~~~~~~~~~~~~~~

.. autoclass:: lief.PE.RESOURCE_SUBLANGS

----------

FIXED_VERSION_FILE_SUB_TYPES
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -621,6 +600,13 @@ FIXED_VERSION_FILE_TYPES

----------

RESOURCE_LANGS
~~~~~~~~~~~~~~

.. autoclass:: lief.PE.RESOURCE_LANGS

-----------

FIXED_VERSION_FILE_SUB_TYPES
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 3 additions & 0 deletions doc/sphinx/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ Changelog
(instead of `lief.MachO.Binary.name`)

:PE:
* ``RESOURCE_SUBLANGS`` has been removed
* ``RESOURCE_LANGS`` is now defined in a dedicated header: ``LIEF/PE/resources/langs.hpp``
* ``RESOURCE_TYPES`` is now scoped in ``ResourcesManager::TYPE``
* ``GUARD_CF_FLAGS`` is now scoped as :class:`~lief.PE.LoadConfigurationV1.IMAGE_GUARD` in
:class:`lief.PE.LoadConfigurationV1`
* ``SECTION_CHARACTERISTICS`` is now scoped within the
Expand Down
Loading

0 comments on commit c01dc6a

Please sign in to comment.