Skip to content

Instantly share code, notes, and snippets.

@jan4984
Last active June 17, 2022 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jan4984/eec3a2295e21f63d9c291b697f3e1cd4 to your computer and use it in GitHub Desktop.
Save jan4984/eec3a2295e21f63d9c291b697f3e1cd4 to your computer and use it in GitHub Desktop.
add pass to linux game console
package main
import (
"encoding/binary"
"fmt"
"io"
"os"
"strings"
)
func main() {
dev := os.Getenv("DEVICE_FILE_PATH")
if dev == "" {
dev = "/dev/input/js0"
}
f, err := os.Open(dev)
if err != nil {
panic(err)
}
defer f.Close()
m := map[rune]string{
'a': "110010",
'b': "111011",
'x': "112012",
'y': "113013",
}
pass := os.Getenv("QUIT_PASS")
if pass == "" {
pass = "abbaxy"
}
passStr := ""
for _, b := range pass {
passStr = passStr + m[b]
}
input := ""
for {
//u32 time; /* event timestamp in milliseconds */
//u16 value; /* value */
//u8 type; /* event type */
//u8 number; /* axis/button number */
a := [8]byte{}
buf := a[:]
_, err = io.ReadFull(f, buf)
if err != nil {
panic(err)
}
//_ = binary.LittleEndian.Uint32(buf)
value := binary.LittleEndian.Uint16(buf[4:])
type_ := buf[6]
number := buf[7]
input = fmt.Sprintf("%v%v%v%v", input, value, type_, number)
if strings.HasPrefix(passStr, input) {
if passStr == input {
println("pass")
break
}
println("good, try more")
continue
}
println("wrong pass")
input = ""
//println(time, value, type_, number)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment