迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:pelya/android-keyboard-gadget开源软件地址:https://github.com/pelya/android-keyboard-gadget开源编程语言:C 78.5%开源软件介绍:Convert your Android device into USB keyboard/mouse, control your PC from your Android device remotely, including BIOS/bootloader. For newer Kernel versions (>= 3.19) the patch is not anymore required and can be replaced by ConfigFS (USB Gadget Tool). Apps & tools using android-keyboard-gadget:
InstallationNexus 7 2012 WiFi (Grouper)
Nexus 7 2013LG G2LG G2 with Cyanogenmod 12.0Nexus 5
Nexus 4
Sony Ericsson phonesMotorola Moto G with Cyanogenmod
Motorola Moto E with CyanogenmodMotorola Moto G 2014Motorola Moto X Style (Pure) 2015OnePlus One
Galaxy S4
Galaxy Note 2Huawei Ideos X5Sony Xperia Z3 and Z3 CompactSony Xperia Z UltraXiaomi Redmi 1SXiaomi Redmi 3SGalaxy Ace 2Xiaomi MI3Galaxy Note 4Asus Zenfone 2 ZE551MLAsus Zenfone 2 Laser (Z00L/Z00T)Sony Xperia Z5 Premium E6853Sony Xperia Z5 CompactXiaomi Redmi 2Sony Xperia SPhttp://forum.xda-developers.com/xperia-sp/development/kernel-helium-v1-t3251298 Xiaomi Redmi Note 3Samsung Galaxy Tab 2 (any espresso3g based device)Other devices
ScriptingThere is a possibility to send keypresses in an automated way, using terminal emulator for Android or similar app. This is done using hid-gadget-test utility. First, copy this utility to your device.
You will need to set world-writable permissions on /dev/hidg0, or run hid-gadget-test from root shell.
To always have root shell, so you don't need to enter 'su' each time, run command
Then, use hid-gadget-test to send keypresses.
You can also run this command without launching ADB shell, from shell script or .bat file.
Advanced examples.
You can check the modification time of file Here's a sample shell script that will send a predefined key sequence when USB cable is plugged into PC:
Here is the list of keys that hid-gadget-test utility supports If you need to crack a PIN code, but the target system loses keypresses (happens in MacOS BIOS), there is a handy app for that, which uses camera to check if each keypress is recognized. You can also run DuckyScript files used by USB Rubber Ducky keystroke injection tool, with the help of this neat shell script. Compiling kernelYou have to run all following commands on Linux. Windows is not supported. These instructions are for Nexus 7 2012, change them for your device accordingly. To compile kernel, launch commands
https://github.com/pelya/android-keyboard-gadget/tree/master/patches/existing_tested - Tested patch files (pro) Tip: generic_kernel_version_3.xx.patch is just patches for AOSP roms and just by basic kernel versions. 3.01 is acceptable for 3.0.101. Other patch files is for devices only. The file named HTC Flounder will be acceptable ONLY FOR HTC Flounder! To compile
You then can find Nexus 7 2012 does not put any SELinux restrictions on the files inside /dev,
however most other devices typically restrict all access inside /dev for apps,
which means you will be able to use SELinux can be temporarily disabled with a command
however this will considerably weaken your device security,
so it's better to add specific SELinux exception for SELinux rules can be found at path
Replace In file
In file
In file
Then recompile Compiling USB Keyboard appTo compile USB Keyboard app, install Android SDK and NDK from site http://developer.android.com/ , and launch commands
How it worksThe custom kernel you have compiled adds two new devices, /dev/hidg0 for keyboard, and /dev/hidg1 for mouse. You can open these two files, using open() system call, and write raw keyboard/mouse events there, using write() system call, which will be sent through USB cable to your PC. Keyboard event is an array of 8 byte length, first byte is a bitmask of currently pressed modifier keys:
Remaining 7 bytes is a list of all other keys currently pressed, one byte for one key, or 0 if no key is pressed. Consequently, the maximum amount of keys that may be pressed at the same time is 7, excluding modifier keys. Professional or 'gamer' USB keyboards report several keyboard HID descriptors, which creates several keyboard devices in host PC, to overcome that 7-key limit. The scancode table for each key is available in hid-gadget-test utility. Extended keys, such as Play/Pause, are not supported, because they require modifying USB descriptor in kernel patch. Mouse event is an array of 4 bytes, first byte is a bitmask of currently pressed mouse buttons:
Remaining 3 bytes are X movement offset, Y movement offset, and mouse wheel offset, represented as signed integers. Horizontal wheel is not supported yet. See functions outputSendKeys() and outputSendMouse() inside file input.cpp for reference implementation. ![]() |
2022-08-15
2022-08-17
2023-10-27
2022-09-23
2022-08-13
请发表评论