Flag: Tornado! Hurricane!

Blogs >> apridgen's Blog

Created: Tuesday, April 22 2008 20:32.48 CDT Modified: Friday, May 9 2008 21:31.18 CDT
Printer Friendly ...
PyVix, Python Bindings for the VMWare VIX SDK
Author: apridgen # Views: 17621

I am not sure how many people use PyVix, but I took some time to go through and update the project.  The project was originally developed by David S. Rushby, and the project provides Python Bindings for VMWare's VIX SDK.    

It looks like the API has not been updated in a while, so rather than just throwing a patch somewhere on the web just to be lost, I posted my updates on Google Code.  The source code can be downloaded from here:

svn checkout http://randomizedcode.googlecode.com/svn/trunk/pyvix-branch pyvix

or in tar ball form here:

http://randomizedcode.googlecode.com/files/latest-pyvix-4.22.2008.tgz

I have only installed this on Linux, but it should install in Windows too.

Prerequisites:

VMWare's VIX SDK
C/C++ compiler (MinGW/GCC)

To Install, drop prompt:

sudo python setup.py install

Updates:

1) I ran into some problems building on Windows Vista for 6.03 using mingw32, so I am still trying to figure out how to build them at this time,

2) Adam35413 pointed this out, and the path needs to be updated to include the _vixmodule.so's path, or it can simply be added to /lib.  

Sorry if anyone ran into problems.  


Blog Comments
cowmix Posted: Monday, May 19 2008 14:58.00 CDT
Hmm.. I'm doing something REALLY wrong here..

cowmix@homewerk5:~/VMWARE/pyvix/latest-pyvix-4.22.2008$ sudo python setup.py install
running install
running build
running build_py
copying ./vix.py -> build/lib.linux-i686-2.5/pyvix
running build_ext
building 'pyvix._vixmodule' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -UNDEBUG -I/usr/include/vmware-vix/ -I/usr/include/python2.5 -c _vixmodule.c -o build/temp.linux-i686-2.5/_vixmodule.o -fno-strict-aliasing
In file included from _vixmodule.c:10:
util.c: In function �pyf_extractNthProperty�:
util.c:98: warning: implicit declaration of function �VixJob_GetNthProperties�
In file included from _vixmodule.c:13:
callback_accumulator.c: In function �VixCallback_accumulateProcessList�:
callback_accumulator.c:120: warning: implicit declaration of function �VixJob_GetNumProperties�
callback_accumulator.c:120: error: �VIX_PROPERTY_JOB_RESULT_ITEM_NAME� undeclared (first use in this function)
callback_accumulator.c:120: error: (Each undeclared identifier is reported only once
callback_accumulator.c:120: error: for each function it appears in.)
callback_accumulator.c:137: error: �VIX_PROPERTY_JOB_RESULT_PROCESS_ID� undeclared (first use in this function)
callback_accumulator.c:140: error: �VIX_PROPERTY_JOB_RESULT_PROCESS_OWNER� undeclared (first use in this function)
callback_accumulator.c:145: error: �VIX_PROPERTY_JOB_RESULT_PROCESS_COMMAND� undeclared (first use in this function)
callback_accumulator.c: In function �VixCallback_accumulateDirectoryList�:

------------------------- etc, etc, etc....................

pseudoyodel Posted: Saturday, August 16 2008 01:59.59 CDT
You need to install the vmware vix SDK from vmware.com.

http://www.vmware.com/download/sdk/vmauto.html

With that and python-dev on Ubuntu 8.04 I got as far as the module compiling and installing but now I get a segfault when I

~$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:31:22)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyvix.vix import *
>>> h = Host()

Segmentation fault

clintd Posted: Tuesday, October 7 2008 12:30.29 CDT
Recently saw your update to PyVix. Thank you!

I'm trying to get it running, but came across some issues, one I fixed, one I cannot:

1) For some installations, the Registry Key is located in 'SOFTWARE\VMware, Inc.\VMware VIX' Code for an updated _support.py after the comment. It looks first in that location, and if an exception occurs (registry key doesn't exist), looks in the previous location.

2) Can't seem to getting the C code compiling on Windows. Any one else have any luck?



# pyvix - Miscellaneous Utility Code
# Copyright 2006 David S. Rushby
# Available under the MIT license (see docs/license.txt for details).

import os.path, sys

PLATFORM_IS_WINDOWS = sys.platform.lower().startswith('win')

def findVixDir():
    if PLATFORM_IS_WINDOWS:
        import _winreg
        r = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
        
        try:
            serverInstKey = _winreg.OpenKey(r,
                r'SOFTWARE\VMware, Inc.\VMware VIX'
              )
            print serverInstKey
            try:
                serverInstDir = _winreg.QueryValueEx(
                    serverInstKey, 'InstallPath'
                  )[0]
            finally:
                _winreg.CloseKey(serverInstKey)
                vixDir = serverInstDir
        except WindowsError:
            try:
                serverInstKey = _winreg.OpenKey(r,
                    r'SOFTWARE\VMware, Inc.\VMware Server'
                  )
                try:
                    serverInstDir = _winreg.QueryValueEx(
                        serverInstKey, 'InstallPath'
                      )[0]
                finally:
                    _winreg.CloseKey(serverInstKey)
            finally:
                vixDir = os.path.join(serverInstDir, os.pardir, 'VMware VIX')
                
        finally:
            r.Close()

        if vixDir.endswith(os.sep):
            vixDir = vixDir[:-len(os.sep)]
        vixDir = os.path.normpath(vixDir)
        return vixDir

