rewrite of kishook.c into python