📄 tty.c
字号:
/* * This file is part of John the Ripper password cracker, * Copyright (c) 1996-98 by Solar Designer */#ifndef __DJGPP__#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <termios.h>#include <unistd.h>#include <stdlib.h>#else#include <bios.h>#endif#ifdef __CYGWIN32__#include <string.h>#include <sys/socket.h>extern int tcgetattr(int fd, struct termios *termios_p);extern int tcsetattr(int fd, int actions, struct termios *termios_p);#endif#include "tty.h"#ifndef __DJGPP__static int tty_fd = 0;static struct termios saved_ti;#endifvoid tty_init(){#ifndef __DJGPP__ int fd; struct termios ti; if (tty_fd) return; if ((fd = open("/dev/tty", O_RDONLY | O_NONBLOCK)) < 0) return;#ifndef __CYGWIN32__ if (tcgetpgrp(fd) != getpid()) { close(fd); return; }#endif tcgetattr(fd, &ti); saved_ti = ti; ti.c_lflag &= ~(ICANON | ECHO); ti.c_cc[VMIN] = 1; ti.c_cc[VTIME] = 0; tcsetattr(fd, TCSANOW, &ti); tty_fd = fd; atexit(tty_done);#endif}int tty_getchar(){#ifndef __DJGPP__ int c;#ifdef __CYGWIN32__ fd_set set; struct timeval tv;#endif if (tty_fd) {#ifdef __CYGWIN32__ FD_ZERO(&set); FD_SET(tty_fd, &set); tv.tv_sec = 0; tv.tv_usec = 0; if (select(tty_fd + 1, &set, NULL, NULL, &tv) <= 0) return -1;#endif c = 0; if (read(tty_fd, &c, 1) > 0) return c; }#else if (_bios_keybrd(_KEYBRD_READY)) return _bios_keybrd(_KEYBRD_READ);#endif return -1;}void tty_done(){#ifndef __DJGPP__ int fd; if (!tty_fd) return; fd = tty_fd; tty_fd = 0; tcsetattr(fd, TCSANOW, &saved_ti); close(fd);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -