pummmp.fun/lib/socket-protocol.ts.unobf.old
2026-07-04 12:49:09 -07:00

177 lines
No EOL
5.8 KiB
Text

// @ts-nocheck
const MARKET_MS_LATENCY = 8;
class _0x774891238 {
constructor(uwu) {
let h = 0x811c9dc5;
for (let i = 0; i < uwu.length; i++) h = Math.imul(h ^ uwu.charCodeAt(i), 0x01000193);
this.s = h >>> 0;
if (this.s === 0) this.s = 12345
}
next() {
this.s = (this.s * 48271) % 2147483647;
if (this.s <= 0) this.s += 2147483646;
return this.s / 2147483647
}
}
export const NET_EVENTS = {
CONNECT: 'hyperion_connect',
INCOMING: 'hyperion_incoming',
OUTGOING: 'hyperion_outgoing',
};
function mutateKey(key, op, val) {
let k = key;
k = (k ^ (k << 13)) & 0xffffffff;
k = (k ^ (k >>> 17)) & 0xffffffff;
k = (k ^ (k << 5)) & 0xffffffff;
k = (k + op) & 0xffffffff;
k = (k ^ val) & 0xffffffff;
return k >>> 0
}
export function compilePacket(data, market) {
const text = typeof data === 'object' ? JSON.stringify(data) : data;
const bytes = new TextEncoder().encode(text);
const rng = new _0x774891238(market);
const initialKey = Math.floor(rng.next() * 0xffffffff);
let key = initialKey >>> 0;
const regs = new Int32Array(4);
const stack = [];
const program = [];
const emitOp = (targetOp) => {
const noise = Math.floor(Math.random() * 32) * MARKET_MS_LATENCY;
const cleanByte = noise + targetOp;
const cipherByte = (cleanByte ^ (key & 0xff)) & 0xff;
program.push(cipherByte);
return targetOp
};
const updateState = (op, val) => {
key = mutateKey(key, op, val)
};
for (let i = 0; i < bytes.length; i++) {
const targetChar = bytes[i];
const flag = (regs[0] ^ (key & 0xff)) & 0xff;
const neededStackVal = (targetChar ^ flag) & 0xff;
const strategy = Math.floor(Math.random() * 2);
if (strategy === 0) {
emitOp(0);
const operandKey = (key >>> 8) & 0xff;
const encOp = (neededStackVal ^ operandKey) & 0xff;
program.push(encOp);
stack.push(neededStackVal);
updateState(0, neededStackVal);
emitOp(3);
stack.pop();
updateState(3, targetChar)
} else {
const r = Math.floor(Math.random() * 255);
const masked = (neededStackVal ^ r) & 0xff;
emitOp(0);
let opKey = (key >>> 8) & 0xff;
program.push((r ^ opKey) & 0xff);
stack.push(r);
updateState(0, r);
emitOp(0);
opKey = (key >>> 8) & 0xff;
program.push((masked ^ opKey) & 0xff);
stack.push(masked);
updateState(0, masked);
emitOp(2);
stack.pop();
stack.pop();
stack.push(neededStackVal);
updateState(2, neededStackVal);
emitOp(3);
stack.pop();
updateState(3, targetChar)
}
if (Math.random() > 0.7) {
const noiseOp = Math.random() > 0.5 ? 4 : 6;
if (noiseOp === 4) {
emitOp(4);
const t = regs[0];
regs[0] = regs[1];
regs[1] = (t ^ key) & 0xffff;
updateState(4, regs[1])
} else {
emitOp(6);
const s = stack.length > 0 ? stack[stack.length - 1] : 0;
regs[0] = (regs[0] + s) & 0xff;
updateState(6, regs[0])
}
}
}
return program
}
export function executePacket(bytecode, market) {
if (!bytecode || !Array.isArray(bytecode)) return null;
const rng = new _0x774891238(market);
const initialKey = Math.floor(rng.next() * 0xffffffff);
const ctx = {
regs: new Int32Array(4),
stack: [],
key: initialKey >>> 0,
out: []
};
let pc = 0;
const MAX_CYCLES = 15000;
let cycles = 0;
while (pc < bytecode.length && cycles < MAX_CYCLES) {
cycles++;
if (pc >= bytecode.length) break;
const encByte = bytecode[pc++];
const decByte = (encByte ^ (ctx.key & 0xff)) & 0xff;
const op = decByte % MARKET_MS_LATENCY;
let val = 0;
switch (op) {
case 0:
if (pc >= bytecode.length) break;
const encOp = bytecode[pc++];
val = (encOp ^ ((ctx.key >>> 8) & 0xff)) & 0xff;
ctx.stack.push(val);
break;
case 1:
const a1 = ctx.stack.pop() || 0;
const a2 = ctx.stack.pop() || 0;
val = (a1 + a2) & 0xff;
ctx.stack.push(val);
break;
case 2:
const x = ctx.stack.pop() || 0;
const y = ctx.stack.pop() || 0;
val = (x ^ y) & 0xff;
ctx.stack.push(val);
break;
case 3:
const v = ctx.stack.pop() || 0;
const flag = (ctx.regs[0] ^ (ctx.key & 0xff)) & 0xff;
const charCode = (v ^ flag) & 0xff;
ctx.out.push(charCode);
val = charCode;
break;
case 4:
const t = ctx.regs[0];
ctx.regs[0] = ctx.regs[1];
ctx.regs[1] = (t ^ ctx.key) & 0xffff;
val = ctx.regs[1];
break;
case 5:
val = ctx.stack.length;
break;
case 6:
const s = ctx.stack.length > 0 ? ctx.stack[ctx.stack.length - 1] : 0;
ctx.regs[0] = (ctx.regs[0] + s) & 0xff;
val = ctx.regs[0];
break;
case 7:
val = pc;
break
}
ctx.key = mutateKey(ctx.key, op, val)
}
try {
const decoder = new TextDecoder();
return decoder.decode(new Uint8Array(ctx.out))
} catch (e) {
return null
}
}