4
4
5
5
** Use at your own risk. For educational purposes only.**
6
6
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 .
9
9
10
10
** Root access is required.**
11
11
@@ -14,69 +14,74 @@ with arbitrary composite USB devices.
14
14
Download debug build artifacts from [ the latest workflow run] ( https://github.com/Netdex/android-usb-script/actions ) .
15
15
16
16
## 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:
21
18
1 . Configures your phone to become a USB keyboard
22
19
2 . Sends a series of key presses to the computer your phone is plugged in to, changing
23
20
its wallpaper
24
21
25
22
``` 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" })
29
30
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
+ }
31
36
32
37
while true do
33
38
print (" idle" )
34
39
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 )
40
44
print (" running" )
41
- wait (1000 )
42
45
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 " )
46
49
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 " )
60
62
61
63
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" )
66
66
end
67
67
```
68
68
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 ) .
71
79
72
80
## Requirements
73
81
** This app will not work on every Android device.** If your Android OS has Linux Kernel
74
82
version >= 3.18 and is compiled with configfs and f_hid, then the app can try to create usb
75
83
gadgets.
76
84
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
-
80
85
## Troubleshooting
81
86
### "Device Malfunctioned" on Windows 10
82
87
There 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.
90
95
91
96
92
97
## Third-party
93
- - [ libsuperuser ] ( https://github.com/Chainfire/libsuperuser )
98
+ - [ libsu ] ( https://github.com/topjohnwu/libsu )
94
99
- [ LuaJ] ( http://www.luaj.org/luaj/3.0/README.html )
0 commit comments