NtManagePartition

NTSTATUS __fastcall NtManagePartition(
        VOID *TargetHandle,
        VOID *SourceHandle,
        _MEMORY_PARTITION_INFORMATION_CLASS PartitionInformationClass,
        VOID *PartitionInformation){
  __int64 v5; 
  char PreviousMode; 
  int v9; 
  __int64 v10; 
  _KPROCESSOR_MODE v11; 
  INT64 v12; 
  int v13; 
  int v14; 
  int v15; 
  int v16; 
  int v17; 
  int v18; 
  NTSTATUS PagingFile; 
  UINT64 Flags; 
  char v22; 
  char v23; 
  INT64 v24; 
  __int64 v25[2]; 
  INT64 Src[30]; 
  size_t Size; 

  v5 = (unsigned int)PartitionInformationClass;
  memset(Src, 0i64, sizeof(Src));
  v23 = 0;
  v22 = 0;
  PreviousMode = KeGetCurrentThread()->PreviousMode;
  v25[0] = 0i64;
  v24 = 0i64;
  if( (unsigned int)v5 >= 9 )
  {
    v9 = -1073741821;
    goto LABEL_47;
  }
  v10 = v5;
  if( Size != WORD2(PspPartitionInfoDetails[v5]) )
  {
    v9 = -1073741820;
    goto LABEL_47;
  }
  if( (PspPartitionInfoDetails[v5] & 0x100000000000000i64) != 0 )
  {
    if( PreviousMode && Size )
    {
      if( ((BYTE6(PspPartitionInfoDetails[v5]) - 1i64) & (unsigned __int64)PartitionInformation) != 0 )
        ExRaiseDatatypeMisalignment();
      if( (unsigned __int64)PartitionInformation + Size > 0x7FFFFFFF0000i64
        || (char *)PartitionInformation + Size < PartitionInformation )
      {
        MEMORY[0x7FFFFFFF0000] = 0;
      }
    }
    memmove(Src, PartitionInformation, Size);
  }
  v9 = PsReferencePartitionByHandle(TargetHandle, LODWORD(PspPartitionInfoDetails[v5]), PreviousMode, 0x704D7350u, &v24);
  if( v9 >= 0 )
  {
    v22 = 1;
    if( (PspPartitionInfoDetails[v5] & 0x400000000000000i64) != 0 )
    {
      v9 = PsReferencePartitionByHandle(
             SourceHandle,
             LODWORD(PspPartitionInfoDetails[v5]),
             PreviousMode,
             0x704D7350u,
             v25);
      if( v9 < 0 )
        goto LABEL_47;
      v23 = 1;
      if( v25[0] == v24 )
        goto LABEL_17;
    }
    else if( SourceHandle )
    {
      v9 = -1073741584;
      goto LABEL_47;
    }
    if( !(_DWORD)v5 )
    {
      PagingFile = MmManagePartitionMemoryInformation((UINT16 **)v24, (INT64)Src);
      goto LABEL_41;
    }
    v13 = v5 - 1;
    if( !v13 )
    {
      PagingFile = MmManagePartitionMoveMemory(
                     (_MI_PARTITION **)v24,
                     (_MI_PARTITION **)v25[0],
                     (__int64)Src,
                     PreviousMode);
      goto LABEL_41;
    }
    v14 = v13 - 1;
    if( !v14 )
    {
      LODWORD(Flags) = Src[4];
      LOBYTE(v12) = PreviousMode;
      PagingFile = MiCreatePagingFile(
                     (_UNICODE_STRING *)PartitionInformation,
                     (_LARGE_INTEGER *)PartitionInformation + 2,
                     (_LARGE_INTEGER *)PartitionInformation + 3,
                     v12,
                     Flags,
                     *(_MI_PARTITION **)v24);
      goto LABEL_41;
    }
    v15 = v14 - 1;
    if( !v15 )
    {
      LOBYTE(v12) = PreviousMode;
      PagingFile = MmManagePartitionCombineMemory((UINT64 **)v24, (INT64)Src, (INT64)PartitionInformation, v12);
      goto LABEL_41;
    }
    v16 = v15 - 1;
    if( !v16 )
    {
      PagingFile = MmManagePartitionInitialAddMemory((UINT64 *)v24, Src, (INT64)PartitionInformation, PreviousMode);
      goto LABEL_41;
    }
    v17 = v16 - 1;
    if( !v17 )
    {
      LOBYTE(v11) = PreviousMode;
      PagingFile = MmManagePartitionGetMemoryEvents((PVOID **)v24, (INT64)Src, v11);
      goto LABEL_41;
    }
    v18 = v17 - 1;
    if( v18 )
    {
      if( v18 == 1 )
        PagingFile = MmManagePartitionNodeInformation(v24, (UINT64 *)Src, PreviousMode);
      else
        PagingFile = MmManagePartitionCreateLargePages((pHalIoWritePartitionTable **)v24, (INT64)Src, PreviousMode);
LABEL_41:
      v9 = PagingFile;
      if( PagingFile < 0 )
        goto LABEL_47;
      goto LABEL_42;
    }
    if( !Src[0] )
    {
      v9 = 0;
LABEL_42:
      if( (PspPartitionInfoDetails[v10] & 0x200000000000000i64) != 0 )
      {
        if( PreviousMode )
          ProbeForWrite((UINT64)PartitionInformation, Size, BYTE6(PspPartitionInfoDetails[v10]));
        memmove(PartitionInformation, Src, Size);
      }
      goto LABEL_47;
    }
    if( (Src[0] & 0xFFFFFFFFFFFFFFFCui64) != 0 || *(_MI_PARTITION **)v24 == &Irp )
    {
LABEL_17:
      v9 = -1073741811;
      goto LABEL_47;
    }
    v9 = PreviousMode != 0 ? -1073741727 : -1073741637;
  }
LABEL_47:
  if( v22 )
    PsDereferencePartition(v24);
  if( v23 )
    PsDereferencePartition(v25[0]);
  return v9;
}

Referenced by:

No references.