[Q] help scripting sooo close - Android Software/Hacking General [Developers Only]

i am so close
I was able to manipulate a database using sqlite
and wrote the following script
Code:
#stuff
su
sqlite3 /data/data/com.nitrodesk.drois20.nitroid/databases/windroid.db <<SQL_ENTRY_TAG_1
update table
set boolean=0 ;
commit;
.exit
SQL_ENTRY_TAG_1
exit
and called it xxx.sh
i can navigate to the directory and cat the file
cat xxx.sh
shows properly
if I drop in to su and try to execute it I get
xxx.sh not found
chmod 777 xxx.sh
did not help
when I get it to work for sure
i will add it to the phone priortizer app and schedule it.

Related

USCC Mesmerize Rooting on Official 2.2 (Froyo)

Okay, this was my first time trying to root my phone and it would figure that non of the automated methods worked for me. Still, I was able to get root on my US Cellular Samsung Galaxy S Mesmerize (SCH-i500 for the kids keeping track at home) and these are the steps that I took. I hope this helps others who may be scratching their head wondering what to do when the developers haven't gotten around to (read: forsaken) us.
The nice thing about this method is that it doesn't require Windows (though you still do download SuperOneClick).
NOTE: This is only for an officially updated Mesmerize. Rooting is unnecessary for the leaked version.
APOLOGY: I can't post any links to anything outside the forum as I am a newer member, so, sorry for not being able to post URLs.
1. Download the Android SDK from the Android developer website and install/unzip it. You may need to add the path to the adb tool (found under platform-tools for me) to your PATH variable.
2. Download the SuperOneClick tool and unzip it
3a. If you are using Windows, then make sure to install the drivers for your phone. I don't have Windows, so don't ask me which file to download. Sorry.
3b. Enable USB Debugging on your phone (Settings->Applications->Development->Check "USB Debugging").
4. Connect your phone to your computer using the USB cable
5. Open a shell (or command prompt on Windows) and change directories to where you unzipped SuperOneClick
6. Run the following commands to copy files to your device
A. adb push psneuter /data/local/tmp/psneuter
B. adb push busybox /sdcard/busybox
C. adb push su-v2 /sdcard/su
NOTE: A quick note of each of these files.
A. psneuter - an exploit to gain root access temporarily on your phone
B. busybox - a compilation of common unix commands to help you along the CLI world
C. su - the super-user command used to gain elevated privileges
7. Run the following command to get a command line interface to your device
adb shell
At this point, you should see a $ prompt indicating that you are on your phone.
From here, you will change directories to where you put the exploit, change the permissions so you can run it, copy over the files that we need to sustain root access, and finally, install the Superuser.apk app so that you can manage root access from the UI.
Execute the following commands:
$ cd /data/local/tmp
$ chmod 777 psneuter
$ ./psneuter
Here, you will be disconnected from your device. This is normal. Just run "adb shell" again to get back in, though now, you will notice that the prompt has changed to a #. The following commands will reflect that.
# mount -t rfs -o remount,rw /dev/block/st19 /system
# cd /system/xbin
# cat /sdcard/busybox > busybox
# cat /sdcard/su > su
# chmod 4755 busybox
# chmod 4755 su
# exit
Now, you will be back on your computer. Type the following to install the Superuser.apk app.
adb install Superuser.apk
That should do it! You now have root access. Go ahead and try to install Titanium Backup (requires root). You can also install a terminal app or anything else.
I hope this helps. Report your successes/failures in the comments.

Run a .sh on android.

Hi,
I have made a little .sh script as a test.
But when i use terminal emulator to run it i get the 'permission denied' error even though my phone is rooted. Please tell me what to do to run a .sh file on my phone.
Script:
#!/bin/sh
echo hi
Thanks in advance. Any help will be greatly appreciated.
i think that if you do:
su (to get superuser privileges)
sh your_script.sh
might work....
alternative is to install gscript and put your script in the gscript folder on sdcard....
The console needs to be granted superuser access, then ran as sh script.sh or bash script.sh. afaik at least. Youll probably have to use su like the person above said.
I did the su command. But i still can't open it. All other commands work.
Ok so it sorta worked.
I used the cd command to get to the file.
I used su command.
Then i typed sh script.sh .
Nothing happened, no echo or anything, just a new line with # on it.
What's happening.
Btw thanks for the replies.
krutle said:
I did the su command. But i still can't open it. All other commands work.
Click to expand...
Click to collapse
Maybe stating the obvious, but did you CHMOD the file to be +X ? Use Root Explorer or chmod at a SU capable command line to change the file mods to allow execute.
krutle said:
I did the su command. But i still can't open it. All other commands work.
Click to expand...
Click to collapse
Maybe stating the obvious, but did you CHMOD the file to be +X ? Use Root Explorer or chmod at a SU capable command line to change the file mods to allow execute.
ryocoon said:
Maybe stating the obvious, but did you CHMOD the file to be +X ? Use Root Explorer or chmod at a SU capable command line to change the file mods to allow execute.
Click to expand...
Click to collapse
This should be the solution. X is the execute bit. Basically without that bit set on the file permissions, the OS won't allow that file to be executed as a program.
chmod +x filename.sh
Try running that command in terminal emulator and it should clear things up.
Sent from my Inspire 4G using XDA App
I used that command and it said 'bad mode'.
It still doesn't work.
If you are running the script with this:
Code:
sh script.sh
then the executable bit doesn't need to be set in order to execute it, since you are specifying 'sh'. If you were trying to run it with this:
Code:
./script.sh
then it would require the executable bit to be set.
In an attempt to answer the question, where abouts is your script saved and which user owns it? Just as a quick test on mine, I made a script named test.sh (containing the same lines as yours) on the root of my sd card, cd'd to it and ran sh test.sh, and that seemed to work. That script ended up being owned by 'system'.
As a test to make sure sh is behaving, can you run the following from the terminal:
Code:
sh -c 'echo hello'
EDIT: note that all of the above was run as a regular user, not root.
Yeh it said hello when i did the command you said.
It must be a problem with the file in some way then. Can you run the following from the folder that your script is in and give the output?
Code:
ls -l | grep script.sh
Also, what did you use to make the script - terminal in Android, or adb'd it from your PC etc?
(Aside: just a thought, you probably can't do chmod's on sdcard files if it's formatted to FAT32 since FAT32 doesn't understand Linux permissions)
you can also try an app i found some time ago. SL4A
I made the file with silveredit. Just renamed .txt to .sh.
Btw i got it working with gscript, thanks for everyone's help
Run a reverse tethering shell script
I am trying to run a reverse tethering shell script using Android terminal Emulator(ATE). The script is saved as tether.unicode.sh under /sbin/. Its content is as follows:
Code:
ifconfig usb0 192.168.137.2 netmask 255.255.255.0 up
route add default gw 192.168.137.1 dev usb0
setprop net.dns1 8.8.8.8
setprop "net.grps.http-proxy" ""
I executed the following command in ATE and got error.
Code:
$su
#sh /sbin/tether.unicode.sh
ifconfig: not found
netmask: not found
255.255.0: not found
..
#
Excuse me posting in this very old thread. I hope its better to continue here instead of opening a new thread.
P.S: I am able to execute all this statements by copying and pasting line by line in ATE.
nok2626 said:
I am trying to run a reverse tethering shell script using Android terminal Emulator(ATE). The script is saved as tether.unicode.sh under /sbin/. Its content is as follows:
Code:
ifconfig usb0 192.168.137.2 netmask 255.255.255.0 up
route add default gw 192.168.137.1 dev usb0
setprop net.dns1 8.8.8.8
setprop "net.grps.http-proxy" ""
I executed the following command in ATE and got error.
Code:
$su
#sh /sbin/tether.unicode.sh
ifconfig: not found
netmask: not found
255.255.0: not found
..
#
Excuse me posting in this very old thread. I hope its better to continue here instead of opening a new thread.
P.S: I am able to execute all this statements by copying and pasting line by line in ATE.
Click to expand...
Click to collapse
it's because android doesn't know about these command, this is a native linux command, try to install busybox, edit your script like this
Code:
busybox ifconfig usb0 192.168.137.2 netmask 255.255.255.0 up
busybox route add default gw 192.168.137.1 dev usb0
busybox setprop net.dns1 8.8.8.8
busybox setprop "net.grps.http-proxy" ""
I hope these helpfull
krutle said:
Hi,
I have made a little .sh script as a test.
But when i use terminal emulator to run it i get the 'permission denied' error even though my phone is rooted. Please tell me what to do to run a .sh file on my phone.
Script:
#!/bin/sh
echo hi
Thanks in advance. Any help will be greatly appreciated.
Click to expand...
Click to collapse
Even though your device is rooted, android environment won't allow applications to execute 'sh' commands.
As android security architecture says, applications run within a secured execution space inside Application Sandbox, sh execution can bypass this security.
If there are any exceptional cases where few devices allow 'sh' execution, well... OEM's needs to be reviewed again.
Answer
Maybe you can try the method that I have specified and check whether it works
http://forum.xda-developers.com/showthread.php?t=2620394
krutle said:
Ok so it sorta worked.
I used the cd command to get to the file.
I used su command.
Then i typed sh script.sh .
Nothing happened, no echo or anything, just a new line with # on it.
What's happening.
Btw thanks for the replies.
Click to expand...
Click to collapse
the script is already run and no need to type the command again, note: some script files can damage your system if run twice
krutle said:
Hi,
I have made a little .sh script as a test.
But when i use terminal emulator to run it i get the 'permission denied' error even though my phone is rooted. Please tell me what to do to run a .sh file on my phone.
Script:
#!/bin/sh
echo hi
Thanks in advance. Any help will be greatly appreciated.
Click to expand...
Click to collapse
You have to put the script somewhere that it has permission to execute from, copy it to /data/local/tmp first. Then in your terminal run each of these commands;
su
cd /data/local/tmp/
chmod 0755 MyScriptName.sh
./MyScriptName.sh

