PureBasic Interface to ImDisk

Share your advanced PureBasic knowledge/code with the community.
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

PureBasic Interface to ImDisk

Post by JHPJHP »

-----------------------------------------------------------------------------------

Download PureBasic Interface to ImDisk from My PureBasic Stuff

-----------------------------------------------------------------------------------

Announcements
PureBasic Interface to OpenCV
PureBasic Interface to WinDivert
PureBasic Interface to WinRAR
PureBasic Interface to 7-Zip
PureBasic Interface to ImDisk
Windows Services & Other Stuff
Invading Space Aliens
Death Star vs Asteroids
GIF Toolkit
LSB Image Steganography
Spider Web Drawing
Deform Image: MLS
Video Snipping Tool
Chromium Edge WebGadget
IAccessible Interface
Stitch Images: SIFT
OldSkool Fire Effect
Image Waves: LUT
YouTube Player & Downloader
MP4 Player & Downloader
Large Image Viewer
Barcode Generator
Google Translate Service
Embed JS into PureBasic
Geolocation: Google Maps
Book & Viewer & Magnify
Video for Windows: VfW
Alternate Console
Network Share Management

-----------------------------------------------------------------------------------

ImDisk Virtual Disk Driver API
- Windows NT, 2000, XP, Vista, 7, 8, 8.1 or Windows Server 2003, 2008, 2012

INCLUDED
- 16 examples, 2 service files, 6 includes

- ImDisk v2.0.10.64: http://www.ltr-data.se/opencode.html/#ImDisk
-- imdisk.cpl / imdisk.lib / imdisk.sys
-- imdisk.h, imdisk.c, imdisk_cpl.cpp, imdisk_sys.cpp, drvio.c, gpl.txt, readme.txt

- Microsoft Windows SDK
-- imapi2fs.h, imapi2sample.cpp

-----------------------------------------------------------------------------------

EXAMPLES
- CreateDevice1.pb
-- creates a RAM Disk linked to the first available drive letter
- RemoveDevice1.pb
-- removes the link between the drive and RAM Disk
- CreateDevice2.pb
-- creates an image file linked to the first available drive letter
- RemoveDevice2.pb
-- removes the link between the drive and image file
- MountDevice.pb
-- mounts an image file to virtual memory or relinks an image file
- CreateMountPoint1.pb
-- creates a MountPoint between a folder location and the first available drive letter
- RemoveMountPoint1.pb
-- removes the link between the two locations
- CreateMountPoint2.pb
-- creates a MountPoint between a folder location and a newly created folder
- RemoveMountPoint2.pb
-- removes the link between the two locations
- AdjustImageFileSize.pb
-- adjusts an image file size
- ExtendDevice.pb
-- extends the size of an image file
- SaveImageFile.pb
-- saves a device to an image file
- SaveImageFileInteractive.pb
-- saves a device to an image file interactively
- QueryDevice.pb
-- displays information about devices
- GetFormattedGeometry.pb
-- displays information about disk drives with a valid boot record signature
- CreateMountableImage.pb
-- creates a mountable image file from either a device or folder location

NOTES
- Compiler Options--Compile/Run--Current directory: binaries\
- Request Administrator mode for Windows Vista and above: checked
-- CreateDriverService.pb: required to create the virtual device driver service
-- DeleteDriverService.pb: required to delete the virtual device driver service (may also need a reboot)
-- CreateDevice1.pb: required by the format-drive window prompt, and the HideDrive registry option
-- RemoveDevice1.pb: required by the HideDrive registry option
-- CreateDevice2.pb: required by the format-drive window prompt, and the HideDrive registry option
-- RemoveDevice2.pb: required by the HideDrive registry option
-- MountDevice.pb: required by the HideDrive registry option
-- ExtendDevice.pb: required by the device driver
-- SaveImageFile.pb: required by the DeviceIoControl function
-- SaveImageFileInteractive.pb: required by the DeviceIoControl function
-- GetFormattedGeometry.pb: required to access the BPB (BIOS Parameter Block)

-----------------------------------------------------------------------------------

Before using the ImDisk Interface for the first time run the file: CreateDriverService.pb (folder: /setservice/).
- after a reboot any virtual drives are removed, but the formatted image files remain intact and can be reused
- if a virtual drive is created or modified in memory, an image file must be saved to be available after reboot
Last edited by JHPJHP on Sat Oct 16, 2021 8:52 pm, edited 153 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
luis
Addict
Addict
Posts: 3715
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy
Contact:

Re: PureBasic Interface to ImDisk

Post by luis »

Cool stuff, not something I can try right now but wanted to say thanks for sharing it.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2453
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: PureBasic Interface to ImDisk

Post by Joakim Christiansen »

Might be cool for creating an encrypted cloud storage app. :D
I like logic, hence I dislike humans but love computers.
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Hi luis, Joakim Christiansen,

You're welcome, and thank you for commenting.

-----------------------------------------------------------------

Updated:
- added Constants, Structures, and Functions
- added folder: references
-- includes license and readme files from ImDisk

Made some minor improvements to the Service-Create/Delete scripts.

NB*: The new Functions and Structures have not been tested.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4107
Joined: Sun Apr 12, 2009 6:27 am

Re: PureBasic Interface to ImDisk

Post by RASHAD »

Hi
You did it as I expected :)
Did not test it yet but I expect again that it will be a very good stuff

Thanks JHPJHP
Egypt my love
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Hi RASHAD,

Thank you for the vote of confidence, I hope it meets your expectations. :mrgreen:

---------------------------------------------------

The entire list of available Functions have now been included, but I can't guarantee they've been correctly declared until I apply them to an example.

I've also added a couple new Procedures that include the option to hide the virtual drive.
- this is a rudimentary attempt to conceal the drive and is not very reliable

Some of the default options have been changed, most notably when removing the virtual device the folder and image file are not deleted.

NB*: It's worth noting that the device-driver service (imdisk.sys) is only needed for "Device" examples.
Last edited by JHPJHP on Mon Jan 12, 2015 5:52 pm, edited 2 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: PureBasic Interface to ImDisk

Post by heartbone »

That was some awesome detective and analytical work JHPJHP.
To help future sleuths I'm adding the word ramdisk to this thread. ;)

Because there are some who would try to run ricardo's program multiple times to attempt to recover the deleted video from the hard drive, this seems to be a better solution.
And don't forget to erase the RAM after use, although that wouldn't stop a determined hacker. ;)
Keep it BASIC.
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Hi heartbone,

Thanks for the kudos.

------------------------------------------------------

Applied various updates to the package, but moving forward is slow due to a lack of API examples.
- added: References, Constants, Structures, and Macros

------------------------------------------------------

Updated the package with additional Constants and Structures, fixing various Function declarations.
- replaced the imdisk.lib file with a newer version (x86 / x64)
- updated the references with newer versions
- removed the i64 binaries
- added an additional test script (x86 / x64)

------------------------------------------------------

Updated:
- added 1 example
-- ExtendDevice.pb: extends the size of an image file

NB*: Various other improvements have been made to multiple examples.

------------------------------------------------------

Updated:
- CreateDevice.pb: added a simple GUI interface

If the created device is less then 32 MB then the format of the drive will be FAT otherwise it's NTFS.
- FAT file systems cannot be extended using ExtendDevice.pb, but the image file size will be increased


NB*: Update also includes some general improvements to the examples.
Last edited by JHPJHP on Mon Jan 19, 2015 5:10 pm, edited 1 time in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Updated:
- fixed an inconsistency where the QUAD data type was required
- small update/patch to the example: ExtendDevice.pb
- removed the test scripts (didn't offer anything new)
- split the example: CreateMountPoint.pb
-- CreateMountPoint1.pb and CreateMountPoint2.pb
- split the example: RemoveMountPoint.pb
-- RemoveMountPoint1.pb and RemoveMountPoint2.pb

--------------------------------------------------------------

After some additional testing I noticed an issue with the DISK_GEOMETRY Structure and the LARGE_INTEGER datatype in the example: QueryDevice.pb. Even though the Structure matched the documentation I had to create an additional Structure: DISK_GEOMETRY_QUERY, modified to work with both 32bit and 64bit versions of PureBasic.

--------------------------------------------------------------

Updated
- added 5 examples
-- AdjustImageFileSize.pb: adjusts an image file size
-- SaveImageFile.pb: saves a device to an image file
-- SaveImageFileInteractive.pb: saves a device to an image file interactively
-- QueryDevice.pb: displays information about devices
-- GetFormattedGeometry.pb: displays information about disk drives with a valid boot record signature

AdjustImageFileSize.pb: This function is used to resize an image file to match the formatted size of the device and cannot be made larger. If the adjusted image file size is smaller then the format size, the next time it is "relinked" using the example: CreateDevice.pb the Windows Format tool will open.

SaveImageFileInteractive.pb: If the image file is saved using the built-in option: New MBR, when it is "linked" using the example: CreateDevice.pb the Windows Format tool will open.
Last edited by JHPJHP on Sat Jan 24, 2015 9:44 am, edited 3 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Updated:
- added 2 examples
-- CreateDevice1.pb: creates a RAM Disk linked to the first available drive letter
-- RemoveDevice1.pb: removes the link between the drive and RAM Disk
- renamed 2 examples
-- CreateDevice.pb to CreateDevice2.pb
-- RemoveDevice.pb to RemoveDevice2.pb

I used the CrystalDiskMark tool to benchmark the speed of the RAM disk, receiving similar results to those in the following link.
- https://www.raymond.cc/blog/12-ram-disk ... ite-speed/
- these are the parameters I used to compare speed between my C:\ drive and a newly created RAM disk: 5 | 50 MB.
Last edited by JHPJHP on Tue Jan 20, 2015 4:41 am, edited 10 times in total.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: PureBasic Interface to ImDisk

Post by heartbone »

Thanks for putting this package together JHPJHP and making it better explained how to interface with it.
It is something that I am saving for probable future use,
and hope that I get to develop an application that will benefit greatly from using it.

As much as the hated Vista thrashes its C: drive, I've long wondered why the OS doesn't do more in RAM.
It sure would speed things along.
Using this really makes sense for any computationally intense work that relies on multiple file I/O, to save on wear and tear.

And thanks for the link.
It led me to this: Make Firefox Faster By Putting Profile and SQLite Database in RAMDisk something that I will try very soon.
If it makes a significant difference, I'm going to identify other areas to implement its use.
It's not the same as running the OS from a SSD, but it is cheaper, and possibly safer.
Keep it BASIC.
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Hi heartbone,

You're welcome, I hope it can be of some use.

My own tests showed a speed increase from 80 MB/s ( C:\ ) to over 5000 MB/s ( RAM disk ).
- benchmark tool (5 | 50 MB): CrystalDiskMark

--------------------------------------------

Updated:
- added the FlushFileBuffers function where appropriate.

Another option would have been to use the CreateFile function instead of the OpenFile function:

Code: Select all

CreateFile_(*lpFileName, #GENERIC_READ | #GENERIC_WRITE, #FILE_SHARE_READ | #FILE_SHARE_WRITE, #Null, #OPEN_EXISTING, #FILE_FLAG_NO_BUFFERING, #Null)
I've set the max drive size (before extending) to 4GB, but if you have the RAM and would like to increase this:
- LARGE_INTEGER Structure handles QUAD type values, not to be confused with: LARGE_INTEGER union or ULARGE_INTEGER union

Code: Select all

DriveSize.LARGE_INTEGER
DriveSize\highpart = 1
DriveSize\lowpart = 1024 * 1024 * 1024
highpart.q = DriveSize\highpart * Pow(2, 32)
lowpart.q = DriveSize\lowpart * 4
Debug highpart
Debug lowpart

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

PureBasic Interface to ImDisk

Post by JHPJHP »

Updated:
- added 1 include
-- datasections.pbi
- added Constants, 1 Structure, Functions (Interfaces)
- added 2 reference files
-- imapi2fs.h, imapi2sample.cpp
- added 1 example
-- CreateMountableImage.pb: creates a mountable image file from either a device or folder location

The device examples have been updated to handle multiple links, a max size of 4 GB (ImDisk has no limit), including various other improvements.

CreateMountableImage.pb: I worked on this example for awhile, but kept hitting a wall when it came to declaring the various interfaces. Using the Microsoft site which lists the Functions alphabetically, I didn't realize my mistake until I found this post by bingo: http://www.purebasic.fr/english/viewtopic.php?t=29757.

NB*: A mountable image file cannot be created from a drive-root, or a circular reference.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
User avatar
JHPJHP
Addict
Addict
Posts: 1851
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Updated:
- CreateDevice2.pb: added a second button to mount an existing image file
-- an ISO video file, or a file created with the example: CreateMountableImage.pb can also be mounted
-- forcing ISO files to be mounted as a CD and IMG files to be mounted as a hard drive
- removed instances of the Function: ImDiskSetAPIFlags previously used to automatically force dismounting a drive and suppressing messages
-- RemoveDevice1.pb and RemoveDevice2.pb
--- if a drive lock cannot be established a messagebox will prompt with a "force dismount" option

NB*: Fixed a few issues in a couple examples, nothing worth documenting.

STATUS: Mostly Unavailable :: Downloads moved to My PureBasic Stuff; free executables, access key required for source code.
_________________
marroh
User
User
Posts: 72
Joined: Wed Aug 06, 2008 8:21 am

Re: PureBasic Interface to ImDisk

Post by marroh »

Thx! :mrgreen:
PureBASIC v5.41 LTS , Windows v8.1 x64
Forget UNICODE - Keep it BASIC !
Post Reply