[tool] ANDROID-ROM-REPACK-TOOLS - Android General

Note:I am sorry I can't post this in the Android development thread because my number of posts is low. Hopefully some mod can move it there.
Introduction
Since this project (Android_IMG_REPACK_TOOLS) is dead for 2 years now (last supported version is Marshmallow). I decided to do a new rom repacker that supports up to Android Oreo.
Supported OS
Linux
Supported Android Versions
android-5 (Lollipop)
android-wear-5
android-6 (Marshmallow)
android-7 (Nougat)
android-8 (Oreo)
android-9 (Pie) beta
Binaries included
append2simg
img2simg
simg2img
simg2simg
make_ext4fs (Google removed it for android 9. I will add a replacement in the future)
mkbootfs
mkbootimg
unpackbootimg (For android-wear-5, you can use the one in android-5)
sefcontext_compile
sefcontext_decompile
Usage
Check this post out for some use case. You'll need img2simg and make_ext4fs from my post.
sefcontext_compile and sefcontext_decompile:
ROMS since Android 7 (Nougat) come with a binary file_contexts but you need a text based file_contexts when you need to repackage the ROM. You'll need it for make_ext4fs. sefcontext_decompile converts the binary file_contexts into text version.
Code:
# file_contexts (human readable text file) -> file_contexts.bin (PCRE formatted binary file)
sefcontext_compile [-o <output_file>] <text_file>
# file_contexts.bin (PCRE formatted binary file) -> file_contexts (human readable text file)
sefcontext_decompile [-o <output_file>] <binary_file>
Source code
Repository
android-5
android-wear-5
android-6
android-7
android-8
android-9
Download links for Linux
Download page
android-5
android-wear-5
android-6
android-7
android-8
android-9
Change Log:
v3:
Added android-5 and android-wear-5 support
Added android-9 beta support
v2:
Added sefcontext_compile and sefcontext_decompile: converts between file_contexts.bin and file_contexts
Static linking to libc++: No need to install 3rd party libraries to use the binaries.
v1:
Added append2simg img2simg simg2img simg2simg make_ext4fs mkbootfs mkbootimg unpackbootimg
credits:
@A.S._id
android.googlesource
LineageOS
Created: 2018-03-16
Updated: 2018-08-18

[Placeholder]

[Placeholder2]

Can i extract a rom if i have only ssyetm. New. Dat??, i have file context. Bin in boot. Img can it be used?
I know usual extraction needs both these+system. Transfer. List but a rom which i m using have just this configuration.

what is simg2simg?
and how to make system.new.dat.br?
thanks for your work

zheshifandian said:
what is simg2simg?
and how to make system.new.dat.br?
thanks for your work
Click to expand...
Click to collapse
Use brtoli. Exe to make. Br from. Dat format

narshi shukla said:
Can i extract a rom if i have only ssyetm. New. Dat??, i have file context. Bin in boot. Img can it be used?
I know usual extraction needs both these+system. Transfer. List but a rom which i m using have just this configuration.
Click to expand...
Click to collapse
I believe this question is better suited in this thread. You'll need system.transfer.list in sdat2img.py which is provided over there. I haven't worked on a ROM that doesn't have system.transfer.list. Isn't system.transfer.list required for flashing the ROM?
Btw you need to convert file_context.bin to text format. There are a couple of closed source solutions here on xda. I am working on an open source version in my free time.
zheshifandian said:
what is simg2simg?
Click to expand...
Click to collapse
You can find answers to a lot of the questions you might have in the old project.
A.S._id said:
Yes, simg2simg can reduce file size by splitting into several parts, but it is usually not necessary, fastboot can flash and in this state
Click to expand...
Click to collapse

Awesomeness, easy and simple

hi bro i want extract oreo system.new.dat.br and also repack dat to .br in windows
please help me bro
and im unable to convert oreo file_context.bin to readable in windows
please help thanks in advance

New version available in Original Post.
Change log
v2:
Added sefcontext_compile and sefcontext_decompile: converts between file_contexts.bin and file_contexts
Static linking to libc++: No need to install 3rd party libraries to use the binaries.

marshharsha said:
hi bro i want extract oreo system.new.dat.br and also repack dat to .br in windows
please help me bro
and im unable to convert oreo file_context.bin to readable in windows
please help thanks in advance
Click to expand...
Click to collapse
Oreo ROMs come compressed by brotili. You can compile from source to get the executable or you can get the binaries directly from the release page (version 1.0). Use it to extract and repack .br.
I added a converter from file_context.bin to a readable format in the new version I just uploaded.
This project only supports Linux as of now. As for using it in Windows, you have 3 options,
Use a linux distro in VirtualBox (I currently use this option)
Install a linux bash shell in Windows 10
Build the project in Cygwin (hopefully someone can make a pull request and share it with the rest)

rkhat said:
Oreo ROMs come compressed by brotili. You can compile from source to get the executable or you can get the binaries directly from the release page (version 1.0). Use it to extract and repack .br.
I added a converter from file_context.bin to a readable format in the new version I just uploaded.
This project only supports Linux as of now. As for using it in Windows, you have 3 options,
Use a linux distro in VirtualBox (I currently use this option)
Install a linux bash shell in Windows 10
Build the project in Cygwin (hopefully someone can make a pull request and share it with the rest)
Click to expand...
Click to collapse
thanks brother for your kind reply can you give guide for make exe from brotli source? with java or c
thanks again

marshharsha said:
thanks brother for your kind reply can you give guide for make exe from brotli source? with java or c
thanks again
Click to expand...
Click to collapse
Just use a pre-built brotli from the release page (there is a window version). It doesn't matter that the executable is not the latest version as you only need to extract compress the .br file.
If you really need to build brotli for windows, just open scripts/appveyor.yml in the github repository. Decide which environment you want (I see they support 32-bit/64-bit versions for Visual Studio, Python, MinGW). Download the necessary software (python, mingw ...). Then run the commands in appveyor.yml using cmd in this order.

@rkhat
Hi and thanks for making the tools for us.
I am getting the below error when ./img2simg new-system.img news-system.img. I downloaded version for Nougat.
img2simg: /android-rom-repacker/external/platform/core/src/libsparse/sparse.c:153: int write_all_blocks(struct sparse_file *, struct output_file *): Assertion `pad >= 0' failed.
Aborted
I am running Ubuntu. Do you know what might be the problem ?

sdeft said:
@rkhat
Hi and thanks for making the tools for us.
I am getting the below error when ./img2simg new-system.img news-system.img. I downloaded version for Nougat.
img2simg: /android-rom-repacker/external/platform/core/src/libsparse/sparse.c:153: int write_all_blocks(struct sparse_file *, struct output_file *): Assertion `pad >= 0' failed.
Aborted
I am running Ubuntu. Do you know what might be the problem ?
Click to expand...
Click to collapse
Just tested a Nougat lineage ROM for Nexus 7 from here. No issues!
Are you sure you used this version for Nougat?
If you still have issues, can you link me the zipped ROM and more importantly the source you got it from so I can test it out? Thank you.

rkhat said:
Just tested a Nougat lineage ROM for Nexus 7 from here. No issues!
Are you sure you used this version for Nougat?
If you still have issues, can you link me the zipped ROM and more importantly the source you got it from so I can test it out? Thank you.
Click to expand...
Click to collapse
I think I found the issue. This is happening only when i perform it on the image created with
./make_ext4fs -s -l 3000M -a system new-system.img tmp/
If I just umount the image and then apply img2simg it works.
Is this strange or what ?

sdeft said:
I think I found the issue. This is happening only when i perform it on the image created with
./make_ext4fs -s -l 3000M -a system new-system.img tmp/
If I just umount the image and then apply img2simg it works.
Is this strange or what ?
Click to expand...
Click to collapse
Don't use "-s" (lowercase s) option. It only writes sparse headers in new-system.img. The file is only couple MBs instead of 3000MB you specified. I am curious how img2simg even worked.
Also, use "-S file_contexts" (uppercase S) option to apply the security contexts on files. The zipped ROM has file_contexts.bin (binary version) since Android Nougat. You'll need to convert it to text format. You can use the executable sefcontext_decompile included in my tools to convert file_contexts.bin to file_contexts.

rkhat said:
Don't use "-s" (lowercase s) option. It only writes sparse headers in new-system.img. The file is only couple MBs instead of 3000MB you specified. I am curious how img2simg even worked.
Also, use "-S file_contexts" (uppercase S) option to apply the security contexts on files. The zipped ROM has file_contexts.bin (binary version) since Android Nougat. You'll need to convert it to text format. You can use the executable sefcontext_decompile included in my tools to convert file_contexts.bin to file_contexts.
Click to expand...
Click to collapse
I am not using a zipped rom with file_contexts.bin, system.new.dat etc.
I am trying to mod a system.img from a fastboot rom for xiaomi. So far only managed to have the userdata.img working but system.img keeps giving me bootloops!. Will try your suggestion above...

build use cygwin window 7 x64
how build use cygwin on w7 x64? or can you make for windows too?
sorry for bad engglish

anggafzkdev99 said:
how build use cygwin on w7 x64? or can you make for windows too?
sorry for bad engglish
Click to expand...
Click to collapse
I don't use windows in this project. So you're on your own in building using cygwin
Alternatively, you can use Ubuntu on VirtualBox which is what I currently use.

Related

[Q] [GT-P3100][Kernel] Compiled kernel does not boot!

