📄 terminalinputchaff.java
字号:
/****************************************************************************** * * Copyright (c) 1999-2003 AppGate Network Security AB. All Rights Reserved. * * This file contains Original Code and/or Modifications of Original Code as * defined in and that are subject to the MindTerm Public Source License, * Version 2.0, (the 'License'). You may not use this file except in compliance * with the License. * * You should have received a copy of the MindTerm Public Source License * along with this software; see the file LICENSE. If not, write to * AppGate Network Security AB, Otterhallegatan 2, SE-41118 Goteborg, SWEDEN * *****************************************************************************/package com.mindbright.terminal;public abstract class TerminalInputChaff implements TerminalInputListener, Runnable{ private Thread chaffThread; private volatile boolean chaffActive; private volatile long chaffLastKeyTime; private int[] lastKeyBuf; private int lastKeyROffs; private int lastKeyWOffs; public void startChaff() { if(!chaffActive) { chaffActive = true; lastKeyBuf = new int[4]; lastKeyROffs = 0; lastKeyWOffs = 0; chaffThread = new Thread(this, "SSH2TerminalAdapterImpl.chaff"); chaffThread.setDaemon(true); chaffThread.start(); } } public void stopChaff() { if(chaffActive) { chaffActive = false; synchronized(chaffThread) { chaffThread.notify(); } chaffThread = null; } } public void typedChar(char c) { if(chaffThread == null) { sendTypedChar((int)c); } else { synchronized(this) { lastKeyBuf[lastKeyWOffs++] = (int)c; lastKeyWOffs &= 0x03; } dispenseChaff(); } } public void run() { long now; int wait; while(chaffActive) { try { synchronized(chaffThread) { chaffThread.wait(); } wait = (int)(System.currentTimeMillis() ^ (new Object()).hashCode()) & 0x1ff; do { int lastKeyChar = -1; synchronized(this) { if(lastKeyWOffs != lastKeyROffs) { lastKeyChar = lastKeyBuf[lastKeyROffs++]; lastKeyROffs &= 0x03; } } if(lastKeyChar >= 0) { sendTypedChar(lastKeyChar); } else { sendFakeChar(); } Thread.sleep(30); now = System.currentTimeMillis(); } while(chaffActive && (now - chaffLastKeyTime) < (1500 + wait)); } catch (InterruptedException e) { /* don't care... */ } } } public void dispenseChaff() { if(chaffThread != null) { long now = System.currentTimeMillis(); if((now - chaffLastKeyTime) > 1000) { chaffLastKeyTime = now; synchronized(chaffThread) { chaffThread.notify(); } } } } protected abstract void sendTypedChar(int c); protected abstract void sendFakeChar();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -