Skip to content

Commit

Permalink
Added "if name == main"
Browse files Browse the repository at this point in the history
  • Loading branch information
WessellUrdata committed Jan 12, 2023
1 parent aac8291 commit 4c63f72
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions patch-vbmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@
FLAGS_TO_SET = b'\x03'


### main program

# if an argument is not provided
if len(sys.argv) != 2:
sys.exit("Usage: python ./" + os.path.basename(__file__) + " <vbmeta-image>")

# try reading the file with read/write to make sure it exists
FILE = sys.argv[1]

try:
fd = os.open(FILE, os.O_RDWR)
except OSError:
sys.exit("Error reading file: " + FILE + ". File not modified. Exiting...")

# making sure it's a vbmeta image by reading the magic bytes at the start of the file
magic = os.read(fd, AVB_MAGIC_LEN)

if (magic != AVB_MAGIC):
fd.close()
sys.exit("Error: The provided image is not a valid vbmeta image. File not modified. Exiting...")

# set the disable-verity and disable-verification flags at offset 123
try:
os.lseek(fd, FLAGS_OFFSET, os.SEEK_SET)
os.write(fd, FLAGS_TO_SET)
except OSError:
fd.close()
sys.exit("Error: Failed when patching the vbmeta image. Exiting...")

# end of program
os.close(fd)
print("Patching successful.")
if __name__ == "__main__":

# if an argument is not provided
if len(sys.argv) != 2:
sys.exit("Usage: python ./" + os.path.basename(__file__) + " <vbmeta-image>")

# try reading the file with read/write to make sure it exists
FILE = sys.argv[1]

try:
fd = os.open(FILE, os.O_RDWR)
except OSError:
sys.exit("Error reading file: " + FILE + ". File not modified. Exiting...")

# making sure it's a vbmeta image by reading the magic bytes at the start of the file
magic = os.read(fd, AVB_MAGIC_LEN)

if (magic != AVB_MAGIC):
fd.close()
sys.exit("Error: The provided image is not a valid vbmeta image. File not modified. Exiting...")

# set the disable-verity and disable-verification flags at offset 123
try:
os.lseek(fd, FLAGS_OFFSET, os.SEEK_SET)
os.write(fd, FLAGS_TO_SET)
except OSError:
fd.close()
sys.exit("Error: Failed when patching the vbmeta image. Exiting...")

# end of program
os.close(fd)
print("Patching successful.")

0 comments on commit 4c63f72

Please sign in to comment.