/* This piece of code is ugly and inefficient. */ #include #include #include #include "cli.h" struct my_module { struct module m; char name[64]; unsigned long jmp; unsigned long delta; } my_module; static int do_cli() { (*(unsigned long*)(((char*)current)+0x1FF4)) &= ~0x200; return 0; } static int do_sti() { (*(unsigned long*)(((char*)current)+0x1FF4)) |= 0x200; return 0; } void init_struct(int (*func)(),struct my_module *dst, struct my_module *p) { dst->m.size_of_struct = sizeof(struct module); dst->m.next=NULL; dst->m.name=p->name; dst->m.size=sizeof(my_module); dst->m.flags=0; dst->m.nsyms=0; dst->m.ndeps=0; dst->m.syms=NULL; dst->m.deps=NULL; dst->m.refs=NULL; dst->m.init=(void*)&(p->jmp); dst->m.cleanup=NULL; dst->m.ex_table_start=NULL; dst->m.ex_table_end=NULL; dst->m.persist_start=NULL; dst->m.persist_end=NULL; dst->m.can_unload=NULL; sprintf(dst->name,"hack_%d_hack",getpid()); dst->jmp=0xE9909090; dst->delta=(unsigned long)func-(unsigned long)(p+1); } static void kernel_call(int (*func)()) { struct my_module my_module; init_struct(func,&my_module,&my_module); init_struct(func,&my_module,(void*)create_module(my_module.name,my_module.m.size)); init_module(my_module.name,&my_module.m); delete_module(my_module.name); } void cli() { kernel_call(do_cli); } void sti() { kernel_call(do_sti); }