-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpanic_report.js
More file actions
127 lines (110 loc) · 4.02 KB
/
panic_report.js
File metadata and controls
127 lines (110 loc) · 4.02 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
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
// SPDX-License-Identifier: MIT
var main_div = document.getElementById('main');
/*
* Check if the parameters are set as a url parameter or as a fragment
*/
function get_parameters() {
const queryString = window.location.search;
const fragString = window.location.hash.substring(1); //skip the leading #
const urlParams = new URLSearchParams(queryString);
const urlFragments = new URLSearchParams(fragString);
if (urlParams.get("z") || urlParams.get("zl")) {
return urlParams;
}
return urlFragments;
}
/*
* Encoding, same as Fido2 specification.
* v6.14+
*/
function numbers_to_data2(numbers) {
/* 17 decimal digits are converted to 7 bytes */
let main_len = Math.floor(numbers.length / 17) * 7;
/* and the remainings bytes, compute the reverse of [0, 3, 5, 8, 10, 13, 15, 17] */
let rem_len = Math.floor((numbers.length % 17) * 2 / 5);
let data = new Uint8Array(main_len + rem_len);
let offset = 0;
for (var i = 0; i < numbers.length; i += 17) {
let chunk = numbers.substring(i, i + 17);
let num = BigInt(chunk);
let num_bytes = 7;
if (chunk.len < 17) {
num_bytes = rem_len;
}
for (var j = 0; j < num_bytes; j++) {
data[offset] = Number(num % 256n);
num = num / 256n;
offset++;
}
}
return data;
}
/*
* Legacy encoding, found in v6.10 to v6.13
*/
function numbers_to_data(numbers) {
const num_chars_to_bits = [0, 4, 7, 10, 13];
const length_in_bits = Math.floor(numbers.length / 4) * 13 + num_chars_to_bits[numbers.length % 4];
const length_in_bytes = length_in_bits / 8;
const extra = length_in_bits % 8;
let data = new Uint8Array(length_in_bytes);
let offset = 0;
let byte_off = 0;
let rem = 0;
for (var i = 0; i < numbers.length; i += 4) {
let chunk = numbers.substring(i, i + 4);
let num = Number(chunk);
let new_length = num_chars_to_bits[chunk.length];
let b = offset + new_length;
if (byte_off * 8 + b >= length_in_bytes * 8) {
b -= extra;
}
if (b < 8) {
rem += num << (8 - b);
offset = b;
} else if (b < 16) {
data[byte_off] = rem + (num >> (b - 8));
byte_off++;
rem = (num << (16 - b)) & 0xff;
offset = (b - 8);
} else {
data[byte_off] = rem + (num >> (b - 8));
byte_off++;
data[byte_off] = num >> (b - 16);
byte_off++;
rem = num << (24 - b) & 0xff;
offset = (b - 16);
}
}
return data;
}
function add_info(name, value) {
if (value) {
div = document.createElement("div");
n = document.createElement("b");
n.innerHTML = name + ": ";
div.appendChild(n);
div.appendChild(document.createTextNode(value));
main_div.appendChild(div);
}
}
function add_data(data) {
uncompressed = pako.inflate(new Uint8Array(data));
text = String.fromCharCode.apply(null, uncompressed);
kmsg = document.createElement("pre");
kmsg.appendChild(document.createTextNode(text));
main_div.appendChild(kmsg);
}
const params = get_parameters();
add_info("Arch", params.get("a"));
add_info("Version", params.get("v"));
add_info("Distribution", params.get("d"));
const numbers = params.get("z");
const legacy_numbers = params.get("zl")
if (numbers) {
data = numbers_to_data2(numbers);
add_data(data);
} else if (legacy_numbers) {
data = numbers_to_data(legacy_numbers);
add_data(data);
}