Running Shell Command? - G1 Android Development

Hey guys. I was wondering...
Is there a way to run a shell command via an application? Meaning, I have a application and once the user clicks a button, i want that that to execute a shell command. For example, if i wanted it to restart the phone, i would want 'reboot' or 'restart' to be executed.
Thanks!!

yes and no.
It can be done, the terminal app does it. but that uses a non-public api and thus you couldn't write such an app using the sdk but if you downloaded the android source code and got a full build enviroment up and running the command line tools that uses could build apks with private api calls.

SilentMobius said:
yes and no.
It can be done, the terminal app does it. but that uses a non-public api and thus you couldn't write such an app using the sdk but if you downloaded the android source code and got a full build enviroment up and running the command line tools that uses could build apks with private api calls.
Click to expand...
Click to collapse
So it can be done, but I will not be able to use the SDK? I have use the Android Source Code?

herbjr said:
So it can be done, but I will not be able to use the SDK? I have use the Android Source Code?
Click to expand...
Click to collapse
Don't see why you would need the Android source. Examine lines 198-205 in the superuser source code:
http://code.google.com/p/superuser/...koushikdutta/superuser/SuperuserActivity.java

Hmm, interesting. The Android Terminal uses "android.os.Exec" (to pipe to and from "sh") which does not exist in the SDK's class library (but does exist in the framework jar on the device) I wonder why they hide that but allow Runtime.Exec.... well that bodes well for the Terminal rewrite I wanted to do, thanks.

Related

Android SDK 1.5 trouble in Linux

