SmKmStoreFileCreate

NTSTATUS __stdcall SmKmStoreFileCreate(
        _DRIVER_OBJECT *DriverObject,
        VOID *CreateParam,
        UINT64 RegionSize,
        UINT64 RegionAlignment,
        _LARGE_INTEGER *FileSizeInOut,
        UINT64 *PerformsFileIoInOut,
        _SMKM_FILE_INFO *FileInfo,
        UINT64 *DeviceSectorSize,
        UINT64 *TotalRegionsOut,
        UINT64 *VdlNotSetOut){
  INT64 v10; 
  unsigned int v11; 
  unsigned int v13; 
  unsigned int v14; 
  UINT64 v15; 
  char v16; 
  VOID **v17; 
  VOID *v18; 
  INT64 v19; 
  LONGLONG QuadPart; 
  int Status; 
  NTSTATUS v22; 
  NTSTATUS v23; 
  unsigned int v24; 
  _SMC_CACHE_PARAMETERS *v25; 
  UINT64 v26; 
  __int128 v27; 
  UINT64 *v28; 
  __int128 v29; 
  __int128 v30; 
  _DWORD *v31; 
  INT16 v32; 
  UINT64 FileInformationClass; 
  UINT64 FileInformationClassa; 
  UINT64 FileInformationClassb; 
  INT64 FileInformationClassc; 
  INT64 v38; 
  INT64 v39; 
  char EnableHardErrors; 
  INT64 v41; 
  UINT64 PerformsFileIo; 
  int v43; 
  int v44; 
  _IO_STATUS_BLOCK IoStatusBlock; 
  unsigned int v46; 
  unsigned int v47; 
  INT64 FileInformation; 
  INT8 v49[8]; 
  PVOID NotificationEntry; 
  _SMKM_FILE_INFO FileHandle[16]; 
  PDRIVER_OBJECT DriverObjecta; 
  UINT64 *v53; 
  UINT64 *v54; 
  UINT64 *v55; 
  _LARGE_INTEGER *v56; 
  _SMKM_FILE_INFO *v57; 
  _DWORD *v58; 
  __int128 FsInformation; 
  __int64 v60; 
  __int128 v61; 
  __int64 v62; 
  __int64 v63; 

  v10 = 0i64;
  v11 = RegionSize;
  v53 = DeviceSectorSize;
  v54 = TotalRegionsOut;
  v55 = VdlNotSetOut;
  v13 = RegionAlignment;
  v58 = (_DWORD *)v63;
  DriverObjecta = (PDRIVER_OBJECT)*(&PnpReplaceEvent + 823);
  v62 = 0i64;
  v60 = 0i64;
  v47 = RegionAlignment;
  v46 = RegionSize;
  v56 = FileSizeInOut;
  v57 = FileInfo;
  IoStatusBlock = 0i64;
  FileInformation = 0i64;
  v61 = 0i64;
  *(_QWORD *)v49 = 0i64;
  FsInformation = 0i64;
  NotificationEntry = 0i64;
  memset(FileHandle, 0i64, sizeof(FileHandle));
  v14 = *FileInfo;
  v44 = 0;
  PerformsFileIo = v14;
  v43 = 0;
  IoSetThreadHardErrorMode(0);
  EnableHardErrors = v16;
  if( ((unsigned __int8)CreateParam & 1) != 0 )
  {
    v17 = (VOID **)((unsigned __int64)CreateParam & 0xFFFFFFFFFFFFFFFEui64);
    v18 = *v17;
    v19 = (INT64)v17[1];
    *(_QWORD *)&FileHandle[10] = v17[5];
    *(_QWORD *)FileHandle = v18;
    *(_QWORD *)&FileHandle[2] = v19;
    memset(v17, 0i64, 0x40u);
    CreateParam = 0i64;
    QuadPart = -1i64;
    v10 = v19;
  }
  else
  {
    QuadPart = FileSizeInOut->QuadPart;
    v19 = *(_QWORD *)&FileHandle[2];
    v18 = *(VOID **)FileHandle;
  }
  v41 = QuadPart;
  if( v13 > v11 )
  {
    Status = -1073741811;
    goto LABEL_40;
  }
  if( CreateParam )
  {
    Status = SmKmStoreFileCreateForIoType(FileHandle, (WCHAR *)CreateParam, &PerformsFileIo, v15, FileInformationClass);
    if( Status < 0 )
      goto LABEL_40;
    v18 = *(VOID **)FileHandle;
    v44 = 1;
    FileInformation = v41;
    LODWORD(FileInformationClassa) = 20;
    v22 = ZwSetInformationFile(
            *(UINT64 *)FileHandle,
            (UINT64)&IoStatusBlock,
            (INT8 *)&FileInformation,
            8ui64,
            FileInformationClassa);
    v19 = *(_QWORD *)&FileHandle[2];
    Status = v22;
    if( v22 == 259 )
    {
      KeWaitForSingleObject(*(_QWORD *)&FileHandle[2] + 152i64, 0, 0, 0, 0i64);
      Status = IoStatusBlock.Status;
    }
    if( Status < 0 )
    {
LABEL_39:
      SmKmStoreFileDelete(FileHandle);
      goto LABEL_40;
    }
    v14 = PerformsFileIo;
    if( (_DWORD)PerformsFileIo )
    {
      *(_QWORD *)v49 = v41;
      LODWORD(FileInformationClassb) = 39;
      v23 = ZwSetInformationFile((UINT64)v18, (UINT64)&IoStatusBlock, v49, 8ui64, FileInformationClassb);
      if( v23 == 259 )
      {
        KeWaitForSingleObject(v19 + 152, 0, 0, 0, 0i64);
        v23 = IoStatusBlock.Status;
      }
      if( v23 < 0 )
        v43 = 1;
    }
LABEL_20:
    v24 = v46;
    if( v41 / v46 < 0xFFFFFFFFi64 )
    {
      LODWORD(FileInformationClassb) = 3;
      Status = ZwQueryVolumeInformationFile(
                 (UINT64)v18,
                 (UINT64)&IoStatusBlock,
                 (UINT64)&FsInformation,
                 0x18ui64,
                 FileInformationClassb);
      if( Status == 259 )
      {
        KeWaitForSingleObject(v19 + 152, 0, 0, 0, 0i64);
        Status = IoStatusBlock.Status;
      }
      if( Status >= 0 )
      {
        if( !HIDWORD(v60)
          || ((HIDWORD(v60) - 1) & HIDWORD(v60)) != 0
          || HIDWORD(v60) > v47
          || HIDWORD(v60) > v24
          || HIDWORD(v60) > 0x1000 )
        {
          Status = -1070071787;
        }
        else
        {
          LODWORD(v39) = v14;
          LODWORD(FileInformationClassc) = v47;
          Status = SmKmStoreFileGetExtents((_HANDLE)v18, v19, (INT64)&v41, v24, FileInformationClassc, v38, v39);
          if( Status >= 0 )
          {
            if( v14
              || (Status = SmKmStoreFileOpenVolume(
                             *(_FILE_OBJECT **)&FileHandle[2],
                             (_FILE_OBJECT **)&FileHandle[4],
                             (PDEVICE_OBJECT *)&FileHandle[6]),
                  Status >= 0) )
            {
              if( !CreateParam || (Status = SmKmStoreFileWriteHeader(FileHandle, v14, v25, v26), Status >= 0) )
              {
                Status = IoRegisterPlugPlayNotification(
                           3i64,
                           0,
                           *(OWORD **)&FileHandle[2],
                           (UINT64)DriverObjecta,
                           (INT64)SmcVolumePnpNotification,
                           0i64,
                           (INT64 *)&NotificationEntry);
                if( Status >= 0 )
                {
                  v27 = *(_OWORD *)&FileHandle[4];
                  *(_QWORD *)&FileHandle[8] = NotificationEntry;
                  v28 = v53;
                  *(_OWORD *)v53 = *(_OWORD *)FileHandle;
                  v29 = *(_OWORD *)&FileHandle[8];
                  *((_OWORD *)v28 + 1) = v27;
                  v30 = *(_OWORD *)&FileHandle[12];
                  *((_OWORD *)v28 + 2) = v29;
                  *((_OWORD *)v28 + 3) = v30;
                  memset(FileHandle, 0i64, sizeof(FileHandle));
                  Status = 0;
                  *(_DWORD *)v54 = HIDWORD(v60);
                  *(_DWORD *)v55 = HIDWORD(PerformsFileIo);
                  v56->QuadPart = v41;
                  v31 = v58;
                  *v57 = v14;
                  *v31 = v43;
                  goto LABEL_40;
                }
              }
            }
          }
        }
      }
    }
    else
    {
      Status = -1073741811;
    }
    if( !v44 )
      goto LABEL_40;
    goto LABEL_39;
  }
  Status = ZwQueryInformationFile(v18, &IoStatusBlock, &v61, 0x18ui64, FileStandardInformation);
  if( Status == 259 )
  {
    KeWaitForSingleObject(v10 + 152, 0, 0, 0, 0i64);
    Status = IoStatusBlock.Status;
  }
  if( Status >= 0 )
  {
    v41 = *((_QWORD *)&v61 + 1);
    goto LABEL_20;
  }
LABEL_40:
  SmKmFileInfoCleanup(FileHandle);
  LOBYTE(v32) = EnableHardErrors;
  IoSetThreadHardErrorMode(v32);
  return Status;
}

Referenced by:

SmcCacheStart