├── unlock.sh └── unlock_5x5.sh /unlock.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Android pattern unlock 4 | # Author: Matt Wilson 5 | # Licence: Free to use and share. If this helps you please buy me a beer :) 6 | # 7 | # This script sends simulated touch input over ADB for remotely swiping on Android's pattern lockscreen. 8 | # This allows you to unlock the device even if the touch screen is broken. 9 | # 10 | # Note: You must have USB debugging enabled on your device for this script to work (in the developer options). 11 | # This script will not work unless this option is enabled. I recommend turning it on to make life easier if you drop your phone. 12 | # Note: The device does not need to be rooted for this method to work. 13 | # 14 | # You need to have adb on your PATH to run this script. 15 | # E.g. on Mac add to ~/.bash_profile: export PATH="/Users/username/Library/Android/sdk/platform-tools:$PATH" 16 | # 17 | # Customise the variables in the top section of the script with your phone's unlock code and coordinates 18 | # 19 | # Usage: 20 | # chmod +x unlock.sh 21 | # ./unlock.sh 22 | 23 | # ======================================================================================================================= 24 | 25 | # Variables 26 | # 27 | # Coordinates will vary depending on the screen resolution of your device (defaults are for Nexus 4 at 768x1280) 28 | # The pattern should be set based on the following layout: 29 | # 1 2 3 30 | # 4 5 6 31 | # 7 8 9 32 | 33 | PATTERN="1 2 3 6 5 4 7 8 9" # The unlock pattern to draw, space seperated 34 | 35 | COL_1=166 # X coordinate of column 1 (in pixels) 36 | COL_2=384 # X coordinate of column 2 (in pixels) 37 | COL_3=576 # X coordinate of column 3 (in pixels) 38 | 39 | ROW_1=553 # Y coordinate of row 1 (in pixels) 40 | ROW_2=738 # Y coordinate of row 2 (in pixels) 41 | ROW_3=984 # Y coordinate of row 3 (in pixels) 42 | 43 | MULTIPLIER=2 # Multiplication factor for coordinates. For Nexus 4, set this to 2. For low res phones such as 44 | # Samsung Galaxy S2, set this to 1. Experiment with this value if you can't see anything happening. 45 | 46 | WAKE_SCREEN_ENABLED=true # If true, the script will start by sending the power button press event 47 | 48 | SWIPE_UP_ENABLED=true # If true, the script will swipe upwards before drawing the pattern (e.g. for lollipop lockscreen) 49 | SWIPE_UP_X=450 # X coordinate for initial upward swipe. Only used if SWIPE_UP_ENABLED is true 50 | SWIPE_UP_Y_FROM=1000 # Start Y coordinate for initial upward swipe. Only used if SWIPE_UP_ENABLED is true 51 | SWIPE_UP_Y_TO=200 # End Y coordinate for initial upward swipe. Only used if SWIPE_UP_ENABLED is true 52 | 53 | # ======================================================================================================================= 54 | 55 | # Define X&Y coordinates for each of the 9 positions. 56 | 57 | X[1]=$(( ${COL_1} * ${MULTIPLIER} )) 58 | X[2]=$(( ${COL_2} * ${MULTIPLIER} )) 59 | X[3]=$(( ${COL_3} * ${MULTIPLIER} )) 60 | X[4]=$(( ${COL_1} * ${MULTIPLIER} )) 61 | X[5]=$(( ${COL_2} * ${MULTIPLIER} )) 62 | X[6]=$(( ${COL_3} * ${MULTIPLIER} )) 63 | X[7]=$(( ${COL_1} * ${MULTIPLIER} )) 64 | X[8]=$(( ${COL_2} * ${MULTIPLIER} )) 65 | X[9]=$(( ${COL_3} * ${MULTIPLIER} )) 66 | 67 | Y[1]=$(( ${ROW_1} * ${MULTIPLIER} )) 68 | Y[2]=$(( ${ROW_1} * ${MULTIPLIER} )) 69 | Y[3]=$(( ${ROW_1} * ${MULTIPLIER} )) 70 | Y[4]=$(( ${ROW_2} * ${MULTIPLIER} )) 71 | Y[5]=$(( ${ROW_2} * ${MULTIPLIER} )) 72 | Y[6]=$(( ${ROW_2} * ${MULTIPLIER} )) 73 | Y[7]=$(( ${ROW_3} * ${MULTIPLIER} )) 74 | Y[8]=$(( ${ROW_3} * ${MULTIPLIER} )) 75 | Y[9]=$(( ${ROW_3} * ${MULTIPLIER} )) 76 | 77 | # Function definitions 78 | 79 | WakeScreen() { 80 | if [ "$WAKE_SCREEN_ENABLED" = true ]; then 81 | adb shell input keyevent 26 82 | fi 83 | } 84 | 85 | SwipeUp() { 86 | if [ "$SWIPE_UP_ENABLED" = true ]; then 87 | adb shell input swipe ${SWIPE_UP_X} ${SWIPE_UP_Y_FROM} ${SWIPE_UP_X} ${SWIPE_UP_Y_TO} 88 | fi 89 | } 90 | 91 | StartTouch() { 92 | adb shell sendevent /dev/input/event2 3 57 14 93 | } 94 | 95 | SendCoordinates () { 96 | adb shell sendevent /dev/input/event2 3 53 $1 97 | adb shell sendevent /dev/input/event2 3 54 $2 98 | adb shell sendevent /dev/input/event2 3 58 57 99 | adb shell sendevent /dev/input/event2 0 0 0 100 | } 101 | 102 | FinishTouch() { 103 | adb shell sendevent /dev/input/event2 3 57 4294967295 104 | adb shell sendevent /dev/input/event2 0 0 0 105 | } 106 | 107 | SwipePattern() { 108 | for NUM in $PATTERN 109 | do 110 | echo "Sending $NUM: ${X[$NUM]}, ${Y[$NUM]}" 111 | SendCoordinates ${X[$NUM]} ${Y[$NUM]} 112 | done 113 | } 114 | 115 | # Actions 116 | 117 | WakeScreen 118 | SwipeUp 119 | StartTouch 120 | SwipePattern 121 | FinishTouch 122 | -------------------------------------------------------------------------------- /unlock_5x5.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Android pattern unlock 4 | # Author: Matt Wilson 5 | # Modified: einsiedlerkrebs 6 | # Licence: Free to use and share. If this helps you please buy me a beer :) 7 | # 8 | # This script sends simulated touch input over ADB for remotely swiping on Android's pattern lockscreen. 9 | # This allows you to unlock the device even if the touch screen is broken. 10 | # 11 | # Note: You must have USB debugging enabled on your device for this script to work (in the developer options). 12 | # This script will not work unless this option is enabled. I recommend turning it on to make life easier if you drop your phone. 13 | # Note: The device does not need to be rooted for this method to work. 14 | # 15 | # You need to have adb on your PATH to run this script. 16 | # E.g. on Mac add to ~/.bash_profile: export PATH="/Users/username/Library/Android/sdk/platform-tools:$PATH" 17 | # 18 | # Customise the variables in the top section of the script with your phone's unlock code and coordinates 19 | # 20 | # Usage: 21 | # chmod +x unlock_5x5.sh 22 | # ./unlock_5x5.sh 23 | 24 | # ======================================================================================================================= 25 | 26 | # Variables 27 | # 28 | # Coordinates will vary depending on the screen resolution of your device (defaults are for Nexus 4 at 768x1280) 29 | # The pattern should be set based on the following layout: 30 | 31 | # 1 2 3 4 5 32 | 33 | # 6 7 8 9 10 34 | 35 | # 11 12 13 14 15 36 | 37 | # 16 17 18 19 20 38 | 39 | # 21 22 23 24 25 40 | 41 | PATTERN="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25" # The unlock pattern to draw, space seperated 42 | 43 | COL_1=138 # X coordinate of column 1 (in pixels) 44 | COL_2=260 # X coordinate of column 2 (in pixels) 45 | COL_3=382 # X coordinate of column 3 (in pixels) 46 | COL_4=502 # X coordinate of column 4 (in pixels) 47 | COL_5=626 # X coordinate of column 5 (in pixels) 48 | 49 | ROW_1=502 # Y coordinate of row 1 (in pixels) 50 | ROW_2=626 # Y coordinate of row 2 (in pixels) 51 | ROW_3=748 # Y coordinate of row 3 (in pixels) 52 | ROW_4=870 # Y coordinate of row 4 (in pixels) 53 | ROW_5=992 # Y coordinate of row 5 (in pixels) 54 | 55 | 56 | MULTIPLIER=2 # Multiplication factor for coordinates. For Nexus 4, set this to 2. For low res phones such as 57 | # Samsung Galaxy S2, set this to 1. Experiment with this value if you can't see anything happening. 58 | 59 | WAKE_SCREEN_ENABLED=true # If true, the script will start by sending the power button press event 60 | 61 | SWIPE_UP_ENABLED=false # If true, the script will swipe upwards before drawing the pattern (e.g. for lollipop lockscreen) 62 | SWIPE_UP_X=450 # X coordinate for initial upward swipe. Only used if SWIPE_UP_ENABLED is true 63 | SWIPE_UP_Y_FROM=1000 # Start Y coordinate for initial upward swipe. Only used if SWIPE_UP_ENABLED is true 64 | SWIPE_UP_Y_TO=200 # End Y coordinate for initial upward swipe. Only used if SWIPE_UP_ENABLED is true 65 | 66 | # ======================================================================================================================= 67 | 68 | # Define X&Y coordinates for each of the 25 positions. 69 | 70 | X[1]=$(( ${COL_1} * ${MULTIPLIER} )) 71 | X[2]=$(( ${COL_2} * ${MULTIPLIER} )) 72 | X[3]=$(( ${COL_3} * ${MULTIPLIER} )) 73 | X[4]=$(( ${COL_4} * ${MULTIPLIER} )) 74 | X[5]=$(( ${COL_5} * ${MULTIPLIER} )) 75 | X[6]=$(( ${COL_1} * ${MULTIPLIER} )) 76 | X[7]=$(( ${COL_2} * ${MULTIPLIER} )) 77 | X[8]=$(( ${COL_3} * ${MULTIPLIER} )) 78 | X[9]=$(( ${COL_4} * ${MULTIPLIER} )) 79 | X[10]=$(( ${COL_5} * ${MULTIPLIER} )) 80 | X[11]=$(( ${COL_1} * ${MULTIPLIER} )) 81 | X[12]=$(( ${COL_2} * ${MULTIPLIER} )) 82 | X[13]=$(( ${COL_3} * ${MULTIPLIER} )) 83 | X[14]=$(( ${COL_4} * ${MULTIPLIER} )) 84 | X[15]=$(( ${COL_5} * ${MULTIPLIER} )) 85 | X[16]=$(( ${COL_1} * ${MULTIPLIER} )) 86 | X[17]=$(( ${COL_2} * ${MULTIPLIER} )) 87 | X[18]=$(( ${COL_3} * ${MULTIPLIER} )) 88 | X[19]=$(( ${COL_4} * ${MULTIPLIER} )) 89 | X[20]=$(( ${COL_5} * ${MULTIPLIER} )) 90 | X[21]=$(( ${COL_1} * ${MULTIPLIER} )) 91 | X[22]=$(( ${COL_2} * ${MULTIPLIER} )) 92 | X[23]=$(( ${COL_3} * ${MULTIPLIER} )) 93 | X[24]=$(( ${COL_4} * ${MULTIPLIER} )) 94 | X[25]=$(( ${COL_5} * ${MULTIPLIER} )) 95 | 96 | Y[1]=$(( ${ROW_1} * ${MULTIPLIER} )) 97 | Y[2]=$(( ${ROW_1} * ${MULTIPLIER} )) 98 | Y[3]=$(( ${ROW_1} * ${MULTIPLIER} )) 99 | Y[4]=$(( ${ROW_1} * ${MULTIPLIER} )) 100 | Y[5]=$(( ${ROW_1} * ${MULTIPLIER} )) 101 | Y[6]=$(( ${ROW_2} * ${MULTIPLIER} )) 102 | Y[7]=$(( ${ROW_2} * ${MULTIPLIER} )) 103 | Y[8]=$(( ${ROW_2} * ${MULTIPLIER} )) 104 | Y[9]=$(( ${ROW_2} * ${MULTIPLIER} )) 105 | Y[10]=$(( ${ROW_2} * ${MULTIPLIER} )) 106 | Y[11]=$(( ${ROW_3} * ${MULTIPLIER} )) 107 | Y[12]=$(( ${ROW_3} * ${MULTIPLIER} )) 108 | Y[13]=$(( ${ROW_3} * ${MULTIPLIER} )) 109 | Y[14]=$(( ${ROW_3} * ${MULTIPLIER} )) 110 | Y[15]=$(( ${ROW_3} * ${MULTIPLIER} )) 111 | Y[16]=$(( ${ROW_4} * ${MULTIPLIER} )) 112 | Y[17]=$(( ${ROW_4} * ${MULTIPLIER} )) 113 | Y[18]=$(( ${ROW_4} * ${MULTIPLIER} )) 114 | Y[19]=$(( ${ROW_4} * ${MULTIPLIER} )) 115 | Y[20]=$(( ${ROW_4} * ${MULTIPLIER} )) 116 | Y[21]=$(( ${ROW_5} * ${MULTIPLIER} )) 117 | Y[22]=$(( ${ROW_5} * ${MULTIPLIER} )) 118 | Y[23]=$(( ${ROW_5} * ${MULTIPLIER} )) 119 | Y[24]=$(( ${ROW_5} * ${MULTIPLIER} )) 120 | Y[25]=$(( ${ROW_5} * ${MULTIPLIER} )) 121 | 122 | # Function definitions 123 | 124 | WakeScreen() { 125 | if [ "$WAKE_SCREEN_ENABLED" = true ]; then 126 | adb shell input keyevent 26 127 | fi 128 | } 129 | 130 | SwipeUp() { 131 | if [ "$SWIPE_UP_ENABLED" = true ]; then 132 | adb shell input swipe ${SWIPE_UP_X} ${SWIPE_UP_Y_FROM} ${SWIPE_UP_X} ${SWIPE_UP_Y_TO} 133 | fi 134 | } 135 | 136 | StartTouch() { 137 | adb shell sendevent /dev/input/event2 3 57 14 138 | } 139 | 140 | SendCoordinates () { 141 | adb shell sendevent /dev/input/event2 3 53 $1 142 | adb shell sendevent /dev/input/event2 3 54 $2 143 | adb shell sendevent /dev/input/event2 3 58 57 144 | adb shell sendevent /dev/input/event2 0 0 0 145 | } 146 | 147 | FinishTouch() { 148 | adb shell sendevent /dev/input/event2 3 57 4294967295 149 | adb shell sendevent /dev/input/event2 0 0 0 150 | } 151 | 152 | SwipePattern() { 153 | for NUM in $PATTERN 154 | do 155 | echo "Sending $NUM: ${X[$NUM]}, ${Y[$NUM]}" 156 | SendCoordinates ${X[$NUM]} ${Y[$NUM]} 157 | done 158 | } 159 | 160 | # Actions 161 | 162 | WakeScreen 163 | SwipeUp 164 | StartTouch 165 | SwipePattern 166 | FinishTouch 167 | --------------------------------------------------------------------------------