| 390 | # - based on common binary headers: https://www.garykessler.net/library/file_sigs.html |
| 391 | # - null bytes (are not very common in text files) |
| 392 | def is_binary(path): |
| 393 | with open(path, 'rb') as f: |
| 394 | first_bytes = f.read(1024) |
| 395 | |
| 396 | # Executable and Linking Format executable file (Linux/Unix) |
| 397 | if first_bytes.startswith(bytes.fromhex('7F454C46')): |
| 398 | return True |
| 399 | |
| 400 | # Windows executable |
| 401 | if first_bytes.startswith(bytes.fromhex('4D5A')): |
| 402 | return True |
| 403 | |
| 404 | # Files with null bytes are usually binary (except rare UTF-16 cases) |
| 405 | if b'\x00\x00' in first_bytes: |
| 406 | return True |
| 407 | |
| 408 | return False |
| 409 | |
| 410 | |
| 411 | def is_broken_symlink(file_path): |