一 源代码
/*
linux-0.11/include/asm/system.h
添加f12_on标志
*/
int f12_on;//定义f12_on表示是否按下f12(每按两次抵消)
/*
linux-0.11/kernel/chr_drv/keyboard.S
注释掉f12显示进程信息的功能
*/
//按键调用键盘中断处理程序
keyboard_interrupt:
...
call key_table(,%eax,4)//根据键盘扫描码调用相应的处理函数
...
key_table:
//查得处理f12键的时func函数
.long func,none,none,none /* 58-5B f12 ? ? ? */
func:
/*
show_stat显示当前进程信息,这里我们重新定义f12的功能,所以注释掉show_stat函数的调用.
pushl %eax
pushl %ecx
pushl %edx
call show_stat
popl %edx
popl %ecx
popl %eax
*/
//筛选功能键
subb $0x3B,%al
jb end_func//排除小于f1
cmpb $9,%al
jbe ok_func//筛选f1-f10
subb $18,%al
cmpb $10,%al
jb end_func//排除小于f11
cmpb $11,%al
ja end_func//排除大于f12
ok_func:
cmpl $4,%ecx /* check that there is enough room */
jl end_func
movl func_table(,%eax,4),%eax//根据扫描码转换成转义字符序列
xorl %ebx,%ebx
jmp put_queue //将转义字符序列放到read_q
end_func:
ret
/*
* function keys send F1:'esc [ [ A' F2:'esc [ [ B' etc.
* 可知f1-f12的转义字符序列是'esc [ [ A-L'
*/
func_table:
.long 0x415b5b1b,0x425b5b1b,0x435b5b1b,0x445b5b1b
.long 0x455b5b1b,0x465b5b1b,0x475b5b1b,0x485b5b1b
.long 0x495b5b1b,0x4a5b5b1b,0x4b5b5b1b,0x4c5b5b1b
/*
linux-0.11/kernel/chr_drv/tty_io.c
根据需要切换f12状态
*/
void copy_to_cooked(struct tty_struct * tty)
{
signed char c;
while (!EMPTY(tty->read_q) && !FULL(tty->secondary)) {
GETCH(tty->read_q,c);//从read_q取出字符
if(c=='L'){
//如果是'L'(即f12转义字符序列的最小字节)表示按下f12键,则切换f12键的状态
if(f12_on)
f12_on=0;
else
f12_on=1;
break;
}
...
}
...
}
/*
linux-0.11/kernel/chr_drv/console.c
过滤控制台输出字符
*/
void con_write(struct tty_struct * tty)
{
int nr;
char c;
nr = CHARS(tty->write_q);
while (nr--) {
GETCH(tty->write_q,c);//从write_q取出字符
if(f12_on){
//如果f12键处于激活状态,则过滤字母数字显示为'*'
if(c>='A'&&c<='Z'||c>='a'&&c<='z'||c>='0'&&c<='9')
c='*';
}
...
}
...
}
/*
linux-0.11/fs/file_dev.c
过滤文件输出字符
*/
...
#include <asm/system.h>//引入f12_on标志
...
int file_write(struct m_inode * inode, struct file * filp, char * buf, int count)
{
...
char tmp;
...
while (c-->0){
tmp=get_fs_byte(buf++);//从用户空间获得缓冲区字符
if(f12_on){
//如果f12处于激活状态,则过滤字母和数字,显示为'*'
if(tmp>='A'&&tmp<='Z'||tmp>='a'&&tmp<='z'||tmp>='0'&&tmp<='9')
tmp='*';
}
*(p++) = tmp;
}
...
}
二 运行结果
//未修改时按f12
//过滤控制台输出
//过滤文件输出