[AT&T Samsung Galaxy S 4 Original Android Developme] sendust7:
Here I consolidate the custom tools necessary to unpack, modify, repack and loki your JB 4.2.2 ROM zip boot.img!

These Windows/cygwin tools invoke the djrbliss loki bootloader exploit for your rooted SGS4!

See my Instructional Demo below! Results are tested working on my AT&T SGH-I337 running Liquid Smooth v2.8 (JB 4.2.2) and TWRP Recovery 2.5.0.2.

SGS4 Boot Image Toolset (sgs4-boot-tools.zip): http://www.mediafire.com/?6sp3pp33lxgm3ua

Contents

Executive shell script: modify-boot-sgs4.sh to unpack boot image to kernel and ramdisk, thus enabling user to modify boot image

Perl scripts: unpack-bootimg-sgs4.pl and repack-bootimg-sgs4.pl

mkbootimg.exe (make boot image from kernel and ramdisk)

loki-boot directory with ROM-like directory structure --- contains all files needed to “loki” your boot.img

The loki-boot directory also contains two boot files: boot-ref.img (extracted directly from Liquid Smooth ROM zip) and a modified boot.img (generated using the Instructional Demo further below).

My custom repack-bootimg-sgs4.pl invokes the following command string:

Preliminaries

If you don’t have cygwin, you can download it here: http://www.cygwin.com/ and install.

Cygwin packages installed on my XP workstation are shown below. You probably don’t need all of them, though I believe many come with the base cygwin.

But you definitely need perl :)

$ cygcheck -c

Cygwin Package Information
Package Version Status
_autorebase 000199-1 OK
_update-info-dir 01102-1 OK
alternatives 1.3.30c-10 OK
base-cygwin 3.1-1 OK
base-files 4.1-1 OK
bash 4.1.10-4 OK
bzip2 1.0.6-2 OK
coreutils 8.15-1 OK
cpio 2.11-2 OK
crypt 1.2-1 OK
cygutils 1.4.10-2 OK
cygwin 1.7.17-1 OK
cygwin-doc 1.7-1 OK
dash 0.5.7-1 OK
diffutils 3.2-1 OK
dos2unix 6.0.3-1 OK
editrights 1.01-2 OK
file 5.11-1 OK
findutils 4.5.9-2 OK
gawk 4.0.2-1 OK
gettext 0.18.1.1-2 OK
grep 2.6.3-1 OK
groff 1.21-2 OK
gzip 1.4-1 OK
ipc-utils 1.0-1 OK
less 444-1 OK
libattr1 2.4.46-1 OK
libbz2_1 1.0.6-2 OK
libdb4.5 4.5.20.2-3 OK
libexpat1 2.1.0-1 OK
libgcc1 4.5.3-3 OK
libgdbm4 1.8.3-20 OK
libgmp3 4.3.2-1 OK
libiconv2 1.14-2 OK
libintl8 0.18.1.1-2 OK
liblzma5 5.0.2_20110517-1 OK
libncurses10 5.7-18 OK
libncursesw10 5.7-18 OK
libopenssl100 1.0.1c-2 OK
libpcre0 8.21-2 OK
libpopt0 1.6.4-4 OK
libreadline7 6.1.2-3 OK
libsigsegv2 2.10-1 OK
libssp0 4.5.3-3 OK
libstdc++6 4.5.3-3 OK
libxml2 2.9.0-1 OK
login 1.10-10 OK
man 1.6g-1 OK
mintty 1.1.2-1 OK
perl 5.14.2-3 OK
perl_vendor 5.14.2-3 OK
rebase 4.4.0-1 OK
run 1.1.13-1 OK
sed 4.2.1-2 OK
tar 1.26-1 OK
terminfo 5.7_20091114-14 OK
texinfo 4.13-4 OK
tzcode 2012j-1 OK
vim 7.3.762-1 OK
vim-common 7.3.762-1 OK
which 2.20-2 OK
xxd 7.3.762-1 OK
xz 5.0.2_20110517-1 OK
zlib0 1.2.7-1 OK

Instructional Demo

1. Boot SGS4 to recovery and Nandroid backup existing ROM for peace of mind

2. (One time) Create a cygwin working directory (e.g. ~/cygwin/home/modify-boot-sgs4) and unzip the SGS4 Boot Image Toolset files to it

3. On Windows, extract ROM boot.img (e.g. from Liquid-JB-v2.8-OFFICIAL-jflteatt.zip) and place boot.img in cygwin working directory.

4. Launch cygwin command window in working directory and enter script command:

sh modify-boot-sgs4.sh boot.img (produces ramdisk directory: boot.img-ramdisk/)​

CNTL-C out of shell script and back to cygwin prompt.

5. Edit boot.img-ramdisk/default.prop, set: ro.secure=0 and save and close.

Note: The setting: ro.secure=0 instructs Android to grant root to ADB so user does not have to keep entering “su” at the beginning of each ADB session.​

6. At cygwin terminal enter:

perl repack-bootimg-sgs4.pl boot.img​

This yields boot-repack.img.

Here’s a dump of my cygwin session…

Robert@DBXRJWH1 /home
$ mkdir modify-boot-sgs4

Robert@DBXRJWH1 /home
$ cd modify-boot-sgs4

Robert@DBXRJWH1 /home/modify-boot-sgs4
$ pwd
/home/modify-boot-sgs4

Robert@DBXRJWH1 /home/modify-boot-sgs4
$ sh modify-boot-sgs4.sh boot.img

Unpack/Repack SGS4 ROM Boot Image
Initial Release (14 Jul 2013)
sendust7 @ xda developers

Current directory: /home/modify-boot-sgs4

Unpacking boot image...
Page size: 2048 (0x00000800)
Kernel size: 4961224 (0x004bb3c8)
Ramdisk size: 488535 (0x00077457)
Second size: 0 (0x00000000)
Board name:
Command line: androidboot.hardware=qcom user_debug=31 zcache
Writing boot.img-kernel ... complete.
Writing boot.img-ramdisk.gz ... complete.

Unzipping: boot.img-ramdisk.gz to boot.img-ramdisk
1708 blocks

Press ENTER to repack boot image or CNTL C to exit (and modify ramdisk offline):

[COLOR="Blue"](Modify /ramdisk/default.prop then resume cygwin session)[/COLOR]

Robert@DBXRJWH1 /home/modify-boot-sgs4
$ perl repack-bootimg-sgs4.pl boot.img

find . | cpio -o -H newc | gzip > /home/modify-boot-sgs4/ramdisk-repack.cpio.gz
1708 blocks

./mkbootimg.exe --cmdline 'androidboot.hardware=qcom user_debug=31 zcache' --base 0x80200000 --kernel boot.img-kernel --ramdisk ramdisk-repack.cpio.gz -o boot-repack.img

Repacked boot image written to boot-repack.img

Robert@DBXRJWH1 /home/modify-boot-sgs4
$

7. Exit cygwin and drop boot-repack.img into loki-boot directory and rename to boot.img. Then 7-zip contents of loki-boot directory to loki-boot.zip (CNTL-A (Select All) then right-click > 7-zip > Add to “loki-boot.zip”).

8. Connect SGS4 to your ADB-enabled computer, then

adb push loki-boot.zip /external_sd/Download (or your favorite flash directory)​

9. Boot to recovery and flash loki-boot.zip (takes a few seconds)

10. Reboot system and achieve “pre-rooted” ADB sessions on Liquid Smooth!

BTW here's a nice little app: https://play.google.com/store/apps/details?id=com.siriusapplications.quickboot&hl=en

With Quick Boot, you can reboot to recovery via soft key, which is easier than booting to recovery from cold start.

Blessings. Enjoy!

Credits:

djrbliss @ xda developers and other contributors for the loki exploit: https://github.com/djrbliss/loki)

William Enck (split_bootimg): http://www.enck.org/

Android Development Team (Unpack, Edit, Repack Boot Images): http://www.android-dls.com/wiki/?title=HOWTO:_Unpack,_Edit,_and_Re-Pack_Boot_Images

Cygwin Project Team: http://cygwin.com/who.html