MfgInitSystem

NTSTATUS __stdcall MfgInitSystem(_LOADER_PARAMETER_BLOCK *LoaderBlock){
  NTSTATUS inited; 
  __int64 v2; 
  unsigned __int16 v3; 
  WCHAR *PoolWithTag; 
  __int64 v6; 
  UINT64 DataSize; 
  UINT64 DataSizea; 
  char *DataSizeb; 
  HANDLE v10; 
  void *KeyHandle; 
  struct _OBJECT_ATTRIBUTES ObjectAttributes; 
  HANDLE Handle; 
  struct _UNICODE_STRING DestinationString; 
  struct _UNICODE_STRING ValueName; 
  __int16 pszDest[256]; 
  Handle = 0i64;
  ExpManufacturingInformation = 0i64;
  *(_QWORD *)Data = 0i64;
  inited = 0;
  v2 = *((_QWORD *)LoaderBlock + 30);
  DestinationString = 0i64;
  v10 = 0i64;
  memset(&ObjectAttributes, 0, sizeof(ObjectAttributes));
  KeyHandle = 0i64;
  ValueName = 0i64;
  v3 = *(_WORD *)(v2 + 2808);
  if( !v3 )
    return inited;
  if( v3 >= 0x80u )
    return -1073741811;
  DWORD2(ExpManufacturingInformation) = *(_DWORD *)(v2 + 2808);
  PoolWithTag = (WCHAR *)ExAllocatePoolWithTag(PagedPool, WORD5(ExpManufacturingInformation), 0x5067664Dui64);
  *(_QWORD *)Data = PoolWithTag;
  if( PoolWithTag )
  {
    inited = RtlStringCbCopyW(PoolWithTag, WORD5(ExpManufacturingInformation), *(PWCHAR *)(v2 + 2816));
    if( inited < 0 )
      goto LABEL_22;
    inited = RtlStringCbPrintfW((WCHAR *)pszDest, 0x200ui64, (WCHAR *)L"%s%s");
    if( inited < 0 )
      goto LABEL_22;
    inited = RtlInitUnicodeStringEx(&DestinationString, (WCHAR *)pszDest);
    if( inited < 0 )
      goto LABEL_22;
    ObjectAttributes.Length = 48;
    ObjectAttributes.RootDirectory = 0i64;
    ObjectAttributes.ObjectName = &DestinationString;
    ObjectAttributes.Attributes = 576;
    *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
    inited = ZwOpenKey(&KeyHandle, 0xF003Fu, &ObjectAttributes);
    if( inited < 0 )
      goto LABEL_22;
    ObjectAttributes.Attributes = 576;
    ObjectAttributes.Length = 48;
    ObjectAttributes.RootDirectory = KeyHandle;
    ObjectAttributes.ObjectName = (_UNICODE_STRING *)((char *)&ExpManufacturingInformation + 8);
    *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
    inited = ZwOpenKey(&Handle, 0xF003Fu, &ObjectAttributes);
    if( inited < 0 )
      goto LABEL_22;
    ZwClose(Handle);
    LODWORD(ExpManufacturingInformation) = ExpManufacturingInformation | 1;
    RtlInitUnicodeStringEx(&ValueName, (WCHAR *)L"LastProfile");
    LODWORD(DataSize) = WORD5(ExpManufacturingInformation);
    inited = ZwSetValueKey(KeyHandle, &ValueName, 0i64, 1ui64, Data, DataSize);
    if( inited < 0 )
      goto LABEL_22;
    inited = RtlInitUnicodeStringEx(&DestinationString, (WCHAR *)L"Current");
    if( inited < 0 )
      goto LABEL_22;
    ObjectAttributes.RootDirectory = KeyHandle;
    ObjectAttributes.Length = 48;
    ObjectAttributes.ObjectName = &DestinationString;
    ObjectAttributes.Attributes = 832;
    *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
    if( ZwOpenKeyEx(&v10, 0xF003Fui64, &ObjectAttributes, 8ui64) >= 0 )
    {
      inited = ZwDeleteKey(v10);
      if( inited < 0 )
        goto LABEL_22;
      ZwClose(v10);
      v10 = 0i64;
    }
    LODWORD(DataSizea) = 3;
    inited = ZwCreateKey(&v10, 0xF003Fui64, &ObjectAttributes, 0i64, 0i64, DataSizea, 0i64);
    if( inited >= 0 )
    {
      DataSizeb = (char *)&ExpManufacturingInformation + 8;
      inited = RtlStringCbPrintfW((WCHAR *)pszDest, 0x200ui64, (WCHAR *)L"%s%s%wZ");
      if( inited >= 0 )
      {
        v6 = -1i64;
        do
          ++v6;
        while( pszDest[v6] );
        LODWORD(DataSizeb) = 2 * v6;
        inited = ZwSetValueKey(v10, &CmSymbolicLinkValueName, 0i64, 6ui64, pszDest, (UINT64)DataSizeb);
      }
    }
    goto LABEL_22;
  }
  inited = -1073741670;
LABEL_22:
  if( v10 )
    ZwClose(v10);
  if( KeyHandle )
    ZwClose(KeyHandle);
  return inited;
}

Referenced by:

Phase1InitializationDiscard