Closed lollita closed 7 months ago
You could take a look at the source code for aim_ll.exe:
I tryed to mount a vhd but not able:
#include <windows.h>
#include <iostream>
#include "common.h"
#include "aimapi.h"
#pragma comment(lib,"aimapi.lib")
int main()
{
//LPWSTR letter = new TCHAR[3];
//wmemcpy(letter, L"F:", 3);
DEVICE_NUMBER device_number;
device_number.LongNumber = IMSCSI_AUTO_DEVICE_NUMBER;
DWORD sector_size = 4096;
DWORD flags = IMSCSI_DEVICE_TYPE_HD| IMSCSI_TYPE_VM;// IMSCSI_TYPE_FILE | IMSCSI_TYPE_PROXY | IMSCSI_PROXY_TYPE_SHM
BOOL aim = ImScsiCreateDeviceEx(
NULL,
INVALID_HANDLE_VALUE,
&device_number,
NULL,
§or_size,
NULL,
&flags,
L"\\??\\vhdaccess\\??\\awealloc\\??\\E:\\Temp\\temp.vhd",
//L"\\??\\E:\\Temp\\temp.vhd",
NULL,
FALSE,//TRUE
NULL,//letter
FALSE
);
wprintf(L"end aim: %d err: %d, id: %06x, sect: %d", aim GetLastError(), device_number.LongNumber, sector_size);
//std::cout << "Hello World!\n";
return 0;
}
I tryed to mount a vhdx but not able:
#include <windows.h> #include "aimapi.h" #pragma comment(lib,"aimapi.lib") #include <iostream> int main() { BOOL ami=ImScsiCreateDevice(NULL, INVALID_HANDLE_VALUE, NULL, 0, 0, 0, 0, L"\\\\?\\vhdaccess\\??\\awealloc\\??\\c:\\temp.vhd", TRUE, (LPWSTR)L"Q:", FALSE); std::cout << "Hello World!\n"; }
You have the Adapter
and DeviceNumber
parameters in the wrong order. Also, the NativePath
parameter should be FALSE
in this case.
Changed NativePath. I see Adapter and DeviceNumber parameters ordered as 2 and 3; why wrong? I set (LPWSTR)L"Q:", but the lettere is in vhdx, as set it?
Changed NativePath. I see Adapter and DeviceNumber parameters ordered as 2 and 3; why wrong?
No sorry, my mistake. You are right!
I set (LPWSTR)L"Q:", but the lettere is in vhdx, as set it?
I do not understand what you mean here. The parameter for mount point looks correct if you want Q: as drive letter.
Also note that what you are trying to do only works for vhd just like in your example code, note vhdx.
my mistake I use vhd not vhdx. You are right! I mean that I set letter in vhd from OS disk management and aim not need it. What about error list that not compile it?
Yes you need to include common.h as well. There are some type definitions in there.
Adding common.h I'm able to compile it. But when I execute, it return without nothing do or write to console.
Adding common.h I'm to compile it. But when I execute, it return without nothing do or write to console.
You need to check return value of API function and call GetLastError
to find out what is going wrong.
The problem is that API function not return value and not execute next instruction. It is as have a silent crash.
The problem is that API function not return value and not execute next instruction. It is as have a silent crash.
Run a debug build inside Visual Studio and select to stop at exceptions etc and see what happens.
You are right! I have to use debug:
Unhandled exception at 0x00007FF9610C3310 (aimapi.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'.
The thread 0x15a8 has exited with code 0 (0x0).
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\bcrypt.dll'.
Exception thrown at 0x00007FF95FFA3310 (aimapi.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
Unhandled exception at 0x00007FF95FFA3310 (aimapi.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
The program '[10180] ConsoleApplication1.exe' has exited with code 0 (0x0).
I updated the source.
I updated the source. Now it not have error and work fine with regular mount vhd file. But I need a again a few step, why L"\\?\vhdaccess\??\awealloc\??\E:\Temp\temp.vhd" not work. I get device but not mount volume:
Device number 000100
Device is \\?\PhysicalDrive4
Image file: \??\vhdaccess\??\awealloc\??\E:\Temp\temp.vhd
Size: 2147483648 bytes (2 GB), Queued unbuffered I/O Image File, HDD, Modified.
same vhd file work fine with command line:
aim_ll.exe -a -f \\?\vhdaccess\??\awealloc\??\E:\Temp\temp.vhd
Device number 000100
Device is \\?\PhysicalDrive4
Image file: \??\vhdaccess\??\awealloc\??\E:\Temp\temp.vhd
Size: 2147483648 bytes (2 GB), Queued unbuffered I/O Image File, HDD, Modified.
Contains volume \\?\Volume{2c975252-ec13-11ed-bb88-5e6c3a1f8af4}\
Mounted at F:\
Now it mount if I use | IMSCSI_TYPE_VM and \??\vhdaccess but it have set "online" from os disk manager. Which piece I still miss?
p.s. I solved this too. The problem is I use a vhd already mounted. But also here, via aim_ll.exe it worked in the same way.
Now it mount if I use | IMSCSI_TYPE_VM and \??\vhdaccess but it have set "online" from os disk manager. Which piece I still miss?
p.s. I solved this too. The problem is I use a vhd already mounted. But also here, via aim_ll.exe it worked in the same way.
IMSCSI_TYPE_VM is not correct here. It would just allocate a large amount of virtual memory for the entire disk size at once, which is not what you want here.
You are right! code work also without IMSCSI_TYPE_VM. I have other strange problem. This code compile and work fine in console application. But if I use same code in dll library I get:
Severity Code Description Project File Line Suppression State
Error (active) E0020 identifier "PSTORAGE_DEVICE_NUMBER" is undefined Test c:\aimapi.h 494
Error C2061 syntax error: identifier 'PSTORAGE_DEVICE_NUMBER' Test 494
how is it possible?
Here is documentation about that structure and what header files you need to include: https://learn.microsoft.com/en-us/windows/win32/api/winioctl/ns-winioctl-storage_device_number
With winioctl.h now compile, but when try to use my DLL including ImScsiCreateDevice with extern "C" _declspec(dllexport) I get "1 = unable to use the DLL file". If I remove AMI routine in my dll it turn to work. Do it not possibile to use in dll?
With winioctl.h now compile, but when try to use my DLL including ImScsiCreateDevice with DLL_EXPORT I get "1 = unable to use the DLL file". If I remove AMI routine in my dll it turn to work. Do it not possibile to use in dll?
If you just include aimapi.h and other header dependencies and use #pragma comment
or similar to link to aimapi.lib, this should work and your DLL should be able to import functions through a depency on aimapi.dll.
It work now ty 👍
Do it is normal that if I include aimapi.lib again I need aimapi.dll ?
Do it is normal that if I include aimapi.lib again I need aimapi.dll ?
Yes.
I tryed to ask c++ code for AIM to ChatGPT but not work. Also google nothing found about "aimapi.h".
Also Powershell code not work: