-
Notifications
You must be signed in to change notification settings - Fork 7
/
Main.js
166 lines (137 loc) · 4.4 KB
/
Main.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Debug
var textArea = document.querySelector("#debug");
textArea.value = "";
function debug(txt) {
if (textArea.value !== '') {
textArea.value += "\n";
}
textArea.value += txt;
textArea.scrollTop = textArea.scrollHeight;
}
// Cap file viewer
function prettyTime(date) {
var result = "", temp;
result += date.getFullYear();
result += "-";
temp = (date.getMonth() + 1).toString();
while (temp.length < 2) temp = "0" + temp;
result += temp;
result += "-";
temp = date.getDate().toString();
while (temp.length < 2) temp = "0" + temp;
result += temp;
result += "T";
temp = date.getHours().toString();
while (temp.length < 2) temp = "0" + temp;
result += temp;
result += ":";
temp = date.getMinutes().toString();
while (temp.length < 2) temp = "0" + temp;
result += temp;
result += ":";
temp = date.getSeconds().toString();
while (temp.length < 2) temp = "0" + temp;
result += temp;
result += ".";
temp = date.getMilliseconds().toString();
while (temp.length < 3) temp = "0" + temp;
result += temp;
return result;
}
function prettyMac(mac) {
var result = "", i;
for (i = 0; i < mac.length; i += 2) {
if (result !== "") {
result = result + ":";
}
result += mac.substring(i, i + 2).toUpperCase();
}
return result;
}
function prettyFrame(frame) {
var tr = document.createElement("tr");
var td = document.createElement("td");
td.className = "prettyFrame";
td.colSpan = 8;
var pre = document.createElement("pre");
pre.className = "payload";
pre.textContent = JSON.stringify(frame, null, 2);
td.appendChild(pre);
tr.appendChild(td);
return tr;
}
function prettyClick(row, frame) {
row.addEventListener('click', function() {
if (this.className === "collapsed") {
this.querySelector(".expando").textContent = "-";
this.className = "expanded";
this.parentNode.insertBefore(prettyFrame(frame), this.nextSibling);
this.scrollIntoView();
} else if (this.className === "expanded") {
this.querySelector(".expando").textContent = "+";
document.querySelector(".prettyFrame").remove();
this.className = "collapsed";
}
}, false);
}
function loadCapfile(capfile) {
var tbody = document.querySelector("#capfileBody");
for (var i = 0; i < capfile.packetFrames.length; i++) {
var frame = capfile.packetFrames[i];
var tr = document.createElement("tr");
tr.className = "collapsed";
var td;
td = document.createElement("td");
td.className = "expando";
td.textContent = "+";
tr.appendChild(td);
// Frame #
td = document.createElement("td");
td.className = "index";
td.textContent = (i + 1);
tr.appendChild(td);
// Timestamp
td = document.createElement("td");
td.textContent = prettyTime(frame.header.timestamp);
tr.appendChild(td);
// Source Address
td = document.createElement("td");
td.textContent = prettyMac(frame.addr2);
tr.appendChild(td);
// Destination Address
td = document.createElement("td");
td.textContent = prettyMac(frame.addr1);
tr.appendChild(td);
// Size
td = document.createElement("td");
td.textContent = frame.header.length;
tr.appendChild(td);
// Type
td = document.createElement("td");
var name = frame.name;
if (frame.description) {
frame.name += " - " + frame.description;
}
td.textContent = frame.name;
tr.appendChild(td);
prettyClick(tr, frame);
tbody.appendChild(tr);
}
}
// FileChooser
document.querySelector('#fileChooser').addEventListener('change', function() {
var reader = new FileReader();
reader.onload = function(){
var capfile = new CapFile(this.result, debug);
loadCapfile(capfile);
//document.querySelector('#result').innerHTML = JSON.stringify(capfile, null, 2);
}
reader.readAsBinaryString(this.files[0]);
}, false);
// Test buttons
document.querySelector("#test1").addEventListener('click', function() {
Crack.test_WPA1(debug);
}, false);
document.querySelector("#test2").addEventListener('click', function() {
Crack.test_WPA2(debug);
}, false);