PiControlGetSetDeviceStatus

INT64 __fastcall PiControlGetSetDeviceStatus(INT64 a1, _WORD *a2){
  unsigned int v2; 
  INT8 v3; 
  unsigned int v4; 
  _DWORD *v5; 
  UINT64 v6; 
  INT8 v7; 
  UINT8 *v9; 
  INT64 result; 
  _DEVICE_OBJECT *v11; 
  int v12; 
  int v13; 
  int v14; 
  int v15; 
  int v16; 
  __int64 *v17; 
  _WORD *v18; 
  _KEVENT *p_Event; 
  UINT8 *PoolWithTag; 
  int *CompletionStatus; 
  VOID *Destination[2]; 
  struct _KEVENT Event; 
  __int64 v24; 
  v4 = (unsigned __int16)*a2;
  LODWORD(v24) = 0;
  v5 = 0i64;
  v6 = v2;
  *(_OWORD *)Destination = 0i64;
  v7 = v3;
  WORD1(Destination[0]) = v4;
  LOWORD(Destination[0]) = v4;
  v9 = 0i64;
  memset(&Event, 0, sizeof(Event));
  if( (unsigned __int16)(v4 - 1) > 0x18Fu || (v4 & 1) != 0 )
    return 3221225485i64;
  LODWORD(CompletionStatus) = 1;
  result = PiControlMakeUserModeCallersCopy(
             &Destination[1],
             *((VOID **)a2 + 1),
             v4,
             2ui64,
             v3,
             (UINT64)CompletionStatus);
  if( (int)result >= 0 )
  {
    PpDevNodeLockTree(0);
    v11 = (_DEVICE_OBJECT *)PnpDeviceObjectFromDeviceInstanceWithTag((INT64)Destination, 0x53706E50ui64);
    PiControlFreeUserModeCallersBuffer(v7, Destination[1]);
    if( v11 )
      v5 = *(_DWORD **)(*((_QWORD *)v11 + 39) + 40i64);
    PpDevNodeUnlockTree(0);
    if( v5 )
    {
      if( v5 == IopRootDeviceNode && *((_DWORD *)a2 + 4) )
      {
        v14 = -1073741790;
      }
      else
      {
        v12 = *((_DWORD *)a2 + 4);
        v13 = *((_DWORD *)a2 + 7) & 1;
        if( v12 )
        {
          v15 = v12 - 1;
          if( v15 )
          {
            if( v15 != 1 )
            {
              v14 = -1073741808;
              goto LABEL_10;
            }
            KeInitializeEvent(&Event, NotificationEvent, 0);
            v16 = PnpRequestDeviceAction(v11, ClearDeviceProblem, 0, 0i64, &Event, (int *)&v24);
            v14 = v16;
          }
          else
          {
            if( v13 )
            {
              PoolWithTag = (UINT8 *)ExAllocatePoolWithTag(PagedPool, v6, 0x55706E50ui64);
              v9 = PoolWithTag;
              if( !PoolWithTag )
              {
                v14 = -1073741670;
                goto LABEL_10;
              }
              memmove(PoolWithTag, (UINT8 *)a2, v6);
            }
            else
            {
              KeInitializeEvent(&Event, NotificationEvent, 0);
            }
            v17 = &v24;
            v18 = v9;
            p_Event = &Event;
            if( v13 )
              v17 = 0i64;
            if( v13 )
              p_Event = 0i64;
            if( !v13 )
              v18 = a2;
            v16 = PnpRequestDeviceAction(v11, SetDeviceProblem, 0, (unsigned __int64)v18, p_Event, (int *)v17);
            v14 = v16;
            if( v13 )
              goto LABEL_10;
          }
          if( v16 < 0 )
            goto LABEL_10;
          v14 = KeWaitForSingleObject(&Event, Executive, 0, 1u, 0i64);
          if( v14 == 257 )
          {
            if( (unsigned int)PnpRemoveDeviceActionRequestFromQueue(0i64) )
            {
              v14 = -1073741536;
              goto LABEL_10;
            }
            PnpCancelDeviceActionRequest(0i64);
            v14 = KeWaitForSingleObject(&Event, Executive, 0, 0, 0i64);
          }
          if( !v14 )
            v14 = v24;
          goto LABEL_10;
        }
        PiControlGetUserFlagsFromDeviceNode((__int64)v5, (int *)a2 + 5);
        *((_DWORD *)a2 + 6) = v5[101];
        *((_DWORD *)a2 + 8) = v5[102];
        v14 = 0;
      }
    }
    else
    {
      v14 = -1073741810;
    }
LABEL_10:
    if( v11 )
      ObfDereferenceObjectWithTag(v11, 0x53706E50ui64);
    if( v14 < 0 )
    {
      if( v9 )
        ExFreePoolWithTag(v9, 0x55706E50u);
    }
    return(unsigned int)v14;
  }
  return result;
}

Referenced by:

No references.