I am a new to using Linux, I just downloaded the SDK 1.5 and I am having some trouble getting the tools to work properly. For example. If I try to open the emulator it will just sit there and do nothing. I cannot get adb to work either. I set it up / the instructions. Any ideas on what I am missing? Thanks
easiest way to fix the adb problem is to move your adb command that is included in the SDK into your /usr/bin or /bin directory. if you have a problem with either of those then type cd ~/<sdk>/tools followed by ./adb the "./" tells the phone to run the command in the current directory, otherwise you could just type the directory to adb to run it i.e. ~/SDK/tools/adb that's all you need. as far as the emulator i have no idea because i have never gotten it up and running properly
How do I add the ADB command to usr/bin?
You can do as followed:
- Run the Terminal
- cd to your sdk/tools directory
- Run these command:
Code:
#./adb kill-server
#./adb devices
If you see your HTC has been remounted, it's done!
sudo mv ~/sdk/tools/adb /usr/bin/adb
tubaking182 said:
sudo mv ~/sdk/tools/adb /usr/bin/adb
Click to expand...
Click to collapse
Got it thanks for your help! I still can't get the emulator to work. Oh well Thanks again
What version of Linux? Are you using 64 Bit? What is the result of typing
Code:
java -version
You created the AVD, right?
What do you get when you type:
Code:
android list avd
stovenator said:
What version of Linux? Are you using 64 Bit? What is the result of typing
Code:
java -version
Ubuntu version 9.04 & 64 Bit
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)
You created the AVD, right?
What do you get when you type:
Code:
android list avd
Click to expand...
Click to collapse
bash: android: command not found
They made a change in 1.5 SDK that you must specifiy the virtual device you want the emulator to run. if you just double click on "emulator", it will print the error to console and exit.
So first cd to the tools directory of the sdk and type android[return]
you will be given the commands that android (the program) will accept. you can also do this for emulator.
Great!! Everything is working well now. Thanks for everyones help!!
How Do I get fastboot working in Ubuntu?
jordanjf86 said:
How Do I get fastboot working in Ubuntu?
Click to expand...
Click to collapse
http://andblogs.net/fastboot/
fastboot is included in the 1.5 sdk, once you get adb working it should start working as well.
billc.cn said:
fastboot is included in the 1.5 sdk, once you get adb working it should start working as well.
Click to expand...
Click to collapse
Actually it doesn't seem to be in the Linux 1.5 SDK; I had to build it. It's in the Windows SDK, though. Kinda weird.
Android SDK 1.5 emulator trouble in windows
hi i m new to xda and to android i m not tech savy
i install sdk 1.5 i try ddms it works good what when i try to lanch emulator nothing happnes and i try by going in command promt im getting this error can any one help me out in this
C:\Documents and Settings\jass>emulator
emulator: ERROR: You did not provide the name of an Android Virtual Device
with the '-avd <name>' option. Read -help-avd for more information.
If you *really* want to *NOT* run an AVD, consider using '-data <file>'
to specify a data partition image file (I hope you know what you're doing).
karan09 said:
hi i m new to xda and to android i m not tech savy
i install sdk 1.5 i try ddms it works good what when i try to lanch emulator nothing happnes and i try by going in command promt im getting this error can any one help me out in this
C:\Documents and Settings\jass>emulator
emulator: ERROR: You did not provide the name of an Android Virtual Device
with the '-avd <name>' option. Read -help-avd for more information.
If you *really* want to *NOT* run an AVD, consider using '-data <file>'
to specify a data partition image file (I hope you know what you're doing).
Click to expand...
Click to collapse
First, this is the wrong thread for such a question. This thread is about SDK issues in Linux, and you're asking about using debugging tools in Windows.
Second, if you say yourself that you are "not tech savvy", then I'm not quite sure why you are wanting to play with the SDK tools. I don't mean this in a derogatory way; I'm just not sure what it is that you're trying to accomplish.
That said, Android dev docs can be found here, and information specifically about the emulator is here.
- Chris

Linux Working on Android

(I'm reposting this under a different title so web searches will bring it up)
I can get Ubuntu 11.04, 11.10 & Debian 6 to mount repeatedly in all sorts of ui updatable configurations using this information:
http://www.nerd65536.com/2011/07/ins...version-2.html
It's a friggin Christmas Miracle! Can't tell you how much time I've wasted working this out, and it all boils down to the sh and run scripts.
So, without further ado, here goes.
!!Make sure you're rooted!!
!!The quotes just tell you what to type. Don't type them!!
1.
Download one of the three builds on the website listed above (or build your own, it should work fine). Extract it from tar.bz2, they should all extract to a linux file, this includes the necessary scripts. Put it on the sd-card on your phone.
2.
Download the new scripts that (Nerd) listed found here: http://ohm.nerd65536.com/android-lin...latest.tar.bz2
And extract them. You'll have another file that says linux. Open it, take the three files inside (install.sh, root-scripts & scripts) and paste them in the linux folder you moved to your sd-card. They will overwrite the ones currently there. These scripts work for sgs4g, the originals did not.
3.
Install the latest BusyBox in both xbin and .bin if it's not already installed (must be rooted), Latest is 1.19.3. Make sure Outside Sources and USB debugging are both enabled in your settings menu. Open your Superuser App and update binaries.
4.
Download a terminal client, like Better Terminal Emulator or Android Terminal Emulator. I use the first. The terminal needs to run the commands as root, especially the linux vnc command as it didn't want to work for me no matter if I started by typing su. Better Terminal Emulator has a check box to always start in root.
5.
Open up your terminal emulator and type su if you are not rooted there. Then change directory to the linux file on the sd-card. run the sh file there.
Like this:
"su"
"cd /sdcard/linux"
"sh install.sh"
If it works, the resulting dialog in terminal won't throw up any problems.
6.
Get back to / on sd by typing in terminal:
"cd /"
You should then have a: / # prompt, which means you are still rooted.
Enter:
"linux"
Which should result in a: [email protected]:/#
This means Linux is running. Congratulations. It should continue to run unless you shut down your phone.
7.
Download a VNC client, like Android VNC Viewer (free) or Remote VNC Pro, which I use. Add a new entry in it, with the following settings:
Host: localhost
Port: 5901
Password: cheesecake
Color: 24-bit
Name: Linux
When that's done save if you can or back out if you can't, and go back to your terminal emulator.
8.
It should still say: [email protected]:/#
If it doesn't, fine, if it does, just go back to root prompt by typing:
"exit"
Which should get you: / #. Then type:
"linux vnc"
Which should run itself and mount the chroot environment. It should tell you your new 'X' desktop is localhost:1, and have a: / # prompt again.
It might also ask you for a password, if so then put whatever password you'll remember in that's longer than 6 characters and verify it. This only happens once.
9.
Go back to your VNC client and if you entered a password in step 8. then edit your listing to your password instead of cheesecake, if not then don't.
Click on the Linux link and BAM! (shameless Emerilism), you're at your Linux desktop which should be running a iceWM desktop interface, which is fast. The LXDE desktop is nicer and if you want that then go into you're terminal and get into the linux shell by typing:
"linux"
And then switch to LXDE by typing:
"apt-get autoremove icewm- lxde+"
Which will run through the removal/ installation, and verify you want to download the <400mb files. Type:
"y"
And give it time to finish. When finished, just go back to your VNC client and hit Linux again, and you will have a nice looking functional desktop, with a cpu load graph on the bottom. I tried using Gnome desktop and Unity 2d, but both of these would install and not fully run with all options. They are heavier and slower, but cool non-the-less. Let me know if anyone has luck with these on Android.
Notes-
You only have to type "linux vnc" once in terminal to start linux every time you boot your phone. Otherwise, just open your VNC client and click on Linux to use it. Easy!
You will want to update and upgrade your linux after install, do so by typing in terminal:
"apt-get update"
"apt-get upgrade"
Also, you might run across a problem if you try to add-apt-repository, that's because that python command is not present. To use it, enable by typing:
"apt-get install python-software-properties"
Also of note, the downloadable linux builds are sized to about 2.15gig on your sd, which is big enough for most. There is a way to resize them which I tried but it gave me trouble in loading. I will try again and see if I can get it to work.
Here's the link from Dangermouse:
http://www.androidfanatic.com/commun...atid=9&id=1610
Thanks to Nerd65536 for the info, write-up and files. He fixed my problem.
You might want to put quote or code tags around all the commands to make them easier to see and read, but good guide! I'll try it out soon since I haven't gotten any linux build to run on my phone in a good while.
Thanks for the post!
I wrote the post noob-style to make it easy for beginners to follow, as I've had to search and test forever to find information that works.
Let me know if you have any problems, I'd be happy to assist. Don't expect you'll have any issues with your knowledge of the os. It works pretty well on the Android system, fun to use.
wasn't this posted ages ago?
No, it's a bleed over from a question post I made under Q&A a week or so ago. I threaded this because I had such a hard time finding a thread with working steps for the Galaxy S under google search. There's not that much new from this post http://www.nerd65536.com/2011/07/in...showComment=1323566336074#c553594301247543088 by Nerd65536 (which took me forever to find and was the only one that worked). Other than that, just a few of my own thoughts and hints on the process.
krylon360 said:
wasn't this posted ages ago?
Click to expand...
Click to collapse
meant to quote not thanks, but anyways, to answer.
There has been a few times this has been posted, but its been many months and this seems like the first the issues have been sorted.
Sent from my SGH-T959V using Tapatalk
Ok, a little more use of Linux builds on my phone and I'm starting to understand why it does or does not work.
Certain kernel builds seem to work well, others not at all. Most of the kernel's I've tried have been problematic, and trying to install the .sh file will fail.
When you install your new kernel (or on your existing one) you need to open your Superuser app which should be there if your phone is rooted. There is a button to update binaries, and they need to be updated. Some builds don't seem to let this work easily and give failure notifications.
Make sure Outside Sources is enabled and USB debugging is too, both are in the settings menu.
Use BusyBox installer to install in both the .bin and .xbin directories, this will not cause any conflicts (or hasn't yet . If this gives you an error, and it will if Superuser did, then either usb debugging has not been selected or the kernel is not playing nice.
Ok, so this kernel by RaverX3X will work for linux, I'm on it now:
http://forum.xda-developers.com/showthread.php?t=1305145
(Thanks for this)
Oh yeah, and Back|Track5 Linux is working too
Fixing the packet injection for the Broadcom now.
sconsylman said:
Oh yeah, and Back|Track5 Linux is working too
Fixing the packet injection for the Broadcom now.
Click to expand...
Click to collapse
. Keep us posted on that. Should be pretty handy.
Wait. why do we need LInux to run on our phone?
Can someone explain?
Android doesn't come with most of what this has:
http://www.backtrack-linux.org/
I know, but why do we need it?
Enlighten me
airfluip1 said:
Wait. why do we need LInux to run on our phone?
Can someone explain?
Click to expand...
Click to collapse
I've seen this comment on every single thread online regarding Linux on Android. It's a joke right?

Is there an assembler and linker included in Android?

From an ADB shell, I tried running:
Code:
as helloworld.s -o helloworld.o
but it seems that the GNU assembler is not included in Android.
I also tried it from a root shell on the device.
I was just wondering if anyone knows whether there is an assembler and linker included on Android? If not, is it possible to install one?
Thanks.
Wondering why Android OS should have included GNU assembler ( GAS ) ?
BTW: GNU assembler for ARM exists
In order to compile your assembly program, you will need the Android NDK, the Native Development Kit, which contains a set of compilers and build tools for the ARM platform. You can get download it directly from the official site, or install it through Android Studio.
But please note that this is for Windows, Mac or Linux instead of Android OS.
James_Watson said:
In order to compile your assembly program, you will need the Android NDK, the Native Development Kit, which contains a set of compilers and build tools for the ARM platform. You can get download it directly from the official site, or install it through Android Studio.
But please note that this is for Windows, Mac or Linux instead of Android OS.
Click to expand...
Click to collapse
I was hoping to find one that will run on Android itself.
OK so as far as I can tell, there is no assembler or linker included on Android, since apps are created from x86_64 machines and then installed on the device. So I went with installing binutils via Termux.
- Installed f-droid
- Installed Termux via f-droid (The version in the play store has an out of date sources.list and the app hasn't been updated since September. Evidently the Termux dev group is releasing via f-droid now, not via the Play store.)
- From Termux, ran the following:
$ pkg update
$ pkg install binutils
This allowed me to use the GNU assmbler (as) and linker (ld).
Just leaving this note here in case anyone else wants to do the same thing and finds this thread.

Is there any version of ADB rewritten in C++?

Yes, the question I'm asking is in the title. Context: I want to use certain adb commands (such as shell) to connect and get some status of the BlueStacks emulator. However, using the system command in C++ requires the platform tools to be put in the same directory as the C++ program, which is kinda large in size if I wanted to distribute it.
Don't know of any.

[Vulnerability] Bluestacks root access via adb

On GitHub: https://github.com/KDVB/BlueStacks-ADB-root-access​​Disclaimer​For informational purposes only. The author does not call for further actions. Created to warn users who use this product
Background​ADB (Android Debug Brigde) - is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps. adb provides access to a Unix shell that you can use to run a variety of commands on a device.
Research Walkthrough​For default, in Bluestacks, ADB port is open, but we can't to use shell command (output "error: closed")
Searching for information in the emulator files found the following file ".adbcmd" in Root.vnhd image. Path to file "dataFS\downloads". In this file we can see adb commands that we can run without connection to shell
For example, "getprop" command, that gives us information about android propetries
As we can see, interaction with android shell is working. So, I think "if I can interact with unix shell, maybe tryed to use pipe operators" and pwn i can interact with file system, but with shell-user privilage.
As a result i continue my search to find su command to get root access. SU file is in "/boot/android/android/system/xbin/bstk/su". I tryed pipe operator to get root access, but get error and shell didn't open(
After that i tryed list terminator ";" and it works. I get root shell
Result​Bluestacks have this vulnerability and people involved in its development know about it and are engaged in its elimination.
The real test is to see if you can actually do anything. Sure, you've ID'd as root, but will it actually let you change anything?
V0latyle said:
The real test is to see if you can actually do anything. Sure, you've ID'd as root, but will it actually let you change anything?
Click to expand...
Click to collapse
Thanks for your reply. Actually you can change in current session, but when emulator reboot, all changes remove. If we speak about system folders. In sdcard folders changes save. Sorry, I didn't mention it in the post.
When i searched information on the virtual disk, i found some scripts that build a system. That takes information from .conf files, but that works only for local work. For example, when you using OpenVPN Connect that port still open and you can interact with it.

Categories

Resources