Help converting Tasker action to ADB shell am command - Android Q&A, Help & Troubleshooting

My goal is simple: Send a command through ADB to bluestacks (which i got working) to FakeGPS (which Is responding) to set GPS location to a specified lat/long (part that doesn't work)
First, background info
my environment is bluestacks 2, with FakeGPS (this one) installed as system app using LuckyPatcher
Setting a location directly in FakeGPS does work corectly - Good
I saw this on the FakeGPS page linked above:
FAQ for integration with Tasker only (Example is lat 18.89768D long: -55.0365D) :
Create a new task and add Action -> Misc -> Send Intent
2. Edit:
- Action: com.incorporateapps.fakegps.ENGAGE (to Stop add a new task and use com.incorporateapps.fakegps.STOP)
- enter 1st extra: lat:18.89768D
- enter 2nd extra: lng:-55.0365D
the "D" at the end is important so add it!
- Target: Service
Click to expand...
Click to collapse
I tried it out with Tasker, and lo and behold, Tasker can indeed send intents to FakeGPS and FakeGPS will set the location correctly - Good
What I want to do is send an intent through ADB (source information here) so I can set the FakeGPS location inside bluestacks from a windows console window. I have gotten it to the point where FakeGPS will respond, but I cannot get it to go to the lat / lng I give it. IT always either does nothing, or goes to lat:0 lng:0.
Commands I have tried:
Code:
Connect to bluestacks:
adb connect 127.0.0.1:5555
adb -s 127.0.0.1:5555 shell am startservice -a com.incorporateapps.fakegps.ENGAGE --ef lat 41.0050073D --ef lng -28.4530577D
adb -s 127.0.0.1:5555 shell am startservice -a com.incorporateapps.fakegps.ENGAGE --ef lat 41.0050073 --ef lng -28.4530577
adb -s 127.0.0.1:5555 shell am startservice -a com.incorporateapps.fakegps.ENGAGE -e lat 41.0050073D -e lng -28.4530577D
adb -s 127.0.0.1:5555 shell am startservice -a com.incorporateapps.fakegps.ENGAGE -e lat 41.0050073 -e lng -28.4530577
adb -s 127.0.0.1:5555 shell am startservice -a com.incorporateapps.fakegps.ENGAGE --ef lat 41.0050073D --ef lon -28.4530577D
adb -s 127.0.0.1:5555 shell am startservice -a com.incorporateapps.fakegps.ENGAGE --ef lat 41.0050073 --ef lon -28.4530577
adb -s 127.0.0.1:5555 shell am startservice -a com.incorporateapps.fakegps.ENGAGE -e lat 41.0050073D -e lon -28.4530577D
adb -s 127.0.0.1:5555 shell am startservice -a com.incorporateapps.fakegps.ENGAGE -e lat 41.0050073 -e lon -28.4530577
I've also tried a few other things, but none of them got any sort of response from FakeGPS. From what I read in the intent documentation and the blurb quoted above, one of these SHOULD work, but none of them do. However I KNOW that what I want to do is possible because Tasker can successfully set the location. Can someone help me get this working from ADB?

I sadly don't know exactly *what* is required to get intents to shell form..
(If anyone knows: Please enlighten us. Using tasker for all intents is a pain in the ...)
But.. you could use XPosed Edge's Export "as broadcast command" option and call that via windows.

Related

[Q] Retrieve default gateway of device

Hi,
I need to get the default gateway of a device on my application. I am coding in native application in android. Here is my current code to get the default gateway.
Code:
static int get_default_gateway(char *def_gateway, int buf_size)
{
FILE* pipe;
char buffer[128];
char result[2049];
char cmd[] = "netstat -r | grep ^default | awk '{print $2}'";
pipe = popen(cmd, "r");
if (!pipe) return 1;
memset(result, 0, sizeof(result));
while(!feof(pipe)) {
memset(buffer, 0, sizeof(buffer));
if(fgets(buffer, 128, pipe) != NULL)
{
strcat(result, buffer);
}
}
pclose(pipe);
memset(def_gateway, 0, buf_size);
strncpy (def_gateway, result, buf_size );
return 0;
}
It works on my LG p500 but on some devices it doesn't return anything.
My question is this. Does popen() works on android? I read somewhere that it is not included in bionic.
And is there any other method to get the default gateway? I need it to be written in C and not java.
Thank you
I think I found the problem. Maybe grep and awk is not working on their phone. Its working on my phone since I created links to awk and grep to busybox.
Can someone confirm this if awk and grep is not working on a stock rom without creating links to busybox?
Thanks
On a stock ROM there is no busybox too. There is toolbox instead and it does not support much commands. When I first ran a shell on Android, was unpleasantly surprised when I didn't find some things like 'find' and 'grep' on a "Linux-based OS".
Here is complete list of the links to the toolbox on the Android 2.2 emulator: cat chmod chown cmp date dd df dmesg getevent getprop hd id ifconfig iftop insmod ioctl ionice kill ln log ls lsmod mkdir mount mv nandread netstat newfs_msdos notify printenv ps reboot renice rm rmdir rmmod route schedtop sendevent setconsole setprop sleep smd start stop sync top umount vmstat watchprops wipe. On my HTC Wildfire (with a stock Android 2.2.1) there is almost the same. The only difference is: reboot on HTC is a separate binary and there is additional link to toolbox here - strange chownto command.
praetorian droid said:
On a stock ROM there is no busybox too. There is toolbox instead and it does not support much commands. When I first ran a shell on Android, was unpleasantly surprised when I didn't find some things like 'find' and 'grep' on a "Linux-based OS".
Here is complete list of the links to the toolbox on the Android 2.2 emulator: cat chmod chown cmp date dd df dmesg getevent getprop hd id ifconfig iftop insmod ioctl ionice kill ln log ls lsmod mkdir mount mv nandread netstat newfs_msdos notify printenv ps reboot renice rm rmdir rmmod route schedtop sendevent setconsole setprop sleep smd start stop sync top umount vmstat watchprops wipe. On my HTC Wildfire (with a stock Android 2.2.1) there is almost the same. The only difference is: reboot on HTC is a separate binary and there is additional link to toolbox here - strange chownto command.
Click to expand...
Click to collapse
Thanks for posting the complete list of commands
Listed commands are only those that implemented by 'toolbox'. There are also some more: for example sh, gzip, ping and others. You can see them all by doing
Code:
ls /sbin /system/bin /system/xbin
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums
Moving to Q&A

[Q] [Root] Wrote a script for mac users, need someone to proofread it.

Hi all,
I'm relatively new to shell scripting and wrote a script I think will work for mac users (yes there are a few of us). I just need someone to proof read it to see if it makes sense and if it will work for the LGOG.
Code:
#!/bin/bash
echo '''
Root LG Optimus G - by Choimobile.vn
Remember. Rooting is dangerous business. XDA and the
authors of the root are not responsible for bricked
devices, damage, poor operational skills, sudden self-
awareness of devices, or anything else. This is at your
own risk. Now get rooting and stay hacky!
1. Enable USB Debugging and Installation from Unknown sources.
2. Connect your phone to your computer.
Cafe.ChoiMobile.vn
Re-written for Mac and Translated to English by bebop_'''
function choice {
set nxt=0
set ric=0
echo Press 'y' to root or 'n' to exit:
set -p type=your choice
if [%type% == y] then function test
if [%type% == n] then exit
}
function test {
echo 'Testing for Device'
stuff/adb-mac wait-for-device
stuff/adb-mac pull system/app/Backup-Restore.apk > null
stuff/adb-mac pull /system/bin/ric > null
if ric
then set (ric = 1)
if ric == 1
then function rootoptimus
else exit
}
function rootoptimus {
echo 'Device will now root. Please be patient, this may take a while'
stuff/adb-mac wait-for-device
echo Pushing Busybox.
stuff/adb-mac push stuff/busybox /data/local/tmp/.
echo Busybox loaded
echo 'Pushing Superuser'
stuff/adb-mac push stuff/su /data/local/tmp/.
stuff/adb-mac push stuff/Superuser.apk /data/local/tmp/.
stuff/adb-mac shell chmod 755 /data/local/tmp/busybox
stuff/adb-mac push stuff/ric /data/local/tmp/ric
stuff/adb-mac restore stuff/fakebackup.ab
stuff/adb-mac shell "while ! ln -s /data/local.prop /data/data/com.android.settings/a/file99; do :; done" > NUL
stuff/adb-mac reboot
stuff/adb-mac wait-for-device
echo Now begining root process
stuff/adb-mac shell "/data/local/tmp/busybox mount -o remount,rw /system && /data/local/tmp/busybox mv /data/local/tmp/su /system/xbin/su && /data/local/tmp/busybox mv /data/local/tmp/Superuser.apk /system/app/Superuser.apk && /data/local/tmp/busybox cp /data/local/tmp/busybox /system/xbin/busybox && chown 0.0 /system/xbin/su && chmod 06755 /system/xbin/su && chmod 655 /system/app/Superuser.apk && chmod 755 /system/xbin/busybox && rm /data/local.prop && reboot"
echo 'Device is now rooted. Enjoy your liberation.'
}
I'm still more or less in the phase of "I have no idea what I'm doing". I ran it by a guy a work with and he said it looked okay. Anyone want to take a closer stab at this? I'd appreciate it.

[HOW TO] Install/Run Android SDK 64 Bit Native on Device

I learned about this here... http://fieldeffect.info/w/NativeCompileSDK
You can install an i386/x86_64 chroot within your existing Debian chroot using qemu-user-static to run the Android SDK on your Android phone/tablet/phablet.
1.
Get yourself a debian chroot, I recommend at least 2gb. I use DebianKit from market.
2.
You will need a X11 desktop environment and a VNC client on your device. I use androidVNC from market.
Here is my working example...
Start your Debian chroot/environment and do...
apt-get install openbox openbox-themes obmenu obconf menu menu-xdg xdg-utils xfonts-base xfonts-terminus* nautilus terminator lxappearance gmrun leafpad man-db hicolor-icon-theme tightvncserver tint2
That gives you a window manager, fonts, filebrowser, terminal emulator, text editor, theme manager, taskbar, and a VNC server.
Now lets get some GTK engines and libraries....
apt-get install gtk2-engines-auroa gtk2-engines-murrine gtk2-engines-oxygen gtk2-engines-pixbuf libgtk2.0-bin gtk3-engines-oxygen gtk3-engines-unico libgtk-3-bin
Now 7zip to handle zips and archives comfortably(put non-free in your apt sources.list)...
apt-get install p7zip p7zip-full p7zip-rar zip unzip
##The Android SDK manager, qemu, and multistrap##
apt-get install ant file openjdk-6-jre openjdk-6-jdk qemu-user-static libswt-gtk-3-java libswt-cairo-gtk-3-jni
3.
Now we can build a small x86_64 rootfs using multistrap
multistrap can use a config, have mine...
http://db.tt/hS5j3wg
Copy multistrap.conf straight into your working(pwd) directory....
cp /sdcard/Download/multistrap.conf .
Do this to avoid multistrap complaining later...
cat multistrap.conf >mstrap
mkdir /data/mnt
Determine size of rootfs for loop image..
du -hs /data/mnt/
Now make an image for x86_64 chroot
dd if=/dev/zero of=/sdcard/64bit.img bs=$(( 0x100000 )) count=YOUR IMAGE SIZE
That byte size makes your image slightly larger than the count value in Mb, for example count=78 will write 82Mb image.
mkfs.ext2 /sdcard/64bit.img
tune2fs -c0 /sdcard/64bit.img
mkdir /data/tmp
busybox mount -o loop /sdcard/64bit.img /data/tmp/
cp -r /data/mnt/* /data/tmp/
umount /data/tmp
rm -r /data/tmp/
rm -r /data/mnt/
mkdir /data/mnt
busybox mount -o loop /sdcard/64bit.img /data/mnt/
5.
Now the environment is set up and mounted, at this point install the SDK
Aim your browser to http://developer.android.com/sdk/index.html
Select "Linux" from "SDK Tools Only", thats the last thing at the bottom of the list.
cp /sdcard/Download/android-sdk_r21.0.1-linux.tgz .
7z x android-sdk_r21.0.1-linux.tgz russosv
7z x android-sdk_r21.0.1-linux.tar
Now we need a couple goodies from http://fieldeffect.info/w/NativeCompileAPK ##--Thanks to russosv from FeildEffect
These are edited from original....
#!/bin/bash
QEMU=/usr/bin/qemu-x86_64-static
64CHROOT=/data/mnt/
case "$1" in
mklinks)
if [ ! -e "./64BIT" ]; then
mkdir ./64BIT
fi
for i in $(file ./* | grep "ELF 32" | awk '{print $1}' | sed s/://g | sed s/[./]//g); do
echo "Moving $i..."
mv $i ./64BIT
ln -s ~/bin/run-64-link $i
done-
;;
*)
$QEMU $64CHROOT/lib64/ld-linux-x86_64.so.2 --library-path $64CHROOT/lib:$64CHROOT/usr/lib:$64CHROOT/usr/share/perl/5.12.4/unicore/lib:$64CHROOT/var/lib:$64CHROOT/lib/x86_64-linux-gnu:$64CHROOT/usr/lib/x86_64-linux-gnu [email protected]
;;
esac
Copy that to run-64, then...
chmod 755 run64
cp run-64 /usr/bin/
One more...
echo $(dirname $0)/64BIT/$(basename $0) [email protected]
/usr/bin/run-i386 $(dirname $0)/64BIT/$(basename $0) [email protected]
Make that run-64-link
chmod 755 run-64-link
cp run-64-link /usr/bin/
5b.
Now launch VNC server
tightvncpasswd
tightvncserver
killall Xtightvnc
cat >.vnc/xstartup<<EOF
tint2 &
terminator &
openbox-session
EOF
tightvncserver
export DISPLAY=:1
6.
Now launch the VNC client I mentioned earlier, should connect with 127.0.0.1:5901 and your password you set.
Go back to terminal or use the one launched on X11 to do...
sh android-sdk-linux/tools/android
Install at least one api.
If all went well you can now go around "debugging" yours and your friends Android devices over wifi now.
For an example, and to see it work do....
svc wifi disable(or enable) ##this turns off/on wifi
setprop service.adb.tcp.port 5555(or -1) ##this turns on/off adb over network
stop adbd
start adbd
adb connect 127.0.0.1(yours) or any other adbd addy listening on your network,
Have fun
Never did a "how to" before, go easy and I'll make corrections and answer things. Thanks for reading. Leave feedback.
Potential necro post but I believe the information is still currently valid and not readily available on searches. I've looked variations of this up for years with no luck until I hit the right search terms.
bump, and thanks.
can't believe there's no comments.
I know it's a slower than real-64-bit-pc method but not all of us have access to new hardware... or pc's. Maybe a novelty, still cool and useful if you've got the time to let the slower hardware compile.
you have preserved the scripts, original link is dead.
here is the Internet Wayback Machine cache of the original circa 2012 for reference.
http://web.archive.org/web/20120502044700/http://fieldeffect.info/w/NativeCompileAPK
appreciate you sharing.

Hacking android, got "system" user, but not root, how to escalate privilege?

Hacking android, got "system" user, but not root, how to escalate privilege?
Hello, i am new to XDA. I am trying to jail-break my android device:
Android 5.1.1, Linux 3.10.49
This device is a rare brand and have no any unlock & flash mechanism.
Currently i have successfully got "system" user (UID 1000) by using a preinstalled DEBUGGABLE system app.
This user can only change /data directory etc, it can not change any file owned by root.
So any help to escalate "system" user to root user will be very appreciate.
the result of command "id":
Code:
uid=1000(system)
gid=1000(system)
groups=1000(system)
1007(log)
1010(wifi)
1015(sdcard_rw)
1021(gps)
1023(media_rw)
1028(sdcard_r)
3001(net_bt_admin)
3002(net_bt)
3003(inet)
3004(net_raw)
3005(net_admin)
3006(net_bw_stats)
3009(qcom_diag)
9997(everybody)
41000(u0_a31000)
context=u:r:system_app:s0
This account can change /data/system/packages.xml etc, but can not change /system/*, nor chown/mount.....
It's CapBound is 0, too strict. And also can not disable SELinux.
Can anyone help me?
----------------------- PS: share how i get system user privilege, maybe helpful to others -----------------------
In a word, just use jdb to attache to the app then print new java.lang.Runtime().exec("sh /sdcard/my.sh").
First, i found a package appeared in Android Device Monitor's debuggable app list, e.x. com.example.app.
Then i use
Code:
pm dump com.example.app
got confirmed it use system UID, then
Code:
run-as com.example.app
but failed due to "Package not found", i don't know why.
Then i try to use JDWP way.
Get the debuggable process ID:
Code:
$ adb jdwp
9424
$ adb forward tcp:8600 jdwp:9424
$ jdb -attach localhost:8600
> threads
group system:
(java.lang.Thread)0x2a86 Signal Catcher ...
(java.lang.Thread)0x2a87 FinalizerWatchdogDaemon ...
...
group main:
(java.lang.Thread)0x2a8d main ...
(java.lang.Thread)0x2a8e Binder_1 ...
...
> thread 0x2a8d
main[1] stepi
>
stepi completed: "thread=main", android.os.MessageQueue.next()、row=145 bci=22
main[1] > print new java.lang.Runtime().exec("sh /sdcard/qj.sh")
There are some files need be upload(adb push .... ) before run the last command.
/sdcard/qj.sh:
Code:
date > /sdcard/log
cp -f /sdcard/busybox /data/ 2>> /sdcard/log || exit 1
chmod 4777 /data/busybox 2>> /sdcard/log || exit 1
(while true; do /data/busybox nc -l -p 7777 -e sh; done) >> /sdcard/log 2>&1 &
echo server OK >> /sdcard/log
/sdcard/busybox:
this file can be found at busybox.net/downloads/binaries/latest, choose ARM7v.
The above jdb command "print new java.lang.Runtime().exec("sh /sdcard/qj.sh")" will create a shell server listening at 7777 port, bridge input/output to sh.
So, to connect to the shell server,
Code:
adb forward tcp:7777 tcp:7777
nc localhost 7777
then in this connection, input shell command.
Sorry: i forgot a very important step: to run the "print new ...." statement, i have to turn on screen, even touch the app so can be trapped into jdb.
---------That's all------------

Running svc in ssh returns Aborted

I've rooted my phone using Magisk
I want to enable/disable Wifi using a shell script
Enabling or diabling works fine using command below
adb -s <serial> shell "svc wifi enable"
But when i start a SSH session svc throws an "Aborted" error
# svc wifi enable
Aborted
Info:
# adb -s <serial> shell "whoami"
shell
# adb -s <serial> shell "which svc"
/system/bin/svc
# adb -s <serial> shell "which sh"
/system/bin/sh
Also tried logging in SSH as user "shell"
Why is svc giving this error, is there a way to fix this ?
ReMiOS said:
I've rooted my phone using Magisk
I want to enable/disable Wifi using a shell script
Enabling or diabling works fine using command below
adb -s <serial> shell "svc wifi enable"
But when i start a SSH session svc throws an "Aborted" error
# svc wifi enable
Aborted
Info:
# adb -s <serial> shell "whoami"
shell
# adb -s <serial> shell "which svc"
/system/bin/svc
# adb -s <serial> shell "which sh"
/system/bin/sh
Also tried logging in SSH as user "shell"
Why is svc giving this error, is there a way to fix this ?
Click to expand...
Click to collapse
I'm facing the same issue here, did you mage to solve it?
estevaofv said:
I'm facing the same issue here, did you mage to solve it?
Click to expand...
Click to collapse
Unfortunately not ...
i have no clue
Hello friend, I just found the solution:
export ANDROID_DATA=/data
just run the above command, it was an environment variable related issue, I found the solution on the link below:
Can not run some CMDs over SSH · Issue #12 · Magisk-Modules-Repo/ssh
PixelExperience_caf_whyred-9.0 Magisk 19.2 Can not run some su CMDs over SSH shell, but over ADB everything is OK The error gives a sign of 'Aborted' Have been using SSH-Module for some time now, s...
github.com
estevaofv said:
Hello friend, I just found the solution:
export ANDROID_DATA=/data
just run the above command, it was an environment variable related issue, I found the solution on the link below:
Can not run some CMDs over SSH · Issue #12 · Magisk-Modules-Repo/ssh
PixelExperience_caf_whyred-9.0 Magisk 19.2 Can not run some su CMDs over SSH shell, but over ADB everything is OK The error gives a sign of 'Aborted' Have been using SSH-Module for some time now, s...
github.com
Click to expand...
Click to collapse
It works now
Great Solution ! Thanks !
I've put it in my ~/.profile to load it automatically at login (using SSH magisk module)
I've upgraded to Android 10 after this svc just gave an rc =1
# svc
1|
# echo $?
1
Fixed is by adding this to my ~/.profile
export PATH=$PATH:/sbin
export ANDROID_DATA=/data
export ANDROID_RUNTIME_ROOT=/apex/com.android.runtime
export ANDROID_TZDATA_ROOT=/apex/com.android.tzdata
# svc
Available commands:
help Show information about the subcommands
power Control the power manager
data Control mobile data connectivity
wifi Control the Wi-Fi manager
usb Control Usb state
nfc Control NFC functions
bluetooth Control Bluetooth service
system-server System server process related command

Categories

Resources