Jump to content











Photo
- - - - -

Use ImDisk API from Python


  • Please log in to reply
6 replies to this topic

#1 NameZero912

NameZero912
  • Members
  • 2 posts
  •  
    Germany

Posted 08 December 2015 - 08:08 AM

Hi everyone. I'd like to use ImDisk from a Python program. Under Windows, Python allows to load C DLLs using a module called "ctypes", which is very powerful.

 

However, ImDisk seems to provide only COM and .NET DLLs for API access (which I cannot use from Python that easily). Is it possible to compile a "normal" C-only DLL (i.e. a DLL with a bunch of 'extern "C"' exported functions)? If so, how? I'm a bit familiar with MSVS, but it seems the source code projects won't open at all in MSVS, and just the console-only nmake is used for compilation.

 

Cheers!



#2 Olof Lagerkvist

Olof Lagerkvist

    Gold Member

  • Developer
  • 1448 posts
  • Location:Borås, Sweden
  •  
    Sweden

Posted 08 December 2015 - 09:09 AM

ImDisk has a "normal" C/C++ API as well. Actually, the .NET and COM API are only layers above and use just forward requests to the underlying C/C++ API. The C/C++ API functions are declared in inc\imdisk.h in the source archive and the dll file that exports the functions is imdisk.cpl.

 

Edit: Btw, I am not very familiar with Python myself, but I am sure I have seen people using the C/C++ API for ImDisk from Python programs once in a while. Isn't there any examples online anywhere? I would have sort of expected that nowadays.



#3 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 08 December 2015 - 09:57 AM

ImDisk has a "normal" C/C++ API as well. Actually, the .NET and COM API are only layers above and use just forward requests to the underlying C/C++ API. The C/C++ API functions are declared in inc\imdisk.h in the source archive and the dll file that exports the functions is imdisk.cpl.

 

Edit: Btw, I am not very familiar with Python myself, but I am sure I have seen people using the C/C++ API for ImDisk from Python programs once in a while. Isn't there any examples online anywhere? I would have sort of expected that nowadays.

Sure, there is an EWF/LibEWF extension written in Python:

http://reboot.pro/to...m-disk-formats/

http://www.schatzfor...vailable-tools/

Cannot say if the above will be useful for the OP, though. :unsure:

 

:duff:

Wonko



#4 NameZero912

NameZero912
  • Members
  • 2 posts
  •  
    Germany

Posted 08 December 2015 - 10:37 AM

Hi. I checked out the LibEWF Project (also their sources on Github) but don't find it useful for my purpose.

 

I've managed to create my own MSVS DLL Project and I started defining functions that internally use the functions from imdisk.h.

 

For the API's usage instructions I'll take a closer look at the CLI-client's source code.

 

I'm a bit bummed that I'll have to run my programs in elevated mode (admin rights) because of Windows Vista (and newer) requiring elevated access rights for formatting a drive.



#5 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 08 December 2015 - 11:28 AM

I'm a bit bummed that I'll have to run my programs in elevated mode (admin rights) because of Windows Vista (and newer) requiring elevated access rights for formatting a drive.

Well, that might depend on which filesystem you want to use, if you are after NTFS probably yes, but if you want to create a FAT12/16/32 filesystem you can maybe apply a bunch of populated sectors to the image.

A thing that was done in the good ol'days was to create a minimal filesystem and then enlarge it, cannot remember if this also needs Administrator rights :unsure: under post-XP OS's.

 

:duff:

Wonko



#6 Olof Lagerkvist

Olof Lagerkvist

    Gold Member

  • Developer
  • 1448 posts
  • Location:Borås, Sweden
  •  
    Sweden

Posted 08 December 2015 - 11:48 AM

Sure, there is an EWF/LibEWF extension written in Python:

http://reboot.pro/to...m-disk-formats/

http://www.schatzfor...vailable-tools/

Cannot say if the above will be useful for the OP, though. :unsure:

 

That Python program does not use the ImDisk API, it rather calls out to imdisk.exe for actual mounting. That works of course for simple tasks, but for instance to query information about mounted devices etc the API would be a lot better. But I am a little bit surprised that I don't seem to find anything better than this either. I was sure that I had seen some other Python integration some years ago.



#7 Olof Lagerkvist

Olof Lagerkvist

    Gold Member

  • Developer
  • 1448 posts
  • Location:Borås, Sweden
  •  
    Sweden

Posted 08 December 2015 - 12:19 PM

However, ImDisk seems to provide only COM and .NET DLLs for API access (which I cannot use from Python that easily). Is it possible to compile a "normal" C-only DLL (i.e. a DLL with a bunch of 'extern "C"' exported functions)? If so, how? I'm a bit familiar with MSVS, but it seems the source code projects won't open at all in MSVS, and just the console-only nmake is used for compilation.

 

I forgot to comment this part. The latest 2.0.7 and 2.0.8 (released today) versions should open in Visual Studio as well. The nmake/build scripts are used for actually building with WDK 7.1.0 to make sure that we get binaries compatible with older versions of Windows than Windows 7. But it should be possible to build everything in Visual Studio as well these days.

 

Note that if you want to build the drivers (awealloc.sys and imdisk.sys) you need to install WDK 8.1 so that Visual Studio finds needed platform toolset for building drivers. But I guess that building the drivers is not something that you need, you could just unload those projects from the solution before you start to build.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users