DrvDbOpenDriverDatabaseRegKey

NTSTATUS __stdcall DrvDbOpenDriverDatabaseRegKey(
        _UNICODE_STRING **pDrvDbCtx,
        WCHAR *DatabaseNodeId,
        UINT64 DesiredAccess,
        UINT8 Create,
        VOID **BaseKeyHandle,
        UINT64 *Disposition){
  unsigned int v9; 
  char v10; 
  INT64 v11; 
  NTSTATUS v12; 
  int v13; 
  _ETHREAD *CurrentThread; 
  _DRVDB_NODE *v15; 
  __int64 v16; 
  INT64 a5; 
  _DRVDB_NODE *DatabaseNode[2]; 

  DatabaseNode[0] = 0i64;
  v9 = DesiredAccess;
  v10 = 0;
  if( wcsicmp(DatabaseNodeId, L"*") )
  {
    v12 = DrvDbFindDatabaseNode((_DRVDB_CONTEXT *)pDrvDbCtx, DatabaseNodeId, DatabaseNode);
    v13 = v12;
    if( v12 == -1073741772 )
    {
      if( !Create )
        return v13;
      LODWORD(a5) = 16;
      v13 = DrvDbCreateDatabaseNode(
              (_DRVDB_CONTEXT *)pDrvDbCtx,
              DatabaseNodeId,
              0i64,
              0i64,
              a5,
              0i64,
              0i64,
              (INT64)DatabaseNode);
      if( v13 < 0 )
        return v13;
      v10 = 1;
    }
    else if( v12 < 0 )
    {
      return v13;
    }
  }
  else
  {
    DatabaseNode[0] = (_DRVDB_NODE *)pDrvDbCtx[4];
  }
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  --CurrentThread->Tcb.KernelApcDisable;
  v15 = DatabaseNode[0];
  ExAcquireResourceExclusiveLite(*((_QWORD *)DatabaseNode[0] + 18), 1, v11);
  if( (v15[14] & 1) != 0 || (v13 = DrvDbLoadDatabaseNode((_DRVDB_CONTEXT *)pDrvDbCtx, v15), v13 >= 0) )
  {
    if( *pDrvDbCtx )
      v16 = *(_QWORD *)&(*pDrvDbCtx)[14].Length;
    else
      v16 = 0i64;
    v13 = SysCtxRegOpenKey(v16, *((VOID **)v15 + 11), 0i64, 0, v9, BaseKeyHandle);
    if( (v15[14] & 1) == 0 )
      DrvDbUnloadDatabaseNode((_DRVDB_CONTEXT *)pDrvDbCtx, v15);
    if( v13 >= 0 && Disposition )
      *(_DWORD *)Disposition = 2;
  }
  ExReleaseResourceLite(*((PERESOURCE *)v15 + 18));
  KeLeaveCriticalRegionThread(KeGetCurrentThread());
  if( v13 < 0 && v10 )
    DrvDbDestroyDatabaseNode((_DRVDB_CONTEXT *)pDrvDbCtx, DatabaseNode[0]);
  return v13;
}

Referenced by:

DrvDbDispatchDriverDatabase
DrvDbGetDriverDatabaseMappedProperty
DrvDbGetDriverDatabaseMappedPropertyKeys
DrvDbSetDriverDatabaseMappedProperty