File size: 2,016 Bytes
3f9d5d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
"""
Simple script to compare two .bin files for exact equality.
Usage: python simple_compare.py file1.bin file2.bin
"""

import sys
import os
import hashlib


def compare_bin_files(file1, file2):
    """Compare two .bin files for exact equality"""
    
    # Check if files exist
    if not os.path.exists(file1):
        print(f"❌ File 1 does not exist: {file1}")
        return False
    
    if not os.path.exists(file2):
        print(f"❌ File 2 does not exist: {file2}")
        return False
    
    # Get file sizes
    size1 = os.path.getsize(file1)
    size2 = os.path.getsize(file2)
    
    print(f"File 1: {file1} ({size1:,} bytes)")
    print(f"File 2: {file2} ({size2:,} bytes)")
    
    # Quick size check
    if size1 != size2:
        print(f"❌ Files have different sizes: {size1:,} vs {size2:,}")
        return False
    
    # Calculate hashes
    print("Calculating hashes...")
    hash1 = hashlib.sha256()
    hash2 = hashlib.sha256()
    
    with open(file1, 'rb') as f1, open(file2, 'rb') as f2:
        while True:
            chunk1 = f1.read(8192)  # 8KB chunks
            chunk2 = f2.read(8192)
            
            if not chunk1 and not chunk2:
                break  # Both files ended
            
            if chunk1:
                hash1.update(chunk1)
            if chunk2:
                hash2.update(chunk2)
    
    hash1_hex = hash1.hexdigest()
    hash2_hex = hash2.hexdigest()
    
    print(f"File 1 hash: {hash1_hex}")
    print(f"File 2 hash: {hash2_hex}")
    
    if hash1_hex == hash2_hex:
        print("✅ Files are identical")
        return True
    else:
        print("❌ Files are different")
        return False


def main():
    if len(sys.argv) != 3:
        print("Usage: python simple_compare.py file1.bin file2.bin")
        sys.exit(1)
    
    file1 = sys.argv[1]
    file2 = sys.argv[2]
    
    result = compare_bin_files(file1, file2)
    sys.exit(0 if result else 1)


if __name__ == "__main__":
    main()