Initial commit

This commit is contained in:
askiiart 2023-09-08 23:44:00 -05:00
commit 56344d685e
No known key found for this signature in database
GPG key ID: 839CB93C6E6B133B
68 changed files with 2164 additions and 0 deletions

1
app/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

42
app/build.gradle.kts Normal file
View file

@ -0,0 +1,42 @@
plugins {
id("com.android.application")
}
android {
namespace = "net.askiiart.usbkeyboard"
compileSdk = 33
defaultConfig {
applicationId = "net.askiiart.usbkeyboard"
minSdk = 28
targetSdk = 33
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.9.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}

21
app/proguard-rules.pro vendored Normal file
View file

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View file

@ -0,0 +1,26 @@
package net.askiiart.usbkeyboard;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("net.askiiart.usbkeyboard", appContext.getPackageName());
}
}

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.USBKbdJava"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View file

@ -0,0 +1,141 @@
/**
* Authorizer
*
* Copyright 2016 by Tjado Mäcke <tjado@maecke.de>
* Licensed under GNU General Public License 3.0.
*
* @license GPL-3.0 <https://opensource.org/licenses/GPL-3.0>
*/
package net.askiiart.usbkeyboard;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import android.util.Log;
/*
* Class by muzikant <http://stackoverflow.com/users/624109/muzikant>
*
* Reference:
* http://muzikant-android.blogspot.com/2011/02/how-to-get-root-access-and-execute.html
* http://stackoverflow.com/a/7102780
*/
public class ExecuteAsRootUtil
{
public static boolean canRunRootCommands()
{
boolean retval = false;
Process suProcess;
try
{
suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
DataInputStream osRes = new DataInputStream(suProcess.getInputStream());
if (null != os && null != osRes)
{
// Getting the id of the current user to check if this is root
os.writeBytes("id\n");
os.flush();
String currUid = osRes.readLine();
boolean exitSu = false;
if (null == currUid)
{
retval = false;
exitSu = false;
Log.d("ROOT", "Can't get root access or denied by user");
}
else if (true == currUid.contains("uid=0"))
{
retval = true;
exitSu = true;
Log.d("ROOT", "Root access granted");
}
else
{
retval = false;
exitSu = true;
Log.d("ROOT", "Root access rejected: " + currUid);
}
if (exitSu)
{
os.writeBytes("exit\n");
os.flush();
}
}
}
catch (Exception e)
{
// Can't get root !
// Probably broken pipe exception on trying to write to output stream (os) after su failed, meaning that the device is not rooted
retval = false;
Log.d("ROOT", "Root access rejected [" + e.getClass().getName() + "] : " + e.getMessage());
}
return retval;
}
public static final boolean execute(String command)
{
boolean retval = false;
try
{
if (command != null && command.length() > 0)
{
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
os.writeBytes(command);
os.flush();
os.writeBytes("exit\n");
os.flush();
try
{
int suProcessRetval = suProcess.waitFor();
if (255 != suProcessRetval)
{
// Root access granted
retval = true;
}
else
{
// Root access denied
retval = false;
}
}
catch (Exception ex)
{
Log.e("ROOT", "Error executing root action", ex);
}
}
}
catch (IOException ex)
{
Log.w("ROOT", "Can't get root access", ex);
}
catch (SecurityException ex)
{
Log.w("ROOT", "Can't get root access", ex);
}
catch (Exception ex)
{
Log.w("ROOT", "Error executing internal operation", ex);
}
return retval;
}
}

View file

@ -0,0 +1,42 @@
package net.askiiart.usbkeyboard;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendString(View view) throws IOException {
EditText tb = findViewById(R.id.textBoxOfText);
OutputUsbKeyboardAsRoot kbd = new OutputUsbKeyboardAsRoot(OutputInterface.Language.en_US);
kbd.sendText(tb.getText().toString());
}
public void sendEscape(View view) throws IOException {
OutputUsbKeyboardAsRoot kbd = new OutputUsbKeyboardAsRoot(OutputInterface.Language.en_US);
kbd.sendSingleKey("escape");
}
public void sendTab(View view) throws IOException {
OutputUsbKeyboardAsRoot kbd = new OutputUsbKeyboardAsRoot(OutputInterface.Language.en_US);
kbd.sendTabulator();
}
public void sendEnter(View view) throws IOException {
OutputUsbKeyboardAsRoot kbd = new OutputUsbKeyboardAsRoot(OutputInterface.Language.en_US);
kbd.sendReturn();
}
public void sendBackspace(View view) throws IOException {
OutputUsbKeyboardAsRoot kbd = new OutputUsbKeyboardAsRoot(OutputInterface.Language.en_US);
kbd.sendSingleKey("backspace");
}
}

View file

@ -0,0 +1,19 @@
/**
* Authorizer
*
* Copyright 2016 by Tjado Mäcke <tjado@maecke.de>
* Licensed under GNU General Public License 3.0.
*
* @license GPL-3.0 <https://opensource.org/licenses/GPL-3.0>
*/
package net.askiiart.usbkeyboard;
public interface OutputInterface {
public enum Language { en_US, en_GB, de_DE, AppleMac_de_DE, de_CH, fr_CH, neo }
public boolean setLanguage(OutputInterface.Language lang);
public int sendText(String text) throws Exception;
public int sendReturn() throws Exception;
public int sendTabulator() throws Exception;
public void destruct() throws Exception;
}

View file

@ -0,0 +1,168 @@
/**
* Authorizer
*
* Copyright 2016 by Tjado Mäcke <tjado@maecke.de>
* Licensed under GNU General Public License 3.0.
*
* @license GPL-3.0 <https://opensource.org/licenses/GPL-3.0>
*/
package net.askiiart.usbkeyboard;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.util.NoSuchElementException;
public class OutputUsbKeyboardAsRoot implements OutputInterface
{
private String devicePath = "/dev/hidg0";
private UsbHidKbd kbdKeyInterpreter;
private static final String TAG = "OutputUsbKeyboardAsRoot";
public OutputUsbKeyboardAsRoot(Language lang) throws FileNotFoundException
{
File devicePathFile = new File(devicePath);
if(!devicePathFile.exists()) {
throw new FileNotFoundException(String.format("No HID support: %s not found!", devicePath));
}
if( !ExecuteAsRootUtil.canRunRootCommands() ) {
throw new SecurityException("Root access rejected!");
}
setLanguage(lang);
}
public void destruct() {}
public boolean setLanguage(Language lang) {
String className = "net.tjado.authorizer.UsbHidKbd_" + lang;
try {
kbdKeyInterpreter = (UsbHidKbd) Class.forName(className).newInstance();
Utilities.dbginfo(TAG, "Set language " + lang);
return true;
}
catch (Exception e) {
Utilities.dbginfo(TAG, "Language " + lang + " not found");
kbdKeyInterpreter = new UsbHidKbd_en_US();
return false;
}
}
public int sendText(String output) throws IOException
{
int ret = 0;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
for (int i = 0; i < output.length(); i++) {
String textCharString = String.valueOf(output.charAt(i) );
try {
byte[] scancode;
scancode = kbdKeyInterpreter.getScancode(textCharString);
Utilities.dbginfo(TAG, "'" + textCharString + "' > " + Utilities
.bytesToHex(scancode) );
outputStream.write( scancode );
// overwriting the last keystroke, otherwise it will be repeated until the next writing
// and it would not be possible to repeat the keystroke
outputStream.write( kbdKeyInterpreter.getScancode(null) );
}
catch (NoSuchElementException e) {
Utilities.dbginfo(TAG, "'" + textCharString + "' mapping not found" );
ret = 1;
}
}
writeToUsbDevice(outputStream.toByteArray());
return ret;
}
private boolean writeToUsbDevice(byte[] scancodesBytes)
{
String scancodeHex = Utilities.bytesToHex(scancodesBytes);
return writeToUsbDevice(scancodeHex);
}
private boolean writeToUsbDevice(String scancodesHex)
{
//String command = String.format("echo %s | xxd -r -p > %s\n", scancodesHex, devicePath);
// Using printf instead of echo with xxd - this should provide a better compability
scancodesHex = scancodesHex.replaceAll("(.{2})", "\\\\x$1");;
String command = String.format("printf '%s' | dd bs=8 of=%s\n", scancodesHex, devicePath);
Utilities.dbginfo(TAG, "Handing over to ExecuteAsRootUtil -> " + command );
boolean cr = ExecuteAsRootUtil.execute( command );
if (cr) {
Utilities.dbginfo(TAG, "Command execution successful");
} else {
Utilities.dbginfo(TAG, "Command execution failed");
}
return cr;
}
public int sendSingleKey(String keyName) throws IOException
{
byte[] scancode;
int ret = 0;
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
scancode = kbdKeyInterpreter.getScancode(keyName);
Utilities.dbginfo(TAG, "'" + keyName + "' > " + Utilities
.bytesToHex(scancode) );
outputStream.write( scancode );
// overwriting the last keystroke, otherwise it will be repeated until the next writing
// and it would not be possible to repeat the keystroke
outputStream.write( kbdKeyInterpreter.getScancode(null) );
writeToUsbDevice(outputStream.toByteArray());
}
catch (NoSuchElementException e) {
Utilities.dbginfo(TAG, "'" + keyName + "' mapping not found" );
ret = 1;
}
return ret;
}
public int sendReturn() throws IOException
{
return sendSingleKey("return");
}
public int sendTabulator() throws IOException
{
return sendSingleKey("tab");
}
public void sendScancode(byte[] output) throws FileNotFoundException,
IOException
{
if( output.length == 8) {
Utilities.dbginfo(TAG, Utilities.bytesToHex(output) );
writeToUsbDevice(output);
} else if (output.length == 1) {
byte[] scancode = new byte[] {0x00, 0x00, output[0], 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Utilities.dbginfo(TAG, Utilities.bytesToHex(scancode) );
writeToUsbDevice(scancode);
}
}
}

