Nvidia and Robotics w/ Barrett Williams – XDA:DevCon 2014

Robotics continues to dominate our videos from this years XDA:DevCon 2014 in … more

Speed Up Deodexing with JoelDroid Batch Deodexer

Android 5.0 Lollipop brings many under-the-hood changes like changing the default compiler … more

Top 5 Apps for 2014 + Top Xposed Mod of 2014 – XDA TV

Its that time of year where you look back and remember the things that happened … more

NVIDIA SHIELD Tablet Gets Android 5.0.1, OTA Available

The NVIDIA SHIELD Tablet is the latest Android-powered device released by famed GPU … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[GPL] Shipped rom extractor (Linux)

OP MartinEve

21st August 2010, 02:35 PM   |  #1  
MartinEve's Avatar
OP Senior Member
Thanks Meter: 14
 
225 posts
Join Date:Joined: Aug 2010
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:
#!/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
Last edited by MartinEve; 21st August 2010 at 02:36 PM. Reason: More info on usage
22nd August 2010, 02:32 PM   |  #2  
warriorvibhu's Avatar
Recognized Developer
Flag San Francisco
Thanks Meter: 170
 
646 posts
Join Date:Joined: Aug 2007
More
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
Last edited by warriorvibhu; 22nd August 2010 at 02:35 PM.
22nd August 2010, 10:50 PM   |  #3  
TheDeadCPU's Avatar
Retired Senior Moderator
Flag ლ(ಠ益ಠლ) Y U WANT MY LOCATION?
Thanks Meter: 684
 
2,015 posts
Join Date:Joined: Jun 2009
More
Ahh! Finally one that works!
Thanks!
23rd August 2010, 11:33 AM   |  #4  
MartinEve's Avatar
OP Senior Member
Thanks Meter: 14
 
225 posts
Join Date:Joined: Aug 2010
Quote:
Originally Posted by TheDeadCpu

Ahh! Finally one that works!
Thanks!

Excellent; glad that my effort wasn't wasted then
28th August 2010, 09:15 PM   |  #5  
Junior Member
Thanks Meter: 0
 
8 posts
Join Date:Joined: Aug 2010
I can't make it work but thanks for your job !
(and for your soft-root too !!)
29th August 2010, 12:45 AM   |  #6  
MartinEve's Avatar
OP Senior Member
Thanks Meter: 14
 
225 posts
Join Date:Joined: Aug 2010
Quote:
Originally Posted by voodka2007

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
29th August 2010, 09:36 PM   |  #7  
Junior Member
Thanks Meter: 0
 
8 posts
Join Date:Joined: 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.
30th August 2010, 01:00 PM   |  #8  
MartinEve's Avatar
OP Senior Member
Thanks Meter: 14
 
225 posts
Join Date:Joined: Aug 2010
Quote:
Originally Posted by voodka2007

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)...
30th August 2010, 08:58 PM   |  #9  
Junior Member
Thanks Meter: 0
 
8 posts
Join Date:Joined: Aug 2010
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/
1st September 2010, 05:58 PM   |  #10  
MartinEve's Avatar
OP Senior Member
Thanks Meter: 14
 
225 posts
Join Date:Joined: Aug 2010
What version of windows have you set in winecfg?

Sent from my HTC Wildfire using XDA App

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes