[Android Software/Hacking General [Developers Only]] Matt07211:
1) Since you've got a Samsung, and it's got a read-only download mode, it essentially almost impossible to brick.

Now, when fiddling with boot.img's always keep a copy of the stock boot.img on hand for flashing via twrp. If it just a bootmimg you've flashed then you won't lose data (unless you do something very stupid, which you won't ;).

So some prep-work.

Grab a copy of your boot.img from the firmware files, put it in a separate directory by itself (make sure your using linux) and run these following commands

tar -H ustar -c boot.img > boot.tar
md5sum -t boot.tar >> boot.tar
mv boot.tar boot.tar.md5

What this does is it, rat's the boot.img, genrates a md5 hash of the tar file, appends the md5 hash onto the tar file and renamed it to boot.tar.md5. This creates an odin flashable file with a file integeraty check before flashing. E.g.if the file gets corrupt then you try and flash it, Odin won't go through with it becuse the md5 sums wont match.

So now you have a backup, you are now able to freely try modifying your boot.img, flash it, if it doesnt work, then restore the stock, so basically now you've got a fall back.

So know into testing to see if any unpacking repacking tools work. (Note, for my device, none of the already availble tools worked or accounted for device tree files, but a kind user who is proficent in "c" rewrote (he adapted degas unpack tool) a unpack till specifically for my device, which is an XCover3. So what I'm saying is these tools may or may not work for your device.)I would recommend unpacking and repacking without any modifications, and then see if it boots. If it does then you know the tool works for the device, if it doesn't just move on.

Know, for ramdisk I have found they can be quiet particular on how they have to be re zipped.(note make sure to do this in Linux to keep symlinks and file permissions etc.)

Most people use this command while inside the ramdisk directory, it will then output the ramdisk.cpio.gz arcvhieve in the directory above the ramdisk folder.

find . | cpio -o -H newc -R 0.0 | gzip -9 > ../ramdisk-repacked.cpio.gz

The find command finds anyfiles in the current directory, pipes them to the cpio command, which then pipes the cpio archive into the gzip command which outputs it in the above directory. For my particular phone I had to use minigzip and mkbootfs to produce a correct ramdisk, it done like so

./mkbootfs ramdisk | ./minigzip > ramdisk-repacked.cpio.gz

So as in the boot.img examples, you've gotta figure out what works for your phone.

You can do anything you want to do with the ramdisk, and as you should know at each reboot the contents of the ramdisk gets copied to your phone.

Before I go I'll give you an example of something you can do with the ramdisk.

Example: Launching a script as root and moving a file to /data

Place a script in the sbin folder of your ramdisk, you can call if anything E.g. Matt.at

making sure it has the .at extension becuse it's a script.

Inside of the script, you can run basch commands etc. Just make sure you have

#!/system/bin/sh

As this important piece of info tells the script where to find the correct item (the item to allow the bash commands to run.

So for our example it could be like,

The contents of "Matt.sh" will be

#!/system/bin/sh

# Remount /system as Read-Write
mount -o remount,rw /system

# Move File.txt to data
mv /data/local/tmp/file.txt /data/file.txt

# Remount /system as Read-Only
mount -o remount,to /system

Then make sure to add necessary info to the init.rc (at the end of the file) to launch the script as the phone boots, like so.

.....
BLAH BALH BLAH FILLER CONTENT

# Launch Matt Script
service mattscript /sbin/Matt.sh
[INDENT] class code
user root
oneshot
[/INDENT]

This above piece of code creates a service called "mattscript" with the location of what to launch. It's also launch the script as root, also allowing it to run only once.

So now you should have a general over view on how to mess around with the boot.img, and the ramdisk, as well as knowing how to launch a script as the phone boots. You've know also created a backup boot.img incease the testing boot.img doesn't work/boot.

Good luck,and message me if you need more help/info etc.

Good luck.