HvpInitMap

__int64 __fastcall HvpInitMap(_HHIVE *Hive, __int64 a2){
  unsigned int v2; 
  _HIVE_LOAD_FAILURE *HiveLoadFailure; 
  unsigned int *v4; 
  unsigned int *v5; 
  unsigned int Length; 
  unsigned int v8; 
  unsigned int v9; 
  __int64 v10; 
  unsigned int v11; 
  void *(__fastcall *Allocate)(unsigned int, unsigned __int8, unsigned int); 
  _HMAP_TABLE *v13; 
  _HMAP_TABLE *v14; 
  _HMAP_DIRECTORY *p_SmallDir; 
  __int64 result; 
  _HMAP_DIRECTORY *v17; 
  unsigned int v18; 
  INT64 v19; 
  INT64 v20; 
  UINT64 Point; 

  v2 = 0;
  HiveLoadFailure = (_HIVE_LOAD_FAILURE *)Hive->HiveLoadFailure;
  v4 = 0i64;
  v5 = 0i64;
  Length = Hive->BaseBlock->Length;
  if( (Length & 0xFFF) != 0 )
  {
    LODWORD(Point) = 0;
    v18 = -1073741492;
    v19 = 3221225804i64;
  }
  else
  {
    v8 = Length >> 12;
    if( Length >> 12 )
      v9 = (v8 - 1) >> 9;
    else
      v9 = 0;
    Hive->Storage[0].Length = Length;
    if( Hive->DirtyVector.Buffer )
      goto LABEL_10;
    v2 = (v8 + 3) & 0xFFFFFFFC;
    LOBYTE(a2) = 1;
    if( !v2 )
      v2 = 4;
    v4 = (unsigned int *)Hive->Allocate(v2, a2, 926043459i64);
    if( v4 )
    {
      LOBYTE(v10) = 1;
      v5 = (unsigned int *)Hive->Allocate(v2, v10, 926043459i64);
      if( !v5 )
      {
        v20 = 3221225495i64;
        goto LABEL_23;
      }
      memset(v4, 0i64, v2);
      memset(v5, 0i64, v2);
      Hive->DirtyVector.Buffer = v4;
      v11 = Length >> 9;
      Hive->DirtyVector.SizeOfBitMap = v11;
      Hive->UnreconciledVector.SizeOfBitMap = v11;
      Hive->UnreconciledVector.Buffer = v5;
      Hive->DirtyAlloc = v2;
LABEL_10:
      Allocate = Hive->Allocate;
      if( v9 )
      {
        v17 = (_HMAP_DIRECTORY *)Allocate(0x2000u, 0, 942820675u);
        p_SmallDir = v17;
        if( v17 )
        {
          memset(v17, 0i64, sizeof(_HMAP_DIRECTORY));
          if( HvpAllocateMap(Hive, p_SmallDir, 0i64, v9) )
          {
            v14 = 0i64;
            goto LABEL_13;
          }
          LODWORD(Point) = 64;
          v18 = -1073741670;
          SetFailureLocation(HiveLoadFailure, 0i64, _HvpInitMap, 3221225626i64, Point);
          HvpFreeMap(Hive, p_SmallDir, 0i64, v9);
          Hive->Free(p_SmallDir, 0x2000u);
          goto LABEL_27;
        }
        v20 = 3221225626i64;
        LODWORD(Point) = 48;
LABEL_25:
        v18 = v20;
        SetFailureLocation(HiveLoadFailure, 0i64, _HvpInitMap, v20, Point);
LABEL_27:
        if( v4 )
        {
          if( Hive->DirtyVector.Buffer == v4 )
            Hive->DirtyVector.Buffer = 0i64;
          Hive->Free(v4, v2);
        }
        if( v5 )
        {
          if( Hive->UnreconciledVector.Buffer == v5 )
            Hive->UnreconciledVector.Buffer = 0i64;
          Hive->Free(v5, v2);
        }
        return v18;
      }
      v13 = (_HMAP_TABLE *)Allocate(12288u, 0, 909266243u);
      v14 = v13;
      if( v13 )
      {
        memset(v13, 0i64, sizeof(_HMAP_TABLE));
        p_SmallDir = (_HMAP_DIRECTORY *)&Hive->Storage[0].SmallDir;
LABEL_13:
        Hive->Storage[0].Map = p_SmallDir;
        result = 0i64;
        Hive->Storage[0].SmallDir = v14;
        return result;
      }
      v20 = 3221225626i64;
LABEL_23:
      LODWORD(Point) = 32;
      goto LABEL_25;
    }
    v19 = 3221225495i64;
    LODWORD(Point) = 16;
    v18 = -1073741801;
  }
  SetFailureLocation(HiveLoadFailure, 0i64, _HvpInitMap, v19, Point);
  return v18;
}

Referenced by:

HvpBuildMapForMemoryBackedHive