Switched rawcapture to use python because it works
This commit is contained in:
parent
6fcaba194a
commit
7f1d95183e
4
Makefile
4
Makefile
@ -19,9 +19,7 @@ build: tangle
|
|||||||
- cd smartkeyboard/client && go mod init keyboard.voidnet.tech
|
- cd smartkeyboard/client && go mod init keyboard.voidnet.tech
|
||||||
- cd smartkeyboard/client && go mod tidy
|
- cd smartkeyboard/client && go mod tidy
|
||||||
- cd smartkeyboard/client && go build -o ../../bin/keyboard-client
|
- cd smartkeyboard/client && go build -o ../../bin/keyboard-client
|
||||||
- cd smartkeyboard/tools/rawcapture && go mod init rawcapture.keyboard.voidnet.tech
|
|
||||||
- cd smartkeyboard/tools/rawcapture && go mod tidy
|
|
||||||
- cd smartkeyboard/tools/rawcapture && go build -o ../../../bin/rawcapture
|
|
||||||
|
|
||||||
|
|
||||||
test: tangle
|
test: tangle
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
This tool captures keyboard input from /dev/input/eventX and pipes it to the fifo accordingly.
|
This tool captures keyboard input from /dev/input/eventX and pipes it to the fifo accordingly.
|
||||||
|
|
||||||
It is meant to be ran from it's own tty, and is not meant to be used with a graphical environment, although a full screen terminal emulator will work for most input.
|
An escape sequence of QKEYBOARD (QWERTY) will exit the program, but this can be changed via a command line argument.
|
||||||
|
|
||||||
An escape sequence of escape+f1 will exit the program, but this can be changed via a command line argument.
|
|
||||||
|
|
||||||
|
|
||||||
## Why
|
## Why
|
||||||
@ -15,99 +13,249 @@ Generally a user would be in this mode when not typing extensively.
|
|||||||
|
|
||||||
# Entrypoint
|
# Entrypoint
|
||||||
|
|
||||||
``` go
|
``` python
|
||||||
|
|
||||||
--- /tools/rawcapture/rawcapture.go
|
--- /tools/rawcapture/rawcapture.py
|
||||||
|
|
||||||
package main
|
#!/usr/bin/python3
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import evdev
|
||||||
|
import traceback
|
||||||
|
import queue
|
||||||
|
import threading
|
||||||
|
|
||||||
import (
|
# Docs http://python-evdev.readthedocs.io/en/latest/tutorial.html
|
||||||
"io/ioutil"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
//"os/signal"
|
|
||||||
"github.com/EgosOwn/keylogger"
|
|
||||||
)
|
|
||||||
//ioutil.WriteFile(clientFifoInputFile, []byte(input), 0644)
|
|
||||||
|
|
||||||
/*
|
device = ""
|
||||||
func receive(signalCh chan os.Signal, doneCh chan struct{}) {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
// Example. Process to receive a message
|
|
||||||
// case msg := <-receiveMessage():
|
|
||||||
case <-signalCh:
|
|
||||||
pass
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func main(){
|
fifo = os.getenv("KEYBOARD_FIFO", "")
|
||||||
@{get client fifo input file from environment}
|
if not fifo:
|
||||||
if ! clientFifoInputFileEnvExists {
|
print("KEYBOARD_FIFO not set, exiting.")
|
||||||
os.Exit(1)
|
exit(0)
|
||||||
}
|
|
||||||
|
try:
|
||||||
/*
|
dev_path = sys.argv[1]
|
||||||
doneCh := make(chan struct{})
|
try:
|
||||||
|
device = evdev.InputDevice(dev_path)
|
||||||
signalCh := make(chan os.Signal, 1)
|
except PermissionError:
|
||||||
signal.Notify(signalCh, os.Interrupt)
|
print("Insufficent permission to read, run me as root!")
|
||||||
|
exit(0)
|
||||||
go receive(signalCh, doneCh)
|
|
||||||
*/
|
except IndexError:
|
||||||
keyboard := ""
|
foundDev = []
|
||||||
|
allDev = [evdev.InputDevice(dev) for dev in evdev.list_devices()]
|
||||||
|
if len(allDev) == 0:
|
||||||
if len(os.Args) > 1 {
|
print("No devices found, run me as root!")
|
||||||
keyboard = os.Args[1]
|
exit(0)
|
||||||
} else {
|
print("Found the following USB input devices: ")
|
||||||
keyboard = keylogger.FindKeyboardDevice()
|
count = 0
|
||||||
}
|
for device in allDev:
|
||||||
if keyboard == "" {
|
if "usb" in device.phys:
|
||||||
fmt.Println("could not find keyboard")
|
count += 1
|
||||||
os.Exit(1)
|
foundDev.append(device)
|
||||||
}
|
print(str(count) + ". " + device.name, device.fn)
|
||||||
fmt.Println("Using keyboard " + keyboard)
|
|
||||||
|
print("Select a device (1 to %s)" % str(len(foundDev)), end=" ")
|
||||||
|
i = int(input())
|
||||||
k, err := keylogger.New(keyboard)
|
i -= 1
|
||||||
if err != nil {
|
device = foundDev[i]
|
||||||
fmt.Println("could not get keyboard")
|
|
||||||
os.Exit(1)
|
print("Using device " + device.fn)
|
||||||
}
|
|
||||||
defer k.Close()
|
print("Grabbing device for exclusive access.")
|
||||||
|
device.grab()
|
||||||
events := k.Read()
|
print("Enter numbers, press enter (Ctrl-C to exit).")
|
||||||
var key = ""
|
|
||||||
//byte keyByte = 0
|
write_queue = queue.Queue()
|
||||||
|
def write_loop():
|
||||||
// range of events
|
while True:
|
||||||
for e := range events {
|
try:
|
||||||
switch e.Type {
|
data = write_queue.get()
|
||||||
// EvKey is used to describe state changes of keyboards, buttons, or other key-like devices.
|
with open(fifo, "w") as f:
|
||||||
// check the input_event.go for more events
|
f.write(data)
|
||||||
case keylogger.EvKey:
|
except Exception as e:
|
||||||
|
print("Error writing to fifo: " + str(e))
|
||||||
|
traceback.print_exc()
|
||||||
// if the state of key is pressed
|
|
||||||
if e.KeyPress() {
|
write_thread = threading.Thread(target=write_loop, daemon=True)
|
||||||
key = e.KeyString()
|
write_thread.start()
|
||||||
fmt.Println(key)
|
|
||||||
fmt.Println(e.Code)
|
KEYMAP = {
|
||||||
ioutil.WriteFile(clientFifoInputFile, []byte(fmt.Sprintf("{KEYDWN}%s", key)), 0644)
|
1: "ESC",
|
||||||
}
|
2: "1",
|
||||||
|
3: "2",
|
||||||
// if the state of key is released
|
4: "3",
|
||||||
if e.KeyRelease() {
|
5: "4",
|
||||||
key = e.KeyString()
|
6: "5",
|
||||||
ioutil.WriteFile(clientFifoInputFile, []byte(fmt.Sprintf("{KEYUP}%s", key)), 0644)
|
7: "6",
|
||||||
|
8: "7",
|
||||||
|
9: "8",
|
||||||
|
10: "9",
|
||||||
|
11: "0",
|
||||||
|
12: "-",
|
||||||
|
13: "=",
|
||||||
|
14: "BS",
|
||||||
|
15: "TAB",
|
||||||
|
16: "Q",
|
||||||
|
17: "W",
|
||||||
|
18: "E",
|
||||||
|
19: "R",
|
||||||
|
20: "T",
|
||||||
|
21: "Y",
|
||||||
|
22: "U",
|
||||||
|
23: "I",
|
||||||
|
24: "O",
|
||||||
|
25: "P",
|
||||||
|
26: "[",
|
||||||
|
27: "]",
|
||||||
|
28: "ENTER",
|
||||||
|
29: "L_CTRL",
|
||||||
|
30: "A",
|
||||||
|
31: "S",
|
||||||
|
32: "D",
|
||||||
|
33: "F",
|
||||||
|
34: "G",
|
||||||
|
35: "H",
|
||||||
|
36: "J",
|
||||||
|
37: "K",
|
||||||
|
38: "L",
|
||||||
|
39: ";",
|
||||||
|
40: "'",
|
||||||
|
41: "`",
|
||||||
|
42: "L_SHIFT",
|
||||||
|
43: "\\",
|
||||||
|
44: "Z",
|
||||||
|
45: "X",
|
||||||
|
46: "C",
|
||||||
|
47: "V",
|
||||||
|
48: "B",
|
||||||
|
49: "N",
|
||||||
|
50: "M",
|
||||||
|
51: ",",
|
||||||
|
52: ".",
|
||||||
|
53: "/",
|
||||||
|
54: "R_SHIFT",
|
||||||
|
55: "*",
|
||||||
|
56: "L_ALT",
|
||||||
|
57: "SPACE",
|
||||||
|
58: "CAPS_LOCK",
|
||||||
|
59: "F1",
|
||||||
|
60: "F2",
|
||||||
|
61: "F3",
|
||||||
|
62: "F4",
|
||||||
|
63: "F5",
|
||||||
|
64: "F6",
|
||||||
|
65: "F7",
|
||||||
|
66: "F8",
|
||||||
|
67: "F9",
|
||||||
|
68: "F10",
|
||||||
|
69: "NUM_LOCK",
|
||||||
|
70: "SCROLL_LOCK",
|
||||||
|
71: "HOME",
|
||||||
|
72: "UP_8",
|
||||||
|
73: "PGUP_9",
|
||||||
|
74: "-",
|
||||||
|
75: "LEFT_4",
|
||||||
|
76: "5",
|
||||||
|
77: "RT_ARROW_6",
|
||||||
|
78: "+",
|
||||||
|
79: "END_1",
|
||||||
|
80: "DOWN",
|
||||||
|
81: "PGDN_3",
|
||||||
|
82: "INS",
|
||||||
|
83: "DEL",
|
||||||
|
84: "",
|
||||||
|
85: "",
|
||||||
|
86: "",
|
||||||
|
87: "F11",
|
||||||
|
88: "F12",
|
||||||
|
89: "",
|
||||||
|
90: "",
|
||||||
|
91: "",
|
||||||
|
92: "",
|
||||||
|
93: "",
|
||||||
|
94: "",
|
||||||
|
95: "",
|
||||||
|
96: "R_ENTER",
|
||||||
|
97: "R_CTRL",
|
||||||
|
98: "/",
|
||||||
|
99: "PRT_SCR",
|
||||||
|
100: "R_ALT",
|
||||||
|
101: "",
|
||||||
|
102: "HOME",
|
||||||
|
103: "UP",
|
||||||
|
104: "PGUP",
|
||||||
|
105: "LEFT",
|
||||||
|
106: "RIGHT",
|
||||||
|
107: "END",
|
||||||
|
108: "DOWN",
|
||||||
|
109: "PGDN",
|
||||||
|
110: "INSERT",
|
||||||
|
111: "DEL",
|
||||||
|
112: "",
|
||||||
|
113: "",
|
||||||
|
114: "",
|
||||||
|
115: "",
|
||||||
|
116: "",
|
||||||
|
117: "",
|
||||||
|
118: "",
|
||||||
|
119: "PAUSE",
|
||||||
|
120: "",
|
||||||
|
121: "",
|
||||||
|
122: "",
|
||||||
|
123: "",
|
||||||
|
124: "",
|
||||||
|
125: "SUPER"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key_str = ""
|
||||||
|
log = []
|
||||||
|
quit_str = "QKEYBOARD"
|
||||||
|
quit_list = []
|
||||||
|
for c in quit_str:
|
||||||
|
for k, v in KEYMAP.items():
|
||||||
|
if v == c:
|
||||||
|
quit_list.append(k)
|
||||||
break
|
break
|
||||||
}
|
|
||||||
}
|
def quit_if_necessry(log):
|
||||||
}
|
if len(log) > len(quit_list):
|
||||||
|
log.pop(0)
|
||||||
|
if log == quit_list:
|
||||||
|
print("Quitting...")
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
try:
|
||||||
|
for event in device.read_loop():
|
||||||
|
|
||||||
|
if event.type == evdev.ecodes.EV_KEY:
|
||||||
|
print(event)
|
||||||
|
#e_code = event.code - 1
|
||||||
|
e_code = event.code
|
||||||
|
if e_code == 2:
|
||||||
|
break
|
||||||
|
try:
|
||||||
|
key_str = KEYMAP[e_code]
|
||||||
|
except KeyError:
|
||||||
|
print("Unknown key: " + str(e_code))
|
||||||
|
if event.value == 1:
|
||||||
|
key_str = "{KEYDWN}" + key_str
|
||||||
|
log.append(e_code)
|
||||||
|
quit_if_necessry(log)
|
||||||
|
elif event.value == 0:
|
||||||
|
key_str = "{KEYUP}" + key_str
|
||||||
|
else:
|
||||||
|
print("Unknown value: " + str(event.value))
|
||||||
|
continue
|
||||||
|
write_queue.put(key_str)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
except (KeyboardInterrupt, SystemExit, OSError):
|
||||||
|
print(traceback.format_exc())
|
||||||
|
device.ungrab()
|
||||||
|
print("\rGoodbye!")
|
||||||
|
exit(0)
|
||||||
|
|
||||||
---
|
---
|
||||||
```
|
```
|
3
tools/TUI.md
Normal file
3
tools/TUI.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# SmartKeyboardTUI
|
||||||
|
|
||||||
|
SmartKeyboardTUI is a terminal user interface for SmartKeyboard. It wraps the other tools in this repository.
|
Loading…
Reference in New Issue
Block a user