Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,739,676 Members 51,409 Now Online
XDA Developers Android and Mobile Development Forum

[GPL] Shipped rom extractor (Linux)

Tip us?
 
MartinEve
Old
(Last edited by MartinEve; 21st August 2010 at 01:36 PM.) Reason: More info on usage
#1  
MartinEve's Avatar
Senior Member - OP
Thanks Meter 13
Posts: 225
Join Date: Aug 2010
Default [GPL] Shipped rom extractor (Linux)

For the first time, I today attempted to extract a rom.zip from a shipped rom release (.exe) on Linux.

The process is problematic as, after launching the executable using wine, the application crashes, deleting all its files. You therefore have to be *very* quick looking inside the ~/.wine/users/username/Temp folder for the rom.zip.

Anyway, I have knocked up a quick python script that will monitor this directory for rom.zip and copy it to your home folder.

The only modification you need to make before running is to change the username field to your own username. I would have used getpass to obtain this but, for some reason, on certain systems you need to use sudo which messes this up.

Usage:
1.) Change username in script
2.) Run script
3.) Run RUU_xxxxxx.exe
4.) Get rom.zip from home folder

Anyway, I hope this is helpful and look forward to hearing feedback.

Best,

Martin

Code:
Select Code
#!/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 IS REQUIRED (you may have to run as root using sudo)
username = "martin"

# Modify these if using a different wine location or rom name; HTC seem to use rom.zip
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):
		 # this seems to be the event fired; IN_CREATE is included just in case, though
		 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):
	 	# on modify, append to the file
	 	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 to /home/%s/rom.zip" % username
			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
 
warriorvibhu
Old
(Last edited by warriorvibhu; 22nd August 2010 at 01:35 PM.)
#2  
warriorvibhu's Avatar
Recognized Developer
Thanks Meter 162
Posts: 626
Join Date: Aug 2007
Location: San Francisco
Hey Martin there is a tool already available for this here in Forums... dint work for me for some reason.. Just informing you so that u do not reinvent the wheel ..
EDIT :: here it is: http://forum.xda-developers.com/showthread.php?t=711298
Regards
 
TheDeadCPU
Old
#3  
TheDeadCPU's Avatar
Retired Senior Moderator
Thanks Meter 681
Posts: 2,014
Join Date: Jun 2009
Location: ლ(ಠ益ಠლ) Y U WANT MY LOCATION?
Ahh! Finally one that works!
Thanks!
Follow me on twitter?
Please only PM on very urgent matter. All other PMs will be ignored.
 
MartinEve
Old
#4  
MartinEve's Avatar
Senior Member - OP
Thanks Meter 13
Posts: 225
Join Date: Aug 2010
Quote:
Originally Posted by TheDeadCpu View Post
Ahh! Finally one that works!
Thanks!
Excellent; glad that my effort wasn't wasted then
 
voodka2007
Old
#5  
Junior Member
Thanks Meter 0
Posts: 8
Join Date: Aug 2010
I can't make it work but thanks for your job !
(and for your soft-root too !!)
 
MartinEve
Old
#6  
MartinEve's Avatar
Senior Member - OP
Thanks Meter 13
Posts: 225
Join Date: Aug 2010
Quote:
Originally Posted by voodka2007 View Post
I can't make it work but thanks for your job !
(and for your soft-root too !!)
Could you be more specific about what happens when you run it and it doesn't work? You need python-py-inotify for it to detect the file...



Sent from my HTC Wildfire using XDA App
 
voodka2007
Old
#7  
Junior Member
Thanks Meter 0
Posts: 8
Join Date: Aug 2010
Script can be run, it just can't found rom.zip... i have install python-pyinotify package, and it's same.

I have try 2 monitoring path :

~/.wine/dosdevices/c:/windows/temp
and

~/.wine/drive_c/windows/temp

I have try with root, sudo, check username, chmod the script, and it's same.
 
MartinEve
Old
#8  
MartinEve's Avatar
Senior Member - OP
Thanks Meter 13
Posts: 225
Join Date: Aug 2010
Quote:
Originally Posted by voodka2007 View Post
Script can be run, it just can't found rom.zip... i have install python-pyinotify package, and it's same.

I have try 2 monitoring path :

~/.wine/dosdevices/c:/windows/temp
and

~/.wine/drive_c/windows/temp

I have try with root, sudo, check username, chmod the script, and it's same.
Check the format of your path. It should be like this:

monitor_path = "~/.wine/drive_c/users/%s/Temp/" % username

This is because it won't extract to c:\Windows\Temp but to c:\Users\Username\Temp

Try leaving monitor path just as it was (but change the username)...
 
voodka2007
Old
#9  
Junior Member
Thanks Meter 0
Posts: 8
Join Date: Aug 2010
Code:
Select Code
[Pyinotify ERROR] add_watch: cannot watch /home/voodka/.wine/drive_c/users/voodka/Temp/ (WD=-1)
I haven't users folder in my .wine/drive_c/
 
MartinEve
Old
#10  
MartinEve's Avatar
Senior Member - OP
Thanks Meter 13
Posts: 225
Join Date: Aug 2010
What version of windows have you set in winecfg?

Sent from my HTC Wildfire using XDA App

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


TRENDING IN THEMER...