Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 7th, 2012  |  syntax: Python  |  size: 1.19 KB  |  views: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Miori Lorenzo Dec 2012
  2. #
  3. # Samsung YP-F3, YP-U7, YP-W1 Firmware Extractor
  4. #
  5. # ~~~~~ Some fields are still unknown ~~~~~~
  6. #
  7.  
  8. import struct, os, sys
  9.  
  10. romFile = sys.argv[1]
  11.  
  12. outFolder = "%s_extracted/" % romFile
  13.  
  14. os.mkdir(outFolder)
  15. f = open(romFile, "rb")
  16. f.seek(0, 2)
  17. original_size = f.tell()
  18. f.seek(0)
  19. def getValue(bytes):
  20.    
  21.     return struct.unpack("I", bytes)[0]
  22.  
  23. files_no = getValue(f.read(4))
  24. total_size = 0
  25. print "Total files: %i"%files_no
  26. f.seek(0x14)
  27.  
  28. for i in xrange(files_no):
  29.    
  30.     fn = f.read(52).replace("\x00", "")
  31.    
  32.     print "File name: %s"%fn
  33.    
  34.     fsize = getValue(f.read(4))
  35.     total_size += fsize
  36.    
  37.     print "File size: 0x%x bytes"%fsize
  38.    
  39.     fpos = getValue(f.read(4))
  40.    
  41.     print "File pos: 0x%x"%fpos
  42.    
  43.     print "Unknown field: 0x%x bytes"%(getValue(f.read(4)))
  44.    
  45.     pos2continue = f.tell()
  46.  
  47.     f.seek(fpos)
  48.    
  49.     fout = open(outFolder + fn, "wb", 1024)
  50.    
  51.     fout.write(f.read(fsize))
  52.    
  53.     fout.close()
  54.    
  55.     f.seek(pos2continue)
  56.  
  57. f.close()
  58.  
  59. print "Original file size: %i"%original_size
  60. print "Total extracted size: %i"%total_size
  61. print "Header & Stuff %i"%abs(original_size-total_size)