View file

@ -0,0 +1,31 @@
/**
* Authorizer
*
* Copyright 2016 by Tjado Mäcke <tjado@maecke.de>
* Licensed under GNU General Public License 3.0.
*
* @license GPL-3.0 <https://opensource.org/licenses/GPL-3.0>
*/
package net.askiiart.usbkeyboard;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
public abstract class UsbHidKbd {
// ToDo: replace byte with ByteArray... everywhere
protected Map<String, byte[]> kbdVal= new HashMap<String, byte[]>();
public byte[] getScancode(String key) {
byte[] value = (byte[]) kbdVal.get(key);
if ( value == null ) {
throw new NoSuchElementException("Scancode for '" + key + "' not found (" + this.kbdVal.size() + ")");
}
return value;
}
}

View file

@ -0,0 +1,133 @@
/**
* Authorizer
*
* Copyright 2016 by Tjado Mäcke <tjado@maecke.de>
* Licensed under GNU General Public License 3.0.
*
* @license GPL-3.0 <https://opensource.org/licenses/GPL-3.0>
*/
package net.askiiart.usbkeyboard;
public class UsbHidKbd_en_US extends UsbHidKbd {
public UsbHidKbd_en_US() {
kbdVal.put(null, new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("a", new byte[] {0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("b", new byte[] {0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("c", new byte[] {0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("d", new byte[] {0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("e", new byte[] {0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("f", new byte[] {0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("g", new byte[] {0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("h", new byte[] {0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("i", new byte[] {0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("j", new byte[] {0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("k", new byte[] {0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("l", new byte[] {0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("m", new byte[] {0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("n", new byte[] {0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("o", new byte[] {0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("p", new byte[] {0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("q", new byte[] {0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("r", new byte[] {0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("s", new byte[] {0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("t", new byte[] {0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("u", new byte[] {0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("v", new byte[] {0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("w", new byte[] {0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("x", new byte[] {0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("y", new byte[] {0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("z", new byte[] {0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("A", new byte[] {0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("B", new byte[] {0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("C", new byte[] {0x02, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("D", new byte[] {0x02, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("E", new byte[] {0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("F", new byte[] {0x02, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("G", new byte[] {0x02, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("H", new byte[] {0x02, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("I", new byte[] {0x02, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("J", new byte[] {0x02, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("K", new byte[] {0x02, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("L", new byte[] {0x02, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("M", new byte[] {0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("N", new byte[] {0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("O", new byte[] {0x02, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("P", new byte[] {0x02, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("Q", new byte[] {0x02, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("R", new byte[] {0x02, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("S", new byte[] {0x02, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("T", new byte[] {0x02, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("U", new byte[] {0x02, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("V", new byte[] {0x02, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("W", new byte[] {0x02, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("X", new byte[] {0x02, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("Y", new byte[] {0x02, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("Z", new byte[] {0x02, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("1", new byte[] {0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("2", new byte[] {0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("3", new byte[] {0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("4", new byte[] {0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("5", new byte[] {0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("6", new byte[] {0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("7", new byte[] {0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("8", new byte[] {0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("9", new byte[] {0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("0", new byte[] {0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("!", new byte[] {0x02, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("@", new byte[] {0x02, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("#", new byte[] {0x02, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("$", new byte[] {0x02, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("%", new byte[] {0x02, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("^", new byte[] {0x02, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("&", new byte[] {0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("*", new byte[] {0x02, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("(", new byte[] {0x02, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put(")", new byte[] {0x02, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("return", new byte[] {0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("enter", new byte[] {0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("tab", new byte[] {0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("tabulator", new byte[] {0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("esc", new byte[] {0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("escape", new byte[] {0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("bckspc", new byte[] {0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("backspace", new byte[] {0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("\t", new byte[] {0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put(" ", new byte[] {0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("-", new byte[] {0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("=", new byte[] {0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("[", new byte[] {0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("]", new byte[] {0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("\\", new byte[] {0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put(";", new byte[] {0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("'", new byte[] {0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("`", new byte[] {0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put(",", new byte[] {0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put(".", new byte[] {0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("/", new byte[] {0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("_", new byte[] {0x02, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("+", new byte[] {0x02, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("{", new byte[] {0x02, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("}", new byte[] {0x02, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("|", new byte[] {0x02, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put(":", new byte[] {0x02, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("\"", new byte[] {0x02, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("~", new byte[] {0x02, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("<", new byte[] {0x02, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put(">", new byte[] {0x02, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00} );
kbdVal.put("?", new byte[] {0x02, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00} );
}
}

View file

@ -0,0 +1,75 @@
/**
* Authorizer
*
* Copyright 2016 by Tjado Mäcke <tjado@maecke.de>
* Licensed under GNU General Public License 3.0.
*
* @license GPL-3.0 <https://opensource.org/licenses/GPL-3.0>
*/
package net.askiiart.usbkeyboard;
import android.util.Log;
public class Utilities
{
final static boolean DEBUG = true;
public static String bytesToHex(byte[] in) {
final StringBuilder builder = new StringBuilder();
for(byte b : in) {
builder.append(String.format("%02x", b));
}
return builder.toString();
}
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i + 1), 16));
}
return data;
}
public static String formatString(String str) {
if (str != null) {
str = str.replaceAll("\\r\\n|\\r|\\n", " ");
}
return str;
}
/** To be more independent of the PasswdSafe code, some code is duplicated */
/** Log a debug message at info level */
public static void dbginfo(String tag, String msg)
{
if (DEBUG)
Log.i(tag, msg);
}
/** Log a debug message and exception at info level */
public static void dbginfo(String tag, Throwable t, String msg)
{
if (DEBUG)
Log.i(tag, msg, t);
}
/** Log a formatted debug message at info level */
public static void dbginfo(String tag, String fmt, Object... args)
{
if (DEBUG) {
Log.i(tag, String.format(fmt, args));
}
}
/** Log a formatted debug message and exception at info level */
public static void dbginfo(String tag, Throwable t,
String fmt, Object... args)
{
if (DEBUG) {
Log.i(tag, String.format(fmt, args), t);
}
}
}

View file

@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>

View file

@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

View file

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/textBoxOfText"
android:layout_width="330dp"
android:layout_height="56dp"
android:layout_marginTop="160dp"
android:ems="10"
android:inputType="text"
android:text="Text to type"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/sendTextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="sendString"
android:text="Send text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textBoxOfText" />
<Button
android:id="@+id/escButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="esc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sendTextButton"
android:onClick="sendEscape"/>
<Button
android:id="@+id/tabButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\\t"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/escButton"
android:onClick="sendTab" />
<Button
android:id="@+id/enterButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\\n"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tabButton"
android:onClick="sendEnter"/>
<Button
android:id="@+id/bkspButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="bksp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/enterButton"
android:onClick="sendBackspace"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View file

@ -0,0 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.USBKbdJava" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
</style>
</resources>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>

View file

@ -0,0 +1,3 @@
<resources>
<string name="app_name">USB kbd java</string>
</resources>

View file

@ -0,0 +1,9 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.USBKbdJava" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>
<style name="Theme.USBKbdJava" parent="Base.Theme.USBKbdJava" />
</resources>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample backup rules file; uncomment and customize as necessary.
See https://developer.android.com/guide/topics/data/autobackup
for details.
Note: This file is ignored for devices older that API 31
See https://developer.android.com/about/versions/12/backup-restore
-->
<full-backup-content>
<!--
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="device.xml"/>
-->
</full-backup-content>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample data extraction rules file; uncomment and customize as necessary.
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
for details.
-->
<data-extraction-rules>
<cloud-backup>
<!-- TODO: Use <include> and <exclude> to control what is backed up.
<include .../>
<exclude .../>
-->
</cloud-backup>
<!--
<device-transfer>
<include .../>
<exclude .../>
</device-transfer>
-->
</data-extraction-rules>

View file

@ -0,0 +1,17 @@
package net.askiiart.usbkeyboard;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}