Skip to content

a Typewriter song for linux using bpf framework, tinycthread and write on c language

License

Notifications You must be signed in to change notification settings

haller33/typewriter-song

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typewriter-song

This is a bpftrace-fork program to run locally that turns your keyboard into a noisy typewriter. Keystrokes make a "click" and the enter key makes a "ting".

This works by tracing the Linux tty driver using kprobes. Brendan Gregg first wrote tracing-typewriter tools in 2005.

Dependencies

  • C Compiler ( Clang )
  • bpftrace
  • pipeweire for the pw-play command. You can edit the source to use a different audio player.

Why a "Fork" ?

because the project with bpftrace need root acess and my root user can't play sound on my pipewire configuration, so i created a client-server side, to inform a key press and play the sound on user space.

also the project have use of a lot of resources because relay on OS process level of fork, to have to play the sound, this project relay on greenthreads for that and single-header files like stb

remember that the amount of code used and created may declassify this a fork of project, and maybe another project by it self.

Build

Just use nobuild build system, with some extensions for this project in particular, for meta programming.

make first
./first 
./bin/typewriter-song

or just use the old legacy with bpftrace by it self and the daemon to play the sound.

make first
./first 
./bin/typewriter-song-daemon &
./typewriter.bt &

also can be run the daemon on another machine and play the typewriter sound on a stereo setup. ( just need some configuration to set network port and socket conection. )

Source

Just the code:

#!/usr/bin/bpftrace --unsafe
/* copy from https://github.com/brendangregg/bpf-typewriter */

kprobe:kbd_event
/arg1 == 1 && arg3 == 1/
{
        if (arg2 == 28) {
	
                 system("./bin/typewriter-song-sender ENT&");
        } else {
       
	         system("./bin/typewriter-song-sender &");
        }
}

the resource is also a systemd service, and TODO need to make more changes to compile eBPF programs from C source code.

considerations

I would have traced kbd_rawcode(), but it appears inlined and unavailable to kprobes. The --unsafe option is necessary because this tool is launching commands via system().

About

a Typewriter song for linux using bpf framework, tinycthread and write on c language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages