concrete

getpartbin.py

Feb 15th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. import os
  2. from struct import *
  3.  
  4. def mbr():
  5.     global offset, partitions
  6.     os.popen("adb shell su -c 'dd if=/dev/block/mmcblk0 of=/cache/partition0.bin bs=512 count=1'").close()
  7.     os.popen("adb shell su -c 'cp /cache/partition0.bin /sdcard/partition0.bin'").close()
  8.     os.popen("adb pull /sdcard/partition0.bin .").close()
  9.     f =  open("partition0.bin", 'rb')
  10.     data = f.read()
  11.     f.close()
  12.     partitions = [ ]
  13.     n=0
  14.     while True:
  15.         buf = data[446+(16*n):446+(16*(n+1))]
  16.         partition = dict(zip(('boot', 'id', 'start', 'size'), unpack('4I', buf)))
  17.         partition['type'] = "MBR"
  18.         n += 1
  19.         partition['no'] = n
  20.         partitions.append(partition)
  21.         if partition['id'] == 5:
  22.             offset = partition['start']
  23.             break
  24.  
  25. def ebr():
  26.     global offset, partitions
  27.     n = 0
  28.     while True:
  29.         a = 0
  30.         os.popen("adb shell su -c 'dd if=/dev/block/mmcblk0 of=/cache/ebr bs=512 count=1 skip=" + str(offset+n) + "\'").close()
  31.         n += 1
  32.         os.popen("adb shell su -c 'dd if=/cache/ebr of=/cache/partition0.bin bs=512 count=1 seek=" + str(n) + "'").close()
  33.         os.popen("adb shell su -c 'cp /cache/ebr /sdcard/partition0.bin'").close()
  34.         os.popen("adb pull /sdcard/partition0.bin .").close()
  35.         f = open("partition0.bin", 'rb')
  36.         data = f.read()
  37.         f.close()
  38.         while True:
  39.             buf = data[446+16*a:446+16*(a+1)]
  40.             partition = dict(zip(('boot', 'id', 'start', 'size'), unpack('4I', buf)))
  41.             if partition['id'] == 5:
  42.                 break
  43.             if partition['id'] == 0:
  44.                 return
  45.             partition['type'] = "EBR"
  46.             partition['no'] = n
  47.             partition['start'] += n-1+offset
  48.             partitions.append(partition)
  49.             a += 1
  50.  
  51.  
  52. if __name__ == "__main__":
  53.     mbr()
  54.     ebr()
  55.     os.popen("adb shell su -c 'cp /cache/partition0.bin /sdcard/partition0.bin'").close()
  56.     os.popen("adb pull /sdcard/partition0.bin .").close()
  57.     for part in partitions:
  58.         print "%s %2i, Boot: 0x%02X, Id: 0x%02X, Start: 0x%08X (%8i), Size: 0x%08X (%8i, %8i KB)" % (part['type'], part['no'], part['boot'], part['id'], part['start'], part['start'], part['size'], part['size'], part['size']/2)
Advertisement
Add Comment
Please, Sign In to add comment