Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env lua5.3
- -- parse files (ex. img and bin) with magic SINGLE_N_LONELY
- -- works on various Motorola devices
- -- Can use on Windows with: https://sourceforge.net/projects/luabinaries/files/5.4.2/Tools%20Executables/lua-5.4.2_Win64_bin.zip/download
- -- Some use cases: https://forum.xda-developers.com/t/rom-official-lineageos-20-android-13-for-the-motorola-edge-30-dubai.4536169/page-7 and from script author: https://forum.xda-developers.com/t/edl-mode-and-test-point-of-the-moto-g-5g-plus.4371213/page-2#post-87931915
- function abort(msg)
- io.stderr:write(msg .. "\n")
- os.exit()
- end
- function getString(n)
- local dat = f:read(n)
- return dat:gsub("\x00", "")
- end
- function getLong()
- local long = { string.unpack("I8", f:read(8), 1) }
- return long[1]
- end
- function extract(name, offset, length)
- of = io.open(name, "wb")
- f:seek("set", offset)
- of:write(f:read(length))
- of:close()
- end
- if #arg < 1 then
- abort("Usage: unpack.lua radio.img")
- end
- f = io.open(arg[1], "rb")
- magic = getString(256)
- if magic ~= "SINGLE_N_LONELY" then
- abort("Unsupported")
- end
- fsize = f:seek("end")
- f:seek("set", 256)
- for i = 1,64 do
- name = getString(248)
- size = getLong()
- if name == "LONELY_N_SINGLE" then
- break -- no more files
- end
- io.write(string.format("Name: %s, Offset: %d, Size: %d", name, f:seek(), size))
- extract(name, f:seek(), size)
- pad = 0
- if size % 4096 ~= 0 then
- pad = 4096 - (size % 4096)
- f:read(pad)
- end
- print(", Padding: " .. pad)
- end
- f:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement