Du bist hier:Start»CyanogenMod»Hacks»Touchscreen-Hack

Touchscreen Hack

28.03.2015

Touchscreen Hack

Unter Android bzw. CyanogenMod läßt sich die Position des Tippens auf den Bildschirm eines Smartphones von der Kommandozeile aus abfragen. Die Funktionen dafür sind ähnlich wie beim Button-Hack. Bei meinem Smartphone Galaxy S3 läßt sich der Touchscreen als Gerät unter Linux über die Datei /dev/input/event2 ansprechen. Diese Information kann je Smartphone unterschiedlich sein und läßt sich mit "getevent -l" als Benutzer "root" abfragen.

adb root
adb shell

# list input devices on the smartphone as root

getevent -l

...

add device 11: /dev/input/event2
  name:     "sec_touchscreen"

Um die Informationen von getevent weiterzuverarbeiten, ist wieder das Programm stdbuf.so notwendig.

# copy stdbuf.so to the smartphone from the computer:

wget https://www.torsten-traenkner.de/cyanogenmod/hacks/stdbuf.so
adb root
adb push stdbuf.so /data/media/0/stdbuf.so
adb shell "chmod 755 /data/media/0/stdbuf.so"

# log in to the smartphone
adb shell

Mit stdbuf.so lassen sich die Ausgaben von getevent ungepuffert über eine Pipe an das nachfolgende Programm weiterreichen:

# get position of touchscreen tap

LD_PRELOAD=/data/media/0/stdbuf.so getevent -l /dev/input/event2 | LD_PRELOAD=/data/media/0/stdbuf.so grep -A4 "ABS_MT_TRACKING_ID   00" | grep ABS_MT_POSITION

EV_ABS       ABS_MT_POSITION_X    00000113
EV_ABS       ABS_MT_POSITION_Y    000002bc

Die Positionen im oberen Beispiel werden hexadezimal angezeigt. Das folgende Skript stellt die Position auch dezimal dar und kann bei dreimaligem Touchscreen-Tap auf eine bestimmte Stelle eine Aktion ausführen: touchscreen_events.sh

# copy touchscreen_events.sh to the smartphone:

wget https://www.torsten-traenkner.de/cyanogenmod/hacks/touchscreen_events.sh
adb push touchscreen_events.sh /data/media/0/touchscreen_events.sh
adb shell "chmod 755 /data/media/0/touchscreen_events.sh"

# log in to the smartphone
adb shell

/data/media/0/touchscreen_events.sh

Das Skript ist eher als Proof-of-Concept gedacht. Im Augenblick funktioniert es so, dass bei dreimaligem Tippen auf den rechten unteren Bereich meines Galaxy S3 der Videoplayer VLC geschlossen wird. Bei einem Bildschirm mit einer Auflösung von 1280 Bildpunkten in der Höhe und 720 Punkten in der Breite muss die X-Koordinate größer 360 Punkte und die Y-Koordinate größer 640 Punkte sein.

Anhang: Listing des Shell-Skripts touchscreen_events.sh

#!/system/xbin/bash

#
#   screen resolution
#   Samsung Galaxy S3
#
# +------------------+
# | x, y      x , y  |
# | 0, 0     720, 0  |
# |                  |
# |                  |
# | x, y     x , y   |
# | 0,1280  720,1280 |
# +------------------+
# |     +------+     |
# |     | Home |     |
# |     +------+     |
# +------------------+
#

echo "Start touch screen event"

index=0
start=0
x_position=0
y_position=0
nano_seconds=0
last_nano_seconds=0
position_index=0

declare -a x_array
declare -a y_array
declare -a time_array