[GUIDE][ADB]Basic Linux/Unix Commands

Basic Linux/Unix Commands
[HIGHLIGHT] DISCLAIMER - You know the drill. I don't deem myself responsible in case you screw up your phone. Always make a backup if you don't trust yourself and if you know that you screwing up is your forte[/HIGHLIGHT]
Thanks -
mihir287 for his FAQ
sweetnsour for his extensively detailed thread
Shen - advice
Zayed from www.addictivetips.com
http://www.linuxtopia.org
This guide aims to give you a background on some of the linux commands available to you once you obtain an adb shell.
In order to obtain an ADB shell, you must have adb set up on your computer (all ADB really consists of in windows is adb + 2 dlls + adb drivers.
However it makes sense to fully set up the Android SDK if you plan on developing for Android.
You need to install adb or get Terminal Emulator. To install adb and get more info about it visit here.
NOTE = All commands in linux/unix are CASE SENSITIVE.
Shell Commands
These commands are to be typed after typing
Code:
adb shell
In the Command Prompt.
Or, you can proceed normally if you are using a Terminal Emulator.
1. cd - Change Directory
To change to any directory, simply type:
Code:
cd <dirname>
dir name is the path. For instance, to switch to system/etc, type:
Code:
cd /system/etc
'..' will allow you to go back one directory. In our example, typing:
Code:
cd ..
would take you back to /system
2. ls - List Files
To list all the files in whatever directory you're in, simply type:
Code:
ls
pressing enter after, of course. This will list all NON-HIDDEN files/directories.
Code:
ls /system/etc
will list the contents of system/etc
Code:
ls -l
will list all NON-HIDDEN files in your current directory with additional details
Code:
ls -a
will list all files/directories(including hidden) within your current directory
Code:
ls *.extension
will list all the files wit the specified extension in the directory
For example i wanna list all apps -
Code:
cd /system/app
ls *.apk
3. su - SuperUser
The standard adb shell (unless you're on an insecure kernel/ramdisk), will be a non-root shell ($)
To obtain root priviliges (if your phone is rooted), simply type:
Code:
su
on obtaining superuser priviliges, you will be presented with a # symbol, which represent a root shell.
4. chmod - Change Mode
The two most commonly used 'modes' you'll come across in Android are '777' and '755'
These numerical pemissions have different meanings, of course. This can be a little confusing, so I hope this explains it in a simple to understand way.
As you can see, there are three numbers in the following example; 'chmod 755'
So, to break that down: The first number in the sequence, '7', represents the USER (aka, you). The second number in the sequence, '5', represents the GROUP (users who are members of the file's group) and the third number, '5' represents OTHERS (aka, everyone else).
Now to explain why they are 755, and the significance of those numbers, see the following list:
7 Full
6 Read/Write
5 Read/Execute
4 Read Only
3 Write/Execute
2 Write Only
1 Execute
0 None
So in the instance of 777, you can see that USER, GROUP and OTHERS have FULL access to the file in question.
To change the permissions of one file (apns-conf.xml for example, type:
Code:
chmod 777 /system/etc/apns-conf.xml
To change the permissions of all files in a directory, use the -R (recursive)option:
Code:
chmod 777 -R /system/etc
5. pwd - Print Working Directory
Couldn't be more simple. if you want to find out which dirctory you're currently in, type:
Code:
pwd
and press enter.
6. cat - Concatenate (evolved from)
The cat command if used to list a file's contents on your screen; or pass via pipeline to use with other Linux commands.
cat /proc/mounts
will output the various mount points in your android OS.
Note that there are many other uses for the cat command.
7. mount - remount as r/w or r/o
The mount command is used to mount a directory as r/w[Read-Write which allows you to modify it] or r/o[Read-Only]
Mount info -
Code:
mount
To mount as r/w and r/o respectively use -
Code:
mount -o remount rw <dirname>
or
mount -o remount ro <dirname>
To mount /system i will use
Code:
mount -o remount rw /system
or
mount -o remount ro /system
8. cp, mv, rm - Copy, Move, Remove
Use the 'cp' and 'mv' commands to copy, move a file/directory respectively and 'rm' to remove one. They are equivalent to copy+paste and cut+paste and delete
If you are planning to copy/move/remove from your android to anywhere else or viceversa you need to mount as r/w prior to this and mount as r/o after it.
They can be used as
Code:
cp <source> <destination>
or
mv <source> <destination>
or
rm <source>
For example i wanna copy/move/delete my zip file to system/media [after mounting system]
Code:
cp /sdcard/bootanimation.zip system/media
or
mv /sdcard/bootanimation.zip system/media
or
rm /sdcard/bootanimation.zip
9. Auto - Install Applications To SDCard
Type the following -
Code:
pm setInstallLocation 2
10. logcat
A logcat is basically a command to view messages in one of the system logs.
Logcat is the command to view the internal log of the Android system.
Viewing logcat is often the best way - and sometimes the only way - to diagnose a problem.
Dev's always need proper and useful feedback. So if you are testing something, you can always obtain the errors an report back to the dev who in turn can solve your problem efficiently.
Code:
su
logcat > /sdcard/log.txt
Will obtain the logcat to your sdcard as log.txt
Googlers have a sense of humour so even 'lolcat' works identically as 'logcat'
Code:
lolcat
Some dev's require extensive logcat info. To know more about it continue reading here.
ADB Commands
The following commands are to be type in your adb folder directory.
For instance, mine is in C:\android-sdk-windows\platform-tools so i will type
Code:
cd C:\android-sdk-windows\platform-tools
and then proceed with the following code lines
Alternatively you can change your PATH variable
Setting Path on Windows
For Windows XP:
Start -> Control Panel -> System -> Advanced
Click on Environment Variables, under System Variables, find PATH, and click on it.
In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
Close the window.
For Windows Vista/Windows 7:
Right click “My Computer” icon
Choose “Properties” from context menu
Click “Advanced” tab (“Advanced system settings” link in Vista)
In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
Click to expand...
Click to collapse
1. Check Connected Phone
To display list of available devices, type
Code:
adb devices
You will get the following output
Code:
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached 21342737ft6273
where the number indicates your devices serial number usually the one one the back of your phone[needs citation]
2. Login To Android Shell
Code:
adb shell
After pressing enter you will either see '$' or '#'
If you get ‘#’ after typing adb shell, you have already get root access on the phone, no need to type su. Otherwise if you get ‘$’ , type ’su’ to get root access (only for rooted device).
3. Install Application
This command installs the app whose directory is specified by you.
Code:
adb install appname.apk
Note that the name of the application should be without any blank spaces in between. Say i have an app called pes 12.apk, I rename it to pes_12.apk - Also don't miss out the .apk extension
example
Code:
adb install C:\programfiles\pes_12.apk
4. Files From Phone To PC And Vice Versa
For Phone - PC
Code:
adb pull <source> <destination>
For PC-Phone
Code:
adb push <source> <destination>
Example
Code:
adb pull /sdcard/bootanimation.zip C:\programfiles
Code:
adb push C:\programfiles\bootanimation.zip /sdcard
^Self Explanatory
5. Reboot To (Normal/Recovery/Bootloader)
Type the following to reboot normally or to recovery/bootloader respectively
Code:
adb reboot
Code:
adb reboot recovery
Code:
adb reboot bootloader
Some Useful Codes-
I do not know many. If you have any suggestions please do tell me
Type them in line by line and don't type in the '$' and '#'
1. Rooting
Code:
adb devices
adb shell
$ echo 1 > /data/local/lge_adb.conf
Then you can proceed onto using SuperOneClick
2. Installing Custom Recovery
The recovery.img and flash_image files must be in /sdcard
Code:
adb shell
$ su
# mount -o remount rw /system
# cat /sdcard/flash_image > /system/xbin/flash_image
# chmod 755 /system/xbin/flash_image
# flash_image recovery /sdcard/recovery.img
# mount -o remount ro /system
# exit
$ exit
adb reboot recovery
Will add FAQ later if needed
Ohh ! so much detail !
As far as i can see its very well written.
Will read tomorrow
Awesome guide! Thank you!
Sent from my LG-P500 using xda premium
MaKTaiL said:
Awesome guide! Thank you!
Sent from my LG-P500 using xda premium
Click to expand...
Click to collapse
Glad You Like It
Rutuj said:
Glad You Like It
Click to expand...
Click to collapse
I knew Half of this but the way you put it is basically noob written and easy to follow through. Thumbs up for this guide. I wish someone posted this when I first started playing with android. This would've made life easier for me >.<
Sent from my LG-P500 using XDA App
purple1 said:
I knew Half of this but the way you put it is basically noob written and easy to follow through. Thumbs up for this guide. I wish someone posted this when I first started playing with android. This would've made life easier for me >.<
Sent from my LG-P500 using XDA App
Click to expand...
Click to collapse
This doesnt make life easier, if one command wrong, bam! A fresh brick phone...
Sent from my Nexus One using Tapatalk
and how to uninstall app from adb ?
nice guide btw
Great guide. I would suggest you add details on how to get logcat as well, since many developers will find it useful if users post logs of bugs
Code:
su
logcat > /sdcard/log.txt
mihir287 said:
Great guide. I would suggest you add details on how to get logcat as well, since many developers will find it useful if users post logs of bugs
Code:
su
logcat > /sdcard/log.txt
Click to expand...
Click to collapse
Thanks !
Added !
Bump !
Thanks commands working perfect.
Tell me onething..how did you get time to type all of this?
royalflusher9 said:
Thanks commands working perfect.
Tell me onething..how did you get time to type all of this?
Click to expand...
Click to collapse
Compiling info takes time.
Type time = 30 mins
Nice thread for n00bs like me !!!! Thanks very much!!!1
Bumping this thread
very helpful guide ......
thanxxxx

Terminal and SSH access

As a new Android user but experienced in Linux I wanted to explore the command shell. I've wanted to change passwords and have use the usual commands I would normally expect to be available.
I'd like to share my experience for any other new user and open the discussion for for additions and corrections. What I say here works on a Galaxy Mini S5570 but should be pretty generic. This really does need the phone to be rooted or much will be inaccessible.
Comparing 3 methods Terminal Emulator, DigiSSHD which is run from DigiControl and SSHDroid.
There is no concept of a root password as access is granted via superuser app. When you connect your id is set from the id of the app you are using to connect.
The simplest connection is via Terminal Emulator. It requires no network connection and gives direct access to the phone. The first thing is that you have no home directory so you are dumped into / the top directory. There is no .bash_profile, .bashrc or .profile so it's customisation is not obvious.
I tested SSHDroid and DigiSSHD using wi-fi. My ssh client was the excellent Putty on Windows7.
As default SSHDroid uses port 22 while DigiSSHD uses port 2222.
For a rooted phone SSHDroid has user "root" with password "admin". This is not your device's root password. You can think of it as an access password for SSHDroid. This access password can be changed in the options for SSHDroid. It is a good idea to do so stop others getting in just as you have done.
You arrive in a home directory data/data/berserker.android.apps.sshdroid/home and inside there you will find a .profile file so you can do some customisations there. The good news is that all the usual linux functions are available in ~/bin via the PATH variable it gives you and its own busybox.
Neither Terminal Emulator nor DigiSSHD give you these functions but this is a good way to do it.
Terminal Emulator by default gives you a PATH which includes /data/local/bin. This is set by Initial Command in the Preferences but I'm taking it as it is.
There was no directory /data/local/bin. This is good because we can create it and put our own stuff in there wihout having inconsistent clashes. Create it with the correct permissions. Copy the permissions of another directory in the path in my case I used /system/bin. To check the permissions:
cd /system
ls -l
The permissions were for bin are drwxr-xr-x with Owner/Group of root and Shell. So create the new directory.
cd /data/local
mkdir bin
chmod 755 bin
chown root.Shell bin
Now you can start creating your utilities. Before you do check that each is not already available by trying to run it. It might already be provided by Toolbox. To see what busybox can do type
busybox --help
To get your utility, assuming it is available in busybox create a symlink to busybox with the name of the utility. As an example this is how to create 'more' and 'less' and the standard 'vi'
cd /data/local/bin
ln -s /system/xbin/busybox more
ln -s /system/xbin/busybox/less
ln -s /system/xbin/busybox/vi
You can carry on activating your favourite utilities. Remember to check if it already there first and NEVER forget you are doing all this as root so take care...
Why do it this way and not use the functions provided by SSHDroid? Well as an ordinary user you may not have access and if you decide to uninstall SSHDroid you would probably lose it.
Now for DigiSSHD. The default user is android with a password of 123. I have not found how to change this yet so comments welcome. Your home directory will be something like /mnt/sdcard/Android/data/org.digimead.digi.ctrl/files/var/1d7a337e-7cf8-4b28-8039-baa894f7185f
There is a .profile file in your home directory that you can edit and add the line
export PATH=/data/local/bin:$PATH
This will give you access to the same utilities (so same versions) as you have with Terminal Emulator.
That's it. The rest is up to you. Which utilities you chose and which command line app suits you. I doubt that all the busybox functions will work on an Android system because it is not an ordinary Linux.
Which is better, SSHDroid or DigiSSHD? I don't know. I'll leave that for others to comment.
Are you the admin on this other site? Terminal and SSH Access Just curious as this is exact copy/paste post from that post with no links or attributions.

Easy terminal emulator startup.

Well currently i am using jackpal.androidterm emulator and always needed to type 2 commands bf new entriws would be allowed.
Namely the following commands. 1. startup su by running su command. 2. mounting r/o to r/w of /system mount blabla.
Well here comes in my helpfull hint (^o^)
go into settings menu and alter the startup command send to shell into this line of text.
su && busybox mount -o remount,rw /system
now ur emulator will always start with su approved (#) and /system
running as r/w mounted. u could add more commands as long as u
add these symbols btween commands && . take note there aint spaces inbetween or it wont work.
ohh and easy command help for terminal u get by typing the next
line of text. replace the COMMAND with desired item.
busybox COMMAND --help
use the busybox command on its own to see commands it can use..
hope helps someone who wanna know more about busybox and terminal emulator commands.
And if u wanna use bash scripts just add it to the startup command.
su && busybox mount -o remount,rw /system && bash
u need bash installed of course, and i used an alternate path so the program stays clean. i used /data/local/foldername to store my bash, busybox, android toolbox so they wouldnt get corrupted. the android toolbox i found in my /system/bin and i put bash and busybox into /system/xbin and all seems to work fine.
Sent from my GT-P3110 using XDA Free mobile app

Categories

Resources