[TOOL][UTILITY] Carliv Image Kitchen for Android - unpack/repack boot-recovery - Miscellaneous Android Development

{
"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"
}
Hi, I present you my tool for unpacking/repacking boot and recovery images for Android phones: Carliv Image Kitchen for Android.
2016-06-30 Update to version 1.3 stable
Changelog:
- detect mtk header during unpacking;
- removed grep method;
Instructions can be found in every variant folder.
To start it just double click on carliv.bat script (windows) or carliv script (Linux) then choose "Run in terminal" from dialog box.
Credits:
yuweng for his assistance and help on testing and troubleshooting (you should thank him too guys - it was a great help);
michfood for initial starting ideea;
osm0sis for bootimg-info source and some hints from his kitchen;
Cyanogenmod for mkbootimg source folder;
Omnirom for their clean implementation of MTK header.
Pete Batard for bootimage tools windows fix.
Thomas Polaert ([email protected]) for CECHO DOS coloring tool (windows version).
If you want to share this in other websites, blogs or forums please keep the credits from script files (I wrote those from scratch), and give proper credits for me.
Contributors
carliv, yuweng

Drag & Drop on linux CarlivImageKitchen version! function implemented by yuweng
Alternative linux version with Drag and Drop functionality, modded by my friend yuweng! -* carliv's edit: copied here from my friend's post.
Yes, now you can also Drag&Drop to UnPack/ RePack Android images on linux using CarlivImageKitchen !
Download CarlivImageKitchen-DnD.zip & extract to your linux Desktop, copy out all the five .desktop files to your Desktop & start Dragging & Dropping . . . :laugh: You can also Drag&Drop it to same .desktop files inside CarlivImageKitchen folder & it'll to work too . . . :good:
Tested working perfectly on BBQLinux & also Ubuntu, however, for Ubuntu you need to open the .desktop launcher shortcut with any text editor & manual edit the command as below . . .
Code:
[COLOR="Blue"]gnome-terminal[/COLOR] -e "bash -c \"~/Desktop/CarlivImageKitchen/image_info %f\""
i have also tested it on numerous of linux terminal program & it works perfectly too so you gotta manual edit it if you are using those . . . :good:
Code:
[URL="https://launchpad.net/terminator"]terminator[/URL] -e "bash -c "~/Desktop/CarlivImageKitchen/image_info %f""
[URL="https://konsole.kde.org/"]konsole[/URL] -e "bash -c "~/Desktop/CarlivImageKitchen/unpack_MTK_img %f""
[URL="http://mate-desktop.org/#mate-terminal"]mate-terminal[/URL] -e "bash -c "~/Desktop/CarlivImageKitchen/image_info %f""
[URL="http://en.wikipedia.org/wiki/GNOME_Terminal"]gnome-terminal[/URL] -e "bash -c "~/Desktop/CarlivImageKitchen/repack_MTK_img %f""
[URL="http://wiki.lxde.org/en/LXTerminal"]lxterminal[/URL] -e "bash -c "~/Desktop/CarlivImageKitchen/image_info %f""
[URL="http://roxterm.sourceforge.net/"]roxterm[/URL] -e "bash -c "~/Desktop/CarlivImageKitchen/image_info %f""
[URL="https://www.enlightenment.org/p.php?p=about/terminology"]terminology[/URL] -e "bash -c "~/Desktop/CarlivImageKitchen/repack_img %f""
[URL="https://launchpad.net/sakura"]sakura[/URL] -e "bash -c "~/Desktop/CarlivImageKitchen/image_info %f""
[URL="http://en.wikipedia.org/wiki/Xterm"]xterm[/URL] -e "bash -c "~/Desktop/CarlivImageKitchen/image_info %f""
[URL="http://en.wikipedia.org/wiki/Terminal_(Xfce)"]xfce4-terminal[/URL] -e "bash -c "~/Desktop/CarlivImageKitchen/unpack_img %f""
No more typing to unpack/ repack, just draaaagggg & drooooopppp it like you use to do that on Windows . . . :laugh:
Full credits to Master Shifu Carliv, i just modded a few lines to support Drag&Drop, that's all . . .
Drag&Drop in Action !
Konsole
roxterm
sakura
gnome-terminal
lxterminal
mate-terminal
xterm
terminator
terminology
xfce4-terminal
If you want to hit the THANKS button for yuweng's version, go here and do it.

Mirror Downloads
2015-04-08 Big Update to version 1.0 stable
Changelog:
- corrected few issues in scripts;
- rebuilt all modules also to correct some issues;
- cleaned up the source;
- added more compression support - see next;
- now the kitchen supports ramdisks compressions as following: gz, bz2, lzma, xz, lzo, lz4;
- converted to a Menu driven interface: now everything can be done from inside kitchen menu with few clicks;
- updated Instructions (can be loaded in kitchen interface for reading).
* for those of you who don't want the menu interface, there is version 0.5 in download list, with the old individual scripts structure but updated with same modules and compression support as version 1.0 (I kept this especially for windows, where it can be used with drag and drop).
2015.02.16 Update version 0.3
rebuilt binaries to correct few issues.
some fixes in scripts.
generate correct sha id.
use minigzip for repacking ramdisk as in recovery building.
compiled standalone bzip2 module.
So, what's this?
It's a utility (tool) for unpacking and repacking boot and recovery images for many kind of android phones. I made two versions, one for windows users and one for linux users. The windows version works by dragging&dropping over the script you want to use, while the linux version will work with terminal commans (very simple commands though).
What's inside?
For windows version the scripts are batch files and for linux bash files, but the names are the same and they do same thing:
clear_all will clear the working folder deleting any unpacked boot/recovery folder, but not the boot or recovery files (original or repacked).
image_info will print on screen all informations about the image you want to check (sizes, offsets, cmdline, etc.) and all these infos will be saved in a text file (which will be deleted when you clear the folder - see point 1). This is handy if you don't want to unpack the image, but only to see its infos. This script works for all kind of images (not specific to a hardware platform).
unpack_img is the script for unpacking images for all kind of phones with different platforms (qcom, exynos,...) but not MTK. It will work I think for AndroidOne project phones.
unpack_MTK_img is the script for unpack any MTK image, including the ones from new platforms (mt6595, mt6752, mt6753, and whatever they are).
repack_img is the repacking script for regular (non-MTK) phones.
repack_MTK_img is the repacking script for all MTK boot/recovery images.
Besides these in Utility folder there is a bin folder (hidden) with all executables needed by the scripts.
How to use it?
As I said, for windows just drag&drop an image (boot or recovery) you want to unpack over the corresponding script, and drag&drop the folder of the unpacked image over the repacking script when you want to repack it. Choose the scripts with MTK in name for MTK images, and the other ones for any other kind.
For linux open a terminal window in CarlivImageKitchen folder and type (or just copy/paste from here) the commands:
Code:
./unpack_img boot.img
or
Code:
./unpack_MTK_img recovery.img
or what name has your image.
To repack type like this:
Code:
./repack_img recovery
or
Code:
./repack_MTK_img boot
and so on.
NOTICE here for repacking just type the name of the folder, without slashes.
Important, my utility doesn't have any request for position on partitions or directories. In testes worked in a third sub-sub-subfolder on an external partition (both in linux and windows), and it proves to work with any kind of name (except special characters that may break the script), including spaces or dots in folders names, but I recommend you to use dashes or underscores instead of spaces, and avoid dots. In repacking procedure, the script will prompt you to introduce a name for the new image, and if it will contain dots or spaces you will see an error. Also the name must include the type of image (boot or recovery) - Eg: "boot-stock-repack" or "recovery_cwm_m7", and without the extension (.img).
Same condition about names applies for images you want to unpack; if they have other names, like "cwm-m7.img", rename it including the type of image in name: eg "recovery-cwm-m7.img". Why this? As many of you used bgcngm's tool you noticed he asked for including an argument in script command ("-boot" or "-recovery") because this is the way his script can apply the right header for ramdisks in repacking. My tool does that from image name and you don't have to add extra arguments in command.
A second note: This tool doesn't support Rockchip Android images.
What's under hood?
All modules used in my tools are compiled by me, both for windows and linux.
Also for windows, because it requires few cygwin libraries to work with compressing/uncompressing executables, I used those libraries and executables from latest cygwin release (gzip, xz, bzip2, cpio and the corresponding dlls).
But my utility doesn't require a cygwin installed. Well, linux version worked very well in cygwin environment, but it's not necessary since I provided a standalone windows version.
The executable modules:
imageinfo - a initial source is shared by osm0sis here, but I used that only for inspiration because I liked the ideea; I used the unpackbootimg from cyanogenmod 12, system/core/mkbootimg and modded to get a similar output as in osm0sis bootimg-info.
mkbootfs - built in cygwin for windows and normal in linux. I used the "stock" source from cyanogenmod 12 /system/core/cpio.
mkbootimg - based cyanogenmod 12 source, but modded, and for windows fixed to work (the standard source it builds in windows but doesn't work). I used for fixing the ideeas from Pete Batard's source. This module repack also dtb-images back to repacked image.
mtkbootimg - same as mkbootimg, but with additions from omnirom code for MTK, to append the MTK header to this kind of images. This one will check first the kernel and then the ramdisk for MTK header, and if it's not there it will append it, but if it's there will skip.
unpackbootimg - from same cyanogenmod 12 source, with few extra additions by me.
unpackmtkimg - same as unpackbootimg but adapted for MTK images, for which will strip the header off before unpacking, to be easy to work with.
For windows I used jeremejevs cmdcolor source to build a module which add colors in cmd console, for a pleasant experience.
All these sources are modified, improved and fixed in some aspects.
Why I did it?
Well, the trigger was the apparition of the new platforms from MTK, which didn't worked with any of the old tools. First who found out what's changed was mrjavum. Starting from his findings I explored more, and then provided the update ideea and binaries for bgcngm's tool. But that is only for linux. I know it can be used in windows with cygwin, but we had a standalone tool, michfood's tool, which now doesn't work with the new platforms.
So I started to think for a new utility for windows to solve that need. After I did it I thought I can do it for linux too even if there exists already bgcngm's tool and works great. And I made it not only for MTK phones.
That's the reason I called it Image Kitchen. It is like a tool that combines michfood's tool with osm0sis Kitchen, and serves for different platforms (I tested MTK, Qualcomm, Exynos, with or without dtb, and all worked great). But it's first release, not fully tested (I don't have all kind of phones for that), and so it is marked beta.[/HIDE]
Cygwin-windows version
Removed since it was only for some specific testing, and anyway the windows version now works and it shows exactly the same with linux, producing same result.

