├── README.md ├── LICENSE └── binary-rev-change.py /README.md: -------------------------------------------------------------------------------- 1 | # binary-rev-change 2 | A simple utility to tinker with Samsung's SW REV byte 3 | 4 | ## Usage 5 | ``` 6 | python3 binary-rev-change.py image target_rev_in_hexadecimal 7 | ``` 8 | 9 | And that's about it :) 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 BotchedRPR 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /binary-rev-change.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import argparse 4 | import os 5 | import pathlib 6 | 7 | verbose = 0 8 | 9 | binRevOffset = 8 # ********X**** 10 | 11 | def parseArgs(): 12 | parser = argparse.ArgumentParser(description="change the binary version of Samsung firmware [v0.2.1]") 13 | parser.add_argument("-v", "--verbose", action="store_true") 14 | parser.add_argument("filename", help="Filename (WITHOUT LZMA (NOT .LZ4))") 15 | parser.add_argument("target", help="Target binary revision") 16 | args = parser.parse_args() 17 | return args 18 | 19 | def printVerbose(text): 20 | if verbose == 1: 21 | print("[D] ", text) 22 | 23 | def askForModelString(): 24 | print("For some reason, the script couldn't find your model string.") 25 | modelString = input("You need to enter it manually. (ex. A528BXXS6EWK1):") 26 | return modelString 27 | 28 | def tryFindModelString(_content): 29 | modelString = _content.decode('ascii', errors='replace').rfind("SM-") # This should be last, in the firmwares that I've seen at least. 30 | 31 | # Try to fix this up soon 32 | if modelString == -1: 33 | finModelString = _content.decode('ascii', errors='replace').rfind(askForModelString()) 34 | if modelString == -1: 35 | print("Can't find your model string. Sorry!") 36 | exit(1) 37 | else: 38 | finModelString = modelString - 48 # Hopefully try to dehardcode this soon? Maybe from SignerVer offset? 39 | 40 | return finModelString 41 | 42 | def main(): 43 | global verbose 44 | 45 | args = parseArgs() 46 | 47 | if args.verbose == True: 48 | verbose = 1 49 | 50 | if "super" in pathlib.Path(args.filename).stem: 51 | print("This tool won't work on super.imgs.") 52 | print("They're too big for the tool to handle.") 53 | exit(2) 54 | 55 | if ".lz4" in pathlib.Path(args.filename).suffix: 56 | print("This tool doesn't support lz4 images.") 57 | exit(2) 58 | 59 | printVerbose("Trying to open file") 60 | 61 | # This should be reworked for huge images! 62 | file = open(args.filename, "rb") 63 | 64 | fileContent = file.read() 65 | file.close() 66 | 67 | modelStringOffset = tryFindModelString(fileContent) 68 | 69 | currentBinRev = chr(fileContent[modelStringOffset + binRevOffset]) 70 | 71 | printVerbose(currentBinRev) 72 | printVerbose(hex(modelStringOffset)) 73 | 74 | if currentBinRev == args.target: 75 | print("Target binary revision is the same as current binary revision.") 76 | exit(1) 77 | 78 | fullBinRevOffset = modelStringOffset + binRevOffset 79 | 80 | newFileContent = fileContent[:fullBinRevOffset] + args.target.encode('ascii') + fileContent[(fullBinRevOffset + 1):] 81 | 82 | file = open(args.filename, "wb") 83 | file.seek(0) 84 | file.write(newFileContent) 85 | file.close() 86 | 87 | print("[*] Done!") 88 | exit(0) 89 | 90 | main() 91 | --------------------------------------------------------------------------------