Академический Документы
Профессиональный Документы
Культура Документы
The Grymoire
Remote Input shell scripts for your Android Device, or my screen is cracked
Posted on September 17, 2014
This is how I recovered my data, and what tools I wrote to make this easier. Luckily I had USB
debugging enabled.
I can remotely install applications using GooglePlay, but I needed to do more as some of these
applications require permissions set using the device. And that requires tapping on the (broken)
screen.
I also tried installing Droid VNC Server. I started the server, and I was able to click the mouse
remotely on the screen, but the VCN client on my Linux machine, Remmina Remote Desktop
Client, did not show me the screen, so I was clicking blindly.
In turned out that the best way to remotely tap on the screen was to use adb. This works very
reliably, but is inconvenient because you need to type dozens of dierent commands to do
anything useful.
I rst had to root my device. I used other methods before, but this time I used geohots TowelRoot.
I downloaded the apk, and used adb to install it:
Follow
1 de 9 08-09-2016 09:49
Remote Input shell scripts for your Android Devic... https://grymoire.wordpress.com/2014/09/17/remo...
where xxx and yyy were the coordinates of the spot I wanted to press. By rotating the screen and
trying several XY combinations, I was able to approve this action. But it wasnt easy. I wanted a
better workaround. But compared to other methods for re-rooting the device, this worked
Let me briey describe my XY script, as I use it a lot. My Nexus 7 has a screen of 1200 by 1920. I
could use the touchscreen option to input, mentioned above, but I wanted an easier way to type in
locations. My home screen has a layout of 5 by 5 icons for each application, with a row on the
bottom for the apps on each screen. I wanted to be able to type XY 2 1 to click on the
application that was over 2, and down one, on this grid. My script converts this 2 and 1 location
into the command adb shell input touchscreen tap 300 350
To make my script more exible, the second version allows fractional values, so XY 2 2.5 is the
position on the second column, midway between icons 2 and 3 down (between rows 2 and 3).
Launching SuperSU
To be frank, once I had SuperSU working, I was in good shape. I could remotely log
into the device, execute su, and change the permission of /data/dalvik-cache. Once
this was done, I could use adb pull /data/dalvik-cache and extract nearly everything.
But I wanted to have multiple backups.
I also installed Helium by ClockworkMod. I installed the Linux version on my Ubuntu system.
Once I started the application on my Linux machine, by executing ./run.sh
I launched the Helium app, and I had to grant SU access. I used the command
XY 5 4.5
Follow
2 de 9 08-09-2016 09:49
Remote Input shell scripts for your Android Devic... https://grymoire.wordpress.com/2014/09/17/remo...
using my script XY, described below, I hit the Helium Menu button, and selected the PC Download:
This launched a web server on the Android device, and gave me the URL to type into my browser.
I was then able to backup my applications using my browser on my Linux machine.
These are based on the adb shell input command. There are several variations to this command,
as the usage shows:
If one wanted to, one can type adb shell and then just type combinations of the above input
command. But thats a lot of typing. I wanted something quicker.
Here is the list of bash shell scripts in my collection below. You can combine them, extend them,
modify them, and add new commands. As an example, suppose I want to power up the device.
unlock it, go to the home screen. swipe right, launch the application at 6,2, and turn up the
volume, I can use the following bash shell script
#!/bin/bash
Power
Unlock
Home
SwipeRight
XY 6 2
sleep 5 # seconds
VolumeUp
If you know the locations of your icons, you can automate several scripts using a series of bash
scripts. Or combine scripts together to make more sophisticated scripts.
Follow
3 de 9 08-09-2016 09:49
Remote Input shell scripts for your Android Devic... https://grymoire.wordpress.com/2014/09/17/remo...
Command that start with Get return values that can be used by other shell scripts.
Here is the source of each one. Each one is a small script, and some could be shell functions or
aliases, but I nd it easier to make each one a separate shell script. For conciseness, I dont show
the complete script with the bash invocation and comments. I just show the meat of the matter. As
always your mileage may vary
This is uses a lot because it undoes the last input. If you get the location wrong, this usually
returns you to the previous screen, so you can try a dierent location.
Follow
4 de 9 08-09-2016 09:49
Remote Input shell scripts for your Android Devic... https://grymoire.wordpress.com/2014/09/17/remo...
adb shell dumpsys input | grep SurfaceOrientation | awk '{ print $2 }'
# http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png
I use this for bound checking in my XY script. It returns the maximum X and Y
positions.
The names of the swipe commands can be confusing. I use Left and Right to indicate that I want to
see what is on the Left or Right, not what direction my nger moves.
Follow
5 de 9 08-09-2016 09:49
Remote Input shell scripts for your Android Devic... https://grymoire.wordpress.com/2014/09/17/remo...
SwipeUp Swipe Up
Because you cannot type spaces using the adb shell test commands, I use sed to convert spaces
into %s
#!/bin/bash
str="$@"
nstr=$(echo "$str" | sed 's/ /%s/g')
echo adb shell text "$nstr"
Follow
6 de 9 08-09-2016 09:49
Remote Input shell scripts for your Android Devic... https://grymoire.wordpress.com/2014/09/17/remo...
This is the most complicated routine. The rst version only accepted integer values. I added the
capability to input oating point numbers to get more precise control.
The positioning is a guestimate. I got the maximum X and Y values using GetXY. I divided these
values by the number of icons to get the XDIM and YDIM values, which represent the size of each
icon. (Improvements are welcome). I had to add an OFFSET to compensate for the rst row.
I also added a warning if the requested position is outside of the maximum dimension.
#!/bin/bash
Follow
7 de 9 08-09-2016 09:49
Remote Input shell scripts for your Android Devic... https://grymoire.wordpress.com/2014/09/17/remo...
Future work
If there is interest, I can make these available in a git repository.
References
http://www.tutorialsbuzz.com/2013/11/android-adb-shell-command-device.html
http://stackoverow.com/questions/15278587/pipe-into-adb-shell
http://www.netmite.com/android/mydroid/development/pdk/docs/keymaps_keyboard_input.html
dated but interesting
http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html
http://bryanmarty.com/2013/06/09/remote-control-now-headless-android-phone/
http://developer.android.com/reference/android/view/KeyEvent.html list of key event codes
Like
One blogger likes this.
Related
The new attack vector - HID Extracting shell commands from Cataloging SDHC Cards on Ubuntu
Kali's application menu using a bash script
Gallery | This entry was posted in Hacking, Linux, Shell Scripting and tagged adb, Android, bash, Helium, Nexus 7, Titanium Backup, TowelRoot, VNC. Bookmark the permalink.
4 Responses to Remote Input shell scripts for your Android Device, or my screen is cracked
raul says:
January 8, 2015 at 4:06 pm
Follow
8 de 9 08-09-2016 09:49
Remote Input shell scripts for your Android Devic... https://grymoire.wordpress.com/2014/09/17/remo...
Reply
grymoire says:
January 9, 2015 at 2:18 am
http://stackoverow.com/questions/11142843/how-can-i-use-adb-to-send-a-longpress-key-event
Reply
mobileqablog says:
August 27, 2016 at 8:26 pm
mobileqablog says:
August 27, 2016 at 8:30 pm
The Grymoire
Create a free website or blog at WordPress.com.
Follow
9 de 9 08-09-2016 09:49