Hi,
I'm trying to boot my galaxy tab2 7 with compiled kernel.
First, I downloaded kernel source from http://opensource.samsung.com.
I download GT-P3100_JB_Opensource_Update2.zip file and extract it.
To compile, I followed ketut.kumajaya's thread (http://forum.xda-developers.com/show....php?t=2086996)
I build only kernel, not other modules. Compile was done without problem.
And I extract boot.img from Stock ROM file downloaded from samsung-updates.com (http://samsung-updates.com/device/?id=GT-P3100).
Stock ROM version is P3100XXCLJ3 (that's my device's baseband version).
I unpacked boot.img and I got boot.img-kernel.gz and boot.img-ramdisk.cpio.gz.
(To make sure unpack/repack tool is working properly, I simply unpack stock boot.img and repack it. And the new boot.img was working properly. So I assume my unpack/repack tool have no problem).
So, I replace boot.img-kernel.gz with zImage and repack it.
But this time new boot image does not working (Device stuck in boot logo)
What did I done wrong? Any body help! I've been stuck with this for a week now...
(When stock ROM is flashed, Kernel version in device info is "3.0.31-595683"
You must compile pvrsrvkm kernel module as I mentioned in http://forum.xda-developers.com/showthread.php?t=1859227 and then you can use KK-Boot 0.5.x core as your flashable zip template (have PowerVR 3D driver binary inside). If you decide to keep the stock PowerVR binary, change:
#define PVRVERSION_BUILD 2166536
Click to expand...
Click to collapse
to
#define PVRVERSION_BUILD 2120756
Click to expand...
Click to collapse
and
#define PVRVERSION_BUILD_HI 216
#define PVRVERSION_BUILD_LO 6536
Click to expand...
Click to collapse
to
#define PVRVERSION_BUILD_HI 212
#define PVRVERSION_BUILD_LO 0756
Click to expand...
Click to collapse
in pvrversion.h
Do not forget to copy pvrsrvkm_sgx540_120.ko to /system/lib/modules (backup the stock modules first!)
For trouble free development, I recommend you to use GT-P3110_JB_Opensource.zip, apply all my kernel patch and use my android_espresso_omap4430_r04_blackhawk_defconfig as your kernel config file. Good luck!
necesriverua
ketut.kumajaya said:
You must compile pvrsrvkm kernel module as I mentioned in http://forum.xda-developers.com/showthread.php?t=1859227 and then you can use KK-Boot 0.5.x core as your flashable zip template (have PowerVR 3D driver binary inside). If you decide to keep the stock PowerVR binary, change:
to
and
to
in pvrversion.h
Do not forget to copy pvrsrvkm_sgx540_120.ko to /system/lib/modules (backup the stock modules first!)
For trouble free development, I recommend you to use GT-P3110_JB_Opensource.zip, apply all my kernel patch and use my android_espresso_omap4430_r04_blackhawk_defconfig as your kernel config file. Good luck!
Click to expand...
Click to collapse
Many thanx.
I really appreiciate it.
I will try this right away.
ketut.kumajaya said:
You must compile pvrsrvkm kernel module as I mentioned in http://forum.xda-developers.com/showthread.php?t=1859227 and then you can use KK-Boot 0.5.x core as your flashable zip template (have PowerVR 3D driver binary inside). If you decide to keep the stock PowerVR binary, change:
to
and
to
in pvrversion.h
Do not forget to copy pvrsrvkm_sgx540_120.ko to /system/lib/modules (backup the stock modules first!)
For trouble free development, I recommend you to use GT-P3110_JB_Opensource.zip, apply all my kernel patch and use my android_espresso_omap4430_r04_blackhawk_defconfig as your kernel config file. Good luck!
Click to expand...
Click to collapse
Dear ketut,
Because I'm behind firewall, I cannot download pvrsrvkm kernel source.
Frankly, I have very little knowledge about android system. so I'm not sure I understand your guide correctly..
What I've done is as follows:
1. Download GT-P3110_JB_Opensource
2. Apply your patch from http://forum.xda-developers.com/showthread.php?t=1859227
3. Modify PVRVERSION_BUILD and PVRVERSION_BUILD_HI and PVRVERSION_BUILD_LOW in drivers/gpu/pvr/pvrversion.h (kernel source)
4. Apply android_espresso_omap4430_r04_blackhawk_defconfig and Build (using arm-2010q1-202..)
5. Repack zImage with ramdisk.cpio.gz (extracted from stock rom file)
6. Replace boot.img in your kkboot-0.5.2-core-p31xx.zip with repacked boot.img
7. Apply new kkboot.zip in CWM and installation failed and aborted.
Am I totally in wrong direction? What am I missing here?
I sincerely ask your help.
(I found that when build kernel after your patch, additional module files (.ko) are generated.
Should I do something with that?)
cks1119 said:
Dear ketut,
Because I'm behind firewall, I cannot download pvrsrvkm kernel source.
Frankly, I have very little knowledge about android system. so I'm not sure I understand your guide correctly..
What I've done is as follows:
1. Download GT-P3110_JB_Opensource
Click to expand...
Click to collapse
Correct.
2. Apply your patch from http://forum.xda-developers.com/showthread.php?t=1859227
Click to expand...
Click to collapse
Correct, all my patch from 01-07.
3. Modify PVRVERSION_BUILD and PVRVERSION_BUILD_HI and PVRVERSION_BUILD_LOW in drivers/gpu/pvr/pvrversion.h (kernel source)
Click to expand...
Click to collapse
Incorrect, nothing to do with pvr driver inside the kernel source, it's useless. You can download eurasia_km.tgz from http://www.mediafire.com/?m9te7t4rosp131d . Do not modify PVRVERSION if you plan to use my kkboot boot image.
4. Apply android_espresso_omap4430_r04_blackhawk_defconfig and Build (using arm-2010q1-202..)
Click to expand...
Click to collapse
Code:
export CROSS_COMPILE='/opt/toolchains/arm-2010q1/bin/arm-none-linux-gnueabi-'
export LDFLAGS=''
export CFLAGS=''
export SUBARCH=arm
export ARCH=arm
make mrproper
make android_espresso_omap4430_r04_blackhawk_defconfig
make -j4
5. Repack zImage with ramdisk.cpio.gz (extracted from stock rom file)
Click to expand...
Click to collapse
Incorrect, use kkboot ramdisk for now.
6. Replace boot.img in your kkboot-0.5.2-core-p31xx.zip with repacked boot.img
Click to expand...
Click to collapse
Correct.
7. Apply new kkboot.zip in CWM and installation failed and aborted.
Click to expand...
Click to collapse
Try to unpack and repack kkboot without modification, is it works?
Am I totally in wrong direction? What am I missing here?
I sincerely ask your help.
(I found that when build kernel after your patch, additional module files (.ko) are generated.
Should I do something with that?)
Click to expand...
Click to collapse
Unpack kkboot, you will see a lot of modules inside system/lib/modules
Try to unpack and repack kkboot without modification, is it works?
Click to expand...
Click to collapse
No, unpack tool that I have is not working.
I found the tool that you've uploaded, but the unzip password was not correct for some reason
I downloaded your tool in http://forum.xda-developers.com/showthread.php?t=1241005
But while unpacking, it says below:
Code:
BOARD_KERNEL_CMDLINE console=ttyO2,115200n8 mem=1024M androidboot.console=ttyO2 vram=20M omapfb.vram=0:16M
BOARD_KERNEL_BASE 80000000
BOARD_PAGE_SIZE 00000800
gzip: ../kkboot.img-ramdisk.gz: not in gzip format
cpio: premature end of archive
Is it require special tools to unpack kkboot image?
Forgot to mention, my ramdisk packed in lzo format You need lzop application to unpack it.
ketut.kumajaya said:
Forgot to mention, my ramdisk packed in lzo format You need lzop application to unpack it.
Click to expand...
Click to collapse
You mean only ramdisk?
If so, as my understanding, unpacking boot.img in kkboot-0.5.2 and repack without any change, should be working
whether your ramdisk is packed with lzo or not.
But when I did it, I still got installation fail.
(I used the unpackbootimg in blackhawk tool from http://forum.xda-developers.com/showthread.php?t=1241005)
By the way,
I've searching about lzop compressed ramdisk and found this: https://github.com/trevd/aos-tools/blob/master/scripts/unpack-ramdisk.sh
And with this method, I could unpack ramdisk file.
Code:
cat boot.img-ramdisk.gz | lzop -d | cpio -i
But, I think this is not the point.
ketut.kumajaya said:
Forgot to mention, my ramdisk packed in lzo format You need lzop application to unpack it.
Click to expand...
Click to collapse
I simply unpack and repack boot.img from kkboot-0.5.2-core-p31xx.zip
with boot.img-tools in http://forum.xda-developers.com/showthread.php?t=1241005
Then change original boot.img with repacked one and make new zip file in external SD card.
When I go to CWM recovery and try to install new zip file, then I got following message:
Code:
-Extracting files
set_perm : some changes failed
E:Error in /external_sd/newfile.zip
(Status 7)
Installation aborted
I've been trying other tools that I could find but still does not working :crying:
ketut.kumajaya said:
Forgot to mention, my ramdisk packed in lzo format You need lzop application to unpack it.
Click to expand...
Click to collapse
Finally done it!
I've got tab 2 running my own kernel!
Again, thank you for your help and all works you've done!:good:
cks1119 said:
Finally done it!
I've got tab 2 running my own kernel!
Again, thank you for your help and all works you've done!:good:
Click to expand...
Click to collapse
Congrat :good:

[DEV][TOOL][Linux]Android System Extraction and Repack Tool

Introduction
You probably know already that starting from Android 5.x (Lollipop) compiled roms (aosp,cm,stock) are not compressed anymore the way they used to be on previous android versions. On previous versions all content inside /system folder that has to be extracted within our device was either uncompressed (simple /system folder inside our flashable zip) or compressed in a system.img file, which it is a ext4 compressed file; both of these, anyway, were readable and we could see all system files (app,framework, etc).
The problem comes in >=5.0 versions, this method is not used anymore. Why? Because roms started to be always larger, so it is necessary to compress them even more.
Note : Introduction was taken from here : https://forum.xda-developers.com/an.../how-to-conver-lollipop-dat-files-to-t2978952 by @xpirt so thanks to him
So in order to save myself and others who most port Custom & Stock Roms, i decided to use some part of my time to write this script for easy work done.
What this script does :
It basically Unpack and Repack system.new.dat alongside with file_context.bin convertion which is seen in android 7.0/7.1
ITS USAGE:
NOTE
First Clone the repo.
Make sure that Android_System_Extraction_and_Repack_Tool is located at Desktop
Run "Xtrakt" from it's location in terminal
Copy "file_contexts.bin" from your Rom to "file_context_zone" folder
Use "f" from menu to convert "file_contexts.bin" to text readable "file_contexts"
Copy : system.new.dat, system.transfer.list & file_contexts to "convert-dat" folder.
Use "i" from menu to unpack, which the output will be name as "rom_system" for modifications of apks & files.
Use "y" from menu to repack, which the complete new "system.new.dat", "system.patch.dat" & "system.transfer.list" will be located at "Finish-new.dat" folder
Done !
EXAMPLE:
Again , Make sure that Android_System_Extraction_and_Repack_Tool is located at Desktop
In your terminal, type the following to start the script:
Code:
git clone https://github.com/iykequame/Android_System_Extraction_and_Repack_Tool.git
mv android_system_extraction_and_repack_tool ~/Desktop/
cd ~/Desktop/android_system_extraction_and_repack_tool/
./Xtrakt
OR
Code:
Double-click the Xtrakt file and choose "Run in Terminal" if your OS supports it.
##ALERT!!!##
sudo is requested in the script.
How To Get It {Tool]
Clone from one of the below ;
From GITHUB :
Code:
git clone https://github.com/iykequame/Android_System_Extractrion_and_Repack_Tool.git
From BITBUCKET :
Code:
git clone https://[email protected]/zac6ix/android_system_extraction_and_repack_tool.git
Or
Download zip
AFH
GIT-RELEASE
Sources :
Android_System_Extraction_and_Repack_Tool
GITHUB
BITBUCKET
Threads :
sdat2img 1.0 - img2sdat 1.2
For file_context.bin conversion by: Pom Kritsada @ MTK THAI Developers.
Credit to :
@xpirt
@SuperR.
-all xda threads which helped
-Android Matrix Development - here
-Nana Yaa for her time.
hi, your tool sounds good but it seems it doesnt work.
i press f and nothing happen ..
Use "f" from menu to convert **"file_contexts.bin"** to text readable **"file_contexts"**
Blackball said:
hi, your tool sounds good but it seems it doesnt work.
i press f and nothing happen ..
Use "f" from menu to convert **"file_contexts.bin"** to text readable **"file_contexts"**
Click to expand...
Click to collapse
Sorry for the Late reply !
Directories linking has been fix .
You can go ahead and try again
Thanks for sharing!
Don't work
When i press i ..Don't work.say file missing.but i already put all file..Please help meView attachment 4249470
Doesn't do anything with file_context.bin, doesn't even check if file is there.
oreo supported???
I am getting this error on repacking:-
Code:
WARNING! WARNING!! WARNING!!!
Please Check & Trace Where Errors.
There Is NO rom_system found
file_contexts -->> Missing !
Android SDK -->> not detected !
Please help.
Black_J said:
I am getting this error on repacking:-
Code:
WARNING! WARNING!! WARNING!!!
Please Check & Trace Where Errors.
There Is NO rom_system found
file_contexts -->> Missing !
Android SDK -->> not detected !
Please help.
Click to expand...
Click to collapse
I see that this thread is not supported.
Anyways, I observed that the tool works for file_contexts.bin but not for other options.
So , I followed the other link in the thread for individual commands and was successful.
Works perfectly on Android Pie! Have to do some tweaks, PM me if anyone wants to make this work for Android Pie.

[DEV][LINUX/OSX] IMG Patch Tools | sdat2img for OTA zips

{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
most part of Introduction from taken sdat2img thread
if you want extract non OTA zip i suggest to use sdat2img tool
FOR AB OTA ZIPS USE THIS SCRIPT AND PAYLOAD EXTRACTOR​
in this tools i made block_image_update() function from android recovery to a binary to run on PC and patch system.img with DAT files on OTA package to update system.img by OTA
also we have apply_patch() function for patching boot.img and other files like firmwares
Introduction
You probably know already that starting from Android 5.x (Lollipop) compiled roms (aosp,cm,stock) are not compressed anymore the way they used to be on previous android versions. On previous versions all content inside /system folder that has to be extracted within our device was either uncompressed (simple /system folder inside our flashable zip) or compressed in a system.img file, which it is a ext4 compressed file; both of these, anyway, were readable and we could see all system files (app,framework, etc).
The problem comes in >=5.0 versions, this method is not used anymore. Why? Because roms started to be always larger, so it is necessary to compress them even more.
What does new Android zips (full roms, but also OTAs) contain?
New Android flashable zips are made this way:
boot.img (kernel)
file_contexts (selinux related)
META-INF (folder containing scripts)
system.new.dat (compressed /system partition)
system.patch.dat (for OTAs)
system.transfer.list (see explanation below)
and other patch files (.p only on OTA zip)​
What does updater-script contains then?
The updater-script uses a brand new function: block_image_update(), this method basically decompresses necessary files inside the device. Let's study it.
From google git source code, if we go inside the new file /bootable/recovery/updater/blockimg.c, we find at the end of it the registration of the function block_image_update() as the method BlockImageUpdateFn() which starts at line 254. Here finally we find all information we need to know about the decompression of the .dat file(s). First file we analyze is system.transfer.list which Google tells us:
The transfer list is a text file containing commands to transfer data from one place to another on the target partition.
Click to expand...
Click to collapse
But what each line means?:
First line is the version number of the transfer list; 1 for android 5.0.x, 2 for android 5.1.x, 3 for android 6.0.x, 4 for android 7.x
Second line is the total number of blocks being written
Third line is how many stash entries are needed simultaneously (only on versions >= 2)
Fourth line is the maximum number of blocks that will be stashed simultaneously (only on versions >= 2)
Fifth line and subsequent lines are all individual transfer commands.
Click to expand...
Click to collapse
all transfer commands is :
bsdiff
*erase
free
imgdiff
move
*new
stash
*zero
BlockImageUpdate is reading system.transfer.list and executing all commands
But BlockImageVerify doesn’t execute * commands, which not to make changes on system.img just verifying update can happen
original sdat2img tool only support "new" command
Ok, but how to Patch the system.img with OTA files?
All instructions are below. binaries are involved. Please read carefully step by step.
You can use/modify these files and/or include them in your work as long as proper credits and a link to this thread are given.
If you have questions or problems
write here
Thanks
- @xpirt , for original sdat2img tool and useful thread
XDA:DevDB Information
IMG Patch Tools, sdat2img for OTA zips, Tool/Utility for all devices (see above for details)
Contributors
erfanoabdi
Source Code: https://github.com/erfanoabdi/imgpatchtools
Version Information
Status: Testing
Created 2017-07-21
Last Updated 2020-01-23
Usage
Code:
./BlockImageUpdate <system.img> <system.transfer.list> <system.new.dat> <system.patch.dat>
args:
<system.img> = block device (or file) to modify in-place
<system.transfer.list> = transfer list (blob) from OTA/rom zip
<system.new.dat> = new data stream from OTA/rom zip
<system.patch.dat> = patch stream from OTA/rom zip
Code:
./ApplyPatch <file> <target> <tgt_sha1> <size> <init_sha1(1)> <patch(1)> [init_sha1(2)] [patch(2)]...
args:
<file> = source file from rom zip
<target> = target file (use "-" to patch source file)
<tgt_sha1> = target SHA1 Sum after patching
<size> = file size
<init_sha1> = file SHA1 sum
<patch> = patch file (.p) from OTA zip
Code:
usage: ./scriptpatcher.sh <updater-script>
args:
<updater-script> = updater-script from OTA zip to patch recovery commands
Example
for example from updater-script of OTA we have:
Code:
block_image_update("/dev/block/bootdevice/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat")
apply_patch("EMMC:/dev/block/bootdevice/by-name/boot:33554432:f32a854298814c18b12d56412f6e3a31afc95e42:33554432:0041a4df844d4b14c0085921d84572f48cc79ff4",
"-", 0041a4df844d4b14c0085921d84572f48cc79ff4, 33554432,
f32a854298814c18b12d56412f6e3a31afc95e42,
package_extract_file("patch/boot.img.p"))
after getting system.img and boot.img from firmware This is equals of previous functions on PC with this tools:
Code:
~$ ./BlockImageUpdate system.img system.transfer.list system.new.dat system.patch.dat
~$ ./ApplyPatch boot.img - 0041a4df844d4b14c0085921d84572f48cc79ff4 33554432 f32a854298814c18b12d56412f6e3a31afc95e42
scriptpatcher.sh will generate all commands automatically from updater script so run it like:
Code:
~$ ./scriptpatcher.sh META-INF/com/google/android/updater-script > fullpatch.sh
check fullpatch.sh your self, you need to provide all images and files in correct name and patch as mentioned in mount and other commands of fullpatch.sh
Building Requirements
For Building this tool you need :
zlib
libbz2
openssl
It currently supports Linux x86/x64 & MacOS, Not tested on Windows.
Compile and Build command:
Code:
make
Youtube
Download links:
GitHub Release
Changelog:
GitHub Commits
Known Bugs/Issues:
Plz test and report
Nice work
Very nice
Sent from my LG-LS997 using Tapatalk
Wow, I tried to apply OTAs manually myself, but never got it to work. Getting the propper tools from you is awesome!
One tiny question though: Does applying/verifying a system update to system.img require a lot of temporary space or memory?
I am running Ubuntu x64 in a VM (VirtualBox) on Windows 10. Verifying a system update doesn't really do much, except keeping the CPU busy.
This is the output of "./BlockImageVerify system.img system.transfer.list system.new.dat system.patch.dat":
Code:
performing verification
creating cache dir cache
cache dir: cache
blockimg version is 3
maximum stash entries 236
creating stash cache/537ed49fb5f6c32dc3d205d78b6084fe54f70cd3/
The cache folder remains empty, there is no harddisk activity and only the CPU is working at 100 %. I interrupted BlockImageVerify after 30 minutes.
daniel_m said:
Wow, I tried to apply OTAs manually myself, but never got it to work. Getting the propper tools from you is awesome!
One tiny question though: Does applying/verifying a system update to system.img require a lot of temporary space or memory?
I am running Ubuntu x64 in a VM (VirtualBox) on Windows 10. Verifying a system update doesn't really do much, except keeping the CPU busy.
This is the output of "./BlockImageVerify system.img system.transfer.list system.new.dat system.patch.dat":
The cache folder remains empty, there is no harddisk activity and only the CPU is working at 100 %. I interrupted BlockImageVerify after 30 minutes.
Click to expand...
Click to collapse
Ah actually yes you need free space on RAM as much as both patch.dat and new.dat sizes
It's on my todo list to fix it, https://github.com/erfanoabdi/imgpatchtools/blob/master/blockimg/blockimg.cpp#L383
How to extract the file system.new.dat
evangelico793 said:
How to extract the file system.new.dat
Click to expand...
Click to collapse
You can find it in OTA zip
Motorola? See this : motorola.erfanabdi.ir
erfanoabdi said:
You can find it in OTA zip
Motorola? See this : motorola.erfanabdi.ir
Click to expand...
Click to collapse
No longer look at the picture
erfanoabdi said:
You can find it in OTA zip
Motorola? See this : motorola.erfanabdi.ir
Click to expand...
Click to collapse
Something Looks Wrong ReCheck inputs Or No Update Available
for moto g4 play 6.0.1
evangelico793 said:
No longer look at the picture
Click to expand...
Click to collapse
Please send picture again
404 not found
evangelico793 said:
Something Looks Wrong ReCheck inputs Or No Update Available
for moto g4 play 6.0.1
Click to expand...
Click to collapse
You are doing something wrong see thread for help and examples
@erfanoabdi
Thank you a ton for these tools!
They work like a charm :good:
I knew there must be a way to do this, but it's definitely above my paygrade.
@erfanoabdi
I've been trying scriptpatcher.sh on various updater-scripts and have noticed some bugs.
If you're interested in looking at the files, let me know and I'll post them.
Q9Nap said:
@erfanoabdi
I've been trying scriptpatcher.sh on various updater-scripts and have noticed some bugs.
If you're interested in looking at the files, let me know and I'll post them.
Click to expand...
Click to collapse
Yeah, there's lots of bugs in that script
I appreciate any kind of help
So far i know :
Only supporting /dev/block/boot.../by-name partitions
Can't mount ext4 in macOS
I disabled verify, but we can verify images
And i haven't tested it so much
If it gets more complicated Maybe we have to rewrite it on python.
erfanoabdi said:
Yeah, there's lots of bugs in that script
I appreciate any kind of help
So far i know :
Only supporting /dev/block/boot.../by-name partitions
Can't mount ext4 in macOS
I disabled verify, but we can verify images
And i haven't tested it so much
If it gets more complicated Maybe we have to rewrite it on python.
Click to expand...
Click to collapse
*removed*
@erfanoabdi
I noticed that there was an update to the source today to enable the bonus file argument.
I tried to create a recovery.img with a boot.img, recovery-from-boot.p, and recovery-resource.dat.
I tried patching to create a new recovery image and also tried patching the boot image in place.
It always returns "Unknown patch file format".
I am able to use these files to create recovery with the on-device applypatch binary, so not sure why it's throwing the "unknown patch file format" error.
Q9Nap said:
@erfanoabdi
I noticed that there was an update to the source today to enable the bonus file argument.
I tried to create a recovery.img with a boot.img, recovery-from-boot.p, and recovery-resource.dat.
I tried patching to create a new recovery image:
#Output:
creating cache dir cache
cache dir: cache
patch boot.img:
failed to stat "recovery.img": No such file or directory
Unknown patch file format
Done with error code : 1
and also tried patching the boot image in place:
#Output:
creating cache dir cache
cache dir: cache
patch boot.img:
Unknown patch file format
Done with error code : 1
I am able to use these files to create recovery with the on-device applypatch binary, so not sure why it's throwing the "unknown patch file format" error.
Any ideas? Is my syntax incorrect?
Click to expand...
Click to collapse
That was chainfire commit changes how can i say "no" to his PR
I didn't had time to check it
I'll check it out when I could
Q9Nap said:
@erfanoabdi
I noticed that there was an update to the source today to enable the bonus file argument.
I tried to create a recovery.img with a boot.img, recovery-from-boot.p, and recovery-resource.dat.
I tried patching to create a new recovery image:
#Output:
creating cache dir cache
cache dir: cache
patch boot.img:
failed to stat "recovery.img": No such file or directory
Unknown patch file format
Done with error code : 1
and also tried patching the boot image in place:
#Output:
creating cache dir cache
cache dir: cache
patch boot.img:
Unknown patch file format
Done with error code : 1
I am able to use these files to create recovery with the on-device applypatch binary, so not sure why it's throwing the "unknown patch file format" error.
Any ideas? Is my syntax incorrect?
Click to expand...
Click to collapse
I've tested recovery-from-boot by chainfire and i can confirm its working
Also i fixed no such file error
Try to compile new source
*edit*
Fixed!

[8/3/2019]Updated Android IMG Tools[Upto Android 9.0]

Since These tools are outdated there has been little movement with the tools since, @rkhat has made a source available to be built for linux, however im unable to get a compile.
So i decided to gather sources and make some modifications to get them compiling in cygwin and works upto android 8.1
Install cygwin in the default directory with the following packages.
libpcre1, zlib-devel, cmake, make, automake, gcc-core, gcc-g++, libgcc1, libstdc++6, cpio, flex, bison, cygwin32-gcc-core, patch, libintl
Source code
Prebuilt binaries
To build simply download and extract the source, open CMD and
Code:
path=%path%C:\cygwin64\bin;
cd to each directory and execture
Code:
make
To build e2fsprogs
Open cygwin
cd to the directory
Code:
mkdir build
cd build
../configure
make
Original Sources
Sparse utillities based on sources https://github.com/anestisb/android-simg2img
mkbootimg based on sources https://github.com/osm0sis/mkbootimg
mkbootfs based on sources https://github.com/osm0sis/mkbootfs
make_ext4fs based on sources https://github.com/jamflux/make_ext4fs
sefcontext_decompile based on sources https://github.com/wuxianlin/sefcontext_decompile
dtc based on sources https://github.com/dgibson/dtc
e2fsprogs based on sources https://github.com/tytso/e2fsprogs
Generates -
append2simg.exe
cpio.exe
dtc.exe
gzip.exe
img2simg.exe
make_ext4fs.exe
mkbootfs.exe
mkbootimg.exe
sefcontext_decompile.exe
simg2img.exe
simg2simg.exe
unpackbootimg.exe
mke2fs.exe
Contributors
SuperR, anestisb, rkhat2, osm0sis, jamflux, wuxianlin, Xannytech, CarmineRovito
Doing God's work I see.
Repo was on private, fixed it now
https://github.com/anpaza/make_ext4fs
I1V1A1N said:
https://github.com/anpaza/make_ext4fs
Click to expand...
Click to collapse
Thats a newer build, i may use it, thanks
Repository has been updated for partial 9.0 support
dose it support pie use make_ext4fs?
Nightmare_MYS said:
dose it support pie use make_ext4fs?
Click to expand...
Click to collapse
Unpacking yes but repacking not at the moment, i havent had time to look into mk2efs and the new e2fsdroid source code, the source for these are in the e2fsprogs repository, mk2efs already has a windows port in cygwin and the e2fsdroid sourcw code is in the contrib/android directory, i have built mk2efs correctly but i havent attempted e2fsdroid yet because i have been busy, maybe @osm0sis may be able to give it a shot
Ricky Divjakovski said:
Unpacking yes but repacking not at the moment, i havent had time to look into mk2efs and the new e2fsdroid source code, the source for these are in the e2fsprogs repository, mk2efs already has a windows port in cygwin and the e2fsdroid sourcw code is in the contrib/android directory, i have built mk2efs correctly but i havent attempted e2fsdroid yet because i have been busy, maybe @osm0sis may be able to give it a shot
Click to expand...
Click to collapse
i have no idea,i checked a lot of method,mke2fs just can creat a new null img,i still don't know e2fsdroid's effect,i had used ClassyKitchen to repack my pie,it working,but ClassyKitchen just a single exe file,
Nightmare_MYS said:
i have no idea,i checked a lot of method,mke2fs just can creat a new null img,i still don't know e2fsdroid's effect,i had used ClassyKitchen to repack my pie,it working,but ClassyKitchen just a single exe file,
Click to expand...
Click to collapse
thats quite odd, from looking into classy kitchen it seems that it does use make_ext4fs?
however i dont know how he has got it working, he tries hiding the functionallity of his tools quite abit, im guessing this is because of licensing issues preventing him to sell whats included in the tools and to stop other people from making a free version, the binaries are unpacked to %tmp%/BIN folder when processing a firmware, check it out
Ricky Divjakovski said:
thats quite odd, from looking into classy kitchen it seems that it does use make_ext4fs?
however i dont know how he has got it working, he tries hiding the functionallity of his tools quite abit, im guessing this is because of licensing issues preventing him to sell whats included in the tools and to stop other people from making a free version, the binaries are unpacked to %tmp%/BIN folder when processing a firmware, check it out
Click to expand...
Click to collapse
the free of classy kitchen just can build new img,if i know its working space,i maybe know it in Disk C,but i can't find it and dont't know the binaries unpacked where,i tryed to use make_ext4fs to build my pie img,it is not working,i sure Classy Kithen can,
Nightmare_MYS said:
the free of classy kitchen just can build new img,if i know its working space,i maybe know it in Disk C,but i can't find it and dont't know the binaries unpacked where,i tryed to use make_ext4fs to build my pie img,it is not working,i sure Classy Kithen can,
Click to expand...
Click to collapse
the binaries are in the %tmp%\BIN folder
Anyway this can be made to support Amazon boot images?
Sent from my MotoG3 using XDA Labs
DragonFire1024 said:
Anyway this can be made to support Amazon boot images?
Sent from my MotoG3 using XDA Labs
Click to expand...
Click to collapse
Please upload the boot image and ill see if i can do this, ill also update the sources soon because i made a utillity to split the MTK header from an MTK ramdisk
Ricky Divjakovski said:
Please upload the boot image and ill see if i can do this, ill also update the sources soon because i made a utillity to split the MTK header from an MTK ramdisk
Click to expand...
Click to collapse
Awesome. Thank you. I'll upload one as soon as I get home
Sent from my MotoG3 using XDA Labs
I'm trying to use img2sing.exe and getting "cygz.dll was not found" error. Is that file supposed to be in the zip?
zxcv888 said:
I'm trying to use img2sing.exe and getting "cygz.dll was not found" error. Is that file supposed to be in the zip?
Click to expand...
Click to collapse
that will be in your cygwin bin directory, either copy it from there to the same folder as the exe or or add the cygwin bin directory to your path environment variable
Ricky Divjakovski said:
the binaries are in the %tmp%\BIN folder
Click to expand...
Click to collapse
i didn't find that,
Nightmare_MYS said:
i didn't find that,
Click to expand...
Click to collapse
you have to run the progran and repack for it to appeart, as soon as its repacked the folder gets deleted
Ricky Divjakovski said:
Please upload the boot image and ill see if i can do this, ill also update the sources soon because i made a utillity to split the MTK header from an MTK ramdisk
Click to expand...
Click to collapse
here is the boot.img from the Amazon Fire HD 10, 2017, firmware version update-kindle-40.6.0.5_user_605485120.bin. Thank you so much. Let me know if you need anything else. Just extract the .img from the zip.

[TOOL][LINUX][ANDROID][WINDOWS] Jancox Tool Unpack Repack ROMs

Jancox Tool Unpack Repack ROMs
Jancox tool is a tool for unpacking and repacking ROMs, in other words this is a tool for modification Android ROM, and it supports Linux, Android and Windows.
Requestment
Requestment Linux
- Installed Python 3
Requestment Android
- Installed Python 3 in Termux
Requestment Windows
- None
How To Use In Linux
]
Code:
~$ ./unpack.sh
~$ ./repack.sh
~$ ./cleanup.sh
How To Use In Android
- Rename your rom to input.zip
- Move input.zip to /sdcard/input.zip or /sdcard/download/input.zip or /data/local/jancox-tool/input/input.zip
- Open termina/termux
Code:
~$ su
~$ jancox
- Output in /data/local/jancox-tool/editor
How To Use In Windows
- Extrack Jancox-Tool-Windows
- Rename your rom to input.zip
- Move input.zip to jancox tool folder
- Run unpack
- Edit rom in editor folder
- Run repack
- Cleanup for clean files
Video
Linux Guide :
Android Guide :
Windows Guide :
Download
Click Here
Source
https://github.com/Wahyu6070/Jancox-tool
https://github.com/Wahyu6070/Jancox-tool-Linux
https://github.com/Wahyu6070/Jancox-tool-Android
https://github.com/Wahyu6070/Jancox-Tool-Windows
Credit :
Jamflux SUR windows : https://github.com/jamflux/SUR
Magiskboot : topjohnwu
make_ext4fs : SuperR
Busybox : https://busybox.net/
7za : https://www.7-zip.org/
Brotli : https://github.com/google/brotli
Img2sdat/sdat2img : https://github.com/xpirt/img2sdat
python : based termux
Changelog
Linux v2.0
- Support img only
- Added brotli support
- Added boot extractor
- Added brotli level set
- and other improvements
Mobile v2.3
- Using kopi installer (support magisk non magisk)
- move zip compression 7z to zip
- improv debloater
- added disable dm-verity
- added change name
- added dat prop (jancox.prop)
- and other improvements
Windows v2.0
- Initial Release
Repack gagal terus pak
How to fix?
Erwin Abs said:
How to fix?
Click to expand...
Click to collapse
try install busybox
Wahyu6070 said:
try install busybox
Click to expand...
Click to collapse
l
Hello! I got error "unzip: invailid zip magic C26CB134"
How can i solve this problem? Busybox was installed.
Thanks
thienmoc198x said:
l
Hello! I got error "unzip: invailid zip magic C26CB134"
How can i solve this problem? Busybox was installed.
Thanks
Click to expand...
Click to collapse
update to version 2.2 if you still find problems send me the log
awesome work bro. thank you so much!
Really excited about this app!
One question: tools can only ota zip? If only .img file is available, then split first in boot.img, system.img, vendor.img etc but then?
How to fix ?
Malware Alert
Sourceforge link is showing a malware alert for your build. See the attached image.
hi, i want unpack only boot.img, made a input.zip with boot.img, unpack perfect, but cant pack again, receive a message please unpack, some idea why?
thanks and good work
sir, do you know how to unpack blackshark1's rom ?
failed by payload dumper
-----
bg, tau cara unpack rom nya blackshark 1 ga ?
pake payload dumper ga mempan
Need to be able to unpack Nokia roms. Format .nb0. Its possible to add this support to your already awesome tool? (Linux) Thanks in advance.
Hi
I unpacked and repacked the miui 12 ROM with this method, but unfortunately, after flashing the ROM, it did not boot and the phone was transferred to fast boot.pleace help to solve this problem .Thank you.
Please help me admin and all,
Has anyone already edited service.jar using the jancoxx tool.?
Wahyu6070 said:
Jancox Tool Unpack Repack ROMs
Jancox tool is a tool for unpacking and repacking ROMs, in other words this is a tool for modification Android ROM, and it supports Linux, Android and Windows.
Requestment
Requestment Linux
- Installed Python 3
Requestment Android
- Installed Python 3 in Termux
Requestment Windows
- None
How To Use In Linux
]
Code:
~$ ./unpack.sh
~$ ./repack.sh
~$ ./cleanup.sh
How To Use In Android
- Rename your rom to input.zip
- Move input.zip to /sdcard/input.zip or /sdcard/download/input.zip or /data/local/jancox-tool/input/input.zip
- Open termina/termux
Code:
~$ su
~$ jancox
- Output in /data/local/jancox-tool/editor
How To Use In Windows
- Extrack Jancox-Tool-Windows
- Rename your rom to input.zip
- Move input.zip to jancox tool folder
- Run unpack
- Edit rom in editor folder
- Run repack
- Cleanup for clean files
Video
Linux Guide :
Android Guide :
Windows Guide :
Download
Android
Linux
Windows
Source
https://github.com/Wahyu6070/Jancox-tool-Linux
https://github.com/Wahyu6070/Jancox-tool-Android
https://github.com/Wahyu6070/Jancox-Tool-Windows
Credit :
Jamflux SUR windows : https://github.com/jamflux/SUR
magiskboot : topjohnwu
make_ext4fs : SuperR
busybox : https://busybox.net/
busybox : https://github.com/Magisk-Modules-Repo/busybox-ndk
7za : https://www.7-zip.org/
brotli : https://github.com/google/brotli
img2sdat/sdat2img : https://github.com/xpirt/img2sdat
python : based termux
XDA:DevDB Information
[TOOL[LINUX][ANDROID][WINDOWS] Jancox Tool Unpack/Repack ROMs, Tool/Utility for the Android General
Contributors
Wahyu6070
Version Information
Status: Stable
Current Stable Version: 2.0
Created 2020-04-11
Last Updated 2020-08-12
Click to expand...
Click to collapse
supports super.img?
How can I add a apk to the priv-apps folder and give the apk all the permissions like camera, location ,draw over other apps, etc
I unpacked miui china rom, added some gapps and now when i am trying to repack i am getting following error.
[system/product/app/LatinImeGoogle] not found in canned fs_config, using defaults
How to fix this issue and continue repacking?
I have only following files related to configs.
RSM10 said:
I unpacked miui china rom, added some gapps and now when i am trying to repack i am getting following error.
[system/product/app/LatinImeGoogle] not found in canned fs_config, using defaults
How to fix this issue and continue repacking?
I have only following files related to configs.
View attachment 5338745
Click to expand...
Click to collapse
add system/product/app/LatinImeGoogle to fs_config file.

Categories

Resources