-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpatch_checker.py
50 lines (39 loc) · 1.28 KB
/
patch_checker.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
from StreamIO import *
def is_overlapping(x1: int, x2: int, y1: int, y2: int):
return x1 <= y2 and y1 <= x2
def eval_patches(patch_data: (bytes, bytearray)) -> None:
patches = []
with StreamIO(patch_data, Endian.BIG) as psio:
while True:
addr = psio.read_uint32()
if addr == 0xFFFFFFFF:
break
size = psio.read_uint32()
patch = psio.read_ubytes(size * 4)
patches.append(range(addr, addr + len(patch)))
for i in range(len(patches)):
tmp = list(patches)
patch_range = tmp.pop(i)
x = patch_range
for j in range(len(tmp)):
y = tmp[j]
if is_overlapping(x.start, x.stop + 1, y.start, y.stop + 1):
print("Patch Conflict!")
print(f"Patch A: 0x{x.start:08X} - 0x{x.stop:08X}")
print(f"Patch B: 0x{y.start:08X} - 0x{y.stop:08X}")
def read_file(filename: str) -> bytes:
with open(filename, "rb") as f:
data = f.read()
return data
def write_file(filename: str, data: (bytes, bytearray)) -> None:
with open(filename, "wb") as f:
f.write(data)
def main() -> int:
eval_patches(read_file("Output/NonZero/RGL_flash.bin"))
eval_patches(read_file("Output/NonZero/RGL_hdd.bin"))
eval_patches(read_file("Output/Zero/VRGL_flash.bin"))
eval_patches(read_file("Output/Zero/VRGL_hdd.bin"))
return 0
if __name__ == "__main__":
exit(main())