MiCompressRelocations

_MI_DYNAMIC_RELOCATIONS *__stdcall MiCompressRelocations(PVOID DynamicRelocations, UINT64 RelocationSize){
  __int64 v2; 
  char v3; 
  int v4; 
  char v5; 
  __int64 v7; 
  __int64 v8; 
  __int64 v9; 
  _WORD *v10; 
  __int16 v11; 
  unsigned int v12; 
  unsigned __int16 v13; 
  unsigned int v14; 
  __int16 v15; 
  unsigned __int16 v16; 
  __int16 v17; 
  __int64 v18; 
  unsigned int v19; 
  unsigned int v20; 
  char *Pool; 
  _MI_DYNAMIC_RELOCATIONS *v22; 
  _QWORD *v23; 
  _QWORD *v24; 
  unsigned __int64 v25; 
  unsigned __int64 v26; 
  __int64 v27; 
  __int64 v28; 
  __int64 v29; 
  char *v30; 
  unsigned __int64 v31; 
  unsigned __int64 v32; 
  bool v34; 
  bool v35; 
  __int64 v36; 
  _WORD *v37; 
  __int16 v38; 
  __int16 v39; 
  unsigned int v40; 
  unsigned int v41; 
  __int16 v42; 
  unsigned __int16 v43; 
  char *v45; 
  _MI_DYNAMIC_RELOCATIONS *v46; 

  v2 = *((_QWORD *)DynamicRelocations + 4);
  v3 = 0;
  v4 = RelocationSize;
  v5 = 0;
  v7 = 0i64;
  v8 = 0i64;
  do
  {
    v9 = *(unsigned int *)(v2 + 4);
    v10 = (_WORD *)(v2 + 8);
    v8 += v9;
    v4 -= v9;
    v2 += v9;
    v11 = 4;
    v12 = (unsigned int)(v9 - 8) >> 1;
    v13 = 0;
    v14 = 0;
    if( v12 )
    {
      do
      {
        v15 = *v10 >> 12;
        if( v15 )
        {
          if( v5 != (_BYTE)v15 )
          {
            if( v3 )
              return(_MI_DYNAMIC_RELOCATIONS *)DynamicRelocations;
            v5 = v15;
            v3 = 1;
          }
          v16 = *v10 & 0xFFF;
          if( v16 <= v13 && v13 )
            return(_MI_DYNAMIC_RELOCATIONS *)DynamicRelocations;
          v17 = v16 - v13;
          if( v17 == v11 )
          {
            v18 = v7 + 2;
            v19 = v14 + 1;
            if( v14 != 254 )
              v18 = v7;
            v7 = v18;
            v20 = v14;
            v14 = 0;
            if( v20 != 254 )
              v14 = v19;
          }
          else
          {
            if( v14 )
            {
              v34 = v14 < 4;
              v35 = v14 == 4;
              v14 = 0;
              v7 += (!v34 && !v35) + 1i64;
            }
            v11 = v17;
            if( (unsigned __int16)v17 >= 0xEBu )
              v7 += 2i64;
            else
              ++v7;
          }
          --v12;
          v13 = *v10 & 0xFFF;
        }
        else
        {
          --v12;
        }
        ++v10;
      }
      while( v12 );
      if( v14 )
      {
        if( v14 <= 4 )
          ++v7;
        else
          v7 += 2i64;
      }
    }
    v7 += (((_BYTE)v7 + 2) & 1) + 2i64;
  }
  while( v4 );
  if( !v3 )
    return(_MI_DYNAMIC_RELOCATIONS *)DynamicRelocations;
  Pool = (char *)MiAllocatePool(256i64, v7 + 8 * (*((_QWORD *)DynamicRelocations + 7) + 14i64), 0x65526D4Dui64);
  v46 = (_MI_DYNAMIC_RELOCATIONS *)Pool;
  v22 = (_MI_DYNAMIC_RELOCATIONS *)Pool;
  if( !Pool )
    return(_MI_DYNAMIC_RELOCATIONS *)DynamicRelocations;
  v23 = DynamicRelocations;
  v24 = Pool + 112;
  v25 = *((_QWORD *)DynamicRelocations + 4) - *(_QWORD *)DynamicRelocations;
  *(_OWORD *)Pool = *(_OWORD *)DynamicRelocations;
  v26 = v25 >> 3;
  *((_OWORD *)Pool + 1) = *((_OWORD *)DynamicRelocations + 1);
  *((_OWORD *)Pool + 2) = *((_OWORD *)DynamicRelocations + 2);
  *((_OWORD *)Pool + 3) = *((_OWORD *)DynamicRelocations + 3);
  *((_OWORD *)Pool + 4) = *((_OWORD *)DynamicRelocations + 4);
  *((_OWORD *)Pool + 5) = *((_OWORD *)DynamicRelocations + 5);
  *((_OWORD *)Pool + 6) = *((_OWORD *)DynamicRelocations + 6);
  Pool[68] = v5;
  *(_QWORD *)Pool = Pool + 112;
  v27 = (__int64)&Pool[8 * *((_QWORD *)DynamicRelocations + 7) + 112];
  *((_QWORD *)Pool + 4) = v27;
  v28 = *((_QWORD *)DynamicRelocations + 4);
  if( (_DWORD)v26 )
  {
    v29 = (unsigned int)v26;
    v30 = (char *)((_BYTE *)DynamicRelocations - Pool);
    v31 = 0i64;
    v45 = (char *)((_BYTE *)DynamicRelocations - Pool);
    do
    {
      if( v31 < v23[7] )
      {
        v32 = *(_QWORD *)((char *)v24 + (_QWORD)v30);
        if( v32 > 1 )
        {
          *v24 = v27;
          if( (*((_BYTE *)v24 + (_QWORD)v30) & 1) != 0 )
            *v24 = v27 | 1;
          v36 = *(unsigned int *)(v28 + 4);
          v37 = (_WORD *)(v28 + 8);
          v28 += v36;
          v38 = 0;
          v39 = 4;
          v40 = 0;
          v41 = (unsigned int)(v36 - 8) >> 1;
          if( v41 )
          {
            do
            {
              if( *v37 >= 0x1000u )
              {
                v42 = *v37 & 0xFFF;
                v43 = v42 - v38;
                if( v42 - v38 == v39 )
                {
                  if( ++v40 == 255 )
                  {
                    *(_WORD *)v27 = -17;
                    v40 = 0;
                    v27 += 2i64;
                  }
                }
                else
                {
                  if( v40 )
                  {
                    if( v40 > 4 )
                    {
                      *(_BYTE *)v27 = -17;
                      *(_BYTE *)(v27 + 1) = v40;
                      v27 += 2i64;
                    }
                    else
                    {
                      *(_BYTE *)v27++ = -17 - v40;
                    }
                    v40 = 0;
                  }
                  v39 = v42 - v38;
                  if( v43 >= 0xEBu )
                  {
                    *(_BYTE *)v27 = v43 | 0xF0;
                    *(_BYTE *)(v27 + 1) = v43 >> 4;
                    v27 += 2i64;
                  }
                  else
                  {
                    *(_BYTE *)v27++ = v43;
                  }
                }
                v38 = v42;
              }
              ++v37;
              --v41;
            }
            while( v41 );
            v30 = v45;
            if( v40 )
            {
              if( v40 <= 4 )
              {
                *(_BYTE *)v27++ = -17 - v40;
              }
              else
              {
                *(_BYTE *)v27 = -17;
                *(_BYTE *)(v27 + 1) = v40;
                v27 += 2i64;
              }
            }
          }
          v23 = DynamicRelocations;
          *(_WORD *)v27 = 240;
          v27 += 2i64;
          if( (v27 & 1) != 0 )
            ++v27;
        }
        else
        {
          *v24 = v32;
        }
      }
      ++v31;
      ++v24;
      --v29;
    }
    while( v29 );
    v22 = v46;
  }
  ExFreePoolWithTag(v23, 0);
  return v22;
}

Referenced by:

MiRelocateImage