37722-vm/process.php
2026-01-24 18:55:46 +00:00

310 lines
14 KiB
PHP

<?php
header('Content-Type: application/json');
require_once __DIR__ . '/db/config.php';
$input = json_decode(file_get_contents('php://input'), true);
if (!$input) {
$input = json_decode(file_get_contents('php://stdin'), true);
}
if (!$input || empty($input['code'])) {
echo json_encode(['success' => false, 'error' => 'No code provided']);
exit;
}
$code = $input['code'];
/**
* Luartex V11.0 - Quantum Singularity Engine
* "The final frontier of untraceable execution."
*/
class LuartexV11_0 {
private $rawCode;
private $constants = [];
private $instructions = [];
private $keys = [];
private $opMap = [];
private $seed;
private $polyKey;
public function __construct($code) {
$this->rawCode = $code;
$this->seed = rand(100000, 999999);
$this->polyKey = rand(1, 255);
for ($i = 0; $i < 256; $i++) {
$this->keys[] = rand(0, 255);
}
$this->setupOpcodes();
}
private function setupOpcodes() {
$ops = [
'LOADK', 'CALL', 'MOVE',
'ADD', 'SUB', 'MUL', 'DIV',
'RETURN', 'GETTABLE', 'SETTABLE', 'NEWTABLE',
'TAMPER_CHECK', 'ENTROPY_SYNC',
'FETCH_ENV', 'RESOLVE_SYMBOL',
'MUTATE_BYTECODE', 'COMPUTE_JUMP',
'GHOST_NOP', 'DECEPTIVE_TRAP',
'JUMP', 'JUMP_IF'
];
shuffle($ops);
foreach ($ops as $op) {
$this->opMap[$op] = rand(0, 255);
}
}
private function genVar($len = 12) {
$chars = 'lIi1OQuvwnmMS5zZ2B8bg9q';
$res = '_';
for($i=0; $i<$len; $i++) $res .= $chars[rand(0, strlen($chars)-1)];
return $res;
}
private function synthesizeChar($char) {
$a = rand(1, 255);
$b = rand(1, 255);
return "(bit32.bxor($char, $a) + $b - $b - $a + $char - $char)";
}
private function synthesizeString($s) {
$res = [];
for ($i = 0; $i < strlen($s); $i++) {
$res[] = "string.char(" . $this->synthesizeChar(ord($s[$i])) . ")";
}
return "function() local _ = " . implode(" .. ", $res) . "; return _ end";
}
private function addConst($val) {
$idx = array_search($val, $this->constants);
if ($idx === false) {
$this->constants[] = $val;
$idx = count($this->constants) - 1;
}
return $idx;
}
private function compile() {
$cleanCode = preg_replace('/--[[]*.*?[]]*--/s', '', $this->rawCode);
$cleanCode = preg_replace('/--.*$/m', '', $cleanCode);
$tokens = preg_split('/[;
]+/', $cleanCode);
$insts = [];
foreach ($tokens as $token) {
$token = trim($token);
if (empty($token)) continue;
$insts[] = [$this->opMap['GHOST_NOP'], rand(0,255), rand(0,255), rand(0,255)];
if (preg_match('/^(?:local\s+)?([a-zA-Z_]\w*)\s*=\s*{\s*}\s*$/', $token, $m)) {
$insts[] = [$this->opMap['NEWTABLE'], 0, 0, 0];
$this->emitSetGlobalInto($insts, 0, $m[1]);
}
elseif (preg_match('/^([a-zA-Z_]\w*)\s*\[\s*["\']?(.*?)["\']?\s*\]\s*=\s*(.*)$/', $token, $m)) {
$this->emitTableSetInto($insts, $m[1], $m[2], $m[3]);
}
elseif (preg_match('/^([a-zA-Z_]\w*(?:\.\w*)*)\s*\((.*?)\)\s*$/', $token, $m)) {
$this->emitCallInto($insts, $m[1], $m[2]);
}
elseif (preg_match('/^(?:local\s+)?([a-zA-Z_]\w*)\s*=\s*(.*)$/', $token, $m)) {
$this->emitAssignmentInto($insts, $m[1], $m[2]);
}
}
$insts[] = [$this->opMap['RETURN'], 0, 0, 0];
$this->instructions = [];
foreach ($insts as $i => $inst) {
$next = ($i < count($insts) - 1) ? 1 : 0;
$this->instructions[] = [$inst[0], $inst[1], $inst[2], $inst[3], $next];
}
}
private function emitGetGlobalInto(&$insts, $reg, $name) {
$insts[] = [$this->opMap['FETCH_ENV'], $reg, 0, 0];
foreach (explode('.', $name) as $part) {
$kIdx = $this->addConst($this->synthesizeString($part));
$insts[] = [$this->opMap['LOADK'], 250, $kIdx, 1];
$insts[] = [$this->opMap['RESOLVE_SYMBOL'], $reg, $reg, 250];
}
}
private function emitSetGlobalInto(&$insts, $reg, $name) {
$insts[] = [$this->opMap['FETCH_ENV'], 251, 0, 0];
$kIdx = $this->addConst($this->synthesizeString($name));
$insts[] = [$this->opMap['LOADK'], 252, $kIdx, 1];
$insts[] = [$this->opMap['SETTABLE'], 251, 252, $reg];
}
private function emitTableSetInto(&$insts, $tableName, $key, $val) {
$this->emitGetGlobalInto($insts, 0, $tableName);
$kIdx = $this->addConst($this->synthesizeString($key));
$insts[] = [$this->opMap['LOADK'], 1, $kIdx, 1];
$val = trim($val); $vReg = 2;
if (preg_match('/^["\'](.*?)["\']$/', $val, $vm)) {
$vIdx = $this->addConst($this->synthesizeString($vm[1]));
$insts[] = [$this->opMap['LOADK'], $vReg, $vIdx, 1];
} elseif (is_numeric($val)) {
$vIdx = $this->addConst($val);
$insts[] = [$this->opMap['LOADK'], $vReg, $vIdx, 0];
} else {
$this->emitGetGlobalInto($insts, $vReg, $val);
}
$insts[] = [$this->opMap['SETTABLE'], 0, 1, $vReg];
}
private function emitCallInto(&$insts, $funcName, $argStr) {
$this->emitGetGlobalInto($insts, 0, $funcName);
$args = [];
if (!empty(trim($argStr))) {
foreach (explode(',', $argStr) as $idx => $arg) {
$arg = trim($arg); $rIdx = $idx + 1;
if (preg_match('/^["\'](.*?)["\']$/', $arg, $m)) {
$vIdx = $this->addConst($this->synthesizeString($m[1]));
$insts[] = [$this->opMap['LOADK'], $rIdx, $vIdx, 1];
} elseif (is_numeric($arg)) {
$vIdx = $this->addConst($arg);
$insts[] = [$this->opMap['LOADK'], $rIdx, $vIdx, 0];
} else {
$this->emitGetGlobalInto($insts, $rIdx, $arg);
}
$args[] = $rIdx;
}
}
$insts[] = [$this->opMap['CALL'], 0, count($args), 0];
}
private function emitAssignmentInto(&$insts, $var, $val) {
$val = trim($val);
if (preg_match('/^["\'](.*?)["\']$/', $val, $m)) {
$vIdx = $this->addConst($this->synthesizeString($m[1]));
$insts[] = [$this->opMap['LOADK'], 0, $vIdx, 1];
} elseif (is_numeric($val)) {
$vIdx = $this->addConst($val);
$insts[] = [$this->opMap['LOADK'], 0, $vIdx, 0];
} else {
$this->emitGetGlobalInto($insts, 0, $val);
}
$this->emitSetGlobalInto($insts, 0, $var);
}
private function serialize() {
$data = pack("N", count($this->instructions));
$data .= pack("N", count($this->constants));
foreach ($this->instructions as $idx => $inst) {
$pc = $idx + 1;
$data .= chr((int)$inst[0] ^ (($this->polyKey + $pc) % 256));
$data .= chr((int)$inst[1] ^ (($pc * 17) % 256));
$data .= pack("n", (int)$inst[2] ^ (($pc * 31) % 65535));
$data .= chr((int)$inst[3] ^ (($pc * 7) % 256));
$data .= chr((int)$inst[4] ^ (($pc * 13) % 256));
}
foreach ($this->constants as $c) {
$t = is_string($c) ? 1 : (is_numeric($c) ? 2 : 0);
$data .= chr($t);
$s = (string)$c;
$data .= pack("N", strlen($s)) . $s;
}
$keyLen = count($this->keys); $res = "";
for ($i = 0; $i < strlen($data); $i++) {
$res .= chr(ord($data[$i]) ^ $this->keys[$i % $keyLen] ^ (($i * 97) % 256));
}
return bin2hex($res);
}
public function build() {
$this->compile();
$v = [];
foreach(['k','b','e','f','d','c','v','stack','handlers','entropy','ptr','rolling','seed','poison','next_ptr','state','quantum','mirror','reality','obfuscated_op','h_idx'] as $var) {
$v[$var] = $this->genVar();
}
$k_str = implode(",", $this->keys);
$lua = "-- [[ Luartex V11.0 | Quantum Singularity | https://discord.gg/GpucUKeCtF ]] --\n";
$lua .= "local " . $v['k'] . " = { " . $k_str . " }; ";
$lua .= "local " . $v['b'] . " = \"" . $this->serialize() . "\"; ";
$lua .= "local " . $v['e'] . " = (getgenv and getgenv()) or (getfenv and getfenv(0)) or _G; ";
$lua .= "local function _H(h) local b = {}; for i = 1, #h, 2 do b[#b+1] = tonumber(h:sub(i, i+1), 16) end return b end; ";
$lua .= "local function _D(b) local o = {}; for i = 1, #b do local k = " . $v['k'] . "[((i-1)%#" . $v['k'] . ")+1]; o[i] = bit32.bxor(b[i], k, ((i-1)*97)%256) end return o end; ";
$lua .= "local " . $v['d'] . " = _D(_H(" . $v['b'] . ")); ";
$lua .= "local function _R32(b, p) return b[p]*16777216 + b[p+1]*65536 + b[p+2]*256 + b[p+3] end; ";
$lua .= "local function _R16(b, p) return b[p]*256 + b[p+1] end; ";
$lua .= "local ic = _R32(" . $v['d'] . ", 1); local cc = _R32(" . $v['d'] . ", 5); ";
$lua .= "local " . $v['c'] . " = {}; local cu = 9 + ic*6; ";
$lua .= "for i = 1, cc do local t = " . $v['d'] . "[cu]; cu = cu + 1; if t > 0 then local l = _R32(" . $v['d'] . ", cu); cu = cu + 4; local s = ''; for j = 1, l do s = s .. string.char(" . $v['d'] . "[cu]); cu = cu + 1 end; if t == 2 then " . $v['c'] . "[i] = tonumber(s) else " . $v['c'] . "[i] = s end else cu = cu + 1 end end; ";
$lua .= "local " . $v['v'] . " = function() ";
$lua .= "local " . $v['stack'] . " = {}; local " . $v['ptr'] . " = 1; local " . $v['seed'] . " = " . $this->seed . "; ";
$lua .= "local " . $v['rolling'] . " = " . $this->polyKey . "; local " . $v['poison'] . " = 0; ";
$lua .= "local " . $v['handlers'] . " = {}; ";
$lua .= "local function " . $v['quantum'] . "() local t1 = os.clock(); for i=1,1000 do end; return (os.clock()-t1) > 0.01 end; ";
foreach ($this->opMap as $name => $val) {
$lua .= $v['handlers'] . "[" . $val . "] = function(a, b, c) ";
$lua .= "if " . $v['poison'] . " > 0 then a = (a + " . $v['poison'] . ") % 256; if math.random() > 0.9 then return end end; ";
switch($name) {
case 'ENTROPY_SYNC':
$lua .= $v['rolling'] . " = bit32.bxor(" . $v['rolling'] . ", math.floor(os.clock()*1000)%256); ";
break;
case 'FETCH_ENV': $lua .= $v['stack'] . "[a] = " . $v['e'] . "; "; break;
case 'RESOLVE_SYMBOL': $lua .= $v['stack'] . "[a] = " . $v['stack'] . "[b][" . $v['stack'] . "[c]]; "; break;
case 'LOADK': $lua .= "local v = " . $v['c'] . "[b + 1]; if c == 1 then v = v()() end; " . $v['stack'] . "[a] = v; "; break;
case 'CALL': $lua .= "local f = " . $v['stack'] . "[a]; local args = {}; for m = 1, b do args[m] = " . $v['stack'] . "[a+m] end; if f then f((unpack or table.unpack)(args)) end; "; break;
case 'RETURN': $lua .= $v['ptr'] . " = -1; "; break;
case 'NEWTABLE': $lua .= $v['stack'] . "[a] = {}; "; break;
case 'SETTABLE': $lua .= "if " . $v['stack'] . "[a] then " . $v['stack'] . "[a][" . $v['stack'] . "[b]] = " . $v['stack'] . "[c] end; "; break;
case 'ADD': $lua .= $v['stack'] . "[a] = (tonumber(" . $v['stack'] . "[b]) or 0) + (tonumber(" . $v['stack'] . "[c]) or 0); "; break;
case 'MUTATE_BYTECODE': $lua .= "local target = 9 + ((" . $v['ptr'] . " + a) % ic) * 6; " . $v['d'] . "[target] = bit32.bxor(" . $v['d'] . "[target], b); "; break;
case 'GHOST_NOP': $lua .= $v['seed'] . " = bit32.bxor(" . $v['seed'] . ", " . $v['rolling'] . ", a, b, c); "; break;
case 'TAMPER_CHECK': $lua .= "if " . $v['quantum'] . "() then " . $v['poison'] . " = " . $v['poison'] . " + 1 end; "; break;
case 'DECEPTIVE_TRAP': $lua .= "local _ = " . $v['e'] . ".string.rep('DECEIVE', a); "; break;
default: break;
}
$lua .= $v['seed'] . " = bit32.bxor(" . $v['seed'] . ", " . $val . ") + 1; ";
$lua .= "end; ";
}
$lua .= "while " . $v['ptr'] . " > 0 do ";
$lua .= "local o = 9 + (" . $v['ptr'] . " - 1) * 6; ";
$lua .= "local _op = bit32.bxor(" . $v['d'] . "[o], (" . $this->polyKey . " + " . $v['ptr'] . ") % 256); ";
$lua .= "local _a = bit32.bxor(" . $v['d'] . "[o+1], (" . $v['ptr'] . " * 17) % 256); ";
$lua .= "local _b = bit32.bxor(_R16(" . $v['d'] . ", o+2), (" . $v['ptr'] . " * 31) % 65535); ";
$lua .= "local _c = bit32.bxor(" . $v['d'] . "[o+4], (" . $v['ptr'] . " * 7) % 256); ";
$lua .= "local _nx = bit32.bxor(" . $v['d'] . "[o+5], (" . $v['ptr'] . " * 13) % 256); ";
$lua .= "local a, b, c; local p = bit32.bxor(" . $v['seed'] . ", " . $v['ptr'] . ") % 3; ";
$lua .= "if p == 0 then a,b,c = _a,_b,_c elseif p == 1 then a,b,c = _b,_c,_a else a,b,c = _c,_a,_b end; ";
$lua .= "local h = " . $v['handlers'] . "[_op]; if h then h(a, b, c) end; ";
$lua .= "if " . $v['ptr'] . " > 0 then ";
$lua .= "if _nx == 0 then " . $v['ptr'] . " = -1 else " . $v['ptr'] . " = " . $v['ptr'] . " + _nx end; ";
$lua .= "end; ";
$lua .= "if " . $v['ptr'] . " % 50 == 0 then if task and task.wait then task.wait() end end; ";
$lua .= "end; ";
$lua .= "end; ";
$lua .= "local s, e = pcall(" . $v['v'] . "); if not s and _G.LUARTEX_DEBUG then print('VM Error:', e) end; ";
return [
'success' => true,
'protected_code' => $lua,
'stats' => ['version' => 'V11.0 (Quantum Singularity)', 'seed' => $this->seed, 'ILD' => 'Active']
];
}
}
try {
$vm = new LuartexV11_0($code);
echo json_encode($vm->build());
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}