FsRtlReleaseFileForModWrite

VOID __stdcall FsRtlReleaseFileForModWrite(_FILE_OBJECT *FileObject, _ERESOURCE *ResourceToRelease){
  signed int v3; 
  INT64 *v4; 
  char v5; 
  __int64 v6; 
  _DEVICE_OBJECT *BaseFileSystemDeviceObject; 
  __int64 v8; 
  __int64 v9; 
  __int64 v10; 
  struct _ERESOURCE *v11; 
  int v12; 
  int v13; 
  __int64(__fastcall *v14)(_FILE_OBJECT *, struct _ERESOURCE *, _DEVICE_OBJECT *); 
  __int64 v15; 
  char v16; 
  int a4; 
  PERESOURCE Resource; 
  _DEVICE_OBJECT *RelatedDeviceObject; 
  INT64 result[8]; 
  char v21; 
  Resource = ResourceToRelease;
  memset((INT64)result, 0i64);
  v3 = 0;
  v4 = result;
  a4 = 0;
  v16 = 0;
  v5 = 0;
  RelatedDeviceObject = IoGetRelatedDeviceObject(FileObject);
  BaseFileSystemDeviceObject = IoGetBaseFileSystemDeviceObject(FileObject);
  v8 = *((_QWORD *)BaseFileSystemDeviceObject + 1);
  v9 = *(_QWORD *)(v8 + 80);
  v10 = *(_QWORD *)(*(_QWORD *)(v8 + 48) + 48i64);
  if( v10 && (*(_DWORD *)v10 >= 0x60u && *(_QWORD *)(v10 + 88) || *(_DWORD *)v10 >= 0x68u && *(_QWORD *)(v10 + 96)) )
    v5 = 1;
  if( RelatedDeviceObject == BaseFileSystemDeviceObject && !v5 )
  {
    v11 = Resource;
    v4 = 0i64;
    goto LABEL_11;
  }
  FsFilterCtrlInit((__int64)result, 252, (__int64)RelatedDeviceObject, v6, (__int64)FileObject, 0);
  v11 = Resource;
  result[3] = (INT64)Resource;
  v12 = FsFilterPerformCallbacks((INT64)result, 0, 1, &a4);
  v13 = 0;
  v3 = v12;
  if( v12 >= 0 )
  {
    if( v12 )
    {
      if( v12 != 294 )
        v13 = v12;
      v3 = v13;
LABEL_23:
      if( v3 >= 0 )
        goto LABEL_24;
      goto LABEL_36;
    }
    FileObject = (_FILE_OBJECT *)result[2];
    if( (v21 & 4) != 0 )
    {
      BaseFileSystemDeviceObject = IoGetDeviceAttachmentBaseRefWithTag((DEVICE_OBJECT *)result[1], 0x746C6644ui64);
      v16 = 1;
      v15 = *((_QWORD *)BaseFileSystemDeviceObject + 1);
      v9 = *(_QWORD *)(v15 + 80);
      v10 = *(_QWORD *)(*(_QWORD *)(v15 + 48) + 48i64);
    }
LABEL_11:
    if( !v10
      || (*(_DWORD *)v10 < 0x60u || !*(_QWORD *)(v10 + 88)) && (*(_DWORD *)v10 < 0x68u || !*(_QWORD *)(v10 + 96)) )
    {
      if( v9
        && *(_DWORD *)v9 >= 0xD0u
        && (v14 = *(__int64(__fastcall **)(_FILE_OBJECT *, struct _ERESOURCE *, _DEVICE_OBJECT *))(v9 + 200)) != 0i64 )
      {
        v3 = v14(FileObject, v11, BaseFileSystemDeviceObject);
      }
      else
      {
        v3 = -1073741808;
      }
      a4 |= 1u;
    }
    if( v16 )
      ObfDereferenceObjectWithTag(BaseFileSystemDeviceObject, 0x746C6644ui64);
    goto LABEL_23;
  }
LABEL_36:
  if( (a4 & 1) != 0 )
  {
    ExReleaseResourceLite(v11);
    v3 = 0;
  }
LABEL_24:
  if( v4 )
  {
    if( *((_WORD *)v4 + 37) )
      FsFilterPerformCompletionCallbacks((__int64)result, v3);
    if( (v21 & 1) != 0 )
      FsFilterFreeCompletionStack((INT64)result);
  }
}

Referenced by:

MiGatherMappedPages
MiWriteComplete