CmpDoFileRead

VOID __fastcall CmpDoFileRead(VOID *FileHandle, INT64 a2, UINT32 a3, CHAR *a4, UINT32 a5, INT64 a6, INT64 a7){
  UINT32 v7; 
  unsigned int v9; 
  NTSTATUS v10; 
  UINT32 v11; 
  CHAR *Buffer; 
  ULONG Length; 
  NTSTATUS Status; 
  int Information; 
  PIO_STATUS_BLOCK IoStatusBlock; 
  _LARGE_INTEGER ByteOffset; 
  PVOID Object; 
  _HANDLE Event[2]; 
  _IO_STATUS_BLOCK v20; 
  UINT32 v21; 

  v21 = a3;
  ByteOffset.QuadPart = 0i64;
  *(_QWORD *)Event = 0i64;
  v7 = a3;
  Object = 0i64;
  v9 = 0x10000000;
  v20 = 0i64;
  v10 = CmpCreateEvent(SynchronizationEvent, (PVOID *)Event, (_KEVENT **)&Object);
  if( v10 < 0 )
  {
    LODWORD(IoStatusBlock) = 16;
    SetFailureLocation((_HIVE_LOAD_FAILURE *)a7, 1ui64, _CmRegistryIO, (unsigned int)v10, (UINT64)IoStatusBlock);
    return;
  }
  v11 = a5;
  if( !a5 )
    goto LABEL_12;
  Buffer = a4;
  while( 1 )
  {
    ByteOffset.QuadPart = v7;
    Length = v9;
    if( v11 <= v9 )
      Length = v11;
    Status = ZwReadFile((_HANDLE)FileHandle, Event[0], 0i64, 0i64, &v20, Buffer, Length, &ByteOffset, 0i64);
    if( Status == 259 )
    {
      KeWaitForSingleObject((UINT64)Object, 0, 0, 0, 0i64);
      Status = v20.Status;
    }
    if( Status < 0 && v9 > 0x10000 )
    {
      Buffer = a4;
      v9 >>= 1;
      goto LABEL_11;
    }
    v11 -= Length;
    v21 = Length + ByteOffset.anonymous_0.LowPart;
    Buffer = &a4[Length];
    a4 = Buffer;
    if( Status < 0 )
      break;
    if( v20.Information != Length )
    {
      ObfDereferenceObjectWithTag(Object, 0x746C6644ui64);
      ZwClose(Event[0]);
      Information = v20.Information;
      if( a7 )
      {
        *(_DWORD *)(a7 + 208) = 1;
        *(_QWORD *)(a7 + 216) = FileHandle;
        *(_DWORD *)(a7 + 224) = Information - Length;
      }
      CmRegistryIODebug = 1;
      dword_140D2DAA0 = Information - Length;
      qword_140D2DA98 = (__int64)FileHandle;
      return;
    }
LABEL_11:
    v7 = v21;
    if( !v11 )
      goto LABEL_12;
  }
  if( a7 )
  {
    *(_DWORD *)(a7 + 208) = 1;
    *(_QWORD *)(a7 + 216) = FileHandle;
    *(_DWORD *)(a7 + 224) = Status;
  }
  CmRegistryIODebug = 1;
  qword_140D2DA98 = (__int64)FileHandle;
  dword_140D2DAA0 = Status;
LABEL_12:
  ObfDereferenceObjectWithTag(Object, 0x746C6644ui64);
  ZwClose(Event[0]);
}

Referenced by:

CmpFileRead