[Scripts support init.d] Developer something that should take into account - Android Software/Hacking General [Developers Only]

Introduction:
Developers and users in general hope that this information will be of help and understand how important this issue is
to develop the script according assume smartphone
Warning:
In most of the roms we can find a folder called init.d where you will find a variety of script that are optimizations for
the system itself there is only a detail as you may have noticed the scripts that are used are the same as those used in xperia x8,
type, among other variety as well as file modifications Encourage build.prop only device in this topic we will learn to notice how
the scripts are built and running as smoothly as possible.
Because I say that the scripts are the same? Simple is good since I have seen your code and have compared with the terminals I have
the code and some things should not be there just do not serve the terminal to Encourage and lagee much scripts are not universal
trust me
Some things like values?? optimzacion kernel (sysctl) such xperia L example of code are these:
-kernel= kernel.auto_msgmni = 0
-vm= vm.block_dump = 0
-fs= fs.aio-max-nr = 65536
-net= net.core.dev_weight = 64
note: and so on the more codes each terminal should be just the scripts for each terminal
some files should not come optimizations init.d support
host file this file is normally used to block advertising terminal does support that file in init.d wonder?
comes as other files named sqlite3 that is used to access the root does support init.d ???? now the other file called zipalign that is
normally used to sign apk applications to sign in support init.d ???
the init.d support should be different for each terminal is different because each firmware should not be general
important: it is my view and my knower that is also something constructive
1.-Basic commands and file handling
command: #!/bin/bash
information: +-/home: User home directories
command cd
command to change directory.
command ls
list contents of directories
command cp
copy files/directories
command rm
delete files/directories
command mkdir
create directories
command sysctl
Configure kernel parameters at runtime
2.-All configurations such scripts
/system/etc
3.- startup file
path of the file to be started: /system/etc/init.d/init
example code:
Seed file support init.d: /system/etc/udev/rules.d/init.rules
KERNEL=="mount*", ACTION=="change", SUBSYSTEM=="platform", RUN+="/system/etc/init.d/init"
5.- permissions script
chmod 755
6.- Example of script
#!/bin/bash
# This is a comment
echo "Hello world"
7.- Conditional if o if-else
example
code if:
if value
then
values
fi
code if-else:
if value
then
values
else
8.- Code if o if-else
example:
-a file: True if the file exists
-e file: The same
-b file: True if file exists and has a special block
-c file: True if file exists and is of type character
-d file: True if file exists and is a directory
-f file: True if file exists and is a common file
-g file: True if file exists and its set bit in September GroupID
-h file: True if file exists and is a symbolic link
-k file: True if file exists and its sticky bit set
-p file: True if file exists and is a named pipe
-r file: True if file exists and is readable
-s file: True if file exists and is greater than 0
-u file: True if file exists and has the setuid bit set
-w file: True if file exists and is writable
-x file: True if file exists and has execute permissions
-O file: True if file exists and is nuetro EUID user
-G file: True if file exists and is in our group EGID
-L file: True if file exists and is a symbolic link
-S file: True if file exists and is a socket
-N file: True if file exists and has changed since the last reading
9.- Checks
example:
if [ ! -e $1 ]
then
echo “No”
fi
10.- the main thing you have to develop the script support init.d
Note: In the coming days I will do a better, more detailed documentation :fingers-crossed:

reserved

Related

[Q] Android Scripting Q

