Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can LIEF be used to update version information in a PE binary? #797

Open
Imagine-Programming opened this issue Sep 20, 2022 · 2 comments
Open

Comments

@Imagine-Programming
Copy link

This is not per say a feature request or bug report, more of a question that might result in either one.

When accessing ResourceVersion through the ResourceManager, it is possible to update the state of the contained ResourceFixedFileInfo and ResourceStringFileInfo. However, upon invoking the write() method to apply the changes and store an updated copy of the binary, the resulting binary still has the original version information.

My question is; does the current version of LIEF even support this, or is the current support for version info only to be able to obtain it from a binary?

Thank you for your time, the library is awesome.

#include <iostream>

#include <LIEF/LIEF.hpp>

int main()
{
    auto pe = LIEF::PE::Parser::parse(R"PATH(path-to-dll.dll)PATH");

    auto manager = pe->resources_manager();

    if (manager.has_version()) {
        auto version = manager.version();
        
        if (version.has_fixed_file_info()) {
            auto* fixed = version.fixed_file_info();
            fixed->file_version_MS(1 | (1 << 16));
            fixed->file_version_LS(4 | (3 << 16));
            fixed->product_version_MS(1 | (1 << 16));
            fixed->product_version_LS(4 | (3 << 16));

            //std::cout << *fixed << std::endl;
            //version.fixed_file_info(*fixed);
        }

        if (version.has_string_file_info()) {
            auto* string = version.string_file_info();
            auto& items = string->langcode_items();

            for (auto& item : items) {
                auto& string_items = item.items();

                std::u16string key1 = u"ProductVersion";
                std::u16string key2 = u"FileVersion";
                std::u16string key3 = u"LegalCopyright";
                std::u16string val1 = u"1.1.3.4";
                std::u16string val2 = u"1.1.3.4";
                std::u16string val3 = u"Copyright © 2022 Bas Groothedde";

                string_items[key1] = val1;
                string_items[key2] = val2;
                string_items[key3] = val3;
            }

            //std::cout << *string << std::endl;
            //version.string_file_info(*string);
        }

        pe->write(R"PATH(path-to-dll-updated.dll)PATH");
    }
}
@romainthomas
Copy link
Member

Hello @Imagine-Programming

Right now LIEF does not support this kind of modification. From a technical perspective it is doable but I would say it is not in the roadmap in the mid-term (in the next ~6/8 months)

@Imagine-Programming
Copy link
Author

Thank you, that answers my question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants