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

distorm3 doesn't install on Windows 10 #155

Open
smclinden opened this issue Jan 19, 2021 · 28 comments
Open

distorm3 doesn't install on Windows 10 #155

smclinden opened this issue Jan 19, 2021 · 28 comments

Comments

@smclinden
Copy link

smclinden commented Jan 19, 2021

The Visual C for Python 2.7 only supports C89 not C99. C89 does not support mixing of assignments and declarations nor does it support variable declarations in for loops.

As a result, distorm3 doesn't install from PIP and attempting to build from source leads to the following:

building '_distorm3' extension
Calling 'vcvarsall.bat x86' (version=9.0)
C:\Users\testaccount\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27\include -IC:\Python27\PC /Tcsrc\decoder.c /Fobuild\temp.win32-2.7\Release\src\decoder.obj
decoder.c
C:\Users\testaccount\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27\include -IC:\Python27\PC /Tcsrc\distorm.c /Fobuild\temp.win32-2.7\Release\src\distorm.obj
distorm.c
src\distorm.c(320) : error C2143: syntax error : missing ';' before 'type'
src\distorm.c(321) : error C2275: '_OffsetType' : illegal use of this type as an expression
c:\users\testaccount\distorm\src../include/distorm.h(110) : see declaration of '_OffsetType'
src\distorm.c(321) : error C2146: syntax error : missing ';' before identifier 'offset'
src\distorm.c(321) : error C2065: 'offset' : undeclared identifier
src\distorm.c(321) : warning C4244: '=' : conversion from 'const _OffsetType' to 'int', possible loss of data
src\distorm.c(345) : error C2065: 'offset' : undeclared identifier
src\distorm.c(346) : error C2065: 'size' : undeclared identifier
error: command '"C:\Users\testaccount\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe"' failed with exit status 2

In distorm.c the lines around 320 look like:

                unsigned int opcode = di->opcode;
                unsigned int prefix = FLAG_GET_PREFIX(di->flags);
                mnemonic = (const _WMnemonic*)&_MNEMONICS[opcode]; <--
                unsigned int size = di->size;
                _OffsetType offset = di->addr & addrMask;

Visual C doesn't permit assignments before declarations in some instances. The solution is to move the flagged line to be after all declarations are completed, e.g.,

                unsigned int opcode = di->opcode;
                unsigned int prefix = FLAG_GET_PREFIX(di->flags);
                unsigned int size = di->size;
                mnemonic = (const _WMnemonic*)&_MNEMONICS[opcode]; <--
                _OffsetType offset = di->addr & addrMask;

A similar issue exists in prefix.c, line 141:

        for (unsigned int index = 0;
                (ci->codeLen > 0) && (index < INST_MAXIMUM_SIZE);
                ci->code++, ci->codeLen--, index++) {

Needs to be replaced with:

        unsigned int index;
        for (index = 0;
                (ci->codeLen > 0) && (index < INST_MAXIMUM_SIZE);
                ci->code++, ci->codeLen--, index++) {
@gdabah
Copy link
Owner

gdabah commented Jan 22, 2021 via email

@smclinden
Copy link
Author

If you do a PIP install, it requires Visual C++ for Python 2.7 which is VS 9. I can, manually, build with later versions of VC (2019) and then install distorm3 by hand, which works but is a bit of a pain.

@gdabah
Copy link
Owner

gdabah commented Feb 20, 2021

Hi @smclinden!
Just committed a fix.
Please let me know if it passes for you.
Thanks

@gdabah
Copy link
Owner

gdabah commented Feb 20, 2021

Seems to work for me with special VC for Python 2.7 Waiting for your confirmation anyway.

@smclinden
Copy link
Author

I will check it out. I can also post the manual steps to build it with newer versions of Visual C, if there is an interest.

@gdabah
Copy link
Owner

gdabah commented Feb 20, 2021

@smclinden If you think it might be useful I will add it to the wiki, then yes, sure. Thanks

@sfinktah
Copy link
Contributor

sfinktah commented Feb 28, 2021

Interesting... I have often had issues install 2.7 without doing a manual compile, but I could never work out why -- the information PIP gives you (along with a suggestion to look at a log file that you can't find) was absolutely zero help.

But I also never had an issue just compiling by hand. I only have VS2017 on this box. Does python 2.7 seriously install VS9 ... that's Visual Studio 2008 -- guess we best keep those stdint.h headers around after all.

I don't know anything about PIP, but I do know it's possible to upload prebuilt binaries. shrug. I'm sure I could whip together a BASH script for the job :)

@smclinden
Copy link
Author

smclinden commented Feb 28, 2021

Yes. I compiled distorm3 using VS2019 after figuring out where to put the output and then built the package manually. I think that if the setup script could be rewritten to check to see if a valid VS was already installed and attempt to build with that, it would probably make the package a little more portable.

@gdabah
Copy link
Owner

gdabah commented Feb 28, 2021

This setup.py distutils is F@cked. So much pain from such a simple (supposed to be) tool.

@smclinden
Copy link
Author

I'm not sure if this helps (I don't use distutils, much):

https://stackoverflow.com/questions/51976015/select-visual-studio-version-in-distutils-setup

@gdabah
Copy link
Owner

gdabah commented Feb 28, 2021 via email

@sfinktah
Copy link
Contributor

sfinktah commented Feb 28, 2021

From what is currently on my system, I get this (running from a python2.7 setup.py install --verbose)

Let's call it a baseline.

building '_distorm3' extension
Calling 'vcvarsall.bat amd64' (version=9.0)
error: [Error 2] The system cannot find the file specified

They really messed with vcvarsall.bat in 2017 and 2019 and ruined all my own lovely build scripts, so this is not that surprising. Let me investigate further now.

Same from pip2 running in the same devenv.

I thought I had fix this already with https://github.com/gdabah/distorm/pull/137/commits

(pulls and updates setup.py from there) .... ok, no errors, but no compile under 2 or 3, and that was from within a vsdev environment too. From a non-vsdev environment, it's the same story.

Lame. :)

I don't have the disk-space to install a py27 built-dist (or whatever it's called) on either of my dev machines, I'm down to the megabytes right now, so any fixes I perform aren't going to apply to anyone who isn't already running vs2017 or 2019 (2015 and earlier used the standard vcvarsall.bat arrangement).

The only other thing I have to offer is my bash script that I use to build my VS projects:

2015:
call "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat" -vcvars_ver=14.15

=2017:
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.15

I used to use Enterprise 2017, so I know that not only can the path be 2017 or 2019, but the folder can be Community or Enterprise (and probably other values). And if that isn't enough you have to negotiate 32 or 64.

Evidently I didn't call vsvarsall.bat, but that has more to do with being in cygwin and needing to be in a cmd window than anything else.

Getting the default VS9 compatibility is starting to sound very attractive right about now.

@sfinktah
Copy link
Contributor

sfinktah commented Mar 1, 2021

Okay, taking a second look. Despite all the notes I see in distutils/msvc9compiler.py regarding things needing to be compiled with VS2008, my Python (installed via the setup binary downloaded from where-ever python lives) says:

>>> import sys
>>> print sys.version
2.7.16 (v2.7.16:413a49145e, Mar  4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)]

That's Visual Studio 2017, right there. So this is all nonsense: [python27-x64/lib/distutils/msvc9compiler.py]

        raise DistutilsPlatformError(
        """Python was built with Visual Studio 2008;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2008 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")

Now to fix the root problem for all packages. Prepend the following to the function find_vcvarsall in aforementioned C:\Python27-x64\Lib\distutils\msvc9compiler.py (I've attached a copy of my own file, if that's too much effort).

msvc9compiler.zip

Want a solution that doesn't involve modifying your past end of lifetime, non-supported python 2.7 installation? Call Python, I'm sure they'll be glad to help. Are you a package maker suffering from having to support binary builds on supported and uncooperative Microsoft platforms? Upload pre-compiled binaries.

Problem solved. Expediency is my middle name.

def find_vcvarsall(version):
    # --[SNIP]-- (start of inserted section)
    import glob
    paths = glob.glob(r"C:\Program Files (x86)\Microsoft Visual Studio\20*\*\vc\Auxiliary\Build\vcvarsall.bat")
    if paths:
        print("{} possible locations for vcvarsall.bat found:".format(len(paths)))
        for i, path in enumerate(paths):
            print("\t[{}] {}".format(i, path))
        if len(paths) > 1:
            print("picking one at random:")
            paths.shuffle()
        path = paths[0]
        print("selecting:  {}".format(path))
        return path

    # otherwise, do what it would have done normally
    # --[SNIP]-- (end of inserted section)
    """Find the vcvarsall.bat file

    At first it tries to find the productdir of VS 2008 in the registry. If
    that fails it falls back to the VS90COMNTOOLS env var.
    """
    vsbase = VS_BASE % version
    # ... and so forth, and so on.

And here it is purring along nicely.

E:\git\distorm>py -2 -m pip install distorm3
Collecting distorm3
  Using cached https://files.pythonhosted.org/packages/93/c4/71dcf0fa683c887253319d92c5d2319fb94cc3f89f7d908fd8275df48cc5/distorm3-3.5.1.tar.gz
Building wheels for collected packages: distorm3
  Running setup.py bdist_wheel for distorm3 ... done
  Stored in directory: C:\Users\sfink\AppData\Local\pip\Cache\wheels\36\be\76\10d3d3fd7158c1f26189a546de3ca3db8df61d05187770a249
Successfully built distorm3
Installing collected packages: distorm3
Successfully installed distorm3-3.5.1

And via the manual route:

E:\git\distorm>py -2 setup.py install
('__import__', 'setuptools.msvc')
('__import__', 'distutils.msvc9compiler')
('__import__', 'distutils.msvc9compiler')
('__import__', 'distutils._msvccompiler')
('__import__', 'distutils._msvccompiler')
running install
running bdist_egg
running egg_info
writing python\distorm3.egg-info\PKG-INFO
writing top-level names to python\distorm3.egg-info\top_level.txt
writing dependency_links to python\distorm3.egg-info\dependency_links.txt
reading manifest file 'python\distorm3.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'python\distorm3.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
building '_distorm3' extension
1 possible locations for vcvarsall.bat found:
        [0] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\vc\Auxiliary\Build\vcvarsall.bat
selecting:  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\vc\Auxiliary\Build\vcvarsall.bat
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
creating build\temp.win-amd64-2.7\Release\src
creating build\temp.win-amd64-2.7\Release\python
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\decoder.c /Fobuild\temp.win-amd64-2.7\Release\src\decoder.obj
decoder.c
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\distorm.c /Fobuild\temp.win-amd64-2.7\Release\src\distorm.obj
distorm.c
...

All happy.

@gdabah
Copy link
Owner

gdabah commented Mar 1, 2021 via email

@sfinktah
Copy link
Contributor

sfinktah commented Mar 3, 2021

@gdabah "it was quirky"... yeah, no arguments here, it simply failed silently when I tested it.

The python setup.py install tests was run from a standard command prompt. I just re-ran the pip2 install from the same prompt, after finally finding all the cached copies of the dll. Worked fine too.

Just to repeat -- this is because of the modification to distutils of the python2 distribution itself. It may be possible to incorporate that (and nothing else) into your own build config, though I am dubious. You could also just provide compiled copies of the dll with instructions to copy it.

Also, having vs2017 or vs2019 is a requirement for the patch to work (well, it won't break without them, it just won't do anything), though vs2015 should conform to the "old school" detection methods. If someone just doesn't have visual studio installed, they're still going to be screwed.

  Created temporary directory: e:\appdat~1\pip-wheel-dooxft
  Running setup.py bdist_wheel for distorm3 ...   Destination directory: e:\appdat~1\pip-wheel-dooxft
  Running command C:\Python27-x64\python.exe -u -c "import setuptools, tokenize;__file__='e:\\appdat~1\\pip-install-rxn3at\\distorm3\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d e:\appdat~1\pip-wheel-dooxft --python-tag cp27
  ('__import__', 'setuptools.msvc')
  ('__import__', 'distutils.msvc9compiler')
  ('__import__', 'distutils.msvc9compiler')
  ('__import__', 'distutils._msvccompiler')
  ('__import__', 'distutils._msvccompiler')
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-2.7
  creating build\lib.win-amd64-2.7\distorm3
  copying python\distorm3\_generated.py -> build\lib.win-amd64-2.7\distorm3
  copying python\distorm3\__init__.py -> build\lib.win-amd64-2.7\distorm3
  copying python\distorm3\__main__.py -> build\lib.win-amd64-2.7\distorm3
  running build_ext
  building '_distorm3' extension
  1 possible locations for vcvarsall.bat found:
        [0] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\vc\Auxiliary\Build\vcvarsall.bat
  selecting:  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\vc\Auxiliary\Build\vcvarsall.bat
  creating build\temp.win-amd64-2.7
  creating build\temp.win-amd64-2.7\Release
  creating build\temp.win-amd64-2.7\Release\src
  creating build\temp.win-amd64-2.7\Release\python
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\decoder.c /Fobuild\temp.win-amd64-2.7\Release\src\decoder.obj
  decoder.c
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\distorm.c /Fobuild\temp.win-amd64-2.7\Release\src\distorm.obj
  distorm.c
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\instructions.c /Fobuild\temp.win-amd64-2.7\Release\src\instructions.obj
  instructions.c
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\insts.c /Fobuild\temp.win-amd64-2.7\Release\src\insts.obj
  insts.c
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\mnemonics.c /Fobuild\temp.win-amd64-2.7\Release\src\mnemonics.obj
  mnemonics.c
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\operands.c /Fobuild\temp.win-amd64-2.7\Release\src\operands.obj
  operands.c
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\prefix.c /Fobuild\temp.win-amd64-2.7\Release\src\prefix.obj
  prefix.c
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\textdefs.c /Fobuild\temp.win-amd64-2.7\Release\src\textdefs.obj
  textdefs.c
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcpython/python_module_init.c /Fobuild\temp.win-amd64-2.7\Release\python/python_module_init.obj
  python_module_init.c
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python27-x64\libs /LIBPATH:C:\Python27-x64\PCbuild\amd64 /LIBPATH:C:\Python27-x64\PC\VS9.0\amd64 /EXPORT:init_distorm3 build\temp.win-amd64-2.7\Release\src\decoder.obj build\temp.win-amd64-2.7\Release\src\distorm.obj build\temp.win-amd64-2.7\Release\src\instructions.obj build\temp.win-amd64-2.7\Release\src\insts.obj build\temp.win-amd64-2.7\Release\src\mnemonics.obj build\temp.win-amd64-2.7\Release\src\operands.obj build\temp.win-amd64-2.7\Release\src\prefix.obj build\temp.win-amd64-2.7\Release\src\textdefs.obj build\temp.win-amd64-2.7\Release\python/python_module_init.obj /OUT:build\lib.win-amd64-2.7\_distorm3.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\src\_distorm3.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\src\_distorm3.pyd.manifest
     Creating library build\temp.win-amd64-2.7\Release\src\_distorm3.lib and object build\temp.win-amd64-2.7\Release\src\_distorm3.exp
  installing to build\bdist.win-amd64\wheel
  running install
  running install_lib
  creating build\bdist.win-amd64
  creating build\bdist.win-amd64\wheel
  creating build\bdist.win-amd64\wheel\distorm3
  copying build\lib.win-amd64-2.7\distorm3\_generated.py -> build\bdist.win-amd64\wheel\.\distorm3
  copying build\lib.win-amd64-2.7\distorm3\__init__.py -> build\bdist.win-amd64\wheel\.\distorm3
  copying build\lib.win-amd64-2.7\distorm3\__main__.py -> build\bdist.win-amd64\wheel\.\distorm3
  copying build\lib.win-amd64-2.7\_distorm3.pyd -> build\bdist.win-amd64\wheel\.
  writing byte-compilation script 'e:\appdat~1\tmpk_i7zp.py'
  C:\Python27-x64\python.exe -O e:\appdat~1\tmpk_i7zp.py
  removing e:\appdat~1\tmpk_i7zp.py
  running install_egg_info
  running egg_info
  writing python\distorm3.egg-info\PKG-INFO
  writing top-level names to python\distorm3.egg-info\top_level.txt
  writing dependency_links to python\distorm3.egg-info\dependency_links.txt
  reading manifest file 'python\distorm3.egg-info\SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  writing manifest file 'python\distorm3.egg-info\SOURCES.txt'
  Copying python\distorm3.egg-info to build\bdist.win-amd64\wheel\.\distorm3-3.5.1-py2.7.egg-info
  running install_scripts
  C:\Python27-x64\lib\site-packages\wheel\pep425tags.py:80: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
    warn=(impl == 'cp')):
  C:\Python27-x64\lib\site-packages\wheel\pep425tags.py:84: RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
    warn=(impl == 'cp')):
  C:\Python27-x64\lib\site-packages\wheel\pep425tags.py:90: RuntimeWarning: Config variable 'Py_UNICODE_SIZE' is unset, Python ABI tag may be incorrect
    sys.version_info < (3, 3))) \
  adding license file "COPYING" (matched pattern "COPYING*")
  creating build\bdist.win-amd64\wheel\distorm3-3.5.1.dist-info\WHEEL
  creating 'e:\appdat~1\pip-wheel-dooxft\distorm3-3.5.1-cp27-cp27m-win_amd64.whl' and adding 'build\bdist.win-amd64\wheel' to it
  adding '_distorm3.pyd'
  adding 'distorm3/__init__.py'
  adding 'distorm3/__init__.pyo'
  adding 'distorm3/__main__.py'
  adding 'distorm3/__main__.pyo'
  adding 'distorm3/_generated.py'
  adding 'distorm3/_generated.pyo'
  adding 'distorm3-3.5.1.dist-info/COPYING'
  adding 'distorm3-3.5.1.dist-info/METADATA'
  adding 'distorm3-3.5.1.dist-info/WHEEL'
  adding 'distorm3-3.5.1.dist-info/top_level.txt'
  adding 'distorm3-3.5.1.dist-info/RECORD'
  removing build\bdist.win-amd64\wheel
done
  Stored in directory: C:\Users\sfink\AppData\Local\pip\Cache\wheels\36\be\76\10d3d3fd7158c1f26189a546de3ca3db8df61d05187770a249
  Removing source in e:\appdat~1\pip-install-rxn3at\distorm3
Successfully built distorm3
Installing collected packages: distorm3

Successfully installed distorm3-3.5.1
Cleaning up...
Removed build tracker 'e:\\appdat~1\\pip-req-tracker-ff3yp7'
You are using pip version 18.1, however version 20.3.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

@sfinktah
Copy link
Contributor

sfinktah commented Mar 4, 2021

@gdabah I can go ahead and make the changes suggested by @smclinden into a PR, I should have a VM somewhere I can test them on with a vanilla Windows 10 install. Reviewing them, (and it took a while to mentally shift gears back from C++), they're the usual super-strict classic C89 rules. I'll check if there's an option to relax the parsing first, though that option may be /TP (which will enable it to parse as C++). So we'll see how that goes.

@gdabah
Copy link
Owner

gdabah commented Mar 4, 2021 via email

@sfinktah
Copy link
Contributor

sfinktah commented Mar 4, 2021

I checked the current build against GCC in -std=c89, and gave it a quick eye-ball looking for (for int i = ... and everything looked fine.

I found a couple of tiny things while making a tinycc build, and that was it. Even tinycc doesn't stoop to C89.

It would appear the reason all my py2 builds failed was that I monkey-patched my distutils back when I was using Enterprise VS, and hardcoded the path.

FWIW the changes I made to your setup.py involved the VsWhere batch (command?) tool that comes with the newer versions of VS, where-as the changes I suggested for distutils don't attempt to get smart (I think that's where they went wrong really). They just use a simple glob to find vsvarsall.bat -- though that could be improved to use the programfiles environment variable from the old setup.py.

I also did some reading on setuptools vs distutils, and thought that might be the answer (after all, it has it's own .py scripts which have different logic for finding MSVC) but I eventually found them frustrating and probably incapable of providing for compilation of the distorm.dll without employing distutils anyway.

@sfinktah
Copy link
Contributor

sfinktah commented Mar 4, 2021

Appendix: I reverted to a stock distutils, and installed the VC9Python as instructed by pip, and compiled the git/distorm folder with py -2 setup.py install --verbose with no issue. A similar attempt with pip on the online version failed with a handful of errors in distorm.c (which I couldn't pin down because the line numbering is different).

E:\git\distorm>py -2 setup.py install --verbose
('__import__', 'setuptools.msvc')
('__import__', 'distutils.msvc9compiler')
('__import__', 'distutils.msvc9compiler')
('__import__', 'distutils._msvccompiler')
('__import__', 'distutils._msvccompiler')
running install
running bdist_egg
running egg_info
writing python\distorm3.egg-info\PKG-INFO
writing top-level names to python\distorm3.egg-info\top_level.txt
writing dependency_links to python\distorm3.egg-info\dependency_links.txt
reading manifest file 'python\distorm3.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'python\distorm3.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build\lib.win-amd64-2.7
creating build\lib.win-amd64-2.7\distorm3
copying python\distorm3\_generated.py -> build\lib.win-amd64-2.7\distorm3
copying python\distorm3\__init__.py -> build\lib.win-amd64-2.7\distorm3
copying python\distorm3\__main__.py -> build\lib.win-amd64-2.7\distorm3
running build_ext
building '_distorm3' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
creating build\temp.win-amd64-2.7\Release\src
creating build\temp.win-amd64-2.7\Release\python
C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\decoder.c /Fobuild\temp.win-amd64-2.7\Release\src\decoder.obj
decoder.c
C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\distorm.c /Fobuild\temp.win-amd64-2.7\Release\src\distorm.obj
distorm.c
C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\instructions.c /Fobuild\temp.win-amd64-2.7\Release\src\instructions.obj
instructions.c
C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\insts.c /Fobuild\temp.win-amd64-2.7\Release\src\insts.obj
insts.c
C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\mnemonics.c /Fobuild\temp.win-amd64-2.7\Release\src\mnemonics.obj
mnemonics.c
C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\operands.c /Fobuild\temp.win-amd64-2.7\Release\src\operands.obj
operands.c
C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\prefix.c /Fobuild\temp.win-amd64-2.7\Release\src\prefix.obj
prefix.c
C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcsrc\textdefs.c /Fobuild\temp.win-amd64-2.7\Release\src\textdefs.obj
textdefs.c
C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DSUPPORT_64BIT_OFFSET -DDISTORM_DYNAMIC -Isrc -Iinclude -IC:\Python27-x64\include -IC:\Python27-x64\PC /Tcpython/python_module_init.c /Fobuild\temp.win-amd64-2.7\Release\python/python_module_init.obj
python_module_init.c
C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python27-x64\libs /LIBPATH:C:\Python27-x64\PCbuild\amd64 /LIBPATH:C:\Python27-x64\PC\VS9.0\amd64 /EXPORT:init_distorm3 build\temp.win-amd64-2.7\Release\src\decoder.obj build\temp.win-amd64-2.7\Release\src\distorm.obj build\temp.win-amd64-2.7\Release\src\instructions.obj build\temp.win-amd64-2.7\Release\src\insts.obj build\temp.win-amd64-2.7\Release\src\mnemonics.obj build\temp.win-amd64-2.7\Release\src\operands.obj build\temp.win-amd64-2.7\Release\src\prefix.obj build\temp.win-amd64-2.7\Release\src\textdefs.obj build\temp.win-amd64-2.7\Release\python/python_module_init.obj /OUT:build\lib.win-amd64-2.7\_distorm3.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\src\_distorm3.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\src\_distorm3.pyd.manifest
python_module_init.obj : warning LNK4197: export 'init_distorm3' specified multiple times; using first specification
   Creating library build\temp.win-amd64-2.7\Release\src\_distorm3.lib and object build\temp.win-amd64-2.7\Release\src\_distorm3.exp
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\distorm3
copying build\lib.win-amd64-2.7\distorm3\_generated.py -> build\bdist.win-amd64\egg\distorm3
copying build\lib.win-amd64-2.7\distorm3\__init__.py -> build\bdist.win-amd64\egg\distorm3
copying build\lib.win-amd64-2.7\distorm3\__main__.py -> build\bdist.win-amd64\egg\distorm3
copying build\lib.win-amd64-2.7\_distorm3.pyd -> build\bdist.win-amd64\egg
byte-compiling build\bdist.win-amd64\egg\distorm3\_generated.py to _generated.pyc
byte-compiling build\bdist.win-amd64\egg\distorm3\__init__.py to __init__.pyc
byte-compiling build\bdist.win-amd64\egg\distorm3\__main__.py to __main__.pyc
writing byte-compilation script 'e:\appdat~1\tmprgad45.py'
C:\Python27-x64\python.exe -O e:\appdat~1\tmprgad45.py
removing e:\appdat~1\tmprgad45.py
creating stub loader for _distorm3.pyd
byte-compiling build\bdist.win-amd64\egg\_distorm3.py to _distorm3.pyc
writing byte-compilation script 'e:\appdat~1\tmpxjasja.py'
C:\Python27-x64\python.exe -O e:\appdat~1\tmpxjasja.py
removing e:\appdat~1\tmpxjasja.py
creating build\bdist.win-amd64\egg\EGG-INFO
copying python\distorm3.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying python\distorm3.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying python\distorm3.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying python\distorm3.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist\distorm3-3.5.1-py2.7-win-amd64.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing distorm3-3.5.1-py2.7-win-amd64.egg
Copying distorm3-3.5.1-py2.7-win-amd64.egg to c:\python27-x64\lib\site-packages
Adding distorm3 3.5.1 to easy-install.pth file

Installed c:\python27-x64\lib\site-packages\distorm3-3.5.1-py2.7-win-amd64.egg
Processing dependencies for distorm3==3.5.1
Finished processing dependencies for distorm3==3.5.1

E:\git\distorm>

@sfinktah
Copy link
Contributor

sfinktah commented Mar 4, 2021

It is probably worth mentioning that this is a 64 bit build, where-as I believe the OP was performing a 32 bit build. I made some changes in my last PR that fixed some issues with 32 bit builds and stdint.h (basically you weren't requiring stdint.h unless SUPPORT_64BIT_OFFSET was defined, but you were using types such as uint8_t which were therefore undefined.

@gdabah
Copy link
Owner

gdabah commented Mar 19, 2021

@smclinden
@sfinktah
What's the current status then with this? Should we change setup.py?

@sfinktah
Copy link
Contributor

sfinktah commented May 9, 2021

@gdabah Well, just looking at my own previous comments regarding having no issues compiling my branch, I attempted an install via pip (since you included my tcc PR), and it seems to build fine.

I guess I just have the magic touch.

I can only check the 64-bit version though.

./Lib/site-packages/_distorm3.pyd: PE32+ executable (DLL) (GUI) x86-64, for MS Windows

    C:\Users\sfink\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python27-x64\libs /LIBPATH:C:\Python27-x64\PCbuild\amd64 /LIBPATH:C:\Python27-x64\PC\VS9.0\amd64 /EXPORT:init_distorm3 build\temp.win-amd64-2.7\Release\src\decoder.obj build\temp.win-amd64-2.7\Release\src\distorm.obj build\temp.win-amd64-2.7\Release\src\instructions.obj build\temp.win-amd64-2.7\Release\src\insts.obj build\temp.win-amd64-2.7\Release\src\mnemonics.obj build\temp.win-amd64-2.7\Release\src\operands.obj build\temp.win-amd64-2.7\Release\src\prefix.obj build\temp.win-amd64-2.7\Release\src\textdefs.obj build\temp.win-amd64-2.7\Release\python/python_module_init.obj /OUT:build\lib.win-amd64-2.7\_distorm3.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\src\_distorm3.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\src\_distorm3.pyd.manifest
    python_module_init.obj : warning LNK4197: export 'init_distorm3' specified multiple times; using first specification
       Creating library build\temp.win-amd64-2.7\Release\src\_distorm3.lib and object build\temp.win-amd64-2.7\Release\src\_distorm3.exp
    running install_lib
    creating C:\Python27-x64\Lib\site-packages\distorm3

@gdabah
Copy link
Owner

gdabah commented May 9, 2021 via email

@sfinktah
Copy link
Contributor

I'm slow, but I get there in the end... or rather, find . -mtime 0 in cygwin does. So AFAIK you have no problem anymore, but it would be nice to test a 32 bit Python install to be 100% sure. I might have a virtual machine somewhere I don't mind polluting with a 32 bit python...

@gdabah
Copy link
Owner

gdabah commented Jun 13, 2021 via email

@sfinktah
Copy link
Contributor

I totally just remembered to finish this. I built a fresh Windows 10 VM, then installed the final python 2.7.18-64bit, distorm3 installed no issues.

I removed the 64bit python and installed the 32bit, and got the error:

    building '_distorm3' extension
    error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27

I visited that URL, to find (in true Microsoft style) that it was no longer valid, and they didn't care to fix it.

End of test.

Can you not just bundle a 32-bit DLL in the same manner as you assumedly bundled a 64-bit DLL?

@gdabah
Copy link
Owner

gdabah commented Jul 17, 2021

@sfinktah you mean for pypi?

@sfinktah
Copy link
Contributor

@gdabah yes -- isn't that the issue here? i mean, yes -- the OP suffered issues compiling, but he was only compiling because it didn't automatically work when obtained from pip.

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

3 participants