GithubHelp home page GithubHelp logo

Comments (6)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Hey there,
thanks for the report.

Since I have never used MinGW before, I would appreciate further help here.
Can you try to compile it and give me the command line switches for the 
compiler?

Gil

Original comment by [email protected] on 12 Apr 2011 at 6:41

from distorm.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
I went through Microsofts documentation and came up with this summary of the 
args passed to MSVC:
/Ox -- Maximize Optimization
/Ob1 -- Expand only functions marked inline, enable inline expansion
/oy -- Omit frame pointer
/D WIN32 -- Declare WIN32
/D _DLL -- Declare _DLL
/D LIBDISTORM -- Declare LIBDISTORM
/D SUPPORT_64BIT_OFFSET
/D _MBCS 
/GF -- Remove Dulplicate Strings
/Gm -- Enable minimul rebuild
/Zi -- Generate debugging information
/EHsc -- Exception Handling: Catch C++ exceptions
/MT -- Use multithreaded staticly linked version of the standard library
/Gy -- Enable function level linking, automatically set by /Zi
/W4 -- Set warning level to 4
/nologo -- Duh!
/c -- Don't link
/TC -- Specify C source
/Fdbuild\\vc90.pdb --  Use the vc90 PDB file


I'v hacked the setup file to use these options instead of the MSVC options:
extra_compile_args=['-fPIC', '-O2', '-Wall',
                    '-DSUPPORT_64BIT_OFFSET', '-D_DLL',
                    '-DLIBDISTORM', '-DWIN32']))]

Building and installing with these options work.... but when you try to run the 
sample python complains that it can't load the dynamic lirary:
C:\Users\tantalum\Documents\Research\ian\distorm_test>python sample.py
Traceback (most recent call last):
  File "sample.py", line 6, in <module>
    import distorm3
  File "C:\Python27\lib\site-packages\distorm3\__init__.py", line 47, in <module>
    raise ImportError("Error loading the diStorm dynamic library")
ImportError: Error loading the diStorm dynamic library

I don't know what's causing this. Trying to link a C program also failes.
C:\Users\tantalum\Documents\Research\ian\distorm_test>gcc disassemble.c -o 
disassemble -ldistorm3 -L C:\Python27\Lib\site-packages\distorm3\
C:\Users\tantalum\AppData\Local\Temp\ccGvYPi3.o:disassemble.c:(.text+0x5a): 
undefined reference to `distorm_version'
C:\Users\tantalum\AppData\Local\Temp\ccGvYPi3.o:disassemble.c:(.text+0x3fd): 
undefined reference to `distorm_decode64'
collect2: ld returned 1 exit status

To make things even more fun I decided to see what 'dumpbin /EXPORTS' had to 
say about distorm3.dll and distorm3.lib, and they both export distorm_decode64 
and distorm_version:
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC>dumpbin /EXPORTS 
C:\Python27\Lib\site-packages\distorm3\distorm3.dll
Microsoft (R) COFF/PE Dumper Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file C:\Python27\Lib\site-packages\distorm3\distorm3.dll

File Type: DLL

  Section contains the following exports for distorm3.dll

    00000000 characteristics
    4DA77270 time date stamp Thu Apr 14 17:17:20 2011
        0.00 version
           1 ordinal base
          37 number of functions
          37 number of names

    ordinal hint RVA      name

          1    0 00007000 II_3dnow
          2    1 00011080 II_arpl
          3    2 0001108C II_movsxd
          4    3 000110A4 II_nop
          5    4 000110B0 II_pause
          6    5 00007050 Instructions
          7    6 00007044 Table_0F
          8    7 00007038 Table_0F_0F
          9    8 0000702C Table_0F_38
         10    9 00007020 Table_0F_3A
         11    A 00012160 _MNEMONICS
         12    B 00017E40 _REGISTERS
         13    C 00010760 _REGISTERTORCLASS
         14    D 000056E0 chrcat_WS
         15    E 000014B0 decode_internal
         16    F 00002C10 distorm_decode64
         17   10 00002230 distorm_decompose64
         18   11 000024B0 distorm_format64
         19   12 00002220 distorm_version
         20   13 00002F40 inst_lookup
         21   14 00002F00 inst_lookup_3dnow
         22   15 00003C80 operands_extract
         23   16 00005010 prefixes_decode
         24   17 00004EE0 prefixes_ignore
         25   18 00004F00 prefixes_ignore_all
         26   19 00004E50 prefixes_is_valid
         27   1A 00004F30 prefixes_set_unused_mask
         28   1B 00005380 prefixes_use_segment
         29   1C 00005640 str_code_hb
         30   1D 00005440 str_code_hdw
         31   1E 000054D0 str_code_hqw
         32   1F 00005690 str_hex_b
         33   20 00005590 str_off64
         34   21 00005700 strcat_WS
         35   22 00005740 strcatlen_WS
         36   23 000056C0 strclear_WS
         37   24 00005780 strcpylen_WS

  Summary

        1000 .CRT
        1000 .bss
        B000 .data
        1000 .edata
        1000 .idata
        7000 .rdata
        2000 .reloc
        6000 .text
        1000 .tls

