IopReassignSystemRoot

UINT8 __stdcall IopReassignSystemRoot(_LOADER_PARAMETER_BLOCK *LoaderBlock, _STRING *NtDeviceName){
  NTSTATUS v3; 
  NTSTATUS v4; 
  VOID *LinkHandle; 
  _UNICODE_STRING DestinationString; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  _UNICODE_STRING v9; 
  WCHAR pszDest[256]; 

  *(&ObjectAttributes.Length + 1) = 0;
  *(&ObjectAttributes.Attributes + 1) = 0;
  LinkHandle = 0i64;
  v9 = 0i64;
  DestinationString = 0i64;
  if( RtlStringCchPrintfW(pszDest, 0x100ui64, (WCHAR *)L"\\ArcName\\%S") < 0 )
    return 0;
  RtlInitUnicodeString(&DestinationString, pszDest);
  DestinationString.MaximumLength = 512;
  while( 1 )
  {
    ObjectAttributes.Length = 48;
    ObjectAttributes.ObjectName = &DestinationString;
    ObjectAttributes.RootDirectory = 0i64;
    ObjectAttributes.Attributes = 576;
    *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
    v3 = NtOpenSymbolicLinkObject(&LinkHandle, 983041, &ObjectAttributes);
    if( v3 == -1073741788 )
      break;
    if( v3 >= 0 )
    {
      DestinationString.Length = 0;
      v4 = NtQuerySymbolicLinkObject(LinkHandle, &DestinationString, 0i64);
      ObCloseHandle(LinkHandle, 0);
      if( v4 >= 0 )
        continue;
    }
    return 0;
  }
  if( RtlUnicodeStringToAnsiString(NtDeviceName, &DestinationString, 0) < 0 )
    return 0;
  RtlInitUnicodeString(&v9, L"\\Device\\BootDevice");
  ObjectAttributes.Length = 48;
  ObjectAttributes.ObjectName = &v9;
  ObjectAttributes.RootDirectory = 0i64;
  ObjectAttributes.Attributes = 576;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  if( NtOpenSymbolicLinkObject(&LinkHandle, 983041, &ObjectAttributes) < 0 )
    return 0;
  NtMakeTemporaryObject(LinkHandle);
  ObCloseHandle(LinkHandle, 0);
  ObjectAttributes.Length = 48;
  ObjectAttributes.ObjectName = &v9;
  ObjectAttributes.RootDirectory = 0i64;
  ObjectAttributes.Attributes = 592;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  NtCreateSymbolicLinkObject(&LinkHandle, 983041, &ObjectAttributes, &DestinationString);
  ObCloseHandle(LinkHandle, 0);
  return 1;
}

Referenced by:

IoInitSystemPreDrivers