Skip to content

Instantly share code, notes, and snippets.

@R0rt1z2
Created October 3, 2021 16:43
Show Gist options
  • Save R0rt1z2/7162d90b8ada352ba1ad8e4835d76e35 to your computer and use it in GitHub Desktop.
Save R0rt1z2/7162d90b8ada352ba1ad8e4835d76e35 to your computer and use it in GitHub Desktop.
Xiaomi Buffer Fix Patcher (based on HighwayStar's ASM patch)
#
# Buffer fix for com.qti.chi.override.so.
# Original fix: https://gist.github.com/HighwayStar/3da60a36395fa992cf4afc9f01449203
#
import sys
ORIG_SEQ = b'2\xffO\xf4\xfab\x11\x99'
PTCH_SEQ = b'2\xffO\xf0\x00\x02\x11\x99'
def main():
try:
library = open(sys.argv[1], "rb")
data = library.read()
except Exception as e:
exit(f"Couldn't read data from {sys.argv[1]} ({e})!'")
library.close()
patch_offset = data.find(ORIG_SEQ)
if (patch_offset == -1):
exit(f"Couldn't find the original sequence!")
print(f"Found sequence at {hex(patch_offset)}")
try:
library = open(sys.argv[1], "wb")
library.write(data)
library.seek(patch_offset)
library.write(PTCH_SEQ)
except Exception as e:
exit(f"Couldn't write data to {sys.argv[1]} ({e})!")
print(f"Successfully patched {sys.argv[1]}!")
if __name__ == "__main__":
if (len(sys.argv) < 2):
exit(f"USAGE: {sys.argv[0]} com.qti.chi.override.so")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment