Git Product home page Git Product logo

Comments (22)

LTRData avatar LTRData commented on August 17, 2024 1

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.

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024 1

It work now ty 👍

from arsenal-image-mounter.

LTRData avatar LTRData commented on August 17, 2024

You could take a look at the source code for aim_ll.exe:

https://github.com/ArsenalRecon/Arsenal-Image-Mounter/blob/master/Unmanaged%20Source/aim_ll/aimcmd.cpp

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

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,
        &sector_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;
}

from arsenal-image-mounter.

LTRData avatar LTRData commented on August 17, 2024

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.

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

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?

from arsenal-image-mounter.

LTRData avatar LTRData commented on August 17, 2024

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.

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

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?

from arsenal-image-mounter.

LTRData avatar LTRData commented on August 17, 2024

Yes you need to include common.h as well. There are some type definitions in there.

https://github.com/ArsenalRecon/Arsenal-Image-Mounter/blob/c91fb636fe559b9985619fe1a7c6bf779a3d63ea/Unmanaged%20Source/phdskmnt/inc/common.h

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

Adding common.h I'm able to compile it.
But when I execute, it return without nothing do or write to console.

from arsenal-image-mounter.

LTRData avatar LTRData commented on August 17, 2024

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.

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

The problem is that API function not return value and not execute next instruction.
It is as have a silent crash.

from arsenal-image-mounter.

LTRData avatar LTRData commented on August 17, 2024

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.

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

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.

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

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:\

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

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.

from arsenal-image-mounter.

LTRData avatar LTRData commented on August 17, 2024

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.

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

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?

from arsenal-image-mounter.

LTRData avatar LTRData commented on August 17, 2024

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

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

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?

from arsenal-image-mounter.

lollita avatar lollita commented on August 17, 2024

Do it is normal that if I include aimapi.lib again I need aimapi.dll ?

from arsenal-image-mounter.

LTRData avatar LTRData commented on August 17, 2024

Do it is normal that if I include aimapi.lib again I need aimapi.dll ?

Yes.

from arsenal-image-mounter.

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.