anestisb / android-simg2img Goto Github PK
View Code? Open in Web Editor NEWTool to convert Android sparse images to raw images
Tool to convert Android sparse images to raw images
Hi there,
After processing Motorola images with simg2img it seems that these files can't be mounted correctly. The mount operation on OS X and Linux works, but the files in the mounted directory can't be listed/accessed.
Example Firmware Files from Motostockrom
After investigating I found some threads and scripts (1, 2, 3, 4) which mention the same problem. They all remove some magic bytes ('\x53\xEF') from the header of the file, but none of the scripts I found worked for me. I tried the following:
Attempt 1 with simg2img:
simg2img system.img_sparsechunk.0 system.raw.img
mount -o loop system.raw.img ./test/
mount -o loop -t auto system.raw.img ./test/
mount -o ro system.raw.img ./test/
mount -o ro -t auto system.raw.img ./test/
# I don't know if the * makes any difference, tested it anyways.
simg2img system.img_sparsechunk.* system.raw.img
mount -o loop system.raw.img ./test/
mount -o loop -t auto system.raw.img ./test/
mount -o ro system.raw.img ./test/
mount -o ro -t ext4 system.raw.img ./test/
mount -o ro -t auto system.raw.img ./test/
OS X
simg2img system.img_sparsechunk.* system.raw.img
ext4fuse -o allow_other,defer_permissions system.raw.img ./test/
Errors - Depending on the file:
- OS X finder hangs
- Shows "Partition doesn't contain EXT4 filesystem"
Attempt 2 - testing the script from [2]:
simg2img system.img_sparsechunk.0 system.raw.img
img2raw system.raw.img system.raw.raw
mount -o ro system.raw.raw ./test/ --> Error
simg2img system.raw.raw system2.raw.img
mount -o ro system.raw.raw ./test/ --> Error
I tested this with around ten samples and all show the same behaviour. Is there a way to convert Motorola firmware files with simg2img so that they are mountable? Do I need to add some special parameters to mount these files?
Thanks for any help in advance!
Best Regards
Tom
Hello,
I'm working in Linux/Ubuntu
i got error then i try to convert the data to raw
Command:
simg2img userdata.img userdata_raw.img
Error message:
Invalid sparse file format at header magi
Failed to read sparse file
Something i do wrong?
Hello @anestisb ,
I've got a system.img from the official ROM G361FXXU1APB1 of Samsung Galaxy SM-G361F.
The problem is, if I "repack" this image, the newly-created image (packed in a tarfile) is accepted by Odin but rejected by the device.
EDIT:
It seems that the size of the input chunks is 2562 in the original system.img, but,
because 2562 % 4 != 0, img2simg is rejecting my command to force the use of
2562-sized blocks `img2simg system.raw.img system.img 2562`
I am showing a case were I didn't modify the filesystem from simg2img before converting it back with img2simg for clarification.
I am "repacking" this way:
root@pc:~/Desktop# simg2img system.img system.raw.img
root@pc:~/Desktop# mv system.img system.original.img
root@pc:~/Desktop# img2simg system.raw.img system.img
root@pc:~/Desktop# tar cvf G361FXXU1APB1.tar system.img
root@pc:~/Desktop# md5sum -t G361FXXU1APB1.tar >> G361FXXU1APB1.tar
root@pc:~/Desktop# mv G361FXXU1APB1.tar G361FXXU1APB1.tar.md5
root@pc:~/Desktop# tar cvf G361FXXU1APB1.tar system.img
root@pc:~/Desktop# md5sum -t G361FXXU1APB1.tar >> G361FXXU1APB1.tar
root@pc:~/Desktop# mv G361FXXU1APB1.tar G361FXXU1APB1.tar.md5
root@pc:~/Desktop# file system.img
system.img: Android sparse image, version: 1.0, Total of 471808 4096-byte output blocks in 2562 input chunks.
root@pc:~/Desktop# python2 ./android-simg2img/simg_dump.py system.img
simg_dump.py: system.img: The file header size was expected to be 28, but is 32.
root@pc:~/Desktop# file system.img
system.img: Android sparse image, version: 1.0, Total of 471808 4096-byte output blocks in 1692 input chunks.
root@pc:~/Desktop# python2 ./android-simg2img/simg_dump.py system.img
system.img: Total of 471808 4096-byte output blocks in 1692 input chunks.
root@pc:~/Desktop# file system.raw.img
system.raw.img: Linux rev 1.0 ext4 filesystem data, UUID=57f8f4bc-abf4-655f-bf67-946fc0f9f25b (extents) (large files)
Under Windows there is no sysconf(_SC_PAGESIZE), so to compile the project the quick&dirty fix is to use:
CFLAGS='-DUSE_MINGW -Dsysconf\(_SC_PAGESIZE\)=4096' LDFLAGS=-lasprintf mingw32-make
While excecuting make this error comes up:
sudo make
cc -c -O2 -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1 -Iinclude output_file.c -o
output_file.o
output_file.c:30:18: fatal error: zlib.h: No such file or directory
#include <zlib.h>
^
compilation terminated.
Makefile:69: recipe for target 'output_file.o' failed
make: *** [output_file.o] Error 1
make version : make-4.0-5.54.x86_64
gcc version : gcc-4.8-9.61.x86_64
make: Circular backed_block.cpp <- backed_block.cpp dependency dropped.
g++ -std=gnu++17 -O2 -W -Wall -Werror -Wextra -Iinclude -Iandroid-base/include -c backed_block.cpp -o backed_block.o
g++: error: unrecognized command line option ‘-std=gnu++17
I get this error with my make : GNU Make 4.2.1
You may want to consider adding a License to the repo and a tag would be nice. I saw the files are licensed but the repo is missing a License/Copyright file. Github doesn't show the license of the repo because such file is missing. Both are minor, but if you do not mind. Thank you!
Compiling against openssl 1.1 results in the following errors
generate_verity_key.c: In function ‘convert_to_mincrypt_format’:
generate_verity_key.c:57:19: error: dereferencing pointer to incomplete type ‘RSA {aka struct rsa_st}’
BN_copy(n, rsa->n);
generate_verity_key.c:75:37: error: dereferencing pointer to incomplete type ‘RSA {aka struct rsa_st}’
pkey->exponent = BN_get_word(rsa->e);
This is a result of api changes
The following patch is a dirty fix; I'm not sure how you would like to handle backward compatibility.
diff --git a/generate_verity_key.c b/generate_verity_key.c
index 0da978f..609ca8a 100644
--- a/generate_verity_key.c
+++ b/generate_verity_key.c
@@ -53,8 +53,12 @@ static int convert_to_mincrypt_format(RSA *rsa, RSAPublicKey *pkey)
BIGNUM* n = BN_new();
BIGNUM* n0inv = BN_new();
+ const BIGNUM *cur_n;
+ const BIGNUM *cur_e;
+ RSA_get0_key(rsa, &cur_n, &cur_e, NULL);
+
BN_set_bit(r32, 32);
- BN_copy(n, rsa->n);
+ BN_copy(n, cur_n);
BN_set_bit(r, RSANUMWORDS * 32);
BN_mod_sqr(rr, r, n, ctx);
BN_div(NULL, rem, n, r32, ctx);
@@ -68,7 +72,7 @@ static int convert_to_mincrypt_format(RSA *rsa, RSAPublicKey *pkey)
BN_div(n, rem, n, r32, ctx);
pkey->n[i] = BN_get_word(rem);
}
- pkey->exponent = BN_get_word(rsa->e);
+ pkey->exponent = BN_get_word(cur_e);
ret = 0;
the sparse image generated by ext2simg is several hundred times larger than img2simg (25354316 vs 131240), and both of them can be converted successfully by simg2img.
Download case.zip
When using a 'dd' image of a system with img2simg, the final result is same size of 'dd' image.
img2simg should trim the empty space to make the file 'sparse'.
Hi there,
First of all, thanks for this awesome tool! It's a great!
I was trying to mount some Android10 system.img files, but it seems that the converted simg2img images for Android10 can't be mounted on Linux and OS X. I converted the system.img with simg2img, which seems to run through without any problem. However, as soon as I try to mount an error on Ubuntu occurs.
On Ubuntu I get the following mount error:
simg2img ./system.img ./system.raw.img
sudo mount ./system.raw.img ./mnt
mount: /home/ubuntu/test/sargo-qq2a.200501.001.a3/mnt: wrong fs type, bad option, bad superblock on /dev/loop4, missing codepage or helper program, or other error.
Which is not really helpful, so I tried it on OS X (10.14.6) as well.
On OS X I can mount the image with ext4fuse, but the files within the image are not readable. I can see the file-system structure, but it seems that somehow the permissions can't be loaded or something and therefore I have no access to the files.
Could someone take a look at this? I tried several Android10 Firmware images from the official Google repo other images (<=9) work fine.
Best Regards,
Tom
When I try to unzip super.img and end up with system.img and other img I use "file system.img" directive and I find that these img seem to be corrupted and it just tells me that it is F2FS file system, please help me
Would it be possible to add the ext2simg utility to this repo? It was until very recently part of the Android FS tools, and has now made it upstream
Hey, when I try to run simg2img with userdata.img I got this error:
Invalid sparse file format at header magi
Failed to read sparse file
I used an Android emulation with API28...can you help me with this? Also when I run "file userdata.img" it returns >>data
Using this firmware version
https://samfrew.com/download/Galaxy__A10__/ja37/INS/A105FDDU3BTF1/A105FODM3BTF1/
I've done the following:
simg2img system.original.img system.raw.img
img2simg system.raw.img system.img
heimdall flash --SYSTEM system.img
The latest fedora have no libz-devel package. I guess they had changed to zlib-devel from some version.
Please update the README.md for install dependency in fedora use
sudo dnf install zlib-devel
Hi, If I understand correctly the Fill
Chunk type will fill the number of blocks with 4 specified data bytes in the data section of fill chunk right? I have't dived deep in the codebase but it always seem to return 0, is that the correct intention of fill ChunkType
I'm not entirely sure the purpose of Fill Chunk Type, reading says this fills the blocks with 4 bytes of data. However, this repo always set the values to 0. Is it the intended behaviour?
Tried to create image from stdin sparse image, but got this error. Source code at master branch commit 2807b36
# cat image.img | simg2img - test.ext4
Unknown error -29 at seeking
Failed to read sparse file
From the code, it looks like the input must be able to seek, but stdin doesn't.
If it doesn't support stdin, just remove this capable in main()?
wv@wv-mint:~/android/N960U$ file system.img
system.img: Linux rev 1.0 ext2 filesystem data (mounted or unclean), UUID=e47eeda7-b9a3-5aaa-9b6c-f0e5d865e7ef, volume name "system" (extents) (large files) (huge files)
zlib dev headers did change their behaviour in an evil way, which forces -lz now to be at the very end of the compile command.
Otherwise it fails with
./libsparse.a(output_file.o): In function `gz_file_close':
output_file.c:(.text+0x689): undefined reference to `gzclose'
./libsparse.a(output_file.o): In function `gz_file_write':
output_file.c:(.text+0x738): undefined reference to `gzwrite'
./libsparse.a(output_file.o): In function `gz_file_pad':
output_file.c:(.text+0x7bf): undefined reference to `gztell64'
output_file.c:(.text+0x7eb): undefined reference to `gzseek64'
output_file.c:(.text+0x803): undefined reference to `gzwrite'
./libsparse.a(output_file.o): In function `gz_file_skip':
output_file.c:(.text+0x82e): undefined reference to `gzseek64'
./libsparse.a(output_file.o): In function `gz_file_open':
output_file.c:(.text+0x88c): undefined reference to `gzdopen'
collect2: error: ld returned 1 exit status
Makefile:58: recipe for target 'simg2img' failed
Most easy and ugly fix is putting -lz
after $< $(LDFLAGS)
make: Circular backed_block.cpp <- backed_block.cpp dependency dropped.
g++ -std=gnu++17 -O2 -W -Wall -Werror -Wextra -Iinclude -Iandroid-base/include -c backed_block.cpp -o backed_block.o
g++: error: unrecognized command line option ‘-std=gnu++17
Firstly, thanks for the useful utility. Has served me well for a couple of years.
Today I'm trying to mount a raw image from the Android Q Beta 1 for the 2016 Pixel XL released today.
"simg2img system.img sys.raw" seems to work ok with no errors.
"mount -t ext4 -o loop sys.raw sys/" gives following error:
mount: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so
Syslog has this message:
EXT4-fs (loop0): couldn't mount RDWR because of unsupported optional features (4000)
I understand there are some changes in the way partitions are mounted in Android Q so I'm not too sure if this is a simg2img issue or not. Apologies if not.
I may finally understand why my android 11 image conversion keeps failing due to "bad magic". What is needed to make this compatible with the new android 11? Because right now, I am unable to try it in DSU.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.