44
55** Use at your own risk. For educational purposes only.**
66
7- An Android app that provides a simple Lua interface for enumerating and interfacing
8- with arbitrary composite USB devices.
7+ An Android app that provides a simple Lua interface for creating and interfacing
8+ with arbitrary composite USB devices, allowing your phone to act as a USB device .
99
1010** Root access is required.**
1111
@@ -14,69 +14,74 @@ with arbitrary composite USB devices.
1414Download debug build artifacts from [ the latest workflow run] ( https://github.com/Netdex/android-usb-script/actions ) .
1515
1616## Demonstration
17-
18- The best way to explain what this app does is with a code example. The following script
19- does the following when interpreted by this app:
20-
17+ When interpreted by this app, the following script:
21181 . Configures your phone to become a USB keyboard
22192 . Sends a series of key presses to the computer your phone is plugged in to, changing
2320its wallpaper
2421
2522``` lua
26- -- create a USB composite device composed of a single keyboard
27- usb = luausb .create ({ id = 0 , type = " keyboard" })
28- kb = usb .dev [1 ]
23+ ---
24+ --- Change Windows 10 desktop wallpaper
25+ ---
26+
27+ require (' common' )
28+
29+ kb = luausb .create ({ type = " keyboard" })
2930
30- local file = prompt (" Wallpaper to download?" , " https://i.imgur.com/46wWHZ3.png" )
31+ local file = prompt {
32+ message = " Enter the URL of the wallpaper to download." ,
33+ hint = " Image URL" ,
34+ default = " https://i.imgur.com/46wWHZ3.png"
35+ }
3136
3237while true do
3338 print (" idle" )
3439
35- -- wait for the phone to be plugged into a computer
36- while usb .state () == " not attached" do
37- wait (1000 )
38- end
39-
40+ -- wait for USB device to be plugged in
41+ wait_for_state (' configured' )
42+ -- wait for host to detect this USB device
43+ wait_for_detect (kb )
4044 print (" running" )
41- wait (1000 )
4245
43- kb . chord (MOD_LSUPER , KEY_R ) -- open Windows run dialog
44- wait (2000 ) -- wait for it to open
45- kb . string (" powershell\n " ) -- open powershell
46+ kb : chord (MOD_LSUPER , KEY_R )
47+ wait (2000 )
48+ kb : string (" powershell\n " )
4649 wait (2000 )
47- -- execute a script that downloads and changes the wallpaper
48- kb .string (" [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;" ..
49- " (new-object System.Net.WebClient).DownloadFile('" .. file .. " ',\" $Env:Temp\\ b.jpg\" );\n " ..
50- " Add-Type @\"\n " ..
51- " using System;using System.Runtime.InteropServices;using Microsoft.Win32;namespa" ..
52- " ce W{public class S{ [DllImport(\" user32.dll\" )]static extern int SystemParamet" ..
53- " ersInfo(int a,int b,string c,int d);public static void SW(string a){SystemParam" ..
54- " etersInfo(20,0,a,3);RegistryKey c=Registry.CurrentUser.OpenSubKey(\" Control Pan" ..
55- " el\\\\ Desktop\" ,true);c.SetValue(@\" WallpaperStyle\" , \" 2\" );c.SetValue(@\" Tile" ..
56- " Wallpaper\" , \" 0\" );c.Close();}}}\n " ..
57- " \" @\n " ..
58- " [W.S]::SW(\" $Env:Temp\\ b.jpg\" )\n " ..
59- " exit\n " )
50+ kb :string (" [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;" ..
51+ " (new-object System.Net.WebClient).DownloadFile('" .. file .. " ',\" $Env:Temp\\ b.jpg\" );\n " ..
52+ " Add-Type @\"\n " ..
53+ " using System;using System.Runtime.InteropServices;using Microsoft.Win32;namespa" ..
54+ " ce W{public class S{ [DllImport(\" user32.dll\" )]static extern int SystemParamet" ..
55+ " ersInfo(int a,int b,string c,int d);public static void SW(string a){SystemParam" ..
56+ " etersInfo(20,0,a,3);RegistryKey c=Registry.CurrentUser.OpenSubKey(\" Control Pan" ..
57+ " el\\\\ Desktop\" ,true);c.SetValue(@\" WallpaperStyle\" , \" 2\" );c.SetValue(@\" Tile" ..
58+ " Wallpaper\" , \" 0\" );c.Close();}}}\n " ..
59+ " \" @\n " ..
60+ " [W.S]::SW(\" $Env:Temp\\ b.jpg\" )\n " ..
61+ " exit\n " )
6062
6163 print (" done" )
62- -- wait until the phone is unplugged
63- while usb .state () == " configured" do
64- wait (1000 )
65- end
64+ -- wait for USB device to be unplugged
65+ wait_for_state (" not attached" )
6666end
6767```
6868
69- Several other sample scripts are
70- [ included in the repository] ( https://github.com/Netdex/android-usb-script/tree/master/app/src/main/assets/scripts ) .
69+ The following USB gadgets are currently supported:
70+ - Keyboard (keyboard)
71+ - Mouse (mouse)
72+ - Mass Storage (storage)
73+
74+ Built-in scripts can be run using the "Select Asset" menu item. You can run an external script using
75+ the "Load Script" menu item. New demo applications can be added to ` assets/scripts ` . The API is
76+ pretty much self-documenting, just look at the existing demos to get a feel for how the API works.
77+ Several other sample scripts
78+ are [ included in the repository] ( https://github.com/Netdex/android-usb-script/tree/master/app/src/main/assets/scripts ) .
7179
7280## Requirements
7381** This app will not work on every Android device.** If your Android OS has Linux Kernel
7482version >= 3.18 and is compiled with configfs and f_hid, then the app can try to create usb
7583gadgets.
7684
77- New demo applications can be added to ` assets/scripts ` . The API is pretty much self-documenting,
78- just look at the existing demos to get a feel for how the API works.
79-
8085## Troubleshooting
8186### "Device Malfunctioned" on Windows 10
8287There may be an incompatibility between the supported USB speed between the USB function and USB
@@ -90,5 +95,5 @@ Try setting SELinux to permissive mode by running `setenforce 0` as root.
9095
9196
9297## Third-party
93- - [ libsuperuser ] ( https://github.com/Chainfire/libsuperuser )
98+ - [ libsu ] ( https://github.com/topjohnwu/libsu )
9499- [ LuaJ] ( http://www.luaj.org/luaj/3.0/README.html )
0 commit comments