Martin Paul Eve bio photo

Martin Paul Eve

Professor of Literature, Technology and Publishing at Birkbeck, University of London

Email Books Twitter Google+ Github Stackoverflow MLA CORE Institutional Repo Hypothes.is ORCID ID   ORCID iD

Email Updates

As my hobby-geek phase draws to a close and I return well and truly to my PhD, I thought it worth sharing this python script I wrote a while back which will extract the update.zip file from an Android RUU.exe file on Linux. There are other items out there that do the same thing, but this is my effort.

Usage: modify the options, start the script and then run the RUU under Wine.

#!/usr/bin/python

'''
    ROM Extractor Copyright (c) 2010 Martin Paul Eve
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

import os
import pyinotify
import io

# USERNAME = REQUIRED
username = "martin"

# Modify these if using a different format; HTC seem to go by this standard
filename = "rom.zip"
monitor_path = "~/.wine/drive_c/users/%s/Temp/" % username


wm = pyinotify.WatchManager()
mask = pyinotify.IN_CREATE | pyinotify.IN_MODIFY | pyinotify.IN_DELETE | pyinotify.IN_MOVED_TO
bd = None

class RExtract(pyinotify.ProcessEvent):
	def process_IN_MOVED_TO(self, event):
		 if event.name.endswith(filename):
	 		 print "Found ROM. Awaiting completion of modification."
	 		 self.f = open(os.path.join(event.path, event.name), "r")
	 		 self.bd = self.f.read()
	def process_IN_CREATE(self, event):
		 if event.name.endswith(filename):
	 		 print "Found ROM. Awaiting completion of modification."
	 		 self.f = open(os.path.join(event.path, event.name), "r")
	def process_IN_MODIFY(self, event):
	 if event.name.endswith(filename):
	 	 if hasattr(self, "bd"):
			 self.bd = self.bd + self.f.read()
		 else:
			 self.bd = self.f.read()
 	def process_IN_DELETE(self, event):
 		 if event.name.endswith(filename):
			 self.f.close()
	 		 self.f = open(os.path.join("/home/%s/" % username, "rom.zip"), "w")
	 		 self.f.write(self.bd)
	 		 self.f.close()
			 print "ROM Copied"
	 		 raise KeyboardInterrupt

notifier = pyinotify.Notifier(wm, RExtract())
print "ROM Extractor Copyright (c) 2010 Martin Paul Eve"
print "This program comes with ABSOLUTELY NO WARRANTY."
print "This is free software, and you are welcome to redistribute it under certain conditions; see the included licence statement"
print ""
print "Monitoring: %(path)s for %(filename)s" % {"path": os.path.expanduser(monitor_path), "filename": filename}
print "Press CTRL+C to exit"

wdd = wm.add_watch(os.path.expanduser(monitor_path), mask, rec=True, auto_add=True)

while True:
	try:
	 notifier.process_events()
	 if notifier.check_events():
		notifier.read_events()
	except KeyboardInterrupt:
	 notifier.stop()
	 break