/p/small .. /

This directory is full of various small hacks I've done that are interesting or otherwise worth preserving. All of these are written in C because C is my mother tongue.
699 bytes as.c
33 loc
An obfuscated program that I've forgotten the original purpose of. Who knows what it was intended to do?
826 bytes box.c
49 loc
A demonstration of polymorphism via boxing.
867 bytes def.c
48 loc
A demonstration of the perils of preprocessor abuse, making C read a lot like... well, like another language.
10163 bytes ed3.c
505 loc
A curses-based visual editor. Arrow keys for movement, C-x to enter a command; commands are: f(ind text) q(uit) r(ead file) s(set) w(rite file) w(rite then )q(uit). Commands are first read from $HOME/.ed3rc on startup.
1411 bytes exn.c
84 loc
Exceptions in C, inspired by plan 9's C error handling mechanism. The exception stack is a stack of jmp_buf (see setjmp(3)), throw is a longjmp to the top of that stack, catch is a setjmp. The poperror function serves to clean up a catch frame. Note that this doesn't work as-is because catch saves the wrong stack frame!
6531 bytes inject.c
173 loc
Injects a thread running the shellcode at the end of the payload into another process. Requires ptrace() access. Change the 0xf00 at 'make me 0x10f00' to 0x10f00 and we'll be inside the same thread group. The basic approach: land stage1 shellcode at the usual ELF entry point (unlikely to be running right now) which maps us some memory in the target, trap back to us via a magic syscall, drop stage2 shellcode into that mapped memory, clean up after stage1, transfer control to stage2; stage2 spawns a new thread then puts everything back on the old target thread.
4797 bytes ped.c
236 loc
A machine-language ptrace-based debugger with a terse interface. Do '?' for a list of commands. Must be invoked with a target pid - it cannot launch targets itself at the moment. Can read & write memory and registers and single-step the target, but doesn't know how to set breakpoints (although you can do so yourself using '!' with 0xcc).
1988 bytes rg.c
124 loc
A maze generator ("rooms generator" in the parlance of 2010 me). Emits a randomly-generated maze on stdout when run.
1119 bytes sort.c
63 loc
A minimal implementation of sort(1) - sorts stdin lexicographically to stdout.