-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpixel_sdm_fix.py
43 lines (31 loc) · 962 Bytes
/
pixel_sdm_fix.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
#!/usr/bin/env python
# Copyright (c) 2021 handymenny
# This file is licensed under the MIT LICENSE.
# A copy of this license may be found at https://opensource.org/licenses/MIT
import shutil
import sys
def backup(filepath):
shutil.copy2(filepath, filepath + '.bak')
def replace_header(filepath):
f = open(filepath, 'rb+')
# check if 4th byte is already ok
f.seek(3)
if f.read(1) == b'\xfd':
print(f'{filepath} already has the right header')
return
# replace 4th byte
f.seek(3)
f.write(bytes((0xfd,)))
f.close()
return
inputArgs = sys.argv
if len(inputArgs) < 2:
print("Missing file operand")
print("Usage: SDM_FILE...\nFix the header of the SDM_FILE(s).\nA backup file (.bak) is generated automatically")
sys.exit(1)
for i in inputArgs[1:]:
try:
backup(i)
replace_header(i)
except Exception as e:
print(e)