Remove All Ads from XDA

[guide] Hacking the startup sequence to run your own code

17 posts
Thanks Meter: 8
By Nick Hill, Junior Member on 5th January 2014, 08:08 PM
Post Reply Email Thread
I have been trying to customise my MTK phones with a pre-defined user experience, with sepcific settings etc.

Perhaps one way to achieve this is to check if the device has been facory reset, then use a script to insert specific settings once. For this I need to launch a script early in the boot sequence.

This could be achieved by dismantling the boot.img, altering the init.rc, then re-building, which requires significant work and risks bricking the device. So I looked for a way to run a script without significant re-flashing. here goes:

xlog changes the system log level, and is called just a few times at boot-up. Xlog is run early, and as root, with the parameter boot.

This script renames xlog as xlogboot, introduces a script in place of xlog, which runs another script, when xlog is called with parameter boot. All the original parameters are passed to the renamed xlog binary, so the system functionality should not be changed.

I pushed the script to the device, then run it as root. I can now edit /system/bin/ to run whatever initialisation commands I wish. I have so far tested on a ZTE v965 .


#This script creates a hook into the bootup system of Android
#This hook operates when /system/bin/xlog is called with
#the first parameter 'boot'

#Use this script entirely at your own risk. I highly recommend 
#you ensure YOU have a backup of YOUR device before going further

#Public Domain Nick Hill 2014

if [ -e /system/bin/xlogboot ] || [ -e /system/bin/ ]; then
echo "This script may have already been run, exiting.."
exit 1

if [ ! -e /system/bin/xlog ] 
echo "This script is not running in an expected environment. Exiting.."
exit 2

if [ $USER != "root" ] 
echo "This script must be run as root. try running su. Exiting.."
exit 3

touch /system/bin/atestfile
if [ ! -e /system/bin/atestfile ] 
echo "It appears system folder is not mounted read-write. Remounting..."
mount -o remount,rw /system
rm /system/bin/atestfile

echo -e '#!/system/bin/sh\n' > /system/bin/
chown root:root  /system/bin/
chmod 755  /system/bin/

mv /system/bin/xlog /system/bin/xlogboot

echo -e '#!/system/bin/sh\n/system/bin/xlogboot $*\nif [ "$1" == "boot" ] \nthen\n/system/bin/\nfi\n' >/system/bin/xlog
chown root:shell /system/bin/xlog
chmod 755 /system/bin/xlog
6th January 2014, 08:40 PM |#2  
OP Junior Member
Thanks Meter: 8
Make your own custom rom
Problem: You have an android device which you want to give/sell in USA or England. The device has come with an array of auto-starting chinese pop-ups, horrible wallpaper, and a Chinese clock applet. You uninstall all those system apps, replace your widgets with nice English ones. The phone when factory reset, starts in Chinese. Returns the user to tacky wallpaper, and you have lost the nice theming and widgets you have painstakingly installed and set up in the system folder.

Solution: This backup script. I have tested it on a v965, it also appears the file system would be OK on an A766 and many other android devices.

Use my previous script on this thread to create a hacked startup sequence. You must already have the /system/bin/ in place.
Unpack the tarball
Check the script lists the files you intend to back up. You will need to edit the script for that. I have set it to preserve settings for language, launcher, the 3D clock app factory.widgets.ThreeDDigitalWeatherClock-1.apk , which I think is really cool, wallpaper and the ADB mode.
Copy the and busybox to a writable directory on your android device.
su (go to root)
In a shell, cd to the directory where you uploaded the files.

This will create a directory /system/perm-config

When you have the device as you would like it,
cd /system/perm-config
This will ceate a directory tree in /system/perm-config/data folder, containing the backups of specific app data.
If all goes well, next time the phone is factory reset, the defaults are reloaded.

You could then re-flash the system partition of devices, perform a factory reset to take the device to your own defaults. You can use the last script (to hack the startup sequence), and this script to make your own custom ROMs. The script should do it's job even after un-rooting a device.

As usual, use at your own risk. I take no responsibility if your phone bricks, explodes, turns to antimatter, suddenly drops into a parallel dimension or starts receiving calls from the future.
Attached Files
File Type: gz permanent-config.tar.gz - [Click for QR Code] (1.05 MB, 24 views)
Post Reply Subscribe to Thread

boot up commands, init sequence

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes