Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,731,985 Members 41,283 Now Online
XDA Developers Android and Mobile Development Forum

Extract files from stock firmware images

Tip us?
 
pmzqla
Old
#1  
Junior Member - OP
Thanks Meter 7
Posts: 17
Join Date: Dec 2013
Default Extract files from stock firmware images

Hi,

when I still hadn't the device, I wanted to know exactly what's included in stock ROMs to have a better idea of what to expect. I hence downloaded a stock firmare and the stock system.img (see below for the steps).
Ok, so what? Well, when KK was released I decided to do the same (I was still waiting for the device), but I couldn't. Unlike before, I didn't find a single system.img, but multiple files (3 to be exact, maybe it's too big to be flashed at once with fastboot, I don't know, I'm new to this) and couldn't understand how the original image was splitted to generate those files.

Did anyone see something similar already and sucesfully merged splitted filesystems?

I know I could simply ask for a system dump (or wait for KK), but now I'm curious to know on how to do this. I tried few things but I couldn't find any way to do it. Maybe I could see how fastboot treat these files, but I wonder if anyone already knows the answer.


Anyway, here the steps to mount the system.img of our stock JB firmwares. Maybe there's an easier way, I honestly don't know. As far as I know, converting the sparge image should be enough, but I had to do more:
Code:
#Convert sparse image with simg2img
simg2img system.img system.img.raw.tmp

#UTF8 may slow down grep, switch to C
export LANG=C

#Look for the ext4 magic and calculate its position
magic=`grep -aobP -m1 '\x53\xEF' system.img.raw.tmp | head -1 | cut -d":" -f1`
offset=$(($magic-1080))

#Remove extra header with dd
dd if=system.img.raw.tmp of=system.img.raw ibs=$offset skip=1

#Remove temp file
rm system.img.raw.tmp
Now you can mount system.img.raw as a normal ext4 filesystem.
The Following 2 Users Say Thank You to pmzqla For This Useful Post: [ Click to Expand ]
 
Darkshado
Old
(Last edited by Darkshado; 18th February 2014 at 12:45 AM.)
#2  
Darkshado's Avatar
Senior Member
Thanks Meter 428
Posts: 958
Join Date: Apr 2011
Location: Montréal

 
DONATE TO ME
Just concatenate the three chunks together like so:

Code:
cat system.img_sparsechunk1 system.img_sparsechunk2 system.img_sparsechunk3 > system.img
Then apply the steps from the OP and voilà!

Edit: Scratch that: the image is accessible, some files are visible but others are missing. To be continued...
My phones: Galaxy Note II SGH-T889V (with LTE enabled / ext4 SD card support on TouchWiz ROMs), Motorola XT-1045 Moto G LTE (TWRP)
Previous phones: Nexus S GT-I9020A, Galaxy Gio GT-S5660M (Arpeggiomod ROM / Discussion, stock rooted ROM), Motorola XT-1032 Moto G.
Phones for which I play "tech support" for family and friends: Galaxy Nexus GT-I9250, Galaxy Q SGH-T589R, Galaxy 551 GT-I5510M, LG C-800G Eclypse, Motorola XT-1032 Moto G
 
scott_doyland
Old
(Last edited by scott_doyland; 18th February 2014 at 10:03 PM.)
#3  
Senior Member
Thanks Meter 131
Posts: 434
Join Date: Dec 2011
Quote:
Originally Posted by Darkshado View Post
Just concatenate the three chunks together like so:

Code:
cat system.img_sparsechunk1 system.img_sparsechunk2 system.img_sparsechunk3 > system.img
Then apply the steps from the OP and voilà!

Edit: Scratch that: the image is accessible, some files are visible but others are missing. To be continued...
As you have found that doesn't work, remember that each file will have metadata headers so that may be one reason you can't just cat them together.

To OP - can't you just mount each img as a filesystem and copy all the files from each mounted filesystem to another entirely separate directory. At least that way you have all the files in one place, eg copy

/sparsechunk1/system/file1 to /newdir/system/file1

And so on.
 
pmzqla
Old
#4  
Junior Member - OP
Thanks Meter 7
Posts: 17
Join Date: Dec 2013
Quote:
Originally Posted by scott_doyland View Post
As you have found that doesn't work, remember that each file will have metadata headers so that may be one reason you can't just cat them together.

To OP - can't you just mount each img as a filesystem and copy all the files from each mounted filesystem to another entirely separate directory. At least that way you have all the files in one place, eg copy

/sparsechunk1/system/file1 to /newdir/system/file1

And so on.
Only the first chunk can be mounted, the other two are not recognized as filesystem and there's no way to mount them.
It's not as if /system was divided in three parts and then an image for each one was created, so that you can treat them as separate files (what you said would work in this case).
One image is created and then it's splitted in three in some unknown way. The first image is the one that holds the informations to access the files, the other two just pieces of files that can't be accessed without the informations in the first chunk.

mfastboot knows how to correctly copy the data from the separate images with the right offsets inside the phone so that in the end all the files can be accessed. Concatenating the files using dd using the correct offsets could maybe work, but after a few attempts I gave up.
 
Al936
Old
#5  
Senior Member
Thanks Meter 147
Posts: 225
Join Date: Mar 2007
There is method to extract files under Windows
 
HolySid
Old
#6  
HolySid's Avatar
Member
Thanks Meter 9
Posts: 35
Join Date: Jun 2012
Quote:
Originally Posted by Al936 View Post
There is method to extract files under Windows
Any change you happen to be willing to share the contents of or principles behind `sparse2img.exe`?
 
Al936
Old
#7  
Senior Member
Thanks Meter 147
Posts: 225
Join Date: Mar 2007
Quote:
Originally Posted by HolySid View Post
Any change you happen to be willing to share the contents of or principles behind `sparse2img.exe`?
What kind of principles you expect from me? I just posted the link to one of the method to extract all files and folders from stock firmware's system partition. The tools were not developed by me - I just informed XDA community about it. As you can see from the tread several persons already confirmed that it works.
 
HolySid
Old
#8  
HolySid's Avatar
Member
Thanks Meter 9
Posts: 35
Join Date: Jun 2012
Quote:
Originally Posted by Al936 View Post
What kind of principles you expect from me? I just posted the link to one of the method to extract all files and folders from stock firmware's system partition. The tools were not developed by me - I just informed XDA community about it. As you can see from the tread several persons already confirmed that it works.
Oh, I'm sorry, I thought it was your work. I just want to know how to merge the system files. I know the exe is working, but I'm running Linux, so my question it is both out of curiosity and simply because I cannot run the code.
 
eksasol
Old
#9  
Senior Member
Thanks Meter 686
Posts: 2,723
Join Date: Nov 2009
Try running it with wine or in virtual machine.

sent via tapatalk
 
HolySid
Old
#10  
HolySid's Avatar
Member
Thanks Meter 9
Posts: 35
Join Date: Jun 2012
Thanks, I managed it by using another laptop. But still, I'd rather know what happened

Sent from my XT1032 using xda app-developers app

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

Samsung Gear Live Stock Firmware Image Pulled, Temp Root

Just yesterday,XDA Recognized Developer and TV ProducerAdamOutlertore apart … more

Draw a Line and Let Your Device Do the Rest with LineitApp

Over the years, since evenbefore Android entered the scene, we have striven to … more

[APK] Chrome Beta 37 Brings First Traces of Material Design

With Android L on the horizon, it’s no surprise that Google’s … more

Immersive Mode on Unrooted Devices with GMD Full Screen Immersive Mode

Everyone likes screen real estate–no question about that. The … more