def _FixNtfsMode(mode: int) -> int:
  """Fix NTFS permissions returned by TSK."""
  # TSK with NTFS reports the following permissions:
  # r-xr-xr-x for hidden files
  # -wx-wx-wx for read-only files
  # We want to report the reversed mapping, because it makes more sense.

  permissions = mode & 0o777

  if permissions == 0o333:
    return (mode & ~0o777) | 0o555
  elif permissions == 0o555:
    return (mode & ~0o777) | 0o333
  else:
    return mode