c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC>dumpbin /EXPORTS 
C:\Python27\Lib\site-packages\distorm3\distorm3.lib
Microsoft (R) COFF/PE Dumper Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file C:\Python27\Lib\site-packages\distorm3\distorm3.lib

File Type: LIBRARY

     Exports

       ordinal    name

                  distorm_decode64
                  distorm_decompose64
                  distorm_format64
                  distorm_version

  Summary

          C6 .debug$S
          14 .idata$2
          14 .idata$3
           8 .idata$4
           8 .idata$5
           E .idata$6

Any hints on how to move forward would be wonderful. I would very much like to 
see this working with mingw. Sorry if I miss something obvious, it's been a 
while since I worked with this kind of stuff on windows and you gotta love the 
way it 'keeps things orignized'.

Original comment by [email protected] on 14 Apr 2011 at 10:44

from distorm.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Hey
I will check it out tomorrow and let you know.

Original comment by [email protected] on 15 Apr 2011 at 11:50

from distorm.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024

Original comment by [email protected] on 16 Apr 2011 at 1:16

  • Changed state: Accepted

from distorm.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
From my test, I bet you compiled the extension as an x86 binary, and your 
Python is x64. Therefore you cannot load the DLL into the process, since it's 
incompatible. You will have to rebuild diStorm as x64 somehow. Or use Python 
for x86, err.
As for now it seems distutils still doesn't support MinGW well, and I'm not 
going to support it. Sorry.

Original comment by [email protected] on 16 Apr 2011 at 2:55

  • Changed state: WontFix

from distorm.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
FYI: I was able to make it working.
I installed MinGW64 from http://www.drangon.org/mingw
make sure you extract the file to c:\mingw
(rename the original 32bits version first, so not to override the files).
Or alternatively, you could set the path to the 64 bits version of gcc.exe of 
the new MinGW... probably doing that is smarter.

Then I tried to compile using: python setup.py --compiler=mingw32
(While having your patch to the setup.py file)
The build failed on the compilation of the .dll file itself, but the object 
files were compiled.
This is where I copy pasted that command line which failed and removed the part 
"-lmsvcr90" and re-ran that command line and it created the actual .dll file 
for x64. After that I copied that .dll to the site-packages\distorm3 and 
imported the distorm3 library in Python and it worked!

The command line I ran was:
c:\mingw\bin\gcc.exe -mno-cygwin -shared -s 
build\temp.win-amd64-2.7\src\decoder.o build\temp.win-amd64-2.7\src\distorm.o 
build\temp.win-amd64-2.7\src\instructions.o 
build\temp.win-amd64-2.7\src\insts.o build\temp.win-amd64-2.7\src\operands.o 
build\temp.win-amd64-2.7\src\prefix.o build\temp.win-amd64-2.7\src\textdefs.o 
build\temp.win-amd64-2.7\src\wstring.o build\temp.win-amd64-2.7\src\x86defs.o 
build\temp.win-amd64-2.7\include\mnemonics.o -lmsvcr90 -o 
build\lib\distorm3\distorm3.dll

Though it's possible on your env the files will be created in a different 
directory, but just so you get the idea.
Hope it solves your problem.

Original comment by [email protected] on 16 Apr 2011 at 3:30

from distorm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.