LdrUnloadAlternateResourceModuleEx

NTSTATUS __stdcall LdrUnloadAlternateResourceModuleEx(VOID *Module){
  VOID *v1; 
  INT64 v2; 
  INT64 v3; 
  void **v4; 
  char v6; 
  int v7; 
  int v8; 
  VOID **v9; 
  char *v10; 
  VOID *v11; 
  int v12; 
  int v13; 
  VOID **PoolWithTag; 
  VOID **v15; 
  INT64 v17; 
  INT64 v18; 
  INT64 v19; 
  INT64 v20; 
  void *retaddr; 

  v4 = &retaddr;
  v6 = 0;
  if( Module )
  {
    LdrpInitMuiCrits((INT64 *)Module, v1, v2, v3, v17, v18, v19, v20);
    KeWaitForSingleObject((UINT64)&MuiMutex, 0, 0, 0, 0i64);
    v7 = AlternateResourceModuleCount;
    if( (_DWORD)AlternateResourceModuleCount )
    {
      while( 1 )
      {
        if( v7 <= 0 )
          goto LABEL_21;
        v8 = v7 - 1;
        v9 = (VOID **)((char *)AlternateResourceModules + 64 * (__int64)(v7 - 1));
        if( v9[1] == Module )
          break;
LABEL_5:
        v7 = v8;
      }
      v10 = (char *)v9[4];
      if( (unsigned __int64)(v10 - 1) <= 0xFFFFFFFFFFFFFFFDui64 )
      {
        MmUnmapViewInSystemSpace(v10);
        v11 = v9[5];
        if( v11 )
        {
          ZwClose((_HANDLE)v11);
          v9[5] = 0i64;
        }
        v9[4] = 0i64;
      }
      v12 = AlternateResourceModuleCount;
      if( v7 != (_DWORD)AlternateResourceModuleCount )
        memmove(v9, v9 + 8, ((_DWORD)AlternateResourceModuleCount - v7) << 6);
      LODWORD(AlternateResourceModuleCount) = v12 - 1;
      if( v12 == 1 )
      {
        ExFreePoolWithTag(AlternateResourceModules, 0);
        AlternateResourceModules = 0i64;
        v13 = 0;
      }
      else
      {
        if( v12 - 1 >= (unsigned int)(AltResMemBlockCount - 32) )
        {
LABEL_20:
          v6 = 1;
          goto LABEL_5;
        }
        PoolWithTag = ExAllocatePoolWithTag(
                        1ui64,
                        (unsigned __int64)(unsigned int)(AltResMemBlockCount - 32) << 6,
                        1766880370i64);
        v15 = PoolWithTag;
        if( !PoolWithTag )
        {
          v6 = 0;
          goto LABEL_21;
        }
        memmove(PoolWithTag, AlternateResourceModules, (AltResMemBlockCount - 32) << 6);
        ExFreePoolWithTag(AlternateResourceModules, 0);
        AlternateResourceModules = v15;
        v13 = AltResMemBlockCount - 32;
      }
      AltResMemBlockCount = v13;
      goto LABEL_20;
    }
    v6 = 1;
LABEL_21:
    LODWORD(v4) = KeReleaseMutant(&MuiMutex, 1i64, 0, 0);
    LOBYTE(v4) = v6;
  }
  else
  {
    LOBYTE(v4) = 0;
  }
  return(int)v4;
}

Referenced by:

LdrUnloadAlternateResourceModule
LdrpGetFromMUIMemCache