PiDeviceRegistration

NTSTATUS __stdcall PiDeviceRegistration(
        _UNICODE_STRING *DeviceInstancePath,
        UINT8 Add,
        _UNICODE_STRING *ServiceKeyName){
  VOID **PropertyBuffer; 
  NTSTATUS DeviceRegProp; 
  VOID *v8; 
  VOID *v9; 
  UINT64 Flags; 
  _UNICODE_STRING DestinationString; 
  WCHAR *DeviceInstanceId; 
  UINT64 PropertySize; 
  UINT64 CmRegPropType; 

  DeviceInstanceId = 0i64;
  LODWORD(CmRegPropType) = 0;
  LODWORD(PropertySize) = 0;
  PropertyBuffer = 0i64;
  DestinationString = 0i64;
  if( ServiceKeyName )
  {
    *(_DWORD *)&ServiceKeyName->Length = 0;
    ServiceKeyName->Buffer = 0i64;
  }
  if( DeviceInstancePath->Length <= 2u )
  {
    DeviceRegProp = -1073741811;
    goto LABEL_23;
  }
  if( DeviceInstancePath->Buffer[((unsigned __int64)DeviceInstancePath->Length >> 1) - 1] == 92 )
    DeviceInstancePath->Length -= 2;
  DeviceRegProp = PnpUnicodeStringToWstr((__int16 **)&DeviceInstanceId, 0i64, &DeviceInstancePath->Length);
  if( DeviceRegProp < 0 )
    goto LABEL_23;
  LODWORD(PropertySize) = 512;
  PropertyBuffer = ExAllocatePoolWithTag(1ui64, 0x200ui64, 538996816i64);
  if( !PropertyBuffer )
  {
    DeviceRegProp = -1073741670;
    goto LABEL_23;
  }
  LODWORD(Flags) = 0;
  DeviceRegProp = CmGetDeviceRegProp(
                    *(&stru_140CF2E80 + 607),
                    DeviceInstanceId,
                    0i64,
                    5i64,
                    &CmRegPropType,
                    (UINT8 *)PropertyBuffer,
                    &PropertySize,
                    Flags);
  PnpUnicodeStringToWstrFree(DeviceInstanceId, (__int64)DeviceInstancePath);
  if( DeviceRegProp < 0 )
  {
    if( DeviceRegProp == -1073741275 )
      DeviceRegProp = 0;
LABEL_13:
    if( DeviceRegProp < 0 )
      goto LABEL_23;
    goto LABEL_14;
  }
  DeviceRegProp = -1073741772;
  if( (_DWORD)CmRegPropType != 1 || (unsigned int)PropertySize <= 2 )
    goto LABEL_23;
  RtlInitUnicodeStringEx(&DestinationString, (WCHAR *)PropertyBuffer);
  if( ServiceKeyName )
  {
    DeviceRegProp = PnpConcatenateUnicodeStrings(ServiceKeyName, &DestinationString);
    goto LABEL_13;
  }
LABEL_14:
  LOBYTE(DeviceInstanceId) = Add;
  DeviceRegProp = PpForEachDeviceInstanceDriver(DeviceInstancePath, v8);
  if( DeviceRegProp >= 0 )
    goto LABEL_15;
  if( Add )
  {
    LOBYTE(DeviceInstanceId) = 0;
    PpForEachDeviceInstanceDriver(DeviceInstancePath, v9);
  }
LABEL_23:
  if( ServiceKeyName && ServiceKeyName->Length )
  {
    ExFreePoolWithTag(ServiceKeyName->Buffer, 0);
    ServiceKeyName->Buffer = 0i64;
    *(_DWORD *)&ServiceKeyName->Length = 0;
  }
LABEL_15:
  if( PropertyBuffer )
    ExFreePoolWithTag(PropertyBuffer, 0);
  return DeviceRegProp;
}

Referenced by:

PpDeviceRegistration