Skip to content

Commit e469bdd

Browse files
committed
configfs: support mass storage gadget
1 parent cbaed1a commit e469bdd

File tree

18 files changed

+279
-262
lines changed

18 files changed

+279
-262
lines changed

app/src/main/assets/scripts/a.lua

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
--- Composite device composed of two keyboards
3+
---
4+
---
5+
usb = luausb.create({ type = "keyboard", id = 0 }, { type = "keyboard", id = 1 })
6+
kb1 = usb.dev[1]
7+
kb2 = usb.dev[2]
8+
9+
while true do
10+
usb.log("idle")
11+
12+
-- poll until usb plugged in
13+
while usb.state() == "not attached" do
14+
usb.delay(1000)
15+
end
16+
17+
usb.log("running")
18+
usb.delay(1000)
19+
20+
-- send a string from keyboard 1
21+
kb1.send_string("kb1")
22+
usb.delay(1000)
23+
-- send a string from keyboard 2
24+
kb2.send_string("kb2")
25+
26+
usb.log("done")
27+
28+
-- poll until usb unplugged
29+
while usb.state() == "configured" do
30+
usb.delay(1000)
31+
end
32+
33+
usb.log("disconnected")
34+
35+
usb.delay(1000)
36+
end

app/src/main/assets/scripts/downloadrun.lua

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
---
2-
--- Created by netdex.
3-
--- DateTime: 12/30/17 10:12 PM
4-
---
52
--- downloadrun.lua: downloads and executes a file
63
--- directly translated from the Java version in previous builds
74
---
@@ -15,8 +12,8 @@ local runAs = usb.should("Task UAC", "Launch exe as admin?");
1512
while true do
1613
usb.log("idle")
1714

18-
-- poll until /dev/hidg0 is writable
19-
while not kb.test() do
15+
-- poll until usb plugged in
16+
while usb.state() == "not attached" do
2017
usb.delay(1000)
2118
end
2219

@@ -54,7 +51,8 @@ while true do
5451
)
5552

5653
usb.log("done")
57-
while kb.test() do
54+
-- poll until usb unplugged
55+
while usb.state() == "configured" do
5856
usb.delay(1000)
5957
end
6058
usb.log("disconnected")

app/src/main/assets/scripts/fuzzer.lua

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
--- Generated by EmmyLua(https://github.com/EmmyLua)
3+
--- Created by netdex.
4+
--- DateTime: 11/16/2020 10:47 AM
5+
---
6+
7+
usb = luausb.create({ id = 0, type = "storage" })
8+
9+
while true do
10+
usb.delay(1000)
11+
end

app/src/main/assets/scripts/wallpaper.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
2-
--- Created by netdex.
3-
--- DateTime: 1/6/2018 4:33 PM
4-
---
52
--- wallpaper.lua: Changes a Windows 10 desktop wallpaper
63
---
7-
---
84

95
usb = luausb.create({ id = 0, type = "keyboard" })
106
kb = usb.dev[1]
@@ -14,8 +10,8 @@ local file = usb.ask("Wallpaper to download?", "https://i.redd.it/ur1mqcbpxou51.
1410
while true do
1511
usb.log("idle")
1612

17-
-- poll until /dev/hidg0 is writable
18-
while not kb.test() do
13+
-- poll until usb plugged in
14+
while usb.state() == "not attached" do
1915
usb.delay(1000)
2016
end
2117

@@ -40,7 +36,8 @@ while true do
4036
"exit\n")
4137

4238
usb.log("done")
43-
while kb.test() do
39+
-- poll until usb unplugged
40+
while usb.state() == "configured" do
4441
usb.delay(1000)
4542
end
4643
end

app/src/main/java/org/netdex/hidfuzzer/MainActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.netdex.hidfuzzer.gui.PromptDialog;
2525
import org.netdex.hidfuzzer.service.LuaUsbService;
2626
import org.netdex.hidfuzzer.service.LuaUsbServiceConnection;
27-
import org.netdex.hidfuzzer.task.AsyncIoBridge;
27+
import org.netdex.hidfuzzer.task.AsyncIOBridge;
2828
import org.netdex.hidfuzzer.task.LuaUsbTask;
2929
import org.netdex.hidfuzzer.task.LuaUsbTaskFactory;
3030

@@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
4949
TextView logView = findViewById(R.id.text_log);
5050
ScrollView scrollView = findViewById(R.id.scrollview);
5151

52-
AsyncIoBridge dialogIO = new AsyncIoBridge() {
52+
AsyncIOBridge dialogIO = new AsyncIOBridge() {
5353
@Override
5454
public void onLogMessage(String s) {
5555
handler_.post(() -> {
@@ -91,7 +91,7 @@ public void createLuaUsbService(LuaUsbTask task) {
9191
public void terminateLuaUsbService() {
9292
if (activeServiceConn_ != null) {
9393
btnCancel_.setEnabled(false);
94-
unbindService(activeServiceConn_);
94+
unbindService(activeServiceConn_); // TODO this can cause ANR
9595
activeServiceConn_ = null;
9696
}
9797
}

app/src/main/java/org/netdex/hidfuzzer/configfs/UsbGadget.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ public static class Parameters {
1818

1919
public String configName;
2020

21-
public static final Parameters DEFAULT = new Parameters(
22-
null,
23-
null,
24-
"0x1d6b",
25-
"0x104",
26-
null,
27-
null
28-
);
29-
3021
public Parameters(String manufacturer, String serial,
3122
String idProduct, String idVendor, String product,
3223
String configName) {
@@ -175,6 +166,10 @@ public String getUDC(Shell.Threaded su) {
175166
return Command.readFile(su, getUDCPath());
176167
}
177168

169+
public String getUDCState(Shell.Threaded su, String udc) {
170+
return Command.readFile(su, String.format("/sys/class/udc/%s/state", udc));
171+
}
172+
178173
public boolean isBound(Shell.Threaded su) {
179174
return !getUDC(su).isEmpty();
180175
}

app/src/main/java/org/netdex/hidfuzzer/configfs/function/UsbGadgetFunction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
import eu.chainfire.libsuperuser.Shell;
88

9-
9+
/**
10+
* https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt
11+
* https://www.kernel.org/doc/Documentation/ABI/testing/
12+
*/
1013
public abstract class UsbGadgetFunction {
1114
public static class Parameters {
1215

app/src/main/java/org/netdex/hidfuzzer/configfs/function/UsbGadgetFunctionHid.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
import eu.chainfire.libsuperuser.Shell;
66

7-
7+
/**
8+
* https://www.kernel.org/doc/Documentation/usb/gadget_hid.txt
9+
* https://www.kernel.org/doc/Documentation/ABI/testing/configfs-usb-gadget-hid
10+
*/
811
public class UsbGadgetFunctionHid extends UsbGadgetFunction {
912
public static class Parameters extends UsbGadgetFunction.Parameters {
1013
public int protocol;
@@ -86,19 +89,4 @@ public void create(Shell.Threaded su, String gadgetPath) throws Shell.ShellDiedE
8689
String.format("functions/%s/report_desc", functionDir), true, false),
8790
});
8891
}
89-
90-
@Override
91-
public void bind(Shell.Threaded su, String gadgetPath, String configDir) throws Shell.ShellDiedException {
92-
super.bind(su, gadgetPath, configDir);
93-
}
94-
95-
@Override
96-
public void unbind(Shell.Threaded su, String gadgetPath, String configDir) throws Shell.ShellDiedException {
97-
super.unbind(su, gadgetPath, configDir);
98-
}
99-
100-
@Override
101-
public void remove(Shell.Threaded su, String gadgetPath) throws Shell.ShellDiedException {
102-
super.remove(su, gadgetPath);
103-
}
10492
}

0 commit comments

Comments
 (0)