Sony to Extend its AOSP Program to Other Devices

Sony will be offering its users the possibility to use AOSP ROMs as an alternative to the … more

Project Ara Smartphone Will Run Modified Android L with Hot Swapping

Project Ara is a very exciting topic–both for hardware and … more

Streamline Android Theme Customization with Graphic Porter

I dont have a custom theme on my Android phone, and the reason for this is because … more

Boost the Brightness of Your Sony Xperia Z1’s LED

I think the last time anyone has ever used a physical torch to find their earphones, … more
Post Reply

Extract files from stock firmware images

12th January 2014, 11:20 PM   |  #1  
OP Junior Member
Thanks Meter: 7
 
17 posts
Join Date:Joined: Dec 2013
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: [ View ]
18th February 2014, 12:32 AM   |  #2  
Darkshado's Avatar
Senior Member
Montréal
Thanks Meter: 461
 
990 posts
Join Date:Joined: Apr 2011
Donate to Me
More
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...
Last edited by Darkshado; 18th February 2014 at 12:45 AM.
18th February 2014, 09:59 PM   |  #3  
Senior Member
Thanks Meter: 132
 
436 posts
Join Date:Joined: Dec 2011
Quote:
Originally Posted by Darkshado

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.
Last edited by scott_doyland; 18th February 2014 at 10:03 PM.
19th February 2014, 07:01 AM   |  #4  
OP Junior Member
Thanks Meter: 7
 
17 posts
Join Date:Joined: Dec 2013
Quote:
Originally Posted by scott_doyland

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.
2nd March 2014, 03:21 PM   |  #5  
Senior Member
Thanks Meter: 162
 
229 posts
Join Date:Joined: Mar 2007
There is method to extract files under Windows
4th March 2014, 10:11 PM   |  #6  
HolySid's Avatar
Member
Thanks Meter: 9
 
35 posts
Join Date:Joined: Jun 2012
Quote:
Originally Posted by Al936

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`?
5th March 2014, 07:22 PM   |  #7  
Senior Member
Thanks Meter: 162
 
229 posts
Join Date:Joined: Mar 2007
Quote:
Originally Posted by HolySid

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.
5th March 2014, 07:48 PM   |  #8  
HolySid's Avatar
Member
Thanks Meter: 9
 
35 posts
Join Date:Joined: Jun 2012
Quote:
Originally Posted by Al936

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.
7th March 2014, 06:16 AM   |  #9  
Senior Member
Thanks Meter: 715
 
2,841 posts
Join Date:Joined: Nov 2009
Try running it with wine or in virtual machine.

sent via tapatalk
7th March 2014, 06:22 AM   |  #10  
HolySid's Avatar
Member
Thanks Meter: 9
 
35 posts
Join Date:Joined: 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

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

Advanced Search
Display Modes


Top Threads in Moto G General by ThreadRank