I am trying to run a script from my nook color running CM7 (2.3.3). The script contains several wget commands designed to download pdf files from specific URLs. I have replaced the stock android busybox wget with a more powerful one that has all of the standard options. The weird thing is that when I execute the script via the command #sh run.sh, only the last line of the script executes properly...
Here is what is contained in the script file (run.sh):
wget -N -P /mnt/sdcard/wget/app/ppm --append-output=log.txt -i /mnt/sdcard/wget/ppm.txt
wget -N -P /mnt/sdcard/wget/app --append-output=log.txt -i /mnt/sdcard/wget/revision_checklist.txt
This returns the log:
/mnt/sdcard/wget/ppm.txt
: No such file or directory
No URLs found in /mnt/sdcard/wget/ppm.txt
.
[Removed Server Data Here]
Server file no newer than local file `/mnt/sdcard/wget/app/checklist.pdf' -- not retrieving.
What is weird is that if I add a third line to the run.sh file, the first two will error out and the third will execute. I've written the file in notepad++ using ANSI encoding. If I show all characters, the carriage return after all but the very last line shows a CR and LF.
I'm stumped...would sure appreciate any help.

[APP][DEV][GUIDE] Using the Android Java Internal/Hidden API classes

Using Java Reflection with Eclipse ADT to Access Internal/Hidden API classes.
Purpose
We present a way to access all the Internal and Hidden Java packages/classes
in the AOS. To do this we need to both repackage the Android.jar and hack the
Eclipse ADT plugin, to allow using these internal packages.
Posting
==================================================
Do NOT post general questions/requests on how to
do this or that, they will not be answered here.
DO post if you have additional tricks, hacks or
information that can help/benefit this tutorial.
==================================================
Background
There are two reasons one cannot use internal packages. One reason is that, if
you're using Eclipse as your development platform, those packages are
internally blocked in the Eclipse ADT plugin. Second reason is that the normal
development android.jar runtime does not contain those *.class files that
belong to the internal packages.
"There is no easy way to use com.android.internal package (internal API) or
anything marked with @hide attribute (hidden API) without using reflection.
That’s because android.jar file does not contain classes from internal and
hidden API and because of this nobody can reference those classes in compile
time."
Thus we need to first restore the "original" android.jar which will allow us
to use internal and hidden APIs. But the runtime equivalent of Android SDK’s
android.jar file is framework.jar. This file is located in the
/system/framework/ directory of your device. We will extract and use this for
our pleasure.
The general procedure:
A) Grab the "full" framwork.jar from your device
B) extract the class files
C) add them to "full" android.jar ??
D) Hack the Eclipse ADT plugin jar.
Finally, NOTHING would have been possible without the excellent step-by-step
instructions on the devmaze-blog by senior Android developer Ievgenii Nazaruk
(aka. "inazaruk"). THANK YOU Ievgenii!​References
http://stackoverflow.com/questions/...d-sdk-with-hidden-and-internal-apis-available
http://stackoverflow.com/questions/...-state-permission-for-apps-ran-on-gingerbread
http://code.google.com/p/smali/wiki/DeodexInstructions
http://code.google.com/p/adt-addons/
​
The General Procedure
NOTE: All this was performed on Windows Vista with Cygwin.(1) Grab BOOTCLASSPATH from init.rc
Find the line in your init.rc file that reads something like:
Code:
[SIZE=2]export BOOTCLASSPATH /system/framework/core.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/core-junit.jar[/SIZE]
Extract and reformat the path to:
Code:
[SIZE=2]core.jar:bouncycastle.jar:ext.jar:framework.jar:android.policy.jar:services.jar:core-junit.jar[/SIZE]
(2) Grab the "framework" from your device
Create a working directory somewhere, let's call it "_framework":
Code:
[SIZE=2]mkdir ./_framework[/SIZE]
[SIZE=2]cd _framework[/SIZE]
Grab all the framework files from your device:
Code:
[SIZE=2]adb pull /system/framework .[/SIZE]
Rename directory if needed.
NOTE-1: From now on I'll assume you know where you are!
NOTE-2: Most GB 2.3.4+ devices uses .odex'ed files,
with name pairs like: <package>.jar and <package>.odex.
These need to be converted.
(3) Use baksmali with (1)
You can also use baksmali with the switch: -d <framwork-dir>.
The general command is something like below, but in windows there may be "wrappers"
that allow you to just type "baksmali" without the "java -jar" prefix and without
the ".jar" post fix. Anyway here is the command I used:
Code:
[SIZE=2]java -Xmx1024m -jar ./../../baksmali.jar -a 10 -c :core.jar:bouncycastle.jar:ext.jar:framework.jar:android.policy.jar:services.jar:core-junit.jar -x framework.odex[/SIZE]
==> This results in all files put in the "out" sub-directory.
This directory contain 3 sub-directories (for GB 2.3.4):
Code:
[I]android [/I](Hidden APIs)
[I]com [/I](Internal APIs)
[I]javax [/I](Hidden APIs)
NOTE: If you are using Google's own API's, you will probably also need to add
those packages to the path above. (Eg. Email.jar, etc etc ?)
(4) Then use smali to create a dex file from "out" directory
Code:
java -jar smali.jar out
==> creates out.dex from "out" directory.
(5) Run dex2jar on out.dex
Code:
[SIZE=2]./dex2jar.bat out.dex[/SIZE]
==> creates out_dex2jar.jar
(This .jar contain close to 4900 files at 12 MB!)
(6) Rename "out_dex2jar.jar" to "framework-classes.zip"
Code:
[SIZE=2]mv out_dex2jar.jar framework-classes.zip
unzip framework-classes.zip[/SIZE]
(7) Find and copy your Android SDK's android.jar file
Go to: /path/to/android-sdk-windows/platforms/android-X/android.jar
where X is the API level of interest. This obviously have to match the
API level of the files you extracted from your device in: /system/framework .
This .jar file contain more than 5300 files when expanded, but missing all
the internal packages. Our job is to add them back in.
Let's first make a copy that we can use to expand and add files from (6):
Code:
cp android.jar custom-android.zip
unzip custom-android.zip
(8) Add all *.class files from (6) in to (7)
Copy and replace all existing *.class files from framework-classes.zip into
custom-android.zip:
Code:
[SIZE=2]cp -R /path/to/framework-classes/* /path/to/custom-android/.[/SIZE]
The root content of that directory should then look something like this:
Code:
[SIZE=2]android[/SIZE]
[SIZE=2]assets[/SIZE]
[SIZE=2]com[/SIZE]
[SIZE=2]dalvik[/SIZE]
[SIZE=2]java[/SIZE]
[SIZE=2]javax[/SIZE]
[SIZE=2]junit[/SIZE]
[SIZE=2]META-INF[/SIZE]
[SIZE=2]org[/SIZE]
[SIZE=2]res[/SIZE]
[SIZE=2]AndroidManifest.xml[/SIZE]
[SIZE=2]resources.arsc[/SIZE]
(9) Rename directory and create your new "classy-android.jar"
We rename it so not confuse with the original:
Code:
mv custom-android classy-android
zip classy-android
mv classy-android.zip classy-android.jar
IMPORTANT:
Make absolutely sure that the folder structure of your zip archive
is exactly the same as what you intended. To check, unzip the file
and see if it is what you (and eventually Eclipse) would expect.
(For example, if you use 7zip to zip a directory file called "test",
into "test.zip", you may end-up extracting it to ./test/test/... )
(10) Enabling & Restricting Access to classy-android.jar
Instead of just replacing the android.jar with classy-android.jar, we choose
to create a customized Android platform. This way you can enable the Internal
and Hidden API's for those projects requiring them, while other standard
projects doesn't have access to those.
(a) Go to: /path/to/android-sdk-windows/platforms/
and copy the relevant directory (for example):
Code:
cp -R android-10 android-10-internals
(b) Replace android.jar with your classy-android.jar:
Code:
cp classy-android.jar android.jar
("cp" overwrites!)
(c) Edit the build.prop file:
Edit/replace the following lines:
Code:
[SIZE=2]ro.build.version.sdk=10 ==> ro.build.version.sdk=[COLOR=Black][B]-10[/B][/COLOR][/SIZE]
[SIZE=2]ro.build.version.release=2.3.3 ==> ro.build.version.release=2.3.internal[/SIZE]
(11) Customizing the Eclipse ADT
In order to be able to use com.android.internal packages in the Eclipse ADT,
you have to disable the internal protection mechanism of the plugin, that
prevent you to use these libraries. You can see this by right-clicking on your
project package and navigate to:
Code:
[SIZE=2]==> Properties ==> Java Build Path ==> Libraries (tab) [/SIZE]
[SIZE=2]--> Android 2.x.x --> android.jar [/SIZE]
[SIZE=2]--> "Access rules: 1 rule defined": [B][COLOR=Red](X)[/COLOR][/B] [B]Forbidden: com/android/internal/**[/B][/SIZE]
This can not be removed (bug?), even though the interface allows changing, it
never persists after closing the Properties window. So we have to hack it!
The way to do it, is to hexedit the correct java class file and change the
name from "internal" to "internax". First let's find the correct file. The
plugin file is located in the ./eclipse/plugins/ directory, and its name is
something like:
Code:
com.android.ide.eclipse.adt_18.0.0.v201203301601-306762.jar
(a) make a backup copy of this (with the exact name preserved) in another directory.
(b) make a another copy of this in another directory.
(c) unzip (b) in that directory
Code:
[SIZE=2]cp com.android.ide.eclipse.adt_18.0.0.v201203301601-306762.jar hacked_adt.zip[/SIZE]
[SIZE=2]unzip hacked_adt.zip[/SIZE]
[SIZE=2]cd hacked_adt[/SIZE]
This is a huge directory system, so forget poking around in it,
just go to the correct sub-directory:
Code:
[SIZE=2]cd ./com/android/ide/eclipse/adt/internal/project/[/SIZE]
Then find the correct file and the approximate string location within that file:
Code:
[SIZE=2]strings.exe -f -4 -t x ./*.class |grep "android\/internal"[/SIZE]
It happens to be in "AndroidClasspathContainerInitializer.class". Now, use a
hexeditor to find and change the string "com/android/internal/**"
to "com/android/internax/**". That will do it!
Now zip-up your hacked jar directory and copy it over the old one.
(Remember that "cp" overwrites without warning!)
Code:
[SIZE=2]zip hacked_adt[/SIZE]
[SIZE=2]cp hacked_adt.zip /path/to/eclipse/plugins/com.android.ide.eclipse.adt_18.0.0.v201203301601-306762.jar[/SIZE]
You Are Done!
Enjoy your newly hacked Eclipse! ​Errors
If you get any errors;
1. make sure you have zipped up everything properly as warned before.
2. make sure you have included Google API packages in your BOOTCLASSPATH in step (3).
3. Try to "clean-up" the Java by: "Right-Click" ==> Source ==> "Clean Up...".
4. Google them
5. Ignore them
6. Give up. Not! But I can't help you!
If it still doesn't work, try to download inazaruk's pre-compiled set of internal android.jar's from here.
(For android 7,8,10,15.)
​
WIP! <here be dragons2>
For a project using internal package imports, see my thread:
"[TOOL][APP][WIP] Native AT Command Injector"
<here be more dragons>
Following the instructions in posts 1-2 above, may not always work. It is not known to me at this time, why it shouldn't. One theory is that it can have something to do with how Eclipse and Android.jar is packaging their files and the resulting sizes.
This was mentioned in this Stackoverflow post:
"Jar files: why does extracting then compression a jar file create a file of a different size to the original?"
Then reading the man pages for "jar" we can inform ourselves with:
Code:
[SIZE=2] c Creates a new archive file named jarfile (if f is specified) or to
standard output (if f and jarfile are omitted). Add to it the
files and directories specified by inputfiles.
u Updates an existing file jarfile (when f is specified) by adding
to it files and directories specified by inputfiles.
x Extracts files and directories from jarfile (if f is specified) or
standard input (if f and jarfile are omitted). If inputfiles is
specified, only those specified files and directories are
extracted. Otherwise, all files and directories are extracted.
t Lists the table of contents from jarfile (if f is specified) or
standard input (if f and jarfile are omitted). If inputfiles is
specified, only those specified files and directories are listed.
Otherwise, all files and directories are listed.
i Generate index information for the specified jarfile and its
dependent jar files.
[/SIZE]
More info is provided here:
The JAR Overview @
http://java.sun.com/javase/6/docs/technotes/guides/jar/jarGuide.html
The JAR File Specification @
http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html
The JARIndex Spec @
http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html
JAR Tutorial @
http://java.sun.com/docs/books/tutorial/jar/
pack200 Reference Page @
http://java.sun.com/javase/6/docs/technotes/tools/share/pack200.html
Another theory is that it may have something to do with what seem to be, that Google have revoked the the use of MODIFY_PHONE_STATE since Android 2.3, and that this influences the Eclipse behavior, when using and modifying older android.jar's. This was mentioned here and here.
Any help would be very much appreciated!
< bump >
Hi, thanks for the info, I made it using linux and worked really nice, these were the lines that I used, hope be useful.
This is my Android folder at home
Code:
Android/
├── eclipse
├── ndk
├── platforms-internals
├── sdk
└── tools
Start an avd running the desired API to modify in this case API-17
Code:
$ emulator -avd avd_api_17 -no-window &
Get the framework
Code:
$ cd ~/Android/
$ mkdir _framework
$ cd _framework
$ adb -s emulator-5554 pull /system/framework .
Grab BOOTCLASSPATH
Code:
$ adb -s emulator-5554 shell cat init.rc | grep BOOTCLASSPATH > bootclasspath
I didn't have the tools used in this tutorial, so I included the steps for getting them
Decompile with baskmali
Code:
$ cd ~/Android/tools
$ wget https://smali.googlecode.com/files/baksmali-1.4.2.jar
$ cd ~/Android/_framework
$ java -Xmx1024m -jar ../tools/baksmali-1.4.2.jar -a 17 -c core.jar:core-junit.jar:bouncycastle.jar:ext.jar:framework.jar:telephony-common.jar:mms-common.jar:android.policy.jar:services.jar:apache-xml.jar -x framework.odex
The parameter -a for baksmali refers to the API we are working with.
Generate out.dex with smali
Code:
$ cd ~/Android/tools
$ wget https://smali.googlecode.com/files/smali-1.4.2.jar
$ cd ~/Android/_framework
$ java -jar ../tools/smali-1.4.2.jar out
Get internal and hidden classes using dex2jar
Code:
$ cd ~/Android
$ wget https://dex2jar.googlecode.com/files/dex2jar-0.0.9.15.zip
$ unzip dex2jar-0.0.9.15.zip
$ rm dex2jar-0.0.9.15.zip
$ cd _framework/
$ ../tools/dex2jar-0.0.9.15/d2j-dex2jar.sh out.dex
$ unzip out-dex2jar.jar -d framework-classes
Add these classes to plataform's default android.jar
Code:
$ cd ~/Android
$ unzip sdk/platforms/android-17/android.jar -d custom-android
$ cp -r _framework/framework-classes/* custom-android/
$ rm -r _framework
$ cd custom-android
$ zip -r ../custom-android.jar *
$ cd ..
$ rm -r custom-android
Create new extended platform
Code:
$ cd ~/Android
$ cp -r sdk/platforms/android-17 platforms-internals/android-17-internals
$ mv custom-android.jar platforms-internals/android-17-internals/android.jar
$ vi platforms-internals/android-17-internals/build.prop
ro.build.version.release=4.2.2
ro.build.version.release=4.2.2.internal
$ ln -s ~/Android/platforms-internals/android-17-internals ~/Android/sdk/platforms/android-17-internals
I use a symlink for keep it a little organized
Hack ADT
Code:
$ cd ~/Android
$ unzip eclipse/plugins/com.android.ide.eclipse.adt_22.0.4.v201307151829--741630.jar -d hacked_adt
Go to right folder
Code:
$ cd hacked_adt/com/android/ide/eclipse/adt/internal/project/
Find file where is our desired string
Code:
$ strings -f -a -t x * | grep "android\/internal"
Edit with an hex editor
Code:
$ bless AndroidClasspathContainerInitializer.class &
Here we change the l for the x.
Replace original file making a backup
Code:
$ cd ~/Android
$ cp eclipse/plugins/com.android.ide.eclipse.adt_22.0.4.v201307151829--741630.jar eclipse/plugins/com.android.ide.eclipse.adt_22.0.4.v201307151829--741630.jar.original
$ cd hacked_adt/
$ zip -r ../eclipse/plugins/com.android.ide.eclipse.adt_22.0.4.v201307151829--741630.jar *
$ cd ..
$ rm -r hacked_adt
This worked for me... thanks E:V:A
I got just one error related to a dropbox class, but i think this is not important... hope that
lenieto3 said:
...Start an avd running the desired API to modify in this case API-17... This worked for me... I got just one error related to a dropbox class, but i think this is not important...
Click to expand...
Click to collapse
Thanks and sorry for late reply. I'm very happy to hear these instructions still works with API-17! Could you also upload your hacked JAR somewhere so that people can save some time when experimenting?
I was just here to check-in and try to bump this thread to see if it is still useful to anyone.
E:V:A said:
Thanks and sorry for late reply. I'm very happy to hear these instructions still works with API-17! Could you also upload your hacked JAR somewhere so that people can save some time when experimenting?
I was just here to check-in and try to bump this thread to see if it is still useful to anyone.
Click to expand...
Click to collapse
ive got access to ActivityManager's hidden methods.
I want to use the removeTask method, but it keeps saying that I dont have the REMOVE_TASKS permissions even though I added it to the manifest (and turned off lint).
Permission Denial: removeTask() from pid=9963, uid=10179 requires android.permission.REMOVE_TASKS
Does someone know if there are any automated tools to do/performs steps 1-9?
I'd like to see a tool to automatically pull (from phone), extract and create a compatible android.jar.
@Mohammad_Adib: Sorry, this is the wrong thread for those type of questions.
see this link stackoverflow.com|questions|30656933|android-system-framework-jar-files

[GUIDE][TUT] Learn basic scripting, how to execute scripts, mod building

Hello guys, I want to share my expirience with users who wants to learn basic scripting stuff, busybox commands, how to use them, how to execute them, how to make .sh files.
Ok, let's start!!! ​
First we must to learn what is busybox. BusyBox is software that provides several stripped-down Unix tools in a single executable file. It runs in a variety of POSIX environments such as Linux, Android.
Busybox allows you or programs to perform actions on your phone using Linux (copied from Unix) commands. Android is basically a specialized Linux OS with a Java compatible (Dalvik) machine for running programs. The Android kernel is a modified version of the Linux kernel (that is why the Android kernel must always be open source). Busybox gives functionality to your phone that it does not have without it. Many programs, especially root programs such as Titanium Backup, require busybox to perform the functions of the program. Without busybox installed your phone is much more limited in what it can do.
{
"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"
}
Here is some info about busybox, you can track here release dates, you can download sources...
http://spblinux.de/2.0/doc/commands.html
Also here is busybox installer for our "linux devices" heheh ^~^ by stericson. You have two versions of it as you see paid and free.
Chose paid if you want to donate him for awesome job.
Free:
https://play.google.com/store/apps/details?id=stericson.busybox
Paid(PRO):
https://play.google.com/store/apps/details?id=stericson.busybox.donate
After that you need Terminal app, you can download it from playstore too.
Link: Download it from here
This app emulates Linux terminal, with it you can access to android shell.
Lets's start with learning basic terminal stuff
The most of shell commands doesn't need root access, but some of them are need it.
To give root access to the terminal app, you need to type next.
Code:
su [I](press enter)[/I]
After pressing enter, another window will popup to grant root access. Tap on GRANT
***When you typing something into the terminal window, take care because EVERYTHING IS CASE SENSITIVE.***
We all know there are three permissions per group on a file read,write,execute or rwx.
To set permissions as rw-r--r-- we use chmod 644 or 0644 but most don't know why ? Here's why
Read or r has a positional weight of 4, Write or w has 2 and Execute or x has 1. Add them up for each group and you'll get the chmod number to use. For above example, the numbers will be (4+2)(4)(4) i.e. 644 or if you want four digits, use 0644 and that's pretty much it. It comes in very handy if you're learning shell scripting because Linux revolves around permissions. (Thanks to @MSF Jarvis)
Let's go trough basic shell commands. ​
If you interested about all commands, you can check them HERE.
cat [file destination] - use this command to print everything from a file to the terminal window
Example:
Open terminal window, and type next:
Code:
busybox cat /proc/meminfo [I](press enter)[/I]
You will get output after pressing enter
Now, you can see here, if you open any file manager and go to destination which was given for example "/proc/meminfo"
You will see next file and stuff inside it
Heheh, is it same?? ^~^ for sure that it is, you can use it for any file on your device which have text in it.
Let's go to the next basic command ^~^
echo - this command can be used for printing arguments to stdout. Also you can use it for adding text in already existing file which we need here, because we are learning scripting stuff, right? ^~^
Example:
Open terminal window, and type next:
Code:
busybox echo "Scripting is awesome" > /sdcard/test [I](press enter)[/I]
Ok, let's explain this.
First you added a command echo to add something in existing file, then between "..." we need to put arguments, for our case this is "Scripting is awesome" next we see symbol " > " which will forward arguments to next added direction, in our case this is "/sdcard/test".
First we need to have a existing file (IMPORTANT)
After we agreed with that we have a file
Open terminal as I already explained and after pressing enter you will get output on the terminal window.
That is a file from our /sdcard/
Don't delete this file, we will use it later with " sh" command.
Let's go to the next basic command
clear - Use this comand to clear whole terminal window.
Example:
You have a terminal window which have a lot of stuff on it, for example stuff from previous lines, text, etc.
You can simply make it blank with just one command
Code:
busybox clear [I](then press enter)[/I]
And voila, terminal window is blank
touch [file destination] - Use this command to create a blank file on any destination on your android device.
Example:
Open terminal window, and type next:
Code:
busybox touch /sdcard/scripting_007 [I](press enter)[/I]
This will create file called "scripting_007" on "/sdcard/" in this case, you can put any.
As you can see file "scripting_007" exist on /sdcard/
mkdir [file destination] - Use this command to create one empty folder on any destination on your android device.
Example:
Open terminal window, and type next:
Code:
busybox mkdir /sdcard/development [I](press enter)[/I]
This will create folder called "development" on "/sdcard/" in this case, you can put any.
sh [path of a file] - Use this command to execute basic script
Example:
Open terminal window, and type next:
Code:
sh /sdcard/test [I](press enter)[/I]
This will execute file which you make before with "echo" command
sleep [time in secs] - Use this command to make an offset between executing lines inside script.
Example:
Open terminal window, and type next:
Code:
busybox echo "Scripting is"
busybox sleep 10
busybox echo "awesome"
This is a combination of two commands as you can see, echo and sleep.
After launching this simple script in terminal window you will get first "Scripting is" and after 10 secs you will get awesome.
rm [ -f (file) -rf (folder)] - this is a command for removing files (-f) and folders (-rf)
Example:
Create a file called "android" on sdcard, then open terminal window, and type next:
Code:
busybox rm -f /sdcard/android
This simple code will remove a file called android from sdcard.
Now do the same thing with a folder, create one with the name "android" and run terminal emulator
Code:
busybox rm -rf /sdcard/android
This will remove folder called android from your sdcard.
Now, let's go with some advanced stuff​
You need any text editor, I suggesting this one
Link: Download from here
Now, open the app and write a new file and give it a name "test1"
Inside a file write next text:
Code:
busybox echo "Android"
busybox sleep 2
busybox echo "is"
busybox sleep 2
busybox echo "Awesome"
Save the file and copy it to some location, i suggest /sdcard/.
Open up terminal emulator and type next
Code:
sh /sdcard/test1 [I](press enter)[/I]
This thing will execute your script with the name test1 from /sdcard/.
Output will be "Android", then after two seconds will appear "is" and then after two more seconds "Awesome" will appear. THATS IT!!! You learned how to make a file (script) and how to execute it with terminal emulator.
Now do the same thing make a file with the name "test2" and make another file with a name "print"
First open "test1" and write next:
Code:
busybox echo "After 5 seconds"
busybox sleep 1
busybox echo "You will get a suprice"
busybox sleep 2
busybox clear
busybox echo "1"
busybox sleep 1
busybox clear
busubox echo "2"
busybox sleep 1
busybox clear
busybox echo "3"
busybox sleep 1
busybox clear
busybox echo "4"
busybox sleep 1
busybox clear
busybox echo "5"
busybox sleep 1
busybox clear
sh /sdcard/print
I think that you already know whats happened here
You have print, then you have sleep to make offset, and after that you have clear command to make window blank
Now open file with the name "print"
Inside it write next:
Code:
busybox echo "Voila, suprise"
Save this file, and open terminal emulator, and write next:
Code:
sh /sdcard/test2
And magic happens
In this example you learned how to execute second file with first, I think that it's not difficult for you
In this example we will play a bit with colors outputs
Codes for colors are below
Code:
busybox echo -e " 1. Black \e[0;100m \e[00;37;40m"
busybox echo -e " 2. Red \e[0;101m \e[00;37;40m"
busybox echo -e " 3. Green \e[0;102m \e[00;37;40m"
busybox echo -e " 4. Yellow \e[0;103m \e[00;37;40m"
busybox echo -e " 5. Blue \e[0;104m \e[00;37;40m"
busybox echo -e " 6. Purple \e[0;105m \e[00;37;40m"
busybox echo -e " 7. Cyan \e[0;106m \e[00;37;40m"
busybox echo -e " 8. White \e[0;107m \e[00;37;40m"
Try to copy this into terminal window and see what will happened or try whing which you learned before with the executing files. Copy whole code to a file and execute it with "sh" command. USE YOUR KNOWLEDGE.
Here you can see all things based on bash script coloring
https://wiki.archlinux.org/index.php/Color_Bash_Prompt
or
http://misc.flogisoft.com/bash/tip_colors_and_formatting
Here you can see all codes and it's nice descirbed.
Now, let's start
Make a file with the name "test3" open it and write or copy next code inside:
Code:
busybox echo " .... "
busybox echo " / / "
busybox echo " / / "
busybox echo " / / "
busybox echo " / /_._._. "
busybox echo -e " /_._._._._./ \e[00;41m SPEED MOD \e[00;37;40m v3.0"
busybox echo "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
busybox echo -e "\e[01;32m Feel smoothness \e[00;37m"
busybox echo " "
As you can see this part was taken from mine L Speed performance/battery mod
Save the file, open terminal and type inside
Code:
sh /sdcard/test3
And you will get the same screen like in first L Speed menu.
Let's play a bit with this
You see the code
Code:
\e[00;41m SPEED MOD \e[00;37;40m v3.0
Just change one number instead of 41 write 42 and you will get green color, then give a try to other nubers. Every number is another color for example:
Code:
# Reset
Color_Off='\e[0m' # Text Reset
# Regular Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
Cyan='\e[0;36m' # Cyan
White='\e[0;37m' # White
# Bold
BBlack='\e[1;30m' # Black
BRed='\e[1;31m' # Red
BGreen='\e[1;32m' # Green
BYellow='\e[1;33m' # Yellow
BBlue='\e[1;34m' # Blue
BPurple='\e[1;35m' # Purple
BCyan='\e[1;36m' # Cyan
BWhite='\e[1;37m' # White
# Underline
UBlack='\e[4;30m' # Black
URed='\e[4;31m' # Red
UGreen='\e[4;32m' # Green
UYellow='\e[4;33m' # Yellow
UBlue='\e[4;34m' # Blue
UPurple='\e[4;35m' # Purple
UCyan='\e[4;36m' # Cyan
UWhite='\e[4;37m' # White
# Background
On_Black='\e[40m' # Black
On_Red='\e[41m' # Red
On_Green='\e[42m' # Green
On_Yellow='\e[43m' # Yellow
On_Blue='\e[44m' # Blue
On_Purple='\e[45m' # Purple
On_Cyan='\e[46m' # Cyan
On_White='\e[47m' # White
# High Intensity
IBlack='\e[0;90m' # Black
IRed='\e[0;91m' # Red
IGreen='\e[0;92m' # Green
IYellow='\e[0;93m' # Yellow
IBlue='\e[0;94m' # Blue
IPurple='\e[0;95m' # Purple
ICyan='\e[0;96m' # Cyan
IWhite='\e[0;97m' # White
# Bold High Intensity
BIBlack='\e[1;90m' # Black
BIRed='\e[1;91m' # Red
BIGreen='\e[1;92m' # Green
BIYellow='\e[1;93m' # Yellow
BIBlue='\e[1;94m' # Blue
BIPurple='\e[1;95m' # Purple
BICyan='\e[1;96m' # Cyan
BIWhite='\e[1;97m' # White
# High Intensity backgrounds
On_IBlack='\e[0;100m' # Black
On_IRed='\e[0;101m' # Red
On_IGreen='\e[0;102m' # Green
On_IYellow='\e[0;103m' # Yellow
On_IBlue='\e[0;104m' # Blue
On_IPurple='\e[0;105m' # Purple
On_ICyan='\e[0;106m' # Cyan
On_IWhite='\e[0;107m' # White
On the next phase we will learn how to use variables, in bash scripts this is simple, just add a simple "tag" then what you want to connext wit this tag.
Here is an example:
Code:
file=/sdcard/test4
busybox touch $file
Ok, here is one simple thing, this is same like in touch command explaining, but there is a little difference. We added variable or you can call it shortcut if it's easier for you.
To call variable somewhere in a file you need to use a dollar sign "$" then name of your variable. Let's to next examole with variables.
As we now have file called test4 on our SD, we can go trough.
Code:
file=/sdcard/test4
busybox echo "hey file" > $file
As you can see everything is repeating from previous examples just with variable. This is much easier, and you will save a bit of time.
Now we can see what is inside file Open terminal emulator and type next
Code:
busybox cat /sdcard/test4
And you will get output "hey file"
Simple isn't it?
In this part we will learn how to use if, elif, else It's pretty simple, let's start.
Pattern for this will be:
Code:
if [what]; then
do something
fi
if [what]; then
do something
elif [what if not "if"]
do something
else
what to do else
fi
Ok what we have here?
The first part of code show us simple code which mean if for example something is true then do something and then close if with fi.
Second part of code is a bit "complicated". If somethig is true then do something, then we have elif, in case that if is false then it will do what is under elif. In case that both of them are false, everything what is under else will be executed.
Ok here is an example:
Code:
if [ -e /sdcard/test5 ]; then
busybox echo "hello" > /sdcard/test5
else
busybox touch /sdcard/test5
busybox echo "hello" > /sdcard/test5
fi
Ok, if file test 5 exists add hello to it, else(if not) then create a file and add text hello in it.
Another example with a bit of complications heheh
Code:
if [ -e /sdcard/test5 ]; then
busybox echo "file 5 exists"
elif [ -e /sdcard/test6 ]; then
busybox echo "file 6 exists"
else
busybox echo "files are not exist"
fi
Ok, here is explanation, if test5 exist then print "file 5 exists" going to the next line, if file test6 exist pri t "file 6 exists" and else if both of them doesn't exist print "files are not exist".
Donation:
http://forum.xda-developers.com/donatetome.php?u=5514152
Everyone who knows a bit of the performance/battery mods wants sometime to learn what is inside and how it's working
Here is a guide by @Paget96 (me) ^~^
As we know for every mod we need root, this is needed because we must to access to android shell.
init.d support, that is a folder which launch files from it on every boot. Init.d is included on some ROM's by default, but on some you need yo enable it by default(I will explain later how).
Next thing what you need is for sure busybox. And a little bit of free space on the /system partition.
Everyone knows how to root, I don't need to explain how to do that right?
User who doesn't have init.d will make it with next steps.
1. Flash superSU by @Chainfire (IMPORTANT)
2. In /system/etc/ make a file with the name "install-recovery-2.sh and push next code in it
Code:
#!/system/bin/sh
/system/bin/sysinit
3. Inside system/bin make a file with the name " sysinit" and push next code in it
Code:
#!/system/bin/sh
busybox sleep 30
export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
run-parts /system/etc/init.d
4. Open /system/etc and make folder with the name "init.d"
Now you need to set permissions for all of this files.
Open terminal emulator and do next:
Code:
su
This will give root access
Code:
busybox chmod 755 /system/etc/install-recovery-2.sh
busybox chown 0.2000 /system/etc/install-recovery-2.sh
With this you will set "executable" permissions.
And we need permission for sysinit
Code:
busybox chmod 755 /system/bin/sysinit
busybox chown 0.2000 /system/bin/sysinit
And that's it
To install busybox use app "busybox installer" by stericson from playstore.
***IMPORTANT*** Don't change too much things, because you will get crap in your hands
Tools which are needed is
Text editor, I suggest Turbo Editor
Terminal emulator
ES file explorer
Ok, let's start
We will start with virtual memory tweaking...
Open file manager and create one folder where you will build a mod.
Inside it we will create one file for beginning and call it "00sysmod"
Code:
#!/system/bin/sh
busybox chmod 644 /proc/sys/vm/*
busybox sysctl -e -w vm.dirty_background_ratio=3
busybox sysctl -e -w vm.dirty_ratio=15
busybox sysctl -e -w vm.swappiness=40
busybox sysctl -e -w vm.dirty_expire_centisecs=500
busybox sysctl -e -w vm.dirty_writeback_centisecs=3000
busybox sysctl -e -w vm.min_free_kbytes=4096
busybox sysctl -e -w vm.overcommit_memory=1
busybox sysctl -e -w vm.overcommit_ratio=75
busybox sysctl -e -w vm.page-cluster=0
busybox sysctl -e -w vm.panic_on_oom=0
Copy this inside file, save it and copy to init.d folder
After that set permissions to 755
Code:
busybox chmod 755 /system/etc/init.d/00sysmod
Let's explain every line:
First line is a header of every script.
Next line will change permissions (in this case read, write, read, read) of a files which are inside /proc/sys/vm/*. * means every file.
Everything below it are vm parameters.
vm.dirty_background_ratio
Contains, as a percentage of total available memory that contains free pages
and reclaimable pages, the number of pages at which the background kernel
flusher threads will start writing out dirty data.
The total avaiable memory is not equal to total system memory.
dirty_ratio
Contains, as a percentage of total available memory that contains free pages
and reclaimable pages, the number of pages at which a process which is
generating disk writes will itself start writing out dirty data.
The total avaiable memory is not equal to total system memory.
swappiness
This control is used to define how aggressive the kernel will swap
memory pages. Higher values will increase agressiveness, lower values
decrease the amount of swap. A value of 0 instructs the kernel not to
initiate swap until the amount of free and file-backed pages is less
than the high water mark in a zone.
The default value is 60.
dirty_expire_centisecs
This tunable is used to define when dirty data is old enough to be eligible
for writeout by the kernel flusher threads. It is expressed in 100'ths
of a second. Data which has been dirty in-memory for longer than this
interval will be written out next time a flusher thread wakes up.
dirty_writeback_centisecs
The kernel flusher threads will periodically wake up and write `old' data
out to disk. This tunable expresses the interval between those wakeups, in
100'ths of a second.
Setting this to zero disables periodic writeback altogether.
min_free_kbytes
This is used to force the Linux VM to keep a minimum number
of kilobytes free. The VM uses this number to compute a
watermark[WMARK_MIN] value for each lowmem zone in the system.
Each lowmem zone gets a number of reserved free pages based
proportionally on its size.
Some minimal amount of memory is needed to satisfy PF_MEMALLOC
allocations; if you set this to lower than 1024KB, your system will
become subtly broken, and prone to deadlock under high loads.
Setting this too high will OOM your machine instantly.
overcommit_memory
This value contains a flag that enables memory overcommitment.
When this flag is 0, the kernel attempts to estimate the amount
of free memory left when userspace requests more memory.
When this flag is 1, the kernel pretends there is always enough
memory until it actually runs out.
When this flag is 2, the kernel uses a "never overcommit"
policy that attempts to prevent any overcommit of memory.
Note that user_reserve_kbytes affects this policy.
DON'T CHANGE THIS VALUE, YOU WILL GET CRAP IN A HANDS, THIS IS JUST FOR INFO
overcommit_ratio
With this parameter you will set how much space will allocations use in physical RAM. (Percentage)
page-cluster
page-cluster controls the number of pages up to which consecutive pages
are read in from swap in a single attempt. This is the swap counterpart
to page cache readahead.
The mentioned consecutivity is not in terms of virtual/physical addresses,
but consecutive on swap space - that means they were swapped out together.
It is a logarithmic value - setting it to zero means "1 page", setting
it to 1 means "2 pages", setting it to 2 means "4 pages", etc.
Zero disables swap readahead completely.
panic_on_oom
This enables or disables panic on out-of-memory feature.
If this is set to 0, the kernel will kill some rogue process,
called oom_killer. Usually, oom_killer can kill rogue processes and
system will survive.
If this is set to 1, the kernel panics when out-of-memory happens.
If this is set to 2, the kernel panics compulsorily even on the
above-mentioned. Even oom happens under memory cgroup, the whole
system panics
In this part we will tweak kernel parameters
Open file manager as before and create a file with the name " 00kerneltweak"
Here we will use if statement, just for a little practise ^~^
Code:
if [ -e /proc/sys/kernel/shmmni ]; then
busybox echo "2048" > /proc/sys/kernel/shmmni
fi
if [ -e /proc/sys/kernel/shmall ]; then
busybox echo "1572864" > /proc/sys/kernel/shmall
fi
if [ -e /proc/sys/kernel/shmmax ]; then
busybox echo "33554432" > /proc/sys/kernel/shmmax
fi
if [ -e /proc/sys/kernel/msgmni ]; then
busybox echo "512" > /proc/sys/kernel/msgmni
fi
if [ -e /proc/sys/kernel/msgmnb ]; then
busybox echo "16384" > /proc/sys/kernel/msgmnb
fi
if [ -e /proc/sys/kernel/msgmax ]; then
busybox echo "8192" > /proc/sys/kernel/msgmax
fi
Copy this inside file, save it and copy to init.d folder
After that set permissions to 755
Code:
busybox chmod 755 /system/etc/init.d/00kerneltweak
Same as we learned before if file exist then do next
Let's explain this parameters:
shmall
The total amount of shared memory (in pages) which can be allocated on the system
shmmax
The maximum size of a shared memory segment (in pages)
shmmni
The maximum number of shared memory segments available on the system
msgmni
The number of IPC message queue resources allowed (by default, 16).
msgmnb
Defines the maximum size in bytes of a single message queue. The default value is 65536 bytes.
msgmax
The maxim...
Remove Google Play Services data
Code:
#!/system/bin/sh
mount -o remount,rw /data
busybox mount -o remount,rw /data
GSM=/data/data/com.google.android.gms
for i in $GSM
do
busybox rm -rf $i/*
done
make a file, and add this inside, like before
copy to /system/etc/init.d
set permissions to 755
Clear browser data
Code:
#!/system/bin/sh
mount -o remount,rw /data
busybox mount -o remount,rw /data
browser=/data/data/com.android.NAME_OF_THE_BROWSER
for i in $browser
do
busybox rm -rf $i/*
done
make a file, and add this inside, like before
copy to /system/etc/init.d
set permissions to 755
first write a name of the browser, some devices have chrome as a default, then name will be
com.android.chrome
I'm sure that its
com.android.browser for default one
Check that inside /data/data, then just change inside the script
Or you can use this package
Code:
#!/system/bin/sh
while true; do
mount -o remount,rw /data
busybox mount -o remount,rw /data
busybox echo -n "Enter a name of the browser: "
busybox read -r name
brw=/data/data/com.android.$name
if [ -d $brw ]; then
for i in $brw
do
busybox rm -rf $i/*
done
busybox echo "Clearing done"
busybox sleep 2
else
busybox echo "Browser doesn't exist, please type another one..."
busybox sleep 3
fi
done
Well, this for this file guide is different,
Call the file "ccleaner" copy it to /system/bin
Set permissions to 755 like before
Open terminal emulator
Code:
su
ccleaner
Thanks Man
Thanks @Paget96 for your Support Man It will help Many user to Learn From You :fingers-crossed::good:
And Am the First to Comment on your Forum
cheers:laugh:
axays said:
Thanks @Paget96 for your Support Man It will help Many user to Learn From You :fingers-crossed::good:
And Am the First to Comment on your Form [emoji14]
Click to expand...
Click to collapse
I hope so
This thread needs too much stuff here, I cannot finish it in one day
Sent from my Nexus 5 using Tapatalk
Wow Good Job and Good Luck @Paget96 Its willbe Awesome
Paget96 said:
I hope so
This thread needs too much stuff here, I cannot finish it in one day
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
I'm a fan of your L Speed Mod, and this tutorial clears up many things. Subscribing now for updates when you add more stuff here.
Sent from my HTC Desire 616 dual sim using Tapatalk
Evolutionzz said:
Wow Good Job and Good Luck @Paget96 Its willbe Awesome
Click to expand...
Click to collapse
Thank you mate ^~^
MSF Jarvis said:
I'm a fan of your L Speed Mod, and this tutorial clears up many things. Subscribing now for updates when you add more stuff here.
Sent from my HTC Desire 616 dual sim using Tapatalk
Click to expand...
Click to collapse
Heh fans everywhere ^~^ Yeah, but TUT is not finished this is maybe 20% of stuff which are need to be here
Sent from my Nexus 5 using Tapatalk
Guys, more stuff will come tomorrow
Sent from my Nexus 5 using Tapatalk
Paget96 said:
Thank you mate ^~^
Heh fans everywhere ^~^ Yeah, but TUT is not finished this is maybe 20% of stuff which are need to be here
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
Just 20%!!!! I'm dying to see the rest....
Paget96 said:
Thank you mate ^~^
Heh fans everywhere ^~^ Yeah, but TUT is not finished this is maybe 20% of stuff which are need to be here
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
Sent from my HTC Desire 616 dual sim using Tapatalk
MSF Jarvis said:
Just 20%!!!! I'm dying to see the rest....
Sent from my HTC Desire 616 dual sim using Tapatalk
Click to expand...
Click to collapse
Heheh, there will be whole stuff about scripting which I used for L Speed building
Sent from my Nexus 5 using Tapatalk
For now, I think that it's enough, if you have more request, type below
Also I want to see screenshots of your attempts
Sent from my Nexus 5 using Tapatalk
Hell yeah!! Awesome Guide my bro @Paget96 Fantastic! This what people wanted from a long time. Amazing.
Sent From dark_world through my Android One
dark_optimistic said:
Hell yeah!! Awesome Guide my bro @Paget96 Fantastic! This what people wanted from a long time. Amazing.
Sent From dark_world through my Android One
Click to expand...
Click to collapse
Thank you, this is why I created it
Sent from my Nexus 5 using Tapatalk
Paget96 said:
For now, I think that it's enough, if you have more request, type below
Also I want to see screenshots of your attempts
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
I borked my phone a bit (this is a non - rooted phone ) so I'll post screenshots later when I UN-bork it.
Sent from my HTC Desire 616 dual sim using Tapatalk
MSF Jarvis said:
I borked my phone a bit (this is a non - rooted phone ) so I'll post screenshots later when I UN-bork it.
Sent from my HTC Desire 616 dual sim using Tapatalk
Click to expand...
Click to collapse
What you mean with borked?? hehh
I'm waiting for your screenshots, just to see how users understood stuff ^~^
Sent from my Nexus 5 using Tapatalk
delete
Awesome work as usual :angel:
Black_Eyes said:
Awesome work as usual :angel:
Click to expand...
Click to collapse
Thank you
I just want to share mine experience with the users
And probably to teach someone
Sent from my Nexus 5 using Tapatalk
Paget96 said:
What you mean with borked?? hehh
I'm waiting for your screenshots, just to see how users understood stuff ^~^
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
Borked means I changed my recovery and flashed a GB ROM instead of using my friends custom built CM 11 build. My trusty Tahr system also broke down, but I am resilient so I'll manage and you WILL see the screenshots before 5PM IST.[emoji16] [emoji16] [emoji16] [emoji6] [emoji6] [emoji6] [emoji6]
Sent from my HTC Desire 616 dual sim using Tapatalk

Init Script and File Copy

I've added a simple shell script to my Z5 (Stock 5.1.1) as an init service. The scipt is intended to simply copy a file to the sdcard. I can see that my script is run on init, that it verifies the source file exists, but the cp command returns 1. dmesg output shows selinux write denials, but it selinux is in permissive mode.
Manually executing the script works fine, and I know the service is executing. I'm sure I'm missing something obvious, but so far this has eluded me. Any help would be appreciated.
script
Code:
#!/system/bin/sh
if [ -e /system/path/myfile ]
then
log -p i -t MYSTUFF "copy file"
cp /system/path/myfile /sdcard/myfile
log -p i -t MYSTUFF "Returned: ${?}"
fi
service setup
Code:
service my-service /system/path/myscript.sh
class myclass
user root
group root
oneshot
on property:init.svc.usf-post-boot=stopped
class_start myclass

Execute Dex File From Shell

(Not sure if it goes here or in another forum)
I've figured out a way to execute a dex file without manually running the dalvikvm command. It works similarly to self-extracting tar archives, by taking the dex file, and adding a little script at the top to run dalvikvm on it. This could probably allow for architecture-independent executables that have more abilities than shell scripts, they would just need to be written in Java and then dexed. Just add this to the start of a dex file (obviously put in the actual main class):
Code:
#!/system/bin/sh
tmpdex="$0".tmp;
sed -e '1,/^exit;$/d' "$0" > "$tmpdex";
dalvikvm -cp "$tmpdex" name.of.main.Class "[email protected]";
rm "$tmpdex";
exit;
(Make sure there are no characters after "exit;" [besides a single new line character], or it will break the dex!)
As an example, I have dexed and added this to topjohnwu's zipsigner utility and attached it.

Categories

Resources