awesome
More goodies for me to test.
Thanks guys

This is great! No need to shuffle programs for unpacking/repacking boot and recovery images of various platforms.
Windows version working (MTK and non-MTK).
Tried to use the Linux version in cygwin and encountered the following errors:

There are already separate package for Windows & Linux so use the appropriate package however for beta-testing sake . . .
Copy all the *.exe from Windows package -> hidden folder bin to Linux .bin folder.
Add the extension exe to all linux binary at the script
Eg.
gzip -> gzip.exe
mkbootfs -> mkbootfs.exe
unpackmtkimg -> unpackmtkimg.exe
mtkbootimg -> mtkbootimg.exe
unpackbootimg -> unpackbootimg.exe
mkbootimg -> mkbootimg.exe
Now the linux script will work on cygwin . . .

Thanks for the suggestion.
Now, unpack (MTK and non-MTK) works but repack does not. The repacked image is much smaller in size than that of the original. It also produces errors when I unpack the repacked image.

iZLeeP said:
Thanks for the suggestion.
Now, unpack (MTK and non-MTK) works but repack does not. The repacked image is much smaller in size than that of the original. It also produces errors when I unpack the repacked image.
Click to expand...
Click to collapse
If you want to test it in cygwin you need to add all binaries from windows bin with exe extension except dlls (those are native) and compressing modules, and to replace those from linux. You can see in linux version all compressing modules are missing - they have to be installed in system. Same for cygwin. It's possible you got a cygwin with some packages missing. That error message you see is because it's missing cpio probably. The linux binaries are much smaller because the compiler works different in linux. In windows the modules are standalone and don't need any dll, except those for archiving from cygwin, but we are not talking about those.
Anyway what you do here is just cross testing, and you don't need to use linux version in windows because windows version works the same.

carliv said:
If you want to test it in cygwin you need to add all binaries from windows bin with exe extension except dlls (those are native) and compressing modules, and to replace those from linux. You can see in linux version all compressing modules are missing - they have to be installed in system. Same for cygwin. It's possible you got a cygwin with some packages missing. That error message you see is because it's missing cpio probably. The linux binaries are much smaller because the compiler works different in linux. In windows the modules are standalone and don't need any dll, except those for archiving from cygwin, but we are not talking about those.
Anyway what you do here is just cross testing, and you don't need to use linux version in windows because windows version works the same.
Click to expand...
Click to collapse
Yes, I was just testing the functionality of the linux version in cygwin. As I don't have linux here (office), I use cygwin instead. I'll re-download full cygwin package and test again. Nonetheless, I have no problems with the windows version (tested in Vista and 7). I'll try it on XP at home.

iZLeeP said:
Yes, I was just testing the functionality of the linux version in cygwin. As I don't have linux here (office), I use cygwin instead. I'll re-download full cygwin package and test again. Nonetheless, I have no problems with the windows version (tested in Vista and 7). I'll try it on XP at home.
Click to expand...
Click to collapse
It's ok, but you have to be carefull to search manually for some packages, because depending from what mirror you install cygwin, they may be there or not. This situation is very well exposed in cygwin forums. When I built mkbootfs in cygwin for windows the compiler complains for few missing packages and I had to add them one by one searching online in cygwin packages. Some of them were on mirrors.kernel.org and some on cygwin.cybermirror.org. In any other mirror site they were missing. Same for compression packages: xz was only in mirrors.kernel.org. When you install cygwin you don't see any message of something not being there.
Or maybe I don't know how to work with cygwin, I don't know...

carliv said:
It's ok, but you have to be carefull to search manually for some packages, because depending from what mirror you install cygwin, they may be there or not. This situation is very well exposed in cygwin forums. When I built mkbootfs in cygwin for windows the compiler complains for few missing packages and I had to add them one by one searching online in cygwin packages. Some of them were on mirrors.kernel.org and some on cygwin.cybermirror.org. In any other mirror site they were missing. Same for compression packages: xz was only in mirrors.kernel.org. When you install cygwin you don't see any message of something not being there.
Or maybe I don't know how to work with cygwin, I don't know...
Click to expand...
Click to collapse
It's working now after updating cygwin. If I recall correctly, I used dsixda's instructions on how to setup cygwin for kitchen. The procedure required to install additional packages including cpio. Maybe, the files were just outdated since I had this last 2011.

Refer to post #2 for details . . .

Fantabulous Work Sir :good: Going To Test it
carliv said:
the name must include the type of image (boot or recovery)
Click to expand...
Click to collapse
Sir if i am Not Mistaken, Michfood's Recovery/Boot UnPacker/Repacker Tool Don't Need This, Right?

EnerJon said:
Fantabulous Work Sir :good: Going To Test it
Sir i Think, Michfood's Recovery/Boot UnPacker/Repacker Tool Don't Need This... Right?
Click to expand...
Click to collapse
Yes, you're right, but his tool uses a different method. It stores the ramdisk and kernel headers on unpack in separate files and add them back for repack. My tool strip off the headers on unpack and will recreate them during repack and it need that info to determine wich header to add for ramdisk (ROOTFS or RECOVERY).

carliv said:
Yes, you're right, but his tool uses a different method. It stores the ramdisk and kernel headers on unpack in separate files and add them back for repack. My tool strip off the headers on unpack and will recreate them during repack and it need that info to determine wich header to add for ramdisk (ROOTFS or RECOVERY).
Click to expand...
Click to collapse
Got it, So Michfood's Tool Just Extracts The Headers Of The IMG File While UnPacking And Adds Them Back As it is, This Way it Don't Need To Take Care Of The IMG Type Because The Type Of Output IMG Automatically Becomes Same as input IMG in The End...
But Your Tool Needs To Know The Type Of IMG Because it Creates Those Headers By itself... Hmm, But Sir, i Don't Understand One Thing, What's Wrong With Extracting And Adding Same Headers As input IMG File?
i Think, You/OmniROM DEVs Did This To Make Boot.img Usable As Recovery.img Or Vice Versa? Thats The Only Reason Comes in My Mind

EnerJon said:
Got it, So Michfood's Tool Just Extracts The Headers Of The IMG File While UnPacking And Adds Them Back As it is, This Way it Don't Need To Take Care Of The IMG Type Because The Type Of Output IMG Automatically Becomes Same as input IMG in The End...
But Your Tool Needs To Know The Type Of IMG Because it Creates Those Headers By itself... Hmm, But Sir, i Don't Understand One Thing, What's Wrong With Extracting And Adding Same Headers As input IMG File?
i Think, You/OmniROM DEVs Did This To Make Boot.img Usable As Recovery.img Or Vice Versa? Thats The Only Reason Comes in My Mind
Click to expand...
Click to collapse
The original MTK module (mkimage) - which source is not published (I never find it anywhere), append the right header during build of a ROM, and that's for boot - ROOTFS and for recovery - RECOVERY (on ramdisk). Omnirom code will add ROOTFS to any ramdisk, and same is the code from dsixda kitchen. This may be fine and may work in some phones, but I wanted to do it the right way, as in bgcngm's tool - because of the new MTK platforms. So I changed the source code to do it as I wanted, and instead of an extra argument I'm using just the name of image. I think it's not that hard to name the new image boot-something or something-boot-something or somethingboot, etc - same for recovery.
And for extracting old headers it's nothing wrong and it's easy to do it, but for adding back it needs an extra module (michfoods use sfk166 - now I think it reached version 173) and I wanted to reduce the number of binaries involved.
And again, really, I think my method with adding the name for newly created image is better.

