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

Feature request: function for checking of validity of PE files #371

Open
TheMythologist opened this issue Mar 29, 2023 · 1 comment
Open

Comments

@TheMythologist
Copy link

Hi, I'm looking through the documentation and I don't think there is currently a way to check if a file / bytes is a valid PE file, other than via the following try...except excerpt:

import pefile

try:
    pefile.PE(filename)
    print("Valid PE file")
except pefile.PEFormatError:
    print("Invalid PE file")

Looking through the functions available, I see the function is_valid in peutils.py, but it currently does nothing (simply a pass statement).

Would it be alright for me to create a pull request, targeting the updating of this function? This will help to implement the functionality of checking if a file is valid PE file, similar to the zipfile standard library's function is_zipfile.

@erocarrera
Copy link
Owner

Hi, if you have a use for such functionality, feel free to send a PR.
I would avoid the "is valid PE" naming. I feel like saying that a PE is valid implies that it is a correct, well-formed, functioning PE, which is a hard thing to say for sure. I would limit it to a is_pe_file() method that attempts a light-weight parse (with fast_load=True). That would differentiate between a parseable PE and non-PE data.

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

No branches or pull requests

2 participants