BBS水木清华站∶精华区

发信人: hellguard (小四), 信区: Linux        
标  题: Re: 问个有关module的问题 
发信站: BBS 水木清华站 (Sun Sep 24 19:13:59 2000) 
 
printf不是系统调用,你无法通过module去hook, 
但是如果你使用动态链接库的话,可以这样 
 
2. vi printftest.c 
 
int main ( int argc, char * argv[] ) 

    printf( "faint, what happenning.\n" ); 
    return 0; 
}  /* end of main */ 
 
[scz@ /home/scz/src]> gcc -O3 -o printftest printftest.c 
[scz@ /home/scz/src]> ./printftest 
faint, what happenning. 
[scz@ /home/scz/src]> 
 
3. vi our_printf.c 
 
int printf ( const char * format, ... ) 

    puts( "hello world." ); 
    return 0; 
}  /* end of printf */ 
 
[scz@ /home/scz/src]> gcc -c -fPIC our_printf.c -O3 -o our_printf.o 
[scz@ /home/scz/src]> ld -m elf_i386 -shared -o our_printf.so -soname our_printf.so our_printf.o 
[scz@ /home/scz/src]> export LD_PRELOAD=/home/scz/src/our_printf.so 
[scz@ /home/scz/src]> ./printftest 
hello world. 
[scz@ /home/scz/src]>  
 
 
【 在 ghxiang (henry) 的大作中提到: 】 
 请问,我是否能编写一个module,在该module中重写例如printf之类的函数,然后 
 insmod一把即可使用自己的printf?清高手指点! 
 
 
-- 
 
            也许有一天,他再从海上蓬蓬的雨点中升起, 
            飞向西来,再形成一道江流,再冲倒两旁的石壁, 
            再来寻夹岸的桃花。然而,我不敢说来生,也不敢信来生...... 
 
 
※ 来源:·BBS 水木清华站 smth.org·[FROM: 210.73.87.125] 

BBS水木清华站∶精华区