Thanks For The info Sir, Yes, its Not That Hard To Rename it, Actually i Work With Dozens Of IMGs, But No Worries, its Just a One Time Process... Previously Michfood's Boot/Recovery RePacking Tool Was Not Working if i Try To RePack The IMGs Made With Sir Yuweng's Easy Magic Tool... But Your Tool Has No Such issues... Thank You Very Much For This Great Tool :highfive:
i Just Tested it And its Working Perfectly Fine For My Qmobile-A900 (Gionee Elife E3)
Just a Suggestion:
instead Of Asking User To input Final IMG Name, The Tool Should Automatically Expand The File Name By Adding "_NEW"
For Example:
Original IMG Name ===> MyStockBoot.img
1st Modified IMG Name ===> MyStockBoot_NEW.img
2nd Modified IMG Name ===> MyStockBoot_NEW_NEW.img
3rd Modified IMG Name ===> MyStockBoot_NEW_NEW_NEW.img
The Code Of You Tool Seems To Be Very Clean, And Handles The Errors Very Well :good:

EnerJon said:
.....Thank You Very Much For This Great Tool :highfive:
i Just Tested it And its Working Perfectly Fine For My Qmobile-A900 (Gionee Elife E3)
Just a Suggestion:
instead Of Asking User To input Final IMG Name, The Tool Should Automatically Expand The File Name By Adding "_NEW"
.... The Code Of You Tool Seems To Be Very Clean, And Handles The Errors Very Well :good:
Click to expand...
Click to collapse
Thanks, I worked quite a bit to make it that way because I do like clean and easy to read codes - easy to spot errors :laugh:
First test version was as you suggest without asking for a name and everything done automatic, but when I send it to my friend yuweng to test it, he came out with the ideea to ask user for the name and I think it's a good ideea and I added that prompt; this way you can repack same image with little modifications again and again, for tests purposes or other, and give related names, like boot-1, boot-2, or recovery-1, etc. In automated method for such things it needs to rename the new repacked image or the unpacked folder and at the end it creates more troubles than current method.

