1- package cf .netdex .hidfuzzer ;
1+ package cf .netdex .hidfuzzer .hid ;
2+
3+ import android .util .Log ;
24
35import java .util .concurrent .CountDownLatch ;
46
810 * Created by netdex on 1/15/2017.
911 */
1012
11- class HID {
12- static int hid_mouse (Shell .Interactive sh , String dev , byte ... offset ) {
13+ public class HID {
14+ /**
15+ * A B C D
16+ * XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
17+ * <p>
18+ * A: Mouse button mask
19+ * B: Mouse X-offset
20+ * C: Mouse Y-offset
21+ * D: Mouse wheel offset
22+ *
23+ * @param sh SU shell
24+ * @param dev Mouse device (/dev/hidg1)
25+ * @param offset HID mouse bytes
26+ * @return error code
27+ */
28+ public static int hid_mouse (Shell .Interactive sh , String dev , byte ... offset ) {
1329 if (offset .length > 4 )
1430 throw new IllegalArgumentException ("Your mouse can only move in two dimensions" );
15- // for some odd reason, 4-byte padding is required
16- byte [] buf = new byte [8 ];
31+ byte [] buf = new byte [4 ];
1732 System .arraycopy (offset , 0 , buf , 0 , offset .length );
1833 return write_bytes (sh , dev , buf );
1934 }
2035
21-
22- static int hid_keyboard (Shell .Interactive sh , String dev , byte ... keys ) {
23- if (keys .length > 8 )
24- throw new IllegalArgumentException ("Cannot send more than 7 keys" );
25- // for some odd reason, every odd byte has to be blank
26- byte [] buf = new byte [16 ];
27- for (int i = 0 ; i < keys .length ; i ++) {
28- buf [2 * i ] = keys [i ];
29- }
36+ /**
37+ * A B C D E F G H
38+ * XXXXXXXX 00000000 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
39+ * <p>
40+ * A: Key modifier mask
41+ * B: Reserved
42+ * C: Key 1; D: Key 2; E: Key 3; F: Key 4; G: Key 5; H: Key 6;
43+ *
44+ * @param sh SU shell
45+ * @param dev Keyboard device (/dev/hidg0)
46+ * @param keys HID keyboard bytes
47+ * @return error code
48+ */
49+ public static int hid_keyboard (Shell .Interactive sh , String dev , byte ... keys ) {
50+ if (keys .length > 7 )
51+ throw new IllegalArgumentException ("Cannot send more than 6 keys" );
52+ byte [] buf = new byte [8 ];
53+ if (keys .length > 0 ) buf [0 ] = keys [0 ];
54+ if (keys .length > 1 ) System .arraycopy (keys , 1 , buf , 2 , keys .length - 1 );
3055 return write_bytes (sh , dev , buf );
3156 }
3257
@@ -39,7 +64,8 @@ private static int write_bytes(Shell.Interactive sh, String dev, byte[] arr) {
3964 try {
4065 // run echo command to write to device as root
4166 final CountDownLatch latch = new CountDownLatch (1 );
42- String c = String .format ("echo -n -e \" %s\" > %s" , bt , dev );
67+ String c = "echo -n -e \" " + bt + "\" > " + dev ;
68+ // Log.d("A", c);
4369 sh .addCommand (c , 0 , new Shell .OnCommandLineListener () {
4470 @ Override
4571 public void onLine (String line ) {
@@ -73,4 +99,6 @@ private static String escapeBytes(byte[] arr) {
7399 }
74100 return sb .toString ();
75101 }
102+
103+
76104}
0 commit comments