MiCaptureRetpolineRelocationTables

NTSTATUS __stdcall MiCaptureRetpolineRelocationTables(CHAR *a1, UINT64 a2, INT64 a3, UINT64 a4, UINT64 *a5){
  unsigned __int64 v5; 
  unsigned __int64 v6; 
  CHAR *v7; 
  VOID *v8; 
  UINT64 *v9; 
  unsigned int v10; 
  unsigned int v11; 
  unsigned int v12; 
  UINT64 *v13; 
  __int64 v14; 
  unsigned int v15; 
  _QWORD **v16; 
  NTSTATUS v17; 
  _QWORD *Pool; 
  __int64 v20; 
  UINT64 v21; 
  UINT64 *v22; 
  unsigned int v24; 
  int v25; 

  v24 = a2;
  v5 = (unsigned int)a4;
  v6 = (unsigned int)a2;
  v7 = a1;
  v22 = 0i64;
  v25 = 0;
  v8 = RtlImageDirectoryEntryToData(a1, 1u, 0xCu, &v21);
  v9 = a5;
  if( v8 )
  {
    v10 = (_DWORD)v8 - (_DWORD)v7;
    *(_DWORD *)a5 = v10;
    if( v10 > (unsigned int)v6 )
      goto LABEL_31;
  }
  else
  {
    *(_DWORD *)a5 = 0;
  }
  if( v5 + 8 >= v5 && v5 + 8 <= v6 )
  {
    v21 = *(_QWORD *)&v7[v5];
    v11 = HIDWORD(v21) + v5 + 8;
    if( v11 >= (unsigned int)v5 && v11 <= (unsigned int)v6 )
    {
      if( (_DWORD)v21 != 1 )
      {
        v17 = -1073741637;
        goto LABEL_32;
      }
      v12 = v5 + 8;
      while( 1 )
      {
        if( v12 >= v11 )
        {
          v17 = 0;
          goto LABEL_20;
        }
        if( (unsigned __int64)v12 + 12 > v11 )
          break;
        v13 = (UINT64 *)&v7[v12];
        v22 = v13;
        v21 = *v13;
        v14 = *((unsigned int *)v13 + 2);
        v15 = v14 + v12 + 12;
        if( v15 < v12 || v15 > v11 )
          break;
        if( v21 == 3 )
        {
          v16 = (_QWORD **)(v9 + 1);
        }
        else
        {
          if( v21 == 4 )
          {
            if( MiIsRetpolineEnabled() )
            {
              v16 = (_QWORD **)(v9 + 2);
              goto LABEL_17;
            }
          }
          else if( v21 == 5 && MiIsRetpolineEnabled() )
          {
            v16 = (_QWORD **)(v9 + 3);
            goto LABEL_17;
          }
          v16 = 0i64;
        }
LABEL_17:
        if( v16 )
        {
          if( *v16 )
            break;
          Pool = MiAllocatePool(256i64, v14 + 12, 0x7252694Dui64);
          *v16 = Pool;
          if( !Pool )
          {
            v17 = -1073741670;
            goto LABEL_32;
          }
          memmove(Pool, v13, v14 + 12);
          v20 = (__int64)*v16;
          *(_QWORD *)v20 = v21;
          *(_DWORD *)(v20 + 8) = v14;
          v17 = RtlValidateRetpolineRelocation(*v16, v24, &v25);
          if( v17 < 0 )
            goto LABEL_20;
          *((_DWORD *)v9 + 1) += v25;
          v12 = v15;
          v7 = a1;
        }
        else
        {
          v12 = v15;
        }
      }
    }
LABEL_31:
    v17 = -1073741701;
    goto LABEL_32;
  }
  v17 = -1073741701;
LABEL_20:
  if( v17 < 0 )
LABEL_32:
    MiFreeImageRetpolineContext(v9);
  return v17;
}

Referenced by:

MiCaptureBootDriverRetpolineInfo
MiParseImageLoadConfig