Hello Sir, i Wanted To Share My Modding Of Your Tool For Better Compression, i Also Did This Long Time Ago With Michfood's Tool, And it Works Effectively... By Doing This, Final Output IMG Can Be More Than 100KB Smaller Compared To Previous IMG Output... Which is a Releaf For 6MB Recovery/Boot Partition Devices...
For This, We Need 7zip Command Line Tool
By Downloading And Extracting "7za" Executable into The BIN Folder Of Your Tool And Modding Your Tool's RePack Script File, We Can Achieve Better Compression For GZIP'ed RAMDISKs...
Original repack_MTK_img.bat
Code:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::: :::
::: Carliv Image Kitchen for Android :::
::: boot+recovery images copyright-2015 [email protected] :::
::: including support for MTK powered phones images :::
::: :::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
cd %~dp0
IF EXIST "%~dp0\bin" SET PATH=%PATH%;"%~dp0\bin"
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal enabledelayedexpansion
set "red=\033[91m"
set "cyan=\033[96m"
set "yellow=\033[93m"
set "deft=\033[0m"
echo(
echo **********************************************************
echo * *
echo * %cyan%Carliv Image Kitchen for Android %deft%v0.1 * | klr
echo * boot+recovery images copyright-2015 %cyan%[email protected]%deft% * | klr
echo * including support for MTK powered phones images *
echo * WINDOWS version *
echo * The repacking MTK images script *
echo * *
echo **********************************************************
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if "%~nx1" == "" goto noinput
echo You have selected the%yellow% %~nx1 %deft%folder. | klr
echo(
echo Processing the%yellow% %~nx1 folder%deft%. | klr
echo(
set "folder=%~nx1"
icacls %folder% /grant Everyone:(IO)(CI)
cd %folder%
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo(
echo Repacking the image....
echo(
for /f "delims=" %%a in ('dir /b *-kernel') do @set nfile=!nfile!%%~na
set "file=%nfile%"
if not exist "%file%.img-kernel" goto error
set kernel=!kernel!%file%.img-kernel
echo The kernel is:%yellow% %kernel%%deft% | klr
echo(
echo Getting the ramdisk compression....
echo(
if not exist "ramdisk" goto error
for /f "delims=" %%a in (%file%.img-ramdisk-compress) do @set compress=!compress!%%a
echo Ramdisk compression:%yellow% %compress%%deft% | klr
goto %compress%
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:gz
echo(
[COLOR="Red"]mkbootfs ramdisk | gzip > %file%.img-ramdisk.gz[/COLOR]
set ramdisk=!ramdisk!%file%.img-ramdisk.gz
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:lzma
echo(
mkbootfs ramdisk | xz -Flzma > %file%.img-ramdisk.lzma
set ramdisk=!ramdisk!%file%.img-ramdisk.lzma
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:xz
echo(
mkbootfs ramdisk | xz -1 -Ccrc32 > %file%.img-ramdisk.xz
set ramdisk=!ramdisk!%file%.img-ramdisk.xz
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:bz2
echo(
mkbootfs ramdisk | bzip2 > %file%.img-ramdisk.bz2
set ramdisk=!ramdisk!%file%.img-ramdisk.bz2
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:repack
echo(
echo Getting the image repacking arguments....
echo(
if not exist "%file%.img-board" goto noboard
for /f "delims=" %%a in (%file%.img-board) do @set nameb=!nameb!%%a
echo Board:%yellow% '%nameb%'%deft% | klr
echo(
:noboard
if not exist "%file%.img-base" goto nobase
for /f "delims=" %%a in (%file%.img-base) do @set base=!base!%%a
echo Base:%yellow% %base%%deft% | klr
echo(
:nobase
for /f "delims=" %%a in (%file%.img-pagesize) do @set pagesize=!pagesize!%%a
echo Pagesize:%yellow% %pagesize%%deft% | klr
echo(
if not exist "%file%.img-cmdline" goto nocmdline
for /f "delims=" %%a in (%file%.img-cmdline) do @set scmdline=!scmdline!%%a
echo Command line:%yellow% '%scmdline%'%deft% | klr
echo(
:nocmdline
if not exist "%file%.img-kernel_offset" goto nokoff
for /f "delims=" %%a in (%file%.img-kernel_offset) do @set koff=!koff!%%a
echo Kernel offset:%yellow% %koff%%deft% | klr
echo(
:nokoff
if not exist "%file%.img-ramdisk_offset" goto noramoff
for /f "delims=" %%a in (%file%.img-ramdisk_offset) do @set ramoff=!ramoff!%%a
echo Ramdisk offset:%yellow% %ramoff%%deft% | klr
echo(
:noramoff
if not exist "%file%.img-second_offset" goto nosecoff
for /f "delims=" %%a in (%file%.img-second_offset) do @set fsecoff=!fsecoff!%%a
echo Second offset:%yellow% %fsecoff%%deft% | klr
set secoff=--second_offset %fsecoff%
echo(
:nosecoff
if not exist "%file%.img-second" goto nosecd
set fsecd=!fsecd!%file%.img-second
echo Second bootloader:%yellow% %fsecd%%deft% | klr
set "second=--second %fsecd%"
echo(
:nosecd
if not exist "%file%.img-tags_offset" goto notagoff
for /f "delims=" %%a in (%file%.img-tags_offset) do @set tagoff=!tagoff!%%a
echo Tags offset:%yellow% %tagoff%%deft% | klr
echo(
:notagoff
if not exist "%file%.img-dt" goto nodt
set fdt=!fdt!%file%.img-dt
echo Device tree blob:%yellow% %fdt%%deft% | klr
set "dtb=--dt %fdt%"
echo(
:nodt
echo(
:newimage
echo Please enter the desired name for the new repacked image without extension (img). Like this %yellow%boot%deft%-stock-2201 or carliv-%yellow%recovery%deft%-30 or %yellow%boot%deft%-new. | klr
set /P newimage=Insert the name here: || set newimage="0"
if "%newimage%"=="0" goto noimage
if not "%newimage%"=="%newimage:boot=%" goto command
if not "%newimage%"=="%newimage:recovery=%" goto command
goto wrongname
echo(
:command
echo Your new image is%yellow% %newimage%.img%deft%. | klr
echo(
echo Executing the repacking command....
echo(
mtkbootimg --kernel %kernel% --ramdisk %ramdisk% --pagesize %pagesize% --base %base% --board "%nameb%" --kernel_offset %koff% --ramdisk_offset %ramoff% --tags_offset %tagoff% %second% --cmdline "%scmdline%" %secoff% %dtb% -o ..\%newimage%.img
del "%file%.img-ramdisk.%compress%"
cd ..\
echo(
echo(
echo Done. Your new image was repacked as%yellow% %newimage%.img%deft%. | klr
goto end
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:noinput
echo(
echo(
echo %red%No folder selected. Exit script.%deft% | klr
echo(
goto end
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:wrongname
echo(
echo(
echo %red%The name have to include the type of image in it, %yellow%boot%red% or%yellow% recovery%red%.%deft% | klr
echo(
goto newimage
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:noimage
echo(
echo(
echo %red%Please enter a name for the repacked image first.%deft% | klr
echo(
goto newimage
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:error
echo(
echo(
echo %red%There is an error in your folder. The kernel or ramdisk is missing. Exit script.%deft% | klr
echo(
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:end
echo(
pause
Modded repack_MTK_img.bat
Code:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::: :::
::: Carliv Image Kitchen for Android :::
::: boot+recovery images copyright-2015 [email protected] :::
::: including support for MTK powered phones images :::
::: :::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
cd %~dp0
IF EXIST "%~dp0\bin" SET PATH=%PATH%;"%~dp0\bin"
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal enabledelayedexpansion
set "red=\033[91m"
set "cyan=\033[96m"
set "yellow=\033[93m"
set "deft=\033[0m"
echo(
echo **********************************************************
echo * *
echo * %cyan%Carliv Image Kitchen for Android %deft%v0.1 * | klr
echo * boot+recovery images copyright-2015 %cyan%[email protected]%deft% * | klr
echo * including support for MTK powered phones images *
echo * WINDOWS version *
echo * The repacking MTK images script *
echo * *
echo **********************************************************
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if "%~nx1" == "" goto noinput
echo You have selected the%yellow% %~nx1 %deft%folder. | klr
echo(
echo Processing the%yellow% %~nx1 folder%deft%. | klr
echo(
set "folder=%~nx1"
icacls %folder% /grant Everyone:(IO)(CI)
cd %folder%
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo(
echo Repacking the image....
echo(
for /f "delims=" %%a in ('dir /b *-kernel') do @set nfile=!nfile!%%~na
set "file=%nfile%"
if not exist "%file%.img-kernel" goto error
set kernel=!kernel!%file%.img-kernel
echo The kernel is:%yellow% %kernel%%deft% | klr
echo(
echo Getting the ramdisk compression....
echo(
if not exist "ramdisk" goto error
for /f "delims=" %%a in (%file%.img-ramdisk-compress) do @set compress=!compress!%%a
echo Ramdisk compression:%yellow% %compress%%deft% | klr
goto %compress%
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:gz
echo(
[COLOR="Blue"]mkbootfs ramdisk > %file%.img-ramdisk
7za a -tgzip -mx=9 %file%.img-ramdisk.gz %file%.img-ramdisk
del /F /Q %file%.img-ramdisk[/COLOR]
set ramdisk=!ramdisk!%file%.img-ramdisk.gz
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:lzma
echo(
mkbootfs ramdisk | xz -Flzma > %file%.img-ramdisk.lzma
set ramdisk=!ramdisk!%file%.img-ramdisk.lzma
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:xz
echo(
mkbootfs ramdisk | xz -1 -Ccrc32 > %file%.img-ramdisk.xz
set ramdisk=!ramdisk!%file%.img-ramdisk.xz
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:bz2
echo(
mkbootfs ramdisk | bzip2 > %file%.img-ramdisk.bz2
set ramdisk=!ramdisk!%file%.img-ramdisk.bz2
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:repack
echo(
echo Getting the image repacking arguments....
echo(
if not exist "%file%.img-board" goto noboard
for /f "delims=" %%a in (%file%.img-board) do @set nameb=!nameb!%%a
echo Board:%yellow% '%nameb%'%deft% | klr
echo(
:noboard
if not exist "%file%.img-base" goto nobase
for /f "delims=" %%a in (%file%.img-base) do @set base=!base!%%a
echo Base:%yellow% %base%%deft% | klr
echo(
:nobase
for /f "delims=" %%a in (%file%.img-pagesize) do @set pagesize=!pagesize!%%a
echo Pagesize:%yellow% %pagesize%%deft% | klr
echo(
if not exist "%file%.img-cmdline" goto nocmdline
for /f "delims=" %%a in (%file%.img-cmdline) do @set scmdline=!scmdline!%%a
echo Command line:%yellow% '%scmdline%'%deft% | klr
echo(
:nocmdline
if not exist "%file%.img-kernel_offset" goto nokoff
for /f "delims=" %%a in (%file%.img-kernel_offset) do @set koff=!koff!%%a
echo Kernel offset:%yellow% %koff%%deft% | klr
echo(
:nokoff
if not exist "%file%.img-ramdisk_offset" goto noramoff
for /f "delims=" %%a in (%file%.img-ramdisk_offset) do @set ramoff=!ramoff!%%a
echo Ramdisk offset:%yellow% %ramoff%%deft% | klr
echo(
:noramoff
if not exist "%file%.img-second_offset" goto nosecoff
for /f "delims=" %%a in (%file%.img-second_offset) do @set fsecoff=!fsecoff!%%a
echo Second offset:%yellow% %fsecoff%%deft% | klr
set secoff=--second_offset %fsecoff%
echo(
:nosecoff
if not exist "%file%.img-second" goto nosecd
set fsecd=!fsecd!%file%.img-second
echo Second bootloader:%yellow% %fsecd%%deft% | klr
set "second=--second %fsecd%"
echo(
:nosecd
if not exist "%file%.img-tags_offset" goto notagoff
for /f "delims=" %%a in (%file%.img-tags_offset) do @set tagoff=!tagoff!%%a
echo Tags offset:%yellow% %tagoff%%deft% | klr
echo(
:notagoff
if not exist "%file%.img-dt" goto nodt
set fdt=!fdt!%file%.img-dt
echo Device tree blob:%yellow% %fdt%%deft% | klr
set "dtb=--dt %fdt%"
echo(
:nodt
echo(
:newimage
echo Please enter the desired name for the new repacked image without extension (img). Like this %yellow%boot%deft%-stock-2201 or carliv-%yellow%recovery%deft%-30 or %yellow%boot%deft%-new. | klr
set /P newimage=Insert the name here: || set newimage="0"
if "%newimage%"=="0" goto noimage
if not "%newimage%"=="%newimage:boot=%" goto command
if not "%newimage%"=="%newimage:recovery=%" goto command
goto wrongname
echo(
:command
echo Your new image is%yellow% %newimage%.img%deft%. | klr
echo(
echo Executing the repacking command....
echo(
mtkbootimg --kernel %kernel% --ramdisk %ramdisk% --pagesize %pagesize% --base %base% --board "%nameb%" --kernel_offset %koff% --ramdisk_offset %ramoff% --tags_offset %tagoff% %second% --cmdline "%scmdline%" %secoff% %dtb% -o ..\%newimage%.img
del "%file%.img-ramdisk.%compress%"
cd ..\
echo(
echo(
echo Done. Your new image was repacked as%yellow% %newimage%.img%deft%. | klr
goto end
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:noinput
echo(
echo(
echo %red%No folder selected. Exit script.%deft% | klr
echo(
goto end
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:wrongname
echo(
echo(
echo %red%The name have to include the type of image in it, %yellow%boot%red% or%yellow% recovery%red%.%deft% | klr
echo(
goto newimage
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:noimage
echo(
echo(
echo %red%Please enter a name for the repacked image first.%deft% | klr
echo(
goto newimage
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:error
echo(
echo(
echo %red%There is an error in your folder. The kernel or ramdisk is missing. Exit script.%deft% | klr
echo(
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:end
echo(
pause

EnerJon said:
Hello Sir, i Wanted To Share My Modding Of Your Tool For Better Compression, i Also Did This Long Time Ago With Michfood's Tool, And it Works Effectively... By Doing This, Final Output IMG Can Be More Than 100KB Smaller Compared To Previous IMG Output... Which is a Releaf For 6MB Recovery/Boot Partition Devices...
For This, We Need 7zip Command Line Tool
By Downloading And Extracting "7za" Executable into The BIN Folder Of Your Tool And Modding Your Tool's RePack Script File, We Can Achieve Better Compression For GZIP'ed RAMDISKs...
.....
Click to expand...
Click to collapse
I understand your point of view, but I have to tell you few things.
First thing I tested was 7zip because at start I didn't want to use any cygwin dll in my tool, but 7zip isn't "the same" in windows and linux (I use ubuntu and it is provided in official ubuntu packages), and I wanted my tool to be consistent across OSes. Then, 7zip changes the original file attributes (date of creation for example, permissions, etc.) and it takes longer to do the job (execution time), so I moved to gzip built by me from source for windows. Gzip keeps original data for files by default and it is faster. But windows standalone module didn't worked - I mean technically worked, repack unpack but the created image didn't worked in phone. That's how I ended up with cygwin compression modules - they do the job.
So, thank you for your suggestion, but I will stick with gzip as "official" way for both versions, since it proves to work in every situation. Maybe if I didn't provided a linux version too and I didn't care about preserving files original infos, I would use 7zip for the advantage of a slightly better compression.
It's good though that you posted here your modd, because if someone wants to try it or use it, all it needs to do is to check your post! :good:

Related

[UTIL] signapk.sh: onboard .apk signing. 100% java-free

Since I tend to modify roms before flashing them to my phone, and sometimes want to do so away from a computer, I ended up writing this. It's an ash script that uses the openssl binary found on most custom roms, and infozip. The sdk test/platform/media/etc keys are included. Usage:
Usage: signapk (options) [command] (files)
commands:
sign FILE sign a .zip or .apk
sign FILE1 FILE2 create a signed copy of FILE1 as FILE2
cert FILE(s) print cert info on FILE's signer
certinfo FILE print detailed cert info on FILE's signer
cmp FILE compare signer of FILE with default/selected cert
cmp FILE1 FILE2 compare signer of FILE1 to signer of FILE2
options:
-k, --key FILE key to sign with
-c, --cert FILE cert to sign with
if -c or -k are not files then they are considered
aliases to builtins (ie -k testkey or -c platform)
-f, --force sign even if cert differs from original
-t, --tmp DIR use DIR for tempdir instead of '/cache'
-d, --debug output debugging
-V, --version print 'signapk v0.3.1'
exit codes:
1: read error (file 1) 2: read error (file 2)
3: write error 4: ssl error
5: zip write error 9: key error
8: sign: cert mismatch 10: cmp: cert mismatch
128: script error 255: user error
Installation:
unpack somewhere. If needed, edit the variables at the top of the script. By default it uses /cache/ for 4 small temporary files.
Faq:
* Why did you include a busybox and openssl? * Some roms don't include the openssl utility. Busybox's unzip refuses to deal with zipaligned apks on alot of roms, because it wasn't compiled with ENABLE_DESKTOP. Busybox's ash is missing things that the script needs, on some roms. The script will use whatever the rom provides, if these binaries are not present. Good luck.
* How do I change the cert? * see signapk --help for cert/key selection flags
* Can I use this in my MarketAppThingy? * Sure, and please let me know. If it's a paid MarketAppThingy, consider sending me a free copy.
Changelog:
release 3: cmp function, key selection, documented exit codes that make sense, and paranoia. Includes trimmed down busybox and openssl binaries. If these are present, script will reload itself to run in it's busybox ash interpreter to avoid broken busybox compiles, and can run without using anything provided by the rom. In theory this means no compatibility issues, but is limited to ARM devices.
release 2: Apparently it's valid to have ANYNAME.SF/ANYNAME.RSA or ANYNAME.DSA. signapk cert and certinfo now handles this. The sign function will blindly write to CERT.SF and CERT.RSA as this is the behavior of the standard SignApk.java. This may be fixed later.
If you don't wanna signup to download attachment, snag this from http://code.google.com/p/signapk/downloads/list
very, very useful. I'm testing this now Signing stuff was always way too complicated.
Cool. Can't wait for someone to make a market app that creates a simple ui to edit update.zips before flashing. Hint hint
I put the files in /system/signapk (new folder)
When i run the script I get the error below. The test file is an unsigned apk exported from eclipse.
Code:
# ./signapk sign /sdcard/unsigned.apk
./signapk sign /sdcard/unsigned.apk
Checksumming /mnt/sdcard/unsigned.apk:
res/layout/main.xml AndroidManifest.xml
resources.arsc res/drawable-hdpi/icon.png res/drawable-ldpi/icon.png res/drawable-mdpi/icon.png classes.dex
[COLOR="Red"]unable to write 'random state'
./signapk: line 132: ./signapk.zip: not found[/COLOR]
#
Any idea what needs changing to fix this?
update: When I used the full path it worked.
Code:
# /system/signapk/signapk sign /sdcard/unsigned.apk
/system/signapk/signapk sign /sdcard/unsigned.apk
Checksumming /mnt/sdcard/unsigned.apk:
res/layout/main.xml AndroidManifest.xml
resources.arsc res/drawable-hdpi/icon.png res/drawable-ldpi/icon.png res/drawable-mdpi/icon.png classes.dex
unable to write 'random state'
adding: META-INF/MANIFEST.MF (deflated 49%)
adding: META-INF/CERT.SF (deflated 48%)
adding: META-INF/CERT.RSA (deflated 33%)
# /system/signapk/signapk cert /sdcard/unsigned.apk
/system/signapk/signapk cert /sdcard/unsigned.apk
/sdcard/unsigned.apk 936EACBE07F201DF SDK Test Key
Was playing around with app inventor and came up with this:
edit: AppInventor does not generate java code and it cannot be worked on further in anything else (i.e eclipse)
I was really hoping I would atleast get the activity xml
Heya, the latest is at http://code.google.com/p/signapk/downloads/list and should fix the zip error. signapk-bb, signapk-zip, and signapk-openssl are static, trimmed down versions of utilities required by the script, and should be extracted to the same directory as the script. If they are not present it will try to use stuff in $PATH
Just throwing it (the obvious) out there that this could enable a new generation of morphs for /data apps
Copy apk,uninstall,morph, install
Hmmmm....
britoso said:
Just throwing it (the obvious) out there that this could enable a new generation of morphs for /data apps
Copy apk,uninstall,morph, install
Click to expand...
Click to collapse
How can i get this to work with a morph and to edit the updater-script?
Someone explain the commands with example...
Another noob question is .. it is for android or pc...
Edit:- Made my own mod here https://forum.xda-developers.com/t/...-apk-zip-within-android.3835975/post-81324327
below code works with latest(1.32.0) busybox
Bash:
#!/system/bin/sh
# depends unzip printf zip openssl
# put zip openssl busybox in PATH
# Usage:-
# Sign.sh key.pk8 key.x509.pem in.zip out.zip
ordie() {
if [ $? -ne 0 ]; then
IFS=" "
$BB printf "$1\n"
exit $2
fi
}
PKEY="$1"
CERT="$2"
ORIG="$3"
TARGET="$4"
BB=busybox
cat "$ORIG" > "$TARGET"; ordie "Cannot write to $TARGET" 3
$BB printf "Checksumming $ORIG:\n"
TMP=$HOME
TMPDIR="$TMP/sign-$$"
TMPPKEY="$TMPDIR/tmp.pkey"
mkdir -p "$TMPDIR/META-INF"; ordie "" 3
$BB printf "Manifest-Version: 1.0\r\nCreated-By: 1.0 (Android SignApk)\r\n\r\n" > "$TMPDIR/META-INF/MANIFEST.MF"
ZIPls=$($BB unzip -qql "$ORIG"); ordie "$ORIG: unzip error" 1
OLDIFS=$IFS
IFS=${IFS:2:2}
for i in $ZIPls; do
IFS=$OLDIFS
set -- $i
if [ "$#" -ge 3 ] && [ "$1" != "0" ]; then
file="${i:30}"
case "$file" in META-INF/MANIFEST.MF|META-INF/CERT.SF|META-INF/CERT.RSA) continue;; esac
$BB printf "$file "
hash=$($BB unzip -p "$ORIG" "$file" | openssl sha1 -binary | openssl base64); ordie "$ORIG: unzip error" 1
ret="Name: $file\r\nSHA1-Digest: $hash\r\n\r\n"
$BB printf "$ret" >> "$TMPDIR/META-INF/MANIFEST.MF"
hash=$($BB printf "$ret" | openssl sha1 -binary | openssl base64)
$BB printf "Name: $file\r\nSHA1-Digest: $hash\r\n\r\n" >> "$TMPDIR/META-INF/CERT.SF.temp"
fi
done
$BB printf "\n"
mfhash=$(cat "$TMPDIR/META-INF/MANIFEST.MF" | openssl sha1 -binary | openssl base64)
$BB printf "Signature-Version: 1.0\r\nCreated-By: 1.0 (Android SignApk)\r\nSHA1-Digest-Manifest: $mfhash\r\n\r\n" > "$TMPDIR/META-INF/CERT.SF"
cat "$TMPDIR/META-INF/CERT.SF.temp" >> "$TMPDIR/META-INF/CERT.SF"
openssl pkcs8 -inform DER -nocrypt -in "$PKEY" > "$TMPPKEY"; ordie "" 4
cat "$TMPDIR/META-INF/CERT.SF" | openssl smime -sign -inkey "$TMPPKEY" -signer "$CERT" -binary -outform DER -noattr > "$TMPDIR/META-INF/CERT.RSA"; ordie "" 4
cd "$TMPDIR"
zip "$TARGET" META-INF/MANIFEST.MF META-INF/CERT.SF META-INF/CERT.RSA; ordie "" 5
cd - > /dev/null
rm -r "$TMPDIR"

(TOOL) Haipai X710D MTK6577 Deodex+zipalign Tools + smooth scroll patched framework.j

MY Haipai x710D CUSTOM ROM is released , Worth check
Go to ROM Download Page
Hi all , I have bought haipai x710d for about a month and I found this phone is quite good , much faster than my one v. I have paid quite a lot of time in digging the potential of this phone. I would like to share my Effort with all guys who bought this phone...here is my first Tool for x710d
" The auto deodex and zipalign Tool "
Using this tool is quite simple... Just copy all files in \system\app\ (.apk + .odex files) and \system\framework\ (.jar + .odex files) under the root folder of the tool
like this
{
"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"
}
and simply run
start_deodex_zipalign.bat and then wait ....
After that of course you need to copy all the processed files back to your phone... manually...sorry I am kind of lazy man... YOU know what I mean...:laugh:
I have tested the tool so many times and worked perfect However I cant guarantee that it will run perfect on your machine too... depends on your
machine config.
As for the smooth scroll patched framework file , simply copy it into \system\framework and replace the original one ...CAUTION: You must deodex the rom before apply the smooth scroll patched file.
Thanks AndroidON for the good tutorial on patching framework.jar
Thank you for your explanation in the PM. Unfortunately I could not get it to work.
I unzipped your tool to a folder, used root explorer to copy the content of system\app and system\framework into the microSD card, and transferred these files from the microSD card to the tool folder. Then I right-click "start_deodex_zipalign.bat" and chose "run as administrator". Command prompt popped up and the tool seemed to run through.
However, all the files I transferred to the tool folder did not disappear. There were no "deodexed framework" and "deodexed zipaligned apk" folders in the tool folder. However, I found these folders in Windows/system32, but they were empty.
I tried moving the unpacked tool folder to the root of the system drive (C:\\) and even into windows\system32 folder, but the result was the same.
I use the Taiwan101 v.2 ROM (based on 20120713 firmware), and I used root uninstaller to remove some of the system apps. I wonder if this may be the cause of your tool not working?
I think different system environment configuration causing the problem...and it's related to the %cd% variable in the batch file.. So the fix is try open the batch file with notepad then "find and replace %cd% with c:\myfastdeodextool-hoipai like below ..
@echo off
@echo ==================================================
@echo.
@echo Auto deodex + Zipalign Tool by BjDanny @ XDA Forum
@echo.
@echo ==================================================
@mkdir c:\myfastdeodextool-hoipai\deodexed_framework
@mkdir c:\myfastdeodextool-hoipai\deodexed_zipaligned_apk
@set df=c:\myfastdeodextool-hoipai\deodexed_framework\
@set daz=c:\myfastdeodextool-hoipai\deodexed_zipaligned_apk
@set baksmali=c:\myfastdeodextool-hoipai\bin\baksmali-1.3.4.jar
@set smali=c:\myfastdeodextool-hoipai\bin\smali-1.3.4.jar
@set zip=c:\myfastdeodextool-hoipai\bin\zip.exe
@set zipalign=c:\myfastdeodextool-hoipai\bin\zipalign.exe
@set apilevel=15
if exist *res.apk (@move *res.apk %df% >>nul)
:dfw
@echo This error log can be ignored because of the reason "Odex file are not exist">>c:\myfastdeodextool-hoipai\err.txt
@echo. >>c:\myfastdeodextool-hoipai\err.txt
@echo Start deodex Framework >> c:\myfastdeodextool-hoipai\deodex.log
@if exist c:\myfastdeodextool-hoipai\out (rmdir /s /q c:\myfastdeodextool-hoipai\out)
@set filetype=jar
@echo Creating Jar file list ...
@dir c:\myfastdeodextool-hoipai /b | findstr /m .jar >>c:\myfastdeodextool-hoipai\jarfile.txt
@for /F "delims=" %%a in (c:\myfastdeodextool-hoipai\jarfile.txt) do @echo Baksmali %%~na.odex ... && @echo. && java -Xmx512m -jar %baksmali% -a %apilevel% -x %%~na.odex 2>>c:\myfastdeodextool-hoipai\err.txt && @echo Smali ... && @echo. && java -Xmx512m -jar %smali% -a %apilevel% -o classes.dex out && @echo Merge %%~na.%filetype% ... && @echo. && @%zip% -r -q %%~na.%filetype% classes.dex && @echo Delete classes.dex && @echo. && @del /f /q c:\myfastdeodextool-hoipai\classes.dex && @echo Delete out folder ... && @echo. && rmdir /s /q c:\myfastdeodextool-hoipai\out && @echo Deodexed %%~na.%filetype% && @echo. && @echo =========================================================== && @echo ( %%~na.%filetype% ) - was deodexed successfully! >> c:\myfastdeodextool-hoipai\deodex.log
@echo Moving Done framework to deodexed_framework\
@move c:\myfastdeodextool-hoipai\*.%filetype% %df%
@echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> c:\myfastdeodextool-hoipai\deodex.log
@echo Deodexed Framework >> c:\myfastdeodextool-hoipai\deodex.log
@echo. >> c:\myfastdeodextool-hoipai\deodex.log
@del /f /q c:\myfastdeodextool-hoipai\jarfile.txt
@goto da
:da
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> c:\myfastdeodextool-hoipai\deodex.log
@echo Start Deodex and Zipalign APK >> c:\myfastdeodextool-hoipai\deodex.log
@echo. >> c:\myfastdeodextool-hoipai\deodex.log
@set filetype=apk
@echo Creating Apk file list ...
@dir c:\myfastdeodextool-hoipai /b | findstr /m .apk >>c:\myfastdeodextool-hoipai\apkfile.txt
@for /F "delims=" %%a in (c:\myfastdeodextool-hoipai\apkfile.txt) do @echo Baksmali %%~na.odex ... && @echo. && java -Xmx512m -jar %baksmali% -a %apilevel% -x %%~na.odex 2>>c:\myfastdeodextool-hoipai\err.txt && @echo Smali ... && @echo. && java -Xmx512m -jar %smali% -a %apilevel% -o classes.dex out && @echo Merge %%~na.%filetype% ... && @echo. && @%zip% -r -q %%~na.%filetype% classes.dex && @echo Delete classes.dex && @echo. && @del /f /q c:\myfastdeodextool-hoipai\classes.dex && @echo Delete out folder ... && @echo. && rmdir /s /q c:\myfastdeodextool-hoipai\out && @echo Deodexed %%~na.%filetype% && @echo. && @echo ( %%~na.%filetype% ) - was deodexed successfully! >> c:\myfastdeodextool-hoipai\deodex.log && @echo.& @echo.&& @echo Zipalign %%~na.%filetype% ... && @%zipalign% -v 4 c:\myfastdeodextool-hoipai\%%~na.%filetype% c:\myfastdeodextool-hoipai\%%~na.%filetype%.ZIPALIGNED && @echo. && @echo ===========================================================
@echo.
@echo Moving Deodexed APKs into deodexed_zipaligned_apk folder ...
@echo.
@move c:\myfastdeodextool-hoipai\*.apk.ZIPALIGNED c:\myfastdeodextool-hoipai\deodexed_zipaligned_apk\
@echo Renaming files
@for %%a in ("c:\myfastdeodextool-hoipai\deodexed_zipaligned_apk\*") do ren "%%a" "%%~na"
@echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>> c:\myfastdeodextool-hoipai\deodex.log
@echo Deodexed and Zipaligned APK >> c:\myfastdeodextool-hoipai\deodex.log
@del /f /q c:\myfastdeodextool-hoipai\apkfile.txt
@del /f /q c:\myfastdeodextool-hoipai\*.odex
@del /f /q c:\myfastdeodextool-hoipai\*.%filetype%
@echo All Action Completed ! Thanks for using
@pause
@goto exit
:err
@echo error found
@pause
:end
@exit
and this time i am using fix path (c:\myfastdeodextool-hoipai) rather than (%cd%)
so you need to put the tool under c:\
The folder name myfastdeodextool-hoipai is up to you ...you can name it with your own idea but pls do use the same name in the batch file
I tested this amended code on my win 7 32 bit OS , ran perfect ...without any errors...
Try it out ... Thanks for using...
Thanks for sharing.
Can you show us the code changes for framework.jar so we can use it for other ROM as well?
Thanks.
Tested and it works perfect after changing the %cd% to C:/XX and unzip downloaded files and ALL system/app and system/framework to the C:/XX.
Thank you.
Can you work out a odex batch file?
---- oriignal post deleted -----
Thanks jbctiong - after reading what you said, I finally understand what I need to do.
Changing %cd% to a fixed folder name means that I have to move the content of the unzipped tool and the content of the \system\app and \system\framework folders to the folder of that name, in the root of the system drive.
ie. If I rename %cd% to c:\deodex, I have to make a new folder called "deodex" in the system drive "C", and move everything into this folder, before running the .bat file.
I got it all worked out finally, thanks!
Sorry one more noob question.
What is the best way to replace the old files in the system/app and system/framework folders with the new files?
I deleted all the files in the app folder first, then realize all the functions of the phone freeze. This is certainly the stoopid way to do it.
slim_thumb said:
---- oriignal post deleted -----
Thanks jbctiong - after reading what you said, I finally understand what I need to do.
Changing %cd% to a fixed folder name means that I have to move the content of the unzipped tool and the content of the \system\app and \system\framework folders to the folder of that name, in the root of the system drive.
ie. If I rename %cd% to c:\deodex, I have to make a new folder called "deodex" in the system drive "C", and move everything into this folder, before running the .bat file.
I got it all worked out finally, thanks!
Click to expand...
Click to collapse
I will post the changed code on smooth scroll patched framework later because i am currently working on custom rom for x710d based on latest official rom which is version 0902
slim_thumb said:
Sorry one more noob question.
What is the best way to replace the old files in the system/app and system/framework folders with the new files?
I deleted all the files in the app folder first, then realize all the functions of the phone freeze. This is certainly the stoopid way to do it.
Click to expand...
Click to collapse
make a cwm update zip file is the best...
using adb shell command is second choice
Sorry more problem.
I tried to backup with CWM, but when I check the CWM folder, although it has created the folder with the date of the backup, it is empty.
Does anyone have problem with their CWM backup?
---------- Post added at 04:59 PM ---------- Previous post was at 04:50 PM ----------
Another question:
When I look at the content of my Taiwan101 custom ROM, I notice the "system" folder has the same "app" and "framework" folders. I guess I can replace the content of these two folders with the deodexed / zipaligned files, repack and flash it with CWM?
If this work, I presume I can do the same for future versions of CWM flashable custom ROMs?
slim_thumb said:
Sorry more problem.
I tried to backup with CWM, but when I check the CWM folder, although it has created the folder with the date of the backup, it is empty.
Does anyone have problem with their CWM backup?
---------- Post added at 04:59 PM ---------- Previous post was at 04:50 PM ----------
Another question:
When I look at the content of my Taiwan101 custom ROM, I notice the "system" folder has the same "app" and "framework" folders. I guess I can replace the content of these two folders with the deodexed / zipaligned files, repack and flash it with CWM?
If this work, I presume I can do the same for future versions of CWM flashable custom ROMs?
Click to expand...
Click to collapse
problem 1: Never met
problem 2: yes you can do that ...
---- oriignal post deleted ----
Thanks. Looking forward to the custom version of the latest official FW. In the meantime I am going to mess around and learn how to get this deodex / zipalign process working.
bjdanny said:
I will post the changed code on smooth scroll patched framework later because i am currently working on custom rom for x710d based on latest official rom which is version 0902
Click to expand...
Click to collapse
Can you post a link to the latest firmware 09/02/2012, and what the bug fixes and changes are? ie. Front camera, bluetooth, wifi, external sd, etc..
brotherman38 said:
Can you post a link to the latest firmware 09/02/2012, and what the bug fixes and changes are? ie. Front camera, bluetooth, wifi, external sd, etc..
Click to expand...
Click to collapse
This phone is made in china. so the page you request is written in chinese
This is the description page
http://www.jajatong.com/article/show-86.aspx
This is the download link
http://l11.yunpan.cn/lk/59k5uxavll
AS for what have been updated sorry I can't find change log of the firmware..
So , I was just guesssing .
under the download page you can see follow message
20120713_e1809c_v77_lx529_x710d2.zip
225.1MB, jajat***@jajatong.com 发布于2012-09-03
20120713_e1809c_v77_lx529_x710d2.zip is the file name
225.1MB, jajat***@jajatong.com 发布于2012-09-03 means the manufacturer uploaded may be updated rom on 2012-09-03 the package is 225.1.MB

How to Batch Sign Zip Files

How do i make this tool by: Ryuinferno Windows Sign Em v2-0
[TOOL][WINDOWS]Sign-em! v2.0 ->Batch sign zip files | No signature verification error
[TOOL][WINDOWS]Sign-em! v2.0 ->Batch sign zip files | No signature verification error Sign-em! v2.0 Hi all! As we know, making zip files is a must no matter when we want to flash a new ROM, theme, mods and so on...but at times we need to sign...
forum.xda-developers.com
Work with the new apksigner.jar file which on windows has to be used through the apksigner bat file?
The batch script in the tool from Ryuinferno is this:
@Echo off
COLOR 70
title "Sign-em! 2.0"
ECHO.
ECHO Sign-em! v2.0 by Ryuinferno @ XDA 2013
ECHO.
ECHO This script signs multiple zip files automatically...
ECHO.
ECHO **REMINDER!!! Do not leave spaces when you name your zip files...**
ECHO.
FOR %%A in (.\Input\*.zip) do (
ECHO Signing - %%~nA.zip
java -jar .\Tools\signapk.jar -w .\Tools\testkey.x509.pem .\Tools\testkey.pk8 %%A .\Output\%%~nA-signed.zip
)
FOR %%A in (.\Output\*.zip) do (
ECHO Calculating md5 checksum
.\Tools\md5sums.exe -u %%A >> ./Output/md5.txt
)
ECHO.
ECHO Files signed successfully if no errors above...
ECHO.
ECHO Hope you enjoyed my work...
ECHO Ryuinferno @ XDA 2013
ECHO.
pause
peter1miller2 said:
How do i make this tool by: Ryuinferno Windows Sign Em v2-0
[TOOL][WINDOWS]Sign-em! v2.0 ->Batch sign zip files | No signature verification error
[TOOL][WINDOWS]Sign-em! v2.0 ->Batch sign zip files | No signature verification error Sign-em! v2.0 Hi all! As we know, making zip files is a must no matter when we want to flash a new ROM, theme, mods and so on...but at times we need to sign...
forum.xda-developers.com
Work with the new apksigner.jar file which on windows has to be used through the apksigner bat file?
Click to expand...
Click to collapse
To execute a .JAR-file on Windows, you need to install Java on your system. Go to Java Download Page and install it.
I am not asking how to execute a JAR file. I am asking how to make the Apk Signer sign all files in a folder like this tool does with the older zip signer.
If you do not have OpenSSL installed on Windows machine, download and install it. You need OpenSSL to create a private key and a corresponding public key, which act as your digital signature.
On elevated Windows command prompt enter the following commands to generate a new private key and a corresponding public key for yourself:
Code:
openssl genrsa -out key.pem 1024
openssl req -new -key key.pem -out request.pem
openssl x509 -req -days 9999 -in request.pem -signkey key.pem -out certificate.pem
openssl pkcs8 -topk8 -outform DER -in key.pem -inform PEM -out key.pk8 -nocrypt
In Windows you create a folder named ZipSignerTool with 4 subfolders named InFiles & OutFiles & Tools & Keys.
In subfolder InFiles you place all the .ZIP-files what should get signed.
In subfolder Tools you place the Java executable named signapk.jar.
In subfolder Keys you place the 2 files you generated by means of OpenSSL as shown above.
You create a Windows batch-file in folder ZipSignerTool named ZipSigner.bat ( or whatever ) that does the job:
Code:
@echo off & setlocal
pushd "%~dp0"
set "InFiles=%CD%\Infiles"
set "OutFiles=%CD%\OutFiles"
set "Signer=%CD%\Tools\signapk.jar"
set "Keys=%CD%\Keys"
for /F %%a in ('dir %InFiles%\*.zip /B') do (
set "ZIP=%%a"
if NOT "?%ZIP%"=="?" (
java -jar %Signer% %Keys%\certificate.pem %Keys%\key.pk8 %ZIP% %OutFiles%\signed-%ZIP%
)
)
popd
endlocal & @echo on & exit
jwoegerbauer said:
If you do not have OpenSSL installed on Windows machine, download and install it. You need OpenSSL to create a private key and a corresponding public key, which act as your digital signature.
On elevated Windows command prompt enter the following commands to generate a new private key and a corresponding public key for yourself:
Code:
openssl genrsa -out key.pem 1024
openssl req -new -key key.pem -out request.pem
openssl x509 -req -days 9999 -in request.pem -signkey key.pem -out certificate.pem
openssl pkcs8 -topk8 -outform DER -in key.pem -inform PEM -out key.pk8 -nocrypt
In Windows you create a folder named ZipSignerTool with 4 subfolders named InFiles & OutFiles & Tools & Keys.
In subfolder InFiles you place all the .ZIP-files what should get signed.
In subfolder Tools you place the Java executable named signapk.jar.
In subfolder Keys you place the 2 files you generated by means of OpenSSL as shown above.
You create a Windows batch-file in folder ZipSignerTool named ZipSigner.bat ( or whatever ) that does the job:
Code:
@echo off & setlocal
pushd "%~dp0"
set "InFiles=%CD%\Infiles"
set "OutFiles=%CD%\OutFiles"
set "Signer=%CD%\Tools\signapk.jar"
set "Keys=%CD%\Keys"
for /F %%a in ('dir %InFiles%\*.zip /B') do (
set "ZIP=%%a"
if NOT "?%ZIP%"=="?" (
java -jar %Signer% %Keys%\certificate.pem %Keys%\key.pk8 %ZIP% %OutFiles%\signed-%ZIP%
)
)
popd
endlocal & @echo on & exit
Click to expand...
Click to collapse
Thank you very much for your answer. I am sure it would work. Thought since i completely failed to explain the real problem i have. it is currently not working for me. I hope i explained the problem better in my new post here: https://forum.xda-developers.com/t/how-can-i-batch-sign-zip-files-on-windows.4361871/ and thank you again wery much for the answer.

How Can i Batch Sign Zip Files On Windows?

I asked this previously.
But i did not specify the problem correctly When i unpack the:
build-tools_r30.0.1-windows.zip to the C drive i get this:
C:\android-11\
If i try to use the ApkSigner.JAR in the:
C:\android-11\lib\
Folder Directly through those two commands:
cd C:\Program Files\AdoptOpenJDK\jre-16.0.1.9-hotspot\bin\
Followed by:
java.exe C:\android-11\lib\apksigner.jar sign --key C:\keys\mykey.pk8 --cert C:\certificates\mycert.pem --min-sdk-version 20 C:\files\MyZipFile.zip
I get this:
Error: Could not find or load main class C:\android-11\lib\apksigner.jar
Caused by: java.lang.ClassNotFoundException: C:\android-11\lib\apksigner.jar
If i use the ApkSigner.JAR INDIRECTLY Through the ApkSigner.BAT File in the:
C:\android-11\
Folder Through those two commands:
cd C:\android-11\
Followed by:
apksigner.bat sign --key C:\keys\mykey.pk8 --cert C:\certificates\mycert.pem --min-sdk-version 20 C:\files\MyZipFile.zip
Than it works But the apksigner.BAT File does not work with the batch signer i mentioned in this post: https://forum.xda-developers.com/t/how-to-batch-sign-zip-files.4258547/
Which is why Batch signing is not working for me with the current apksigner.JAR File.
Since because of this
Error:
Could not find or load main class C:\android-11\lib\apksigner.jar
Caused by: java.lang.ClassNotFoundException: C:\android-11\lib\apksigner.jar
I cannot use it directly.
The script from the apksigner.BAT File is this:
@Echo off
REM Copyright (C) 2016 The Android Open Source Project
REM
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with the License.
REM You may obtain a copy of the License at
REM
REM http://www.apache.org/licenses/LICENSE-2.0
REM
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.
REM don't modify the caller's environment
setlocal
REM Locate apksigner.jar in the directory where apksigner.bat was found and start it.
REM Set up prog to be the path of this script, including following symlinks,
REM and set up progdir to be the fully-qualified pathname of its directory.
set prog=%~f0
@Rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
exit /b 1
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
exit /b 1
:init
set jarfile=apksigner.jar
set "frameworkdir=%~dp0"
rem frameworkdir must not end with a dir sep.
set "frameworkdir=%frameworkdir:~0,-1%"
if exist "%frameworkdir%\%jarfile%" goto JarFileOk
set "frameworkdir=%~dp0lib"
if exist "%frameworkdir%\%jarfile%" goto JarFileOk
set "frameworkdir=%~dp0..\framework"
:JarFileOk
set "jarpath=%frameworkdir%\%jarfile%"
set javaOpts=
set args=
REM By default, give apksigner a max heap size of 1 gig and a stack size of 1meg.
rem This can be overridden by using "-JXmx..." and "-JXss..." options below.
set defaultXmx=-Xmx1024M
set defaultXss=-Xss1m
REM Capture all arguments that are not -J options.
REM Note that when reading the input arguments with %1, the cmd.exe
REM automagically converts --name=value arguments into 2 arguments "--name"
REM followed by "value". apksigner has been changed to know how to deal with that.
set params=
:firstArg
if [%1]==[] goto endArgs
set "a=%~1"
if [%defaultXmx%]==[] goto notXmx
if "%a:~0,5%" NEQ "-JXmx" goto notXmx
set defaultXmx=
:notXmx
if [%defaultXss%]==[] goto notXss
if "%a:~0,5%" NEQ "-JXss" goto notXss
set defaultXss=
:notXss
if "%a:~0,2%" NEQ "-J" goto notJ
set javaOpts=%javaOpts% -%a:~2%
shift /1
goto firstArg
:notJ
set params=%params% %1
shift /1
goto firstArg
:endArgs
set javaOpts=%javaOpts% %defaultXmx% %defaultXss%
call "%java_exe%" %javaOpts% -jar "%jarpath%" %params%
The script From the SignEm v2.0 Tool: From this Post:
https://forum.xda-developers.com/t/...iles-no-signature-verification-error.1966007/
By @Ryuinferno is this
@Ryuinferno said:
@Echo off
COLOR 70
title "Sign-em! 2.0"
ECHO.
ECHO Sign-em! v2.0 by Ryuinferno @ XDA 2013
ECHO.
ECHO This script signs multiple zip files automatically...
ECHO.
ECHO **REMINDER!!! Do not leave spaces when you name your zip files...**
ECHO.
FOR %%A in (.\Input\*.zip) do (
ECHO Signing - %%~nA.zip
java -jar .\Tools\signapk.jar -w .\Tools\testkey.x509.pem .\Tools\testkey.pk8 %%A .\Output\%%~nA-signed.zip
)
FOR %%A in (.\Output\*.zip) do (
ECHO Calculating md5 checksum
.\Tools\md5sums.exe -u %%A >> ./Output/md5.txt
)
ECHO.
ECHO Files signed successfully if no errors above...
ECHO.
ECHO Hope you enjoyed my work...
ECHO Ryuinferno @ XDA 2013
ECHO.
pause
Click to expand...
Click to collapse
And the Script created by: @jwoegerbauer As this answer:
https://forum.xda-developers.com/t/how-to-batch-sign-zip-files.4258547/post-84798393
To my earlier post is here:
@jwoegerbauer said:
@Echo off & setlocal
pushd "%~dp0"
set "InFiles=%CD%\Infiles"
set "OutFiles=%CD%\OutFiles"
set "Signer=%CD%\Tools\signapk.jar"
set "Keys=%CD%\Keys"
for /F %%a in ('dir %InFiles%\*.zip /B') do (
set "ZIP=%%a"
if NOT "?%ZIP%"=="?" (
java -jar %Signer% %Keys%\certificate.pem %Keys%\key.pk8 %ZIP% %OutFiles%\signed-%ZIP%
)
)
popd
endlocal & @ECHO on & exit
Click to expand...
Click to collapse
And I wery much Hope someone can help me with this problem.
Are you sure that apksigner.jar is in the folder of 'C:\android-11\lib'?
James_Watson said:
Are you sure that apksigner.jar is in the folder of 'C:\android-11\lib'?
Click to expand...
Click to collapse
Yes i am sure about that.

Process cannot access the file as it is used by another process

I am trying to create windows batch script to check the size of file after it is downloaded but it fails with this message. The Process cannot access the file as it is used by another process 2048 was unexpected at this time. Thanks in advance for any help.
Code -
@Echo off
d:\wget.exe ...
Rem this wget process downloads tst_file.xml
set file="tst_file.xml"
set maxbytesize=2048
for /F "usebackq" %%A IN ('%file%') DO set size=%%~zA
if %size% LSS %maxbytesize% (echo file is less than 2KB)
If download gets interrupted for whatever reason then file isn't get properly closed by WGET.
BTW:
1. Location of downloaded file isn't correctly determined: file's path is missing.
2. Use FORFILES to determine file size
Code:
rem List the size of downloaded file:
for /F "tokens=*" %%a in ('FORFILES /M %downloaded_file% /C "cmd /c echo @fsize"') do ( set /A downloaded_bytes=%%a )

Categories

Resources