KsepPatchDriverImportsTable

NTSTATUS __stdcall KsepPatchDriverImportsTable(_KLDR_DATA_TABLE_ENTRY *DataTableEntry, _KSE_SHIM *Shim){
  UINT64 *v4; 
  NTSTATUS result; 
  __int64 v6; 
  __int64 v7; 
  __int64 v8; 
  int v9; 
  UINT64 v10; 
  UINT64 v11; 
  UINT64 v12; 
  UINT64 v13; 
  UINT64 ImportSize; 

  LODWORD(ImportSize) = 0;
  if( DataTableEntry && Shim )
  {
    v4 = (UINT64 *)RtlImageDirectoryEntryToData(DataTableEntry->DllBase, 1u, 0xCu, &ImportSize);
    if( !v4 )
      return -1073741823;
    v6 = *((_QWORD *)Shim + 6);
    if( v6 )
    {
      LODWORD(v7) = 0;
      while( 1 )
      {
        if( *(_DWORD *)v6 == 4 )
          return 0;
        if( *(_DWORD *)v6 <= 2u )
          break;
LABEL_24:
        v7 = (unsigned int)(v7 + 1);
        v6 = *((_QWORD *)Shim + 6) + 24 * v7;
        if( !v6 )
          return 0;
      }
      v8 = *(_QWORD *)(v6 + 16);
      if( v8 )
      {
        v9 = 0;
        while( 1 )
        {
          if( *(_DWORD *)v8 == 2 )
            goto LABEL_24;
          v10 = *(_QWORD *)(v8 + 16);
          if( !v10 )
            return -1073741811;
          v11 = *(_QWORD *)(v8 + 24);
          if( !v11 || *(_DWORD *)v8 )
            return -1073741811;
          result = KsepPatchImportTableEntry(v4, (unsigned int)ImportSize, v11, v10);
          if( result == -1073741275 )
          {
            if( !VfIsVerifierEnabled() )
              goto LABEL_23;
            if( !VfIsVerificationEnabledForImage(DataTableEntry) )
              goto LABEL_23;
            LODWORD(v12) = VfGetHookAddressForOriginal(*(PSTR *)(v8 + 8));
            v13 = v12;
            if( !v12 )
              goto LABEL_23;
            result = KsepPatchImportTableEntry(v4, (unsigned int)ImportSize, v12, *(_QWORD *)(v8 + 16));
            if( result < 0 )
              goto LABEL_22;
            *(_QWORD *)(v8 + 24) = v13;
          }
          if( result < 0 )
          {
LABEL_22:
            if( result != -1073741275 )
              return result;
          }
LABEL_23:
          v8 = *(_QWORD *)(v6 + 16) + 32i64 * (unsigned int)++v9;
          if( !v8 )
            goto LABEL_24;
        }
      }
    }
  }
  return -1073741811;
}

Referenced by:

KsepApplyShimsToDriver