-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
90 lines (70 loc) · 2.61 KB
/
main.js
File metadata and controls
90 lines (70 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {Terminal} from '@xterm/xterm';
import {FitAddon} from '@xterm/addon-fit';
import {AttachAddon} from '@xterm/addon-attach';
import {CanvasAddon} from '@xterm/addon-canvas';
import {Unicode11Addon} from '@xterm/addon-unicode11';
import '@xterm/xterm/css/xterm.css';
import './style.css';
function setup() {
// THERE IS STILL SOMETHING CONFUSING HERE... SUCH AS IT CANT HANDLE ENDL WELL
// setup terminal
let term = new Terminal();
term.options.allowProposedApi = true;
term.loadAddon(new CanvasAddon());
let fitAddon = new FitAddon();
term.loadAddon(fitAddon);
term.loadAddon(new Unicode11Addon());
term.unicode.activeVersion = '11';
term.open(document.getElementById('terminal'));
fitAddon.fit();
window.addEventListener('resize', ()=>{
fitAddon.fit();
});
term.attachCustomKeyEventHandler((e) => {
// Ctrl + Shift + C, to prevent browser from opening devtools
if(e.ctrlKey && e.shiftKey && e.key.toLowerCase() === 'c') {
e.preventDefault();
document.execCommand('copy');
}
});
// load wsrx
let wsrx = new URLSearchParams(window.location.search).get('wsrx');
window.history.replaceState({}, null, '/');
if(!wsrx) {
// ask user for wsrx
wsrx = prompt('请输入 WSRX 地址:');
if(wsrx) {
wsrx = wsrx.trim();
} else {
alert('未提供 WSRX 地址,无法连接到题目。');
return;
}
}
// open socket
let socket = new WebSocket(wsrx);
term.loadAddon(new AttachAddon(socket));
let firstmsg = true;
socket.addEventListener('open', ()=>{
term.clear();
});
socket.addEventListener('close', ()=>{
term.writeln('');
term.writeln('\n--- 连接中断 ---');
});
term.writeln('');
term.writeln('\n--- 正在连接到题目 ---');
// done
window.term = term;
window.socket = socket;
queueMicrotask(console.log.bind(
console,
'%c网页终端不是题目的一部分,解出题目无需分析网页终端的源码。\n可以绕过网页终端,在使用 WSRX 等工具连接到 WebSocket 后使用 netcat 或 pwntools 等任何工具连接到本题目。',
'font-size: 1.5em; background-color: yellow; color: black; font-weight: bold; padding: .5em',
));
queueMicrotask(console.log.bind(
console,
'\n如果你仍然想用网页终端解题,可以借助全局变量 socket。\n例如通过 socket.send("...\\n"); 和 socket.onmessage = console.log; 来与题目交互。\n\n',
));
term.focus();
}
setup();