LdrRelocateImageWithBias

NTSTATUS __stdcall LdrRelocateImageWithBias(
        PVOID NewAddress,
        _LONGLONG AdditionalBias,
        PCCH LoaderName,
        ULONG Success,
        ULONG Conflict,
        ULONG Invalid){
  NTSTATUS v6; 
  __int64 v8; 
  __int16 v9; 
  __int64 v10; 
  unsigned int *v11; 
  int v12; 
  unsigned int v13; 
  __int64 v15; 
  UINT64 Size; 

  v6 = 0;
  LODWORD(Size) = 0;
  v15 = 0i64;
  if( (int)RtlImageNtHeaderEx(1, (unsigned __int64)NewAddress, 0i64, &v15) < 0 )
    return -1073741701;
  v8 = v15;
  v9 = *(_WORD *)(v15 + 24);
  if( v9 == 267 )
  {
    v10 = *(unsigned int *)(v15 + 52);
  }
  else
  {
    if( v9 != 523 )
      return -1073741701;
    v10 = *(_QWORD *)(v15 + 48);
  }
  v11 = (unsigned int *)RtlImageDirectoryEntryToData(NewAddress, 1u, 5u, &Size);
  if( !v11 )
    return(*(_BYTE *)(v8 + 22) & 1) != 0 ? 0xC0000018 : 0;
  v12 = Size;
  if( !(_DWORD)Size )
    return(*(_BYTE *)(v8 + 22) & 1) != 0 ? 0xC0000018 : 0;
  while( 1 )
  {
    v13 = v11[1];
    v12 -= v13;
    v11 = (unsigned int *)LdrProcessRelocationBlockLongLong(
                            *(unsigned __int16 *)(v8 + 4),
                            (UINT64)NewAddress + *v11,
                            (PUSHORT)((v13 - 8) >> 1),
                            (int)v11 + 8,
                            (INT64)NewAddress - v10);
    if( !v11 )
      break;
    if( !v12 )
      return v6;
  }
  return -1073741701;
}

Referenced by:

MiMapSystemImageWithLargePage