Advertisement
Guest User

Motorola unpack radio.img / gpt.bin / "SINGLE_N_LONELY" layout files

a guest
May 12th, 2023
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | Source Code | 0 0
  1. #!/usr/bin/env lua5.3
  2. -- parse files (ex. img and bin) with magic SINGLE_N_LONELY
  3. -- works on various Motorola devices
  4.  
  5. -- Can use on Windows with: https://sourceforge.net/projects/luabinaries/files/5.4.2/Tools%20Executables/lua-5.4.2_Win64_bin.zip/download​​​
  6. -- 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
  7.  
  8. function abort(msg)
  9.   io.stderr:write(msg .. "\n")
  10.   os.exit()
  11. end
  12.  
  13. function getString(n)
  14.   local dat = f:read(n)
  15.   return dat:gsub("\x00", "")
  16. end
  17.  
  18. function getLong()
  19.   local long = { string.unpack("I8", f:read(8), 1) }
  20.   return long[1]
  21. end
  22.  
  23. function extract(name, offset, length)
  24.   of = io.open(name, "wb")
  25.   f:seek("set", offset)
  26.   of:write(f:read(length))
  27.   of:close()
  28. end
  29.  
  30. if #arg < 1 then
  31.   abort("Usage: unpack.lua radio.img")
  32. end
  33.  
  34. f = io.open(arg[1], "rb")
  35.  
  36. magic = getString(256)
  37. if magic ~= "SINGLE_N_LONELY" then
  38.   abort("Unsupported")
  39. end
  40.  
  41. fsize = f:seek("end")
  42. f:seek("set", 256)
  43.  
  44. for i = 1,64 do
  45.   name = getString(248)
  46.   size = getLong()
  47.   if name == "LONELY_N_SINGLE" then
  48.     break -- no more files
  49.   end
  50.   io.write(string.format("Name: %s, Offset: %d, Size: %d", name, f:seek(), size))
  51.   extract(name, f:seek(), size)
  52.   pad = 0
  53.   if size % 4096 ~= 0 then
  54.     pad = 4096 - (size % 4096)
  55.     f:read(pad)
  56.   end
  57.   print(", Padding: " .. pad)
  58. end
  59.  
  60. f:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement