forked from osresearch/airbreak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offset_diff.py
32 lines (29 loc) · 1.47 KB
/
offset_diff.py
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
import sys
def comparer(file1, file2):
content1 = file1.readlines()
content2 = file2.readlines()
if len(content1) != len(content2):
print("Something went wrong. Length mismatch")
exit(1)
output = open("offset_differences.csv", "w")
# Grabbing the filename. It's weird, but it works
output.write("offset, " + str(file1).split("name='")[1].split("'")[0] + ", " +
str(file2).split("name='")[1].split("'")[0] + "\n")
for counter in range(len(content1)):
offset1, hexvalue1 = content1[counter].split(":")[0], content1[counter].split(" ")[1]
offset2, hexvalue2 = content2[counter].split(":")[0], content2[counter].split(" ")[1]
if offset1 != offset2:
print("Offset mismatch. Please run 'xxd -c 1 <file> > <file>.hex on both files again")
exit(1)
if hexvalue1 != hexvalue2:
# Looks weird, but just doing some CSV formatting
output.write("\"=\"\""+offset1+"\"\"\""+", \"=\"\""+hexvalue1+"\"\"\""+", \"=\"\""+hexvalue2+"\"\"\"\n")
# "=""123"""
if len(sys.argv) == 3 and sys.argv[1][-3:] != "bin" and sys.argv[2][-3:] != "bin":
with open(sys.argv[1],"r") as file1, open(sys.argv[2],"r") as file2:
comparer(file1,file2)
else:
print("This program will compare two hex dumps and will output non-matching offsets")
print("Run 'xxd -c 1 <file> > <file>.hex' on both files first.")
print("Usage: python offset_diff.py hexfile1 hexfile2")
sys.exit(1)