Last active
November 1, 2023 01:13
-
-
Save adithya2306/88e8fc468695bcdaa8b880ba4bd01420 to your computer and use it in GitHub Desktop.
Revisions
-
adithya2306 revised this gist
May 20, 2023 . 1 changed file with 2 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,29 +7,24 @@ import struct import sys def abort(msg): sys.stderr.write(msg + "\n") sys.exit() def get_string(f, n): dat = f.read(n) return dat.replace(b"\x00", b"") def get_long(f): long_bytes = f.read(8) long_value = struct.unpack("Q", long_bytes)[0] return long_value def extract(name, offset, length): with open(name, "wb") as of: f.seek(offset) of.write(f.read(length)) if len(sys.argv) < 2: abort("Usage: unpack.py radio.img") @@ -46,10 +41,10 @@ def extract(name, offset, length): size = get_long(f) if name == b"LONELY_N_SINGLE": break # no more files extract(name.decode(), f.tell(), size) pad = 0 if size % 4096 != 0: pad = 4096 - (size % 4096) f.read(pad) print("Name: {}, Offset: {}, Size: {}, Padding: {}".format(name.decode(), f.tell(), size, pad)) -
adithya2306 created this gist
May 20, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ #!/usr/bin/env python # # based on https://pastebin.com/raw/9w5TBnSv # credits to original author HemanthJabalpuri @ XDA # converted to python using chatgpt import struct import sys def abort(msg): sys.stderr.write(msg + "\n") sys.exit() def get_string(f, n): dat = f.read(n) return dat.replace(b"\x00", b"") def get_long(f): long_bytes = f.read(8) long_value = struct.unpack("Q", long_bytes)[0] return long_value def extract(name, offset, length): with open(name, "wb") as of: f.seek(offset) of.write(f.read(length)) if len(sys.argv) < 2: abort("Usage: unpack.py radio.img") with open(sys.argv[1], "rb") as f: magic = get_string(f, 256) if magic != b"SINGLE_N_LONELY": abort("Unsupported") fsize = f.seek(0, 2) f.seek(256) for i in range(1, 65): name = get_string(f, 248) size = get_long(f) if name == b"LONELY_N_SINGLE": break # no more files print("Name: {}, Offset: {}, Size: {}".format(name.decode(), f.tell(), size)) extract(name.decode(), f.tell(), size) pad = 0 if size % 4096 != 0: pad = 4096 - (size % 4096) f.read(pad) print(", Padding: {}".format(pad))