Skip to content

Instantly share code, notes, and snippets.

@kcliu
Created December 21, 2009 17:30
Show Gist options
  • Save kcliu/261093 to your computer and use it in GitHub Desktop.
Save kcliu/261093 to your computer and use it in GitHub Desktop.
combines several binary files
#!/usr/bin/python
import os
import string
import struct
img = ['partition.mbn','oemsblhd.mbn','appsboothd.mbn','qcsblhd_cfgdata.mbn','qcsbl.mbn','oemsbl.mbn','amss.mbn','appsboot.mbn','boot.img','system.img','userdata.img'];
class Combine(object) :
#constructor
def __init__(self, filename):
if os.path.exists(filename) :
self.filename = filename
self.fsize = os.path.getsize(filename)
print "file name =", self.filename, "\nfile size =", self.fsize
else :
print "file doesn't exist"
def writeImg(self):
inputfile = open(self.filename,'rb');
outputfile = open('SD.nb0','wb');
outputfile.write(struct.pack("i",self.fsize)) #write length (packed as integer)
content = inputfile.read();
for i in content :
outputfile.write(i); #write img
inputfile.close();
outputfile.close();
Parti = Combine(img[0])
Parti.writeImg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment