IoGetDeviceProperty

NTSTATUS __stdcall IoGetDeviceProperty(
        _DEVICE_OBJECT *DeviceObject,
        _DEVICE_REGISTRY_PROPERTY DeviceProperty,
        UINT64 BufferLength,
        VOID *PropertyBuffer,
        UINT64 *ResultLength){
  __int16 v5; 
  unsigned int v6; 
  UINT64 *v9; 
  unsigned int v10; 
  _DEVICE_NODE *DeviceNode; 
  unsigned int v12; 
  _CM_REG_PROP v13; 
  unsigned int v14; 
  NTSTATUS DeviceRegProp; 
  bool v16; 
  VOID **PoolWithTag; 
  const VOID **v19; 
  int v20; 
  unsigned int v21; 
  unsigned int v22; 
  unsigned int v23; 
  unsigned int v24; 
  unsigned int v25; 
  unsigned int v26; 
  unsigned int v27; 
  unsigned int v28; 
  unsigned __int32 ChildInterfaceType; 
  unsigned int v30; 
  unsigned int v31; 
  _CM_RESOURCE_LIST *ResourceList; 
  _CM_RESOURCE_LIST *ResourceListTranslated; 
  __int64 v34; 
  size_t v35; 
  unsigned int v36; 
  unsigned int Address; 
  unsigned int v38; 
  unsigned int v39; 
  int v40; 
  unsigned int v41; 
  unsigned int v42; 
  _CM_RESOURCE_LIST *BootResourcesTranslated; 
  size_t v44; 
  _IO_RESOURCE_REQUIREMENTS_LIST *ResourceRequirements; 
  unsigned int ListSize; 
  UINT64 Flags; 
  UINT64 Length; 
  UINT8 PropertyBuffera[4]; 
  VOID *Object; 
  __int128 v51; 
  _DEVICE_CAPABILITIES Capabilities; 
  VOID *retaddr; 

  v5 = DeviceProperty;
  Object = DeviceObject;
  v6 = BufferLength;
  v51 = 0i64;
  memset(&Capabilities, 0i64, sizeof(Capabilities));
  v10 = v5 & 0xFFF;
  *(_DWORD *)PropertyBuffera = 0;
  HIDWORD(Length) = 0;
  *(_DWORD *)ResultLength = 0;
  if( !DeviceObject )
    return -1073741808;
  DeviceNode = (_DEVICE_NODE *)DeviceObject->DeviceObjectExtension->DeviceNode;
  if( !DeviceNode || (DeviceNode->Flags & 0x20000) != 0 )
  {
    if( v10 != 18 && (v10 != 15 || !DeviceNode) )
      PpvUtilFailDriver(PPVERROR_DDI_REQUIRES_PDO, retaddr, DeviceObject, 0i64);
    return -1073741808;
  }
  if( v10 > 0xB )
  {
    v14 = 17;
    if( v10 <= 0x11 )
    {
      if( v10 == 17 )
      {
        v13 = CM_REG_PROP_UNUSED0;
        goto LABEL_11;
      }
      v26 = v10 - 12;
      if( !v26 )
      {
        DeviceRegProp = PnpBusTypeGuidGet(DeviceNode->ChildBusTypeIndex, &v51);
        if( DeviceRegProp < 0 )
          return DeviceRegProp;
        *(_DWORD *)ResultLength = 16;
        if( v6 >= 0x10 )
        {
          *(_OWORD *)PropertyBuffer = v51;
          return DeviceRegProp;
        }
        return -1073741789;
      }
      v27 = v26 - 1;
      if( !v27 )
      {
        if( DeviceNode->ChildInterfaceType == InterfaceTypeUndefined )
          return -1073741772;
        *(_DWORD *)ResultLength = 4;
        if( v6 < 4 )
          return -1073741789;
        ChildInterfaceType = DeviceNode->ChildInterfaceType;
LABEL_43:
        *(_DWORD *)PropertyBuffer = ChildInterfaceType;
        return 0;
      }
      v28 = v27 - 1;
      if( !v28 )
      {
        if( (DeviceNode->ChildBusNumber & 0x80000000) != 0 )
          return -1073741772;
        *(_DWORD *)ResultLength = 4;
        if( v6 < 4 )
          return -1073741789;
        ChildInterfaceType = DeviceNode->ChildBusNumber;
        goto LABEL_43;
      }
      v36 = v28 - 1;
      if( !v36 )
      {
        v14 = 23;
        goto LABEL_31;
      }
      if( v36 != 1 )
        return -1073741584;
      if( PpIrpQueryCapabilities(DeviceObject, &Capabilities) < 0 )
        return -1073741772;
      Address = Capabilities.Address;
      if( Capabilities.Address == -1 )
        return -1073741772;
      *(_DWORD *)ResultLength = 4;
      if( v6 < 4 )
        return -1073741789;
      *(_DWORD *)PropertyBuffer = Address;
      return 0;
    }
    v24 = v10 - 18;
    if( !v24 )
    {
      if( DeviceNode == (_DEVICE_NODE *)*(&PnpReplaceEvent + 831) )
      {
        v40 = 0;
        DeviceRegProp = 0;
      }
      else
      {
        if( !DeviceNode->InstancePath.Buffer )
          return -1073741808;
        while( 1 )
        {
          LODWORD(Flags) = 0;
          LODWORD(Length) = 4;
          DeviceRegProp = CmGetDeviceRegProp(
                            *(&stru_140CF2E80 + 607),
                            DeviceNode->InstancePath.Buffer,
                            0i64,
                            11i64,
                            (UINT64 *)((char *)&Length + 4),
                            PropertyBuffera,
                            &Length,
                            Flags);
          if( DeviceRegProp < 0 || Length != 0x400000004i64 )
            break;
          if( (PropertyBuffera[0] & 0x20) != 0 )
          {
            v40 = 1;
          }
          else if( (PropertyBuffera[0] & 0x40) != 0 )
          {
            v40 = 2;
          }
          else
          {
            v40 = (*(_WORD *)PropertyBuffera & 0x400) != 0 ? 3 : 0;
          }
          DeviceNode = DeviceNode->Parent;
          if( v40 || DeviceNode == (_DEVICE_NODE *)*(&PnpReplaceEvent + 831) )
            goto LABEL_80;
        }
        v40 = 2;
LABEL_80:
        if( DeviceRegProp < 0 )
        {
          if( DeviceRegProp == -1073741275 )
            return -1073741772;
          v16 = DeviceRegProp == -1073741810;
          goto LABEL_13;
        }
      }
      *(_DWORD *)ResultLength = 4;
      if( v6 >= 4 )
      {
        *(_DWORD *)PropertyBuffer = v40;
        return DeviceRegProp;
      }
      return -1073741789;
    }
    v25 = v24 - 1;
    if( !v25 )
    {
      *(_DWORD *)ResultLength = 4;
      if( v6 < 4 )
        return -1073741789;
      PpHotSwapGetDevnodeRemovalPolicy(DeviceNode, 1u, (_DEVICE_REMOVAL_POLICY *)PropertyBuffer);
      return 0;
    }
    v30 = v25 - 1;
    if( v30 )
    {
      v31 = v30 - 1;
      if( v31 )
      {
        if( v31 != 1 )
          return -1073741584;
        v14 = 37;
        goto LABEL_31;
      }
      ExAcquireFastMutex((PFAST_MUTEX)((char *)&PnpReplaceEvent + 6336));
      ResourceList = DeviceNode->ResourceList;
      if( !ResourceList || (ResourceListTranslated = DeviceNode->ResourceListTranslated) == 0i64 )
      {
        *(_DWORD *)ResultLength = 0;
        DeviceRegProp = 0;
        goto LABEL_54;
      }
      v34 = (unsigned int)PnpDetermineResourceListSize(ResourceList);
      v35 = PnpDetermineResourceListSize(ResourceListTranslated);
      *(_DWORD *)ResultLength = v35 + v34;
      if( v35 + (unsigned int)v34 > v6 )
        goto LABEL_53;
      memmove(PropertyBuffer, DeviceNode->ResourceList, v34);
      memmove((char *)PropertyBuffer + v34, DeviceNode->ResourceListTranslated, v35);
    }
    else
    {
      ExAcquireFastMutex((PFAST_MUTEX)((char *)&PnpReplaceEvent + 6336));
      ResourceRequirements = DeviceNode->ResourceRequirements;
      if( ResourceRequirements )
      {
        ListSize = ResourceRequirements->ListSize;
        *(_DWORD *)ResultLength = ResourceRequirements->ListSize;
        if( ListSize > v6 )
        {
LABEL_53:
          DeviceRegProp = -1073741789;
LABEL_54:
          KeReleaseGuardedMutex((PKGUARDED_MUTEX)((char *)&PnpReplaceEvent + 6336));
          return DeviceRegProp;
        }
        memmove(PropertyBuffer, ResourceRequirements, ResourceRequirements->ListSize);
      }
      else
      {
        *(_DWORD *)ResultLength = 0;
      }
    }
    DeviceRegProp = 0;
    goto LABEL_54;
  }
  if( v10 != 11 )
  {
    if( v10 > 5 )
    {
      v22 = v10 - 6;
      if( v22 )
      {
        v23 = v22 - 1;
        if( v23 )
        {
          v38 = v23 - 1;
          if( v38 )
          {
            v39 = v38 - 1;
            if( v39 )
            {
              if( v39 != 1 )
                return -1073741584;
              v14 = 14;
            }
            else
            {
              v14 = 13;
            }
          }
          else
          {
            v14 = 12;
          }
        }
        else
        {
          v14 = 10;
        }
      }
      else
      {
        v14 = 9;
      }
    }
    else
    {
      if( v10 != 5 )
      {
        if( v10 )
        {
          v12 = v10 - 1;
          if( !v12 )
          {
            v13 = CM_REG_PROP_UNUSED2;
            v14 = 2;
            goto LABEL_11;
          }
          v41 = v12 - 1;
          if( v41 )
          {
            v42 = v41 - 1;
            if( !v42 )
            {
              *(_DWORD *)ResultLength = v6;
              return PiGetDeviceRegistryProperty(DeviceObject, 0i64, v9);
            }
            if( v42 == 1 )
            {
              BootResourcesTranslated = DeviceNode->BootResourcesTranslated;
              if( BootResourcesTranslated )
              {
                v44 = PnpDetermineResourceListSize(BootResourcesTranslated);
                *(_DWORD *)ResultLength = v44;
                if( v44 <= v6 )
                {
                  memmove(PropertyBuffer, DeviceNode->BootResourcesTranslated, v44);
                  return 0;
                }
                return -1073741789;
              }
              return 0;
            }
            return -1073741584;
          }
          v13 = CM_REG_PROP_UNUSED2;
          v14 = 3;
        }
        else
        {
          v13 = CM_REG_PROP_DEVICEDESC;
          v14 = 1;
        }
LABEL_11:
        if( DeviceNode->InstancePath.Buffer )
        {
          *(_DWORD *)ResultLength = v6;
          DeviceRegProp = PiGetDeviceRegProperty(
                            DeviceNode->InstancePath.Buffer,
                            0i64,
                            v13,
                            (VOID *)v14,
                            (UINT64 *)PropertyBuffer);
          v16 = DeviceRegProp == -1073741275;
LABEL_13:
          if( !v16 )
            return DeviceRegProp;
          return -1073741772;
        }
        return -1073741808;
      }
      v14 = 8;
    }
LABEL_31:
    v13 = CM_REG_PROP_DEVICEDESC;
    goto LABEL_11;
  }
  LODWORD(Length) = v6 + 16;
  PoolWithTag = ExAllocatePoolWithTag(1ui64, v6 + 16, 1869181008i64);
  v19 = (const VOID **)PoolWithTag;
  if( !PoolWithTag )
    return -1073741670;
  DeviceRegProp = ObQueryNameStringMode(
                    Object,
                    (_OBJECT_NAME_INFORMATION *)PoolWithTag,
                    (unsigned int)Length,
                    ResultLength,
                    0);
  if( DeviceRegProp == -1073741820 )
    DeviceRegProp = -1073741789;
  if( DeviceRegProp < 0 )
  {
    *(_DWORD *)ResultLength -= 16;
  }
  else
  {
    v20 = *(unsigned __int16 *)v19;
    if( (_WORD)v20 )
    {
      v21 = v20 + 2;
      *(_DWORD *)ResultLength = v21;
      if( v21 > v6 )
      {
        DeviceRegProp = -1073741789;
      }
      else
      {
        memmove(PropertyBuffer, v19[1], *(unsigned __int16 *)v19);
        *(_WORD *)((char *)PropertyBuffer + *(unsigned __int16 *)v19) = 0;
      }
    }
    else
    {
      *(_DWORD *)ResultLength = 0;
    }
  }
  ExFreePoolWithTag(v19, 0);
  return DeviceRegProp;
}

Referenced by:

ArbQueryConflict
ArbShareDriverExclusive
IoGetDmaAdapter
IoWMISuggestInstanceName
IopIsPciRootBus
IopProcessSetInterfaceState
KseDsCallbackHookAddDevice
PiControlGetPropertyData
PiRebalanceOptOut
PoStoreRequester
PopDiagQueryDevicePropertyString
PopGenerateDeviceFriendlyName
PopRegisterCoolingExtensionProtection
PopWakeSourceGetDeviceProperty
SshpGenerateDeviceFriendlyName
VfIsPCIBus