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

Make lief.DictStringVersion a MutableMapping #52

Closed
Rafiot opened this issue Jul 10, 2017 · 5 comments
Closed

Make lief.DictStringVersion a MutableMapping #52

Rafiot opened this issue Jul 10, 2017 · 5 comments
Labels

Comments

@Rafiot
Copy link

Rafiot commented Jul 10, 2017

I'm not sure I'm doing it right, but accessing the file information of a PE is a bit difficult:

pe = lief.parse("./2805/f325970fd24bb088f1befdae5788152329e26bf3")
string_info = lief.to_json(pe.resources_manager.version.string_file_info.langcode_items[0])
# and then, json.loads, and so on 

It would be very nice to be able to access all the data as a collections.abc.MutableMapping so we could read and write the attributes directly in a pythonic way.

I may be doing it wrong ;)

@romainthomas
Copy link
Member

Could you be more precise about the API you would like ?

@Rafiot
Copy link
Author

Rafiot commented Jul 10, 2017

I'd like to be able to do things like that:

for key, value in pe.resources_manager.version.string_file_info.langcode_items[0].items():
    print(key, value)

But in general, having such APIs for everything that looks like a dictionary in the whole project would be great.

@romainthomas
Copy link
Member

Well actually the underlying C++ container is a std::map: include/LIEF/PE/resources/LangCodeItem.hpp#L96 and the translation to Python (thanks to pybind11) is performed with a dict like. The conversion to collections.abc.MutableMapping is not trivial

But you can iterate over the items property as follow:

for k, v in pe.resources_manager.version.string_file_info.langcode_items[0].items.items():
    print(k, v)

@Rafiot
Copy link
Author

Rafiot commented Jul 11, 2017

Hmmm, yeah, I get the problem.
The list of tuples if fine for me to get the data out, but if you want to edit it at some point, it will be tricky.

@Rafiot Rafiot closed this as completed Jul 11, 2017
@Rafiot
Copy link
Author

Rafiot commented Jul 11, 2017

FYI, I create my dict this way:
dict(pe.resources_manager.version.string_file_info.langcode_items[0].items)

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

No branches or pull requests

2 participants