Skip to content

Commit 968bbc1

Browse files
committed
Added new -s/-scan option, archive new blobs and -f does support 'a' for all of them.
Signed-off-by: Diego Casorran <[email protected]>
1 parent 81b3c39 commit 968bbc1

File tree

4 files changed

+307
-1880
lines changed

4 files changed

+307
-1880
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ on:
99

1010
jobs:
1111
build:
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-20.04
1313

1414
strategy:
1515
matrix:
16-
node-version: [12.x, 16.x, 18.x]
16+
node-version: [20.x, 12.x]
1717

1818
steps:
1919
- uses: actions/checkout@v3

index.js

+64-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ const config = {
153153
async preload(page) {
154154
'use strict';
155155
if (!config.last) {
156-
return page.evaluate(async() => Promise.resolve(M.require('chat')));
156+
return page.evaluate(async() => {
157+
const files = ['chat', 'rewind', 's4'];
158+
return Promise.all(files.map(n => M.require(n)));
159+
});
157160
}
158161
},
159162
parser(blobs) {
@@ -167,7 +170,7 @@ const config = {
167170
type = null;
168171
switch (content[1]) {
169172
case ' * sjcl.js':
170-
if (String(content[6]).includes('embedplayer.js')) {
173+
if (String(content[8]).includes('embedplayer.js')) {
171174
type = 'embed';
172175
}
173176
else if (String(content).includes('the mobile web site')) {
@@ -180,13 +183,23 @@ const config = {
180183
case ' * var handler = {':
181184
type = 'chat';
182185
break;
186+
case '/** @property s4.ui */':
187+
type = 's4';
188+
break;
189+
case `lazy(mega, 'rewind', () => {`:
190+
type = 'rewind';
191+
break;
183192
default: {
184193
const exclude = /^es6s|css\//.test(content.slice(0, 2))
185194
|| String(content).slice(35).startsWith('IllegalStateError');
186195

187196
if (exclude) {
188197
continue;
189198
}
199+
200+
if (content[1].includes('var buildVersion = {')) {
201+
type = 'boot';
202+
}
190203
}
191204
}
192205

@@ -211,7 +224,7 @@ async function getSiteBlobs(page) {
211224
return page.evaluate(async() => {
212225
const result = [];
213226

214-
for (const elm of document.querySelectorAll('script[src^="blob:"]')) {
227+
for (const elm of document.querySelectorAll('script[src^="blob:"], script[src*="secureboot"]')) {
215228
const {src} = elm;
216229
const response = await fetch(src).catch(console.error);
217230

@@ -290,7 +303,7 @@ async function siteHandler(domain, page, target, options) {
290303
for (let i = files.length; i--;) {
291304
const [name, content] = files[i];
292305

293-
if (!FS.write(path.join(target, name), content.join('\n'), config.COMPRESS)) {
306+
if (!FS.write(path.join(target, name), content.join('\n'), config.COMPRESS, true)) {
294307
return null;
295308
}
296309
}
@@ -376,6 +389,17 @@ function getArchivedFile(ver = 'last', domain = 'meganz', type = 'main') {
376389
}
377390
}
378391

392+
if (type === '*') {
393+
const vp = path.join(config.ARCHIVE_PATH, version);
394+
const rv = Object.create(null);
395+
const ls = fs.readdirSync(vp);
396+
397+
for (let i = ls.length; i--;) {
398+
rv[ls[i]] = FS.read(path.join(vp, ls[i]));
399+
}
400+
return rv;
401+
}
402+
379403
const data = FS.read(path.join(config.ARCHIVE_PATH, version, `${domain}.${type}.js`));
380404
if (!data) {
381405
process.exit(1);
@@ -387,6 +411,14 @@ function printCodeAt(data, ln, bc = 0, ac = 0) {
387411
const n = ln - 1;
388412
const c = Math.max(0, n - bc);
389413

414+
if (typeof data === 'object') {
415+
for (const fn in data) {
416+
stdout(`\n: ${fn}`);
417+
printCodeAt(data[fn], ln, bc, ac);
418+
}
419+
return;
420+
}
421+
390422
String(data).split('\n')
391423
.slice(c, 1 + c + bc + ac)
392424
.forEach((x, i) => {
@@ -405,6 +437,7 @@ OPTIONS:
405437
-f, --file <name> Locate exception under specific bundle name (default: main)
406438
-v, --version <tag> Find code on specific version (default: last archived)
407439
-n, --line <n> Print code at specified source line number.
440+
-s, --scan [p] Find source line numbers from stadin given a pattern.
408441
-B, --before <n> Show N lines of leading code (default: 9)
409442
-A, --after <n> Show N lines of trailing code (default: 4)
410443
-t, --dump Parse stack-trace dump from stdin.
@@ -445,11 +478,18 @@ for (let i = 0; i < argv.length; ++i) {
445478
case 'f':
446479
case 'file':
447480
argv.file = word(argv[++i]);
481+
if (argv.file === 'a') {
482+
argv.file = '*';
483+
}
448484
break;
449485
case 'n':
450486
case 'line':
451487
argv.ln = parseInt(argv[++i]);
452488
break;
489+
case 's':
490+
case 'scan':
491+
argv.scan = JSON.parse(argv[i + 1] && argv[i + 1][0] !== '-' ? argv[++i] : '["\\n","\\n@"]');
492+
break;
453493
case 'v':
454494
case 'version':
455495
argv.ver = String(argv[++i]).replace(/[^\d.]+/g, '').replace(/\.+/g, '.');
@@ -529,11 +569,30 @@ for (let i = 0; i < argv.length; ++i) {
529569
if (argv.ln > 0) {
530570
printCodeAt(getArchivedFile(argv.ver, argv.domain, argv.file), argv.ln, argv.bc, argv.ac);
531571
}
572+
else if (argv.scan) {
573+
const input = await FS.readStream(process.stdin, RegExp(`\x18\\s*$`)).catch(stderr);
574+
if (input) {
575+
const [pp, sep, ml = 10] = argv.scan;
576+
const file = getArchivedFile(argv.ver, argv.domain, argv.file);
577+
578+
String(input).split(sep).forEach((val, idx, obj) => {
579+
if (idx > 0) {
580+
const ln = parseInt(val);
581+
if (ln > ml) {
582+
const pl = obj[idx - 1].split(pp).pop();
583+
584+
stdout(`\n\r\n\n${pl}`);
585+
printCodeAt(file, ln, argv.bc, argv.ac);
586+
}
587+
}
588+
});
589+
}
590+
}
532591
else if (argv.dump) {
533592
const file = getArchivedFile(argv.ver, argv.domain, argv.file);
534593
const input = String(await FS.prompt('Paste stack-trace (^C to quit):').catch(stderr)).split('\n');
535594

536-
input.map((line) => String(line.split(/\s\(|@/)[1]).replace(/(?:blob:)?https?:/,'').split(':')[1])
595+
input.map((line) => String(line.split(/\s\(|@|\s\.\./)[1]).replace(/(?:blob:)?https?:/, '').split(':')[1])
537596
.forEach((ln, idx) => {
538597
if (parseInt(ln) > 0) {
539598
stdout(`\n: ${input[idx].trim()}`);

0 commit comments

Comments
 (0)