function main() {

  createNecessaryFiles

LD_PRELOAD=/data/media/0/stdbuf.so getevent -t -l /dev/input/event2 | while read line; do
  if [ $start -gt 0 ];then
    if [[ "$line" =~ .*"ABS_MT_POSITION_X    00".* ]]; then

      length=$(expr ${#line} - 8)
      substring="${line:$length}"
      x_position=$((16#$substring))

      nano_seconds=$(echo "$line" | sed 's|^\[ *\([0-9]*\)\.\([0-9]*\)\] .*|\1\2|g')

      #echo "time: $nano_seconds"
      #echo "x   : $x_position"
      start=2

    elif [ $start -eq 2 ] && [[ "$line" =~ .*"ABS_MT_POSITION_Y    00".* ]]; then
      length=$(expr ${#line} - 8)
      substring="${line:$length}"
      y_position=$((16#$substring))

      echo "time: $nano_seconds"
      echo "x   : $x_position"
      echo "y   : $y_position"
      echo

      if [ $(expr $nano_seconds - $last_nano_seconds) -lt 800000 ] || [ $position_index -eq 0 ];then
        if [ $y_position -gt 640 ] && [ $x_position -gt 360 ]; then
          let position_index++
        else
          position_index=0
          echo "Reset because outside"
        fi
        if [ $position_index -gt 2 ];then
          position_index=0
          echo "Example Action: killing VLC video player"
          killall org.videolan.vlc
          am force-stop org.videolan.vlc
        fi
      else
        position_index=0
        echo "Reset position."
      fi

      last_nano_seconds=$nano_seconds

      # reset start
      start=0
    fi
  fi

  if [[ "$line" =~ .*"ABS_MT_TRACKING_ID   00".* ]]; then
    #echo "start: $line"
    start=1
  elif [[ "$line" =~ .*"ABS_MT_TRACKING_ID   ff".* ]]; then
    #echo "end  : $line"
    start=0
  fi
done

}

function createNecessaryFiles() {

  # create binary "unbuffer" program
  # source code see below
  if [ ! -e /data/media/0/stdbuf.so ];then

    echo "QlpoOTFBWSZTWSuU0FkAAwJ///////5h9054L+c2\
MP/n/3LsRtRFwFRUBwkQRABa+GBw0AMisKoajAaa\
kxCU9TMymnppEHqNNqep6TT1NMmho9QNGnqeoADQ\
0eptJtIPUMgAzUNlPU9QaiYTUwp6ZAgBoAAAAAAA\
AAAAANA0AAABIkgSbSIDEADQMgDTQYQDIaGgANAa\
AAAAGhoBBgCYTAmEwmmCYjAEwBGhkwCYAAABGAmA\
AAQYAmEwJhMJpgmIwBMARoZMAmAAAARgJgAAGNda\
K9cFEUCQ8DA/IBURwo+44/rw4/ljzl5E/CwKnK3M\
B3dZq9GcJ7o0ONltz4nqtOTwMbAhU6gA+2Dw2z31\
0aGHQi3CBKEhZkBR3TFSvg5xdCjBSlhsooiVsmSn\
J48qDg4dKRLnZkypFj0HqGU7HCw4VW7bTkwvNRGJ\
RVcZDzylFUYss5Ovq0xwq1XMeci2Vw2HXg9jaDNr\
SN1uRC/NZm1FL81rX91ObNxQ/Zyol40YAslBCQFG\
eQEEZAA1FmAqczCGCUMJDEWnDCGoczRXPA7EMe6o\
dMSCRTEzmbY2YLpchk8QDaBzwqWXvzrkqLaKHDJM\
UMCpohyiIcOTW7YsVrJYAF80BtHU75gjTtNpDlCI\
YFLtNIC+YZKUALHNOr566sjSbqWH3CNkgDLIvlEz\
NM6brFrc1dSq8mdVGTRE1vYljM7TDMu8WQCMthpk\
DCkL2CGLWNdGmFEMlRSF6PednEBK94EFSImCahhH\
yFHEWJxGSQAz6O0c91KxYZTQYJdF/Mt+y4YGhHsY\
Ihtiq+mBGXNTg38sxzMLjsQkNrVMQWmi8wD8SDVt\
XTEZj1LK2iwxbC7UNAxSbY3U0FmIAbuWDcNuzTCr\
7uVbYVVjvVIuWp/JCryoxB5TPO0m08KFZ60Hcd5F\
cSn4YTy9eN0I4lEkVPovVfcrLc0wDWUYYM3IJdjB\
1+cHEwT5NtFA5qq6CZW6M9PBf+jGiKEjImnRLqxd\
sx8SJTOcok8eXHMikIIs1Fww02CmXJ1JQwXHSliS\
aXBQ2dcyVBQFDHbRIApMrJZgHC0c5TMBCyyzbbQY\
YghgKSlwPB0OdOYyaIaCVRDmBgZ+KItPHZcLDXgA\
4MyQFUiEsRdCSP4QCSIgSZRJPRIbhILa2AmOY5So\
C2CWi5kImMRodWBJhEsil38+tVVtbSlkFaOrFthQ\
hTnVt61txjALge53LXcBTSITYIqkAYgax1egbpZ2\
GuAOlA8UT8lLwt3sVYsAp29sP7JVZI29sRpd2Abi\
r12f/bzYrRhpWpgCZsTZxIBIBAv357g8D3/F3JFO\
FCQK5TQWQA==" | base64 -d > /data/media/0/stdbuf.so.bz2

    bunzip2 /data/media/0/stdbuf.so.bz2

    chmod 755 /data/media/0/stdbuf.so
  fi
}

main

Viel Spaß beim Experimentieren ! Falls noch etwas unklar sein sollte, dann kannst du die Kommentar-Funktion benutzen.

Kommentar schreiben

Ihre Daten werden verschlüsselt übertragen. Der Kommentar wird gelesen und eventuell veröffentlicht.
Wenn der Inhalt des Kommentars oder Teile des Kommentars nicht veröffentlicht werden, dann werden die gespeicherten Daten nach maximal 4 Wochen gelöscht. Um zukünftigen Missbrauch der Kommentarfunktion zu verhindern, werden die zum Kommentar gehörenden IP Adressen maximal 4 Wochen gespeichert.