clintd Posted: Tuesday, October 7 2008 16:22.08 CDT
I got it compiled, but it still does not work yet.

To get it compiled, I just ran 'python setup.py install' after having MS Visual Studio 2003 installed. I also had copy a number of dll and lib files from my VMware VIX directory to the directory where the pyvix source was located.

The VMware VIX had several folders with some of the files in them: server-1, ws-1, ws-2, ws-3, ws-5. I guess these correspond to the different VMware apps you intend this to work with. Since I'm woring VMware Player, and there isn't an option for it, I went with ws-5.

The in python, I run
>>> import pyvix.vix

and the result is an error popping up in Windows with:

"python.exe - Unable To Locate Component"
------------------------------------------
This application has failed to start because VIX.DLL was not found. Re-installing the application may fix this problem.

And an error in Python:
Traceback <most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python25\lib\site=packages\py-vix\vix.py, line 18, in <module>
    import _vixmodule as _v # the underlying C mode
ImportError: DLL load failed: The specified module could not be found.

Not really sure why. _vixmodule.pyd was successfully compiled and stored in that directory.

Any ideas

clintd Posted: Tuesday, October 7 2008 16:29.27 CDT
Ahh!

I needed to copy all those dlls and libs to the directory in the python library as well, not just the one I compiled from.

Now that I can successfully run >>> from pyvix.vix import *
I just need to figure out how to use the library and actually see if it will do what I need!


braindrive Posted: Tuesday, November 25 2008 16:34.11 CST
How to connect to a remote VMWare server using the Host object of pyvix.vix module. For a Server running locally, I can do h = Host() and it can provide paths of all running VM's etc.

Thanks

slug Posted: Thursday, December 11 2008 07:23.43 CST
Just the same as for the local case, but you add some extra named parameters to the Host() constructor, e.g.:

remote = Host(hostName='foo.bar.com',
username='someone',password='secret')
for p in remote.findRunningVMPaths():
    print p

Tanelorn Posted: Wednesday, December 17 2008 15:56.15 CST
I installed VMware-vix-1.1.5-109488.exe under Windows XP and have not been able to compile using the default setup.py (some symbols seems missing in "C:\Program Files\VMware\VMware VIX\vix.lib").

As noted by clintd, one can choose a specific vix.lib; the ViX documentation (available in "C:\Program Files\VMware\VMware VIX\doc") calls this "Compiling Without the Wrapper Library", and hints that ws-1 is for VMware Server 1.0, ws-2 for Workstation 6.0 and ws-3 for Workstation 6.0.1 (I found no description of ws-4 and ws-5, though).

But another mode of compilation is described as "Compiling Using the Wrapper Library" and seems more generic: here, the proper lib is loaded as needed, depending on the VMWare product used.

To enable it, I replaced:
        libNames.append('vix')
by:
        libNames.append('VixAllProducts')
        libNames.append('kernel32')
        libNames.append('user32')
        libNames.append('advapi32')
        libNames.append('ole32')
        libNames.append('oleaut32')
        libNames.append('ws2_32')

HTH.

Tanelorn Posted: Wednesday, December 17 2008 16:09.00 CST
Well, no luck.

When compiling without the wrapper library, I get :
Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyvix.vix import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\Lib\site-packages\pyvix\vix.py", line 18, in <module>
    import _vixmodule as _v # The underlying C module.
ImportError: DLL load failed: The specified procedure could not be found.

And when compiling using the wrapper library, "from pyvix.vix import *" is successful but "h=Host()" segfaults, similarly to pseudoyodel above :-(

How would you debug those?

Regards.

Tanelorn Posted: Tuesday, December 23 2008 01:06.53 CST
It works better now.

I have installed the lastest VIX distribution (1.6.2) and added a dependency to setup.py, which now reads:

        libDirs.append(vixDir)
        libNames.append('VixAllProducts')
        libNames.append('kernel32')
        libNames.append('user32')
        libNames.append('advapi32')
        libNames.append('ole32')
        libNames.append('oleaut32')
        libNames.append('ws2_32')
        libNames.append('shell32') # Needed by VIX 1.6.2

Note that I do not link in vix.lib; VixAllProducts does it on demand.

I also edited vm.c due to a crash in pyf_VM_powerOnOrOff: when no argument was passed, "args" was null which confused PyArg_ParseTuple. Hence the fix is:

        if (args != NULL && !PyArg_ParseTuple(args, "|i",&options)) { goto fail; }

I can now register and power on a VM from pyvix.

HTH!

On a related note, is there any gathering of pyvix users somewhere, or is this largely an abandonned project? I fail to see why, since python is considered a nice language for system administration, and pyvix definitely looks like a good tool for the trade considering how hot virtualization is currently.

Feel free to comment ;-)



Add New Comment
Comment:









There are 31,322 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
hi!
Jul/01
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit