Repository navigation
Expand file tree
/
Copy pathbinary-rev-change.py
More file actions
90 lines (64 loc) · 2.54 KB
/
Copy pathbinary-rev-change.py
File metadata and controls
90 lines (64 loc) · 2.54 KB
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
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
import argparse
import os
import pathlib
verbose = 0
binRevOffset = 8 # ********X****
def parseArgs():
parser = argparse.ArgumentParser(description="change the binary version of Samsung firmware [v0.2.1]")
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument("filename", help="Filename (WITHOUT LZMA (NOT .LZ4))")
parser.add_argument("target", help="Target binary revision")
args = parser.parse_args()
return args
def printVerbose(text):
if verbose == 1:
print("[D] ", text)
def askForModelString():
print("For some reason, the script couldn't find your model string.")
modelString = input("You need to enter it manually. (ex. A528BXXS6EWK1):")
return modelString
def tryFindModelString(_content):
modelString = _content.decode('ascii', errors='replace').rfind("SM-") # This should be last, in the firmwares that I've seen at least.
# Try to fix this up soon
if modelString == -1:
finModelString = _content.decode('ascii', errors='replace').rfind(askForModelString())
if modelString == -1:
print("Can't find your model string. Sorry!")
exit(1)
else:
finModelString = modelString - 48 # Hopefully try to dehardcode this soon? Maybe from SignerVer offset?
return finModelString
def main():
global verbose
args = parseArgs()
if args.verbose == True:
verbose = 1
if "super" in pathlib.Path(args.filename).stem:
print("This tool won't work on super.imgs.")
print("They're too big for the tool to handle.")
exit(2)
if ".lz4" in pathlib.Path(args.filename).suffix:
print("This tool doesn't support lz4 images.")
exit(2)
printVerbose("Trying to open file")
# This should be reworked for huge images!
file = open(args.filename, "rb")
fileContent = file.read()
file.close()
modelStringOffset = tryFindModelString(fileContent)
currentBinRev = chr(fileContent[modelStringOffset + binRevOffset])
printVerbose(currentBinRev)
printVerbose(hex(modelStringOffset))
if currentBinRev == args.target:
print("Target binary revision is the same as current binary revision.")
exit(1)
fullBinRevOffset = modelStringOffset + binRevOffset
newFileContent = fileContent[:fullBinRevOffset] + args.target.encode('ascii') + fileContent[(fullBinRevOffset + 1):]
file = open(args.filename, "wb")
file.seek(0)
file.write(newFileContent)
file.close()
print("[*] Done!")
exit(0)
main()