quarkslab / python-binexport

Python interface for Binexport, the Bindiff export format
Apache License 2.0
14 stars 2 forks source link

Windows issue #12

Closed llaubin closed 8 months ago

llaubin commented 9 months ago

Hola o/

tl;dr; python-binexport does not work on Windows.

It requires python-magic, which is not working on Windows without an auxiliary package named python-magic-bin, embedding some native code in a DLL. This package seems to be un-maintained from years, but, well, anyway, it still works with recent Python version 🤷‍♂️

But when adding this auxiliary package, there is another bug, in the way magic is used (see https://github.com/quarkslab/python-binexport/blob/main/bin/binexporter#L42) :

def recursive_file_iter(p: Path) -> Generator[Path, None, None]:
    if p.is_file():
        mime_type = magic.from_file(p, mime=True)

The argument passed to magic.from_file is a Path object, not a string. On Linux, when calling the native code from https://github.com/ahupp/python-magic/blob/master/magic/__init__.py#L321-L322, the coerce_function will return a string from the Path object, But on Windows, the original Path object will be returned ... so the call to the native code will receive an object instead of the expected string (see https://github.com/ahupp/python-magic/blob/master/magic/__init__.py#L317) , which results in an ctypes.ArgumentError: argument 2: TypeError: wrong type

A quick fix could be to ""cast"" the Path object to a string when calling magic.from_file.

Maybe another option could be to replace the usage of python-magic by LIEF and the various utilities functions lief.is_elf(), lief.is_pe(), lief.is_macho() ?

patacca commented 8 months ago

This should have been solved with #9 in version 0.3.0

patacca commented 8 months ago

Confirmed to be working after #18 in version 0.3.1