CmpDoFileWrite

UINT8 __stdcall CmpDoFileWrite(
        PVOID FileHandle,
        CMP_OFFSET_ARRAY *offsetArray,
        UINT64 offsetArrayCount,
        UINT64 *FileOffset,
        UINT64 Flags){
  int v6; 
  unsigned int v7; 
  INT64 v8; 
  INT64 v9; 
  unsigned int v10; 
  _DWORD *v11; 
  char *Buffer; 
  unsigned int v13; 
  HANDLE *v14; 
  NTSTATUS Event; 
  ULONG Length; 
  unsigned int v17; 
  INT64 v18; 
  _IO_PRIORITY_HINT v20; 
  unsigned int v21; 
  unsigned int v22; 
  NTSTATUS *v23; 
  unsigned int v24; 
  _IO_PRIORITY_HINT IoPriority; 
  unsigned int Priority; 
  union _LARGE_INTEGER ByteOffset; 
  char *v28; 
  char v30; 
  unsigned int v31; 
  UINT8 RespectIoPriority; 
  v31 = (unsigned int)FileOffset;
  ByteOffset.QuadPart = 0i64;
  v30 = 0;
  Priority = 0;
  IoPriority = IoPriorityVeryLow;
  v6 = (int)FileOffset;
  v7 = 0;
  CmpAllocateTransientPoolWithTag((_HHIVE *)0x200, 0x1400ui64, 0x77624D43ui64, (_CHILD_LIST *)FileOffset);
  v9 = v8;
  if( v8 )
  {
    memset(v8, 0i64);
    if( (Flags & 1) != 0 )
    {
      CmpSetIoPriorityThread((_ETHREAD *)KeGetCurrentThread(), IoPriorityVeryLow);
      IoPriority = v20;
      CmpSetPriorityThread((_ETHREAD *)KeGetCurrentThread(), 4i64);
      Priority = v21;
      v30 = 1;
    }
    RespectIoPriority = CmpSetRespectIoPriorityThread((_ETHREAD *)KeGetCurrentThread(), 1u);
    v10 = 0;
    v24 = 0;
    if( v6 )
    {
      v11 = (_DWORD *)(offsetArrayCount + 16);
      while( 1 )
      {
        Buffer = (char *)*((_QWORD *)v11 - 1);
        v13 = *v11;
        ByteOffset.QuadPart = (unsigned int)*(v11 - 4);
        v28 = Buffer;
        if( v13 )
          break;
LABEL_16:
        ++v10;
        v11 += 6;
        v24 = v10;
        if( v10 >= v31 )
          goto LABEL_17;
      }
      while( 1 )
      {
        v14 = (HANDLE *)(v9 + 8i64 * v7);
        if( !*v14 )
        {
          Event = CmpCreateEvent(SynchronizationEvent, (PVOID *)(v9 + 8i64 * v7), (KEVENT **)(v9 + 512 + 8i64 * v7));
          if( Event < 0 )
            goto LABEL_18;
          Buffer = v28;
        }
        Length = 0x100000;
        if( v13 < 0x100000 )
          Length = v13;
        if( ZwWriteFile(
               FileHandle,
               *v14,
               0i64,
               0i64,
               (PIO_STATUS_BLOCK)(v9 + 16 * (v7 + 256i64)),
               Buffer,
               Length,
               &ByteOffset,
               0i64) < 0 )
        {
          Length = 0x10000;
          if( v13 < 0x10000 )
            Length = v13;
          Event = ZwWriteFile(
                    FileHandle,
                    *v14,
                    0i64,
                    0i64,
                    (PIO_STATUS_BLOCK)(v9 + 16 * (v7 + 256i64)),
                    Buffer,
                    Length,
                    &ByteOffset,
                    0i64);
          if( Event < 0 )
            goto LABEL_18;
          Buffer = v28;
        }
        v13 -= Length;
        ByteOffset.QuadPart += Length;
        Buffer += Length;
        ++v7;
        v28 = Buffer;
        if( v7 == 64 )
          break;
LABEL_14:
        if( !v13 )
        {
          v10 = v24;
          goto LABEL_16;
        }
      }
      KeWaitForMultipleObjects(
        (_BYTE *)0x40,
        (VOID **)(v9 + 512),
        WaitAll,
        Executive,
        0,
        0,
        0i64,
        (_KWAIT_BLOCK *)(v9 + 1024));
      v22 = 0;
      v23 = (NTSTATUS *)(v9 + 4096);
      v7 = 0;
      while( 1 )
      {
        Event = *v23;
        if( *v23 < 0 )
          break;
        ++v22;
        v23 += 4;
        if( v22 >= 0x40 )
        {
          Buffer = v28;
          goto LABEL_14;
        }
      }
    }
    else
    {
LABEL_17:
      LOBYTE(Event) = 0;
LABEL_18:
      if( v7 )
        KeWaitForMultipleObjects(
          (_BYTE *)v7,
          (VOID **)(v9 + 512),
          WaitAll,
          Executive,
          0,
          0,
          0i64,
          (_KWAIT_BLOCK *)(v9 + 1024));
    }
    if( v30 )
    {
      CmpSetIoPriorityThread((_ETHREAD *)KeGetCurrentThread(), IoPriority);
      CmpSetPriorityThread((_ETHREAD *)KeGetCurrentThread(), Priority);
    }
    CmpSetRespectIoPriorityThread((_ETHREAD *)KeGetCurrentThread(), RespectIoPriority);
    v17 = 0;
    v18 = v9;
    do
    {
      if( !*(_QWORD *)v18 )
        break;
      HalPutDmaAdapter(*(PADAPTER_OBJECT *)(v18 + 512));
      ZwClose(*(HANDLE *)v18);
      ++v17;
      v18 += 8i64;
    }
    while( v17 < 0x40 );
    CmSiFreeMemory((PPRIVILEGE_SET)v9);
  }
  else
  {
    LOBYTE(Event) = -102;
  }
  return Event;
}

Referenced by:

CmpFileWrite
CmpWriteOffsetArrayToFile