VhdiMountVhdFile
INT64 __fastcall VhdiMountVhdFile(WCHAR *VhdFileName){
NTSTATUS DeviceInterfaces;
WCHAR v3;
PZZWSTR v4;
__int64 v5;
__int64 v6;
unsigned int v7;
unsigned int v8;
char *PoolWithTag;
void *v10;
unsigned int v11;
_DWORD *v12;
_IRP *v13;
char *v14;
WCHAR v15;
__int128 v16;
PZZWSTR v17;
_DEVICE_OBJECT *RelatedDeviceObject;
_IRP *v19;
UINT64 FileAttributes;
UINT64 FileAttributesa;
UINT64 FileAttributesb;
UINT64 ShareAccess;
UINT64 CreateDisposition;
UINT64 CreateOptions;
UINT64 EaLength;
_KEVENT Object_8;
PZZWSTR SymbolicLinkList;
PDEVICE_OBJECT DeviceObject;
PFILE_OBJECT FileObject;
struct _IO_STATUS_BLOCK IoStatusBlock;
struct _UNICODE_STRING DestinationString;
struct _UNICODE_STRING v34;
struct _OBJECT_ATTRIBUTES ObjectAttributes;
INT64 result[4];
__int128 v37;
__int128 v38;
__int128 v39;
int v40;
__int128 InputBuffer[3];
__int64 v42;
int EaBuffer[2];
__int64 v44;
GUID v45;
__int128 v46;
__int128 v47;
__int128 v48;
__int128 v49;
int v50;
int v51;
PVOID retaddr;
DeviceObject = 0i64;
SymbolicLinkList = 0i64;
v42 = 0i64;
FileObject = 0i64;
DestinationString = 0i64;
memset(&Object_8, 0, sizeof(Object_8));
v34 = 0i64;
IoStatusBlock = 0i64;
memset(&ObjectAttributes, 0, sizeof(ObjectAttributes));
memset(InputBuffer, 0, sizeof(InputBuffer));
if( !VhdFileName )
{
DeviceInterfaces = -1073741811;
goto LABEL_3;
}
memset((INT64)result, 0i64);
DeviceInterfaces = IoGetDeviceInterfaces(&GUID_DEVINTERFACE_SURFACE_VIRTUAL_DRIVE, 0i64, 0, &SymbolicLinkList);
if( DeviceInterfaces < 0 )
goto LABEL_3;
v4 = SymbolicLinkList;
if( !*SymbolicLinkList )
{
DeviceInterfaces = -1073741275;
goto LABEL_3;
}
RtlInitUnicodeString(&DestinationString, SymbolicLinkList, v3);
DeviceInterfaces = IoGetDeviceObjectPointer(&DestinationString, 0x10000000ui64, &FileObject, &DeviceObject);
if( DeviceInterfaces < 0 )
goto LABEL_3;
v5 = -1i64;
v6 = -1i64;
do
++v6;
while( VhdFileName[v6] );
v7 = 2 * v6 + 2;
v8 = 2 * v6 + 34;
PoolWithTag = (char *)ExAllocatePoolWithTag(NonPagedPoolNx, v8, 0x42646856ui64);
v10 = PoolWithTag;
if( !PoolWithTag )
goto LABEL_11;
*((_DWORD *)PoolWithTag + 1) = 0;
*(GUID *)(PoolWithTag + 8) = VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN;
*(_DWORD *)PoolWithTag = 1;
*((_DWORD *)PoolWithTag + 6) = 32;
*((_DWORD *)PoolWithTag + 7) = v7;
memmove((UINT8 *)PoolWithTag + 32, (UINT8 *)VhdFileName, v7);
v11 = v7 + 540;
v12 = ExAllocatePoolWithTag(NonPagedPoolNx, v11, 0x42646856ui64);
if( !v12 )
{
LABEL_11:
DeviceInterfaces = -1073741801;
goto LABEL_3;
}
Object_8.Header.WaitListHead.Blink = &Object_8.Header.WaitListHead;
Object_8.Header.SignalState = 0;
Object_8.Header.WaitListHead.Flink = &Object_8.Header.WaitListHead;
LODWORD(FileAttributes) = v11;
LOWORD(Object_8.Header.Lock) = 1;
Object_8.Header.Size = 6;
v13 = IopBuildDeviceIoControlRequest(
0x2D592Cui64,
DeviceObject,
v10,
v8,
v12,
FileAttributes,
0,
&Object_8,
&IoStatusBlock,
retaddr);
if( !v13 )
goto LABEL_14;
DeviceInterfaces = IofCallDriver(DeviceObject, v13);
if( DeviceInterfaces == 259 )
{
KeWaitForSingleObject(&Object_8, Executive, 0, 0, 0i64);
DeviceInterfaces = IoStatusBlock.Status;
}
if( DeviceInterfaces < 0 )
goto LABEL_3;
v14 = (char *)v12 + (unsigned int)v12[5];
if( *(_WORD *)v14 == 92 && *((_WORD *)v14 + 1) == 92 && *((_WORD *)v14 + 2) == 46 && *((_WORD *)v14 + 3) == 92 )
*(_DWORD *)(v14 + 2) = 4128831;
do
++v5;
while( VhdFileName[v5] );
wcscat_s((WCHAR *)v14, (unsigned int)(v5 + 257), VhdFileName);
RtlInitUnicodeString(&v34, (PCWSTR)v14, v15);
LODWORD(EaLength) = 103;
ObjectAttributes.ObjectName = &v34;
ObjectAttributes.Length = 48;
v51 = 0;
ObjectAttributes.RootDirectory = 0i64;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
ObjectAttributes.Attributes = 512;
*(_QWORD *)((char *)&v37 + 4) = 0x400000054i64;
v44 = 0x4B534454524956i64;
EaBuffer[0] = 0;
EaBuffer[1] = 5506944;
v16 = *(_OWORD *)v12;
LODWORD(v37) = v12[4];
v46 = v16;
DWORD1(v38) = 2;
v50 = v40;
LODWORD(CreateOptions) = 0;
LODWORD(CreateDisposition) = 2;
v45 = GUID_DEVINTERFACE_SURFACE_VIRTUAL_DRIVE;
LODWORD(ShareAccess) = 1;
v47 = v37;
LODWORD(FileAttributesa) = 128;
v48 = v38;
v49 = v39;
DeviceInterfaces = ZwCreateFile(
&FileHandle,
0x80000000ui64,
&ObjectAttributes,
&IoStatusBlock,
0i64,
FileAttributesa,
ShareAccess,
CreateDisposition,
CreateOptions,
EaBuffer,
EaLength);
if( DeviceInterfaces < 0 )
goto LABEL_3;
SymbolicLinkList = 0i64;
DeviceInterfaces = ObReferenceObjectByHandle(FileHandle, 0xC0100000, 0i64, 0, (PVOID *)&SymbolicLinkList, 0i64);
if( DeviceInterfaces < 0 )
goto LABEL_3;
v17 = SymbolicLinkList;
RelatedDeviceObject = IoGetRelatedDeviceObject((_FILE_OBJECT *)SymbolicLinkList);
LODWORD(InputBuffer[0]) = 1;
LOWORD(Object_8.Header.Lock) = 1;
Object_8.Header.WaitListHead.Blink = &Object_8.Header.WaitListHead;
Object_8.Header.Size = 6;
Object_8.Header.WaitListHead.Flink = &Object_8.Header.WaitListHead;
Object_8.Header.SignalState = 0;
LODWORD(FileAttributesb) = 0;
v19 = IopBuildDeviceIoControlRequest(
0x2D191Cui64,
RelatedDeviceObject,
InputBuffer,
0x38ui64,
0i64,
FileAttributesb,
0,
&Object_8,
&IoStatusBlock,
retaddr);
if( !v19 )
{
LABEL_14:
DeviceInterfaces = -1073741670;
goto LABEL_3;
}
*(_QWORD *)(*((_QWORD *)v19 + 23) - 24i64) = v17;
DeviceInterfaces = IofCallDriver(RelatedDeviceObject, v19);
if( DeviceInterfaces == 259 )
{
KeWaitForSingleObject(&Object_8, Executive, 0, 0, 0i64);
DeviceInterfaces = IoStatusBlock.Status;
}
if( DeviceInterfaces < 0 )
LABEL_3:
KeBugCheckEx(0x12Fu, 5ui64, DeviceInterfaces, 0i64, 0i64);
ExFreeHeapPool(v10);
ExFreeHeapPool(v12);
if( v17 )
ObfDereferenceObjectWithTag(v17, 0x746C6644ui64);
if( FileObject )
ObfDereferenceObjectWithTag(FileObject, 0x746C6644ui64);
ExFreeHeapPool(v4);
return(unsigned int)DeviceInterfaces;
}Referenced by:
VhdInitialize