37722-vm/process.php
2026-01-24 17:22:06 +00:00

343 lines
16 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 V3.2 - Advanced Non-Deterministic VM
* Features:
* - Runtime-generated keys (Jitter, GC side effects)
* - Self-Modifying Bytecode (Dynamic instruction mutation)
* - Unstable Opcodes (Context-sensitive behavior)
* - Silent Failure (Believable but incorrect results on tamper)
* - Constant Synthesis & Deferred Decoding
* - Deceptive Logic Injection (Fake crypto/protocols)
*/
class LuartexV3_2 {
private $rawCode;
private $constants = [];
private $instructions = [];
private $keys = [];
private $opMap = [];
private $polyKey;
private $seed;
public function __construct($code) {
$this->rawCode = $code;
$this->polyKey = rand(50, 250);
$this->seed = rand(5000, 20000);
for ($i = 0; $i < 64; $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_PC',
'MORPH_STATE', 'GHOST_NOP', 'DECEPTIVE_TRAP'
];
shuffle($ops);
foreach ($ops as $op) {
$this->opMap[$op] = rand(0, 255);
}
}
private function genVar($len = 20) {
$sets = ['l1Ii', 'O0Q', 'uvvw', 'nmM', 'S5s', 'Z2z', 'B8b', 'g9q'];
$res = '_';
for($i=0; $i<$len; $i++) {
$set = $sets[array_rand($sets)];
$res .= $set[rand(0, strlen($set)-1)];
}
return $res . bin2hex(random_bytes(2));
}
private function synthesizeString($s) {
$res = [];
for ($i = 0; $i < strlen($s); $i++) {
$char = ord($s[$i]);
$a = rand(1, 200);
$b = rand(1, 200);
$op = rand(0, 3);
if ($op == 0) { $x = $char - ($a + $b); $res[] = "($x + $a + $b)"; }
elseif ($op == 1) { $x = $char + ($a - $b); $res[] = "($x - $a + $b)"; }
elseif ($op == 2) { $x = $char ^ $a ^ $b; $res[] = "bit32.bxor($x, $a, $b)"; }
else {
$c = rand(1, 100);
$x = ($char + $c) ^ $a;
$res[] = "bit32.bxor($x, $a) - $c";
}
}
return "function() local r = ''; for _, v in ipairs({" . implode(",", $res) . "}) do r = r .. string.char(v) end return r 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() {
$this->addConst("Luartex V3.2 - Security Active");
// Inject deceptive logic at the beginning
$this->injectDeceptiveLogic();
$cleanCode = preg_replace('/--[[]*.*?[]]*--/s', '', $this->rawCode);
$cleanCode = preg_replace('/--.*$/m', '', $cleanCode);
$tokens = preg_split('/[;
]+/', $cleanCode);
foreach ($tokens as $token) {
$token = trim($token);
if (empty($token)) continue;
// Randomly inject Ghost NOPs or State Morphs
if (rand(0, 4) == 0) {
$this->instructions[] = [$this->opMap['GHOST_NOP'], rand(0,255), rand(0,255), rand(0,255)];
}
if (rand(0, 10) == 0) {
$this->instructions[] = [$this->opMap['MUTATE_BYTECODE'], rand(0, 255), rand(0, 255), rand(0, 255)];
}
$this->instructions[] = [$this->opMap['ENTROPY_SYNC'], 0, 0, 0];
if (preg_match('/^(?:local\s+)?([a-zA-Z_]\w*)\s*=\s*{\}\s*$/', $token, $m)) {
$this->instructions[] = [$this->opMap['NEWTABLE'], 0, 0, 0];
$this->emitSemanticSetGlobal(0, $m[1]);
}
elseif (preg_match('/^([a-zA-Z_]\w*)\s*[.[\\\]\s*["\\\]?(.*?)["\\]?\s*[\\]]?\s*=\s*(.*)$/', $token, $m)) {
$this->emitTableSet($m[1], $m[2], $m[3]);
}
elseif (preg_match('/^([a-zA-Z_]\w*(?:[.:]\w*)*)\s*\((.*?)\)\s*$/', $token, $m)) {
$this->emitCall($m[1], $m[2]);
}
elseif (preg_match('/^(?:local\s+)?([a-zA-Z_]\w*)\s*=\s*(.*)$/', $token, $m)) {
$this->emitAssignment($m[1], $m[2]);
}
}
$this->instructions[] = [$this->opMap['RETURN'], 0, 0, 0];
}
private function injectDeceptiveLogic() {
// Fake Crypto Ops
for ($i = 0; $i < 3; $i++) {
$this->instructions[] = [$this->opMap['DECEPTIVE_TRAP'], rand(0,255), rand(0,255), rand(0,255)];
}
}
private function emitSemanticGetGlobal($reg, $name) {
$this->instructions[] = [$this->opMap['FETCH_ENV'], $reg, 0, 0];
foreach (explode('.', $name) as $part) {
$kIdx = $this->addConst($this->synthesizeString($part));
$this->instructions[] = [$this->opMap['LOADK'], 250, $kIdx, 1];
$this->instructions[] = [$this->opMap['RESOLVE_SYMBOL'], $reg, $reg, 250];
}
}
private function emitSemanticSetGlobal($reg, $name) {
$this->instructions[] = [$this->opMap['FETCH_ENV'], 251, 0, 0];
$kIdx = $this->addConst($this->synthesizeString($name));
$this->instructions[] = [$this->opMap['LOADK'], 252, $kIdx, 1];
$this->instructions[] = [$this->opMap['SETTABLE'], 251, 252, $reg];
}
private function emitTableSet($tableName, $key, $val) {
$this->emitSemanticGetGlobal(0, $tableName);
$kIdx = $this->addConst($this->synthesizeString($key));
$this->instructions[] = [$this->opMap['LOADK'], 1, $kIdx, 1];
$val = trim($val); $vReg = 2;
if (preg_match('/^["\\\](.*?)["\\]$/', $val, $vm)) {
$vIdx = $this->addConst($this->synthesizeString($vm[1]));
$this->instructions[] = [$this->opMap['LOADK'], $vReg, $vIdx, 1];
} elseif (is_numeric($val)) {
$vIdx = $this->addConst($val);
$this->instructions[] = [$this->opMap['LOADK'], $vReg, $vIdx, 0];
} else {
$this->emitSemanticGetGlobal($vReg, $val);
}
$this->instructions[] = [$this->opMap['SETTABLE'], 0, 1, $vReg];
}
private function emitCall($funcName, $argStr) {
$this->emitSemanticGetGlobal(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]));
$this->instructions[] = [$this->opMap['LOADK'], $rIdx, $vIdx, 1];
} elseif (is_numeric($arg)) {
$vIdx = $this->addConst($arg);
$this->instructions[] = [$this->opMap['LOADK'], $rIdx, $vIdx, 0];
} else {
$this->emitSemanticGetGlobal($rIdx, $arg);
}
$args[] = $rIdx;
}
}
$this->instructions[] = [$this->opMap['CALL'], 0, count($args), 0];
}
private function emitAssignment($var, $val) {
$val = trim($val);
if (preg_match('/^["\\\](.*?)["\\]$/', $val, $m)) {
$vIdx = $this->addConst($this->synthesizeString($m[1]));
$this->instructions[] = [$this->opMap['LOADK'], 0, $vIdx, 1];
} elseif (is_numeric($val)) {
$vIdx = $this->addConst($val);
$this->instructions[] = [$this->opMap['LOADK'], 0, $vIdx, 0];
} else {
$this->emitSemanticGetGlobal(0, $val);
}
$this->emitSemanticSetGlobal(0, $var);
}
private function serializeAll() {
$bin = pack("N", count($this->instructions));
foreach ($this->instructions as $pc_idx => $inst) {
$pc = $pc_idx + 1;
$op = (int)$inst[0];
$mask = ($this->polyKey + $pc * 7) % 256;
$bin .= chr($op ^ $mask);
$bin .= chr((int)$inst[1] & 0xFF);
$bin .= pack("n", (int)$inst[2]);
$bin .= chr((int)$inst[3] & 0xFF);
}
$bin .= pack("N", count($this->constants));
foreach ($this->constants as $c) {
$t = is_string($c) ? 1 : (is_numeric($c) ? 2 : 0);
$bin .= chr($t);
$s = (string)$c;
$bin .= pack("N", strlen($s)) . $s;
}
$keyLen = count($this->keys); $enc = "";
for ($i = 0; $i < strlen($bin); $i++) {
$enc .= chr(ord($bin[$i]) ^ $this->keys[$i % $keyLen] ^ (($i * 31) % 256) ^ (($i + 13) % 256));
}
return bin2hex($enc);
}
public function build() {
$this->compile();
$vars = [];
foreach(['k','b','e','f','d','c','v','stack','asm','poly','handlers','tamper','watchdog','fetch','tk','entropy','pc','rolling','inst','op','a','b_p','c_p','res','env','hash','sym','prev_op','state_hash','ctx','seed','morph','perm','corrupted','dispatcher','mutate','deceptive'] as $v) {
$vars[$v] = $this->genVar();
}
$k_str = implode(",", $this->keys);
$lua = "-- [[ Luartex V3.2 | https://discord.gg/GpucUKeCtF ]] --\n";
$lua .= "local " . $vars['k'] . " = { " . $k_str . " }; ";
$lua .= "local " . $vars['b'] . " = \"" . $this->serializeAll() . "\"; ";
$lua .= "local " . $vars['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 = ((i - 1) % 64) + 1; o[i] = bit32.bxor(b[i], " . $vars['k'] . "[k], ((i - 1) * 31) % 256, ((i - 1) + 13) % 256) end return o end; ";
$lua .= "local " . $vars['d'] . " = _D(_H(" . $vars['b'] . ")); ";
$lua .= "local function " . $vars['entropy'] . "() return bit32.bxor(math.floor(os.clock() * 1000) % 65536, collectgarbage('count') % 256, 0x5A) end; ";
$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(" . $vars['d'] . ", 1); local co = 5 + ic * 5; local cc = _R32(" . $vars['d'] . ", co); ";
$lua .= "local " . $vars['c'] . " = {}; local cu = co + 4; ";
$lua .= "for i = 1, cc do local t = " . $vars['d'] . "[cu]; cu = cu + 1; if t > 0 then local l = _R32(" . $vars['d'] . ", cu); cu = cu + 4; local s = ''; for j = 1, l do s = s .. string.char(" . $vars['d'] . "[cu]); cu = cu + 1 end; if t == 2 then " . $vars['c'] . "[i] = tonumber(s) else " . $vars['c'] . "[i] = s end else cu = cu + 1 end end; ";
$lua .= "local " . $vars['fetch'] . " = function(p) local o = 5 + (p - 1) * 5; return " . $vars['d'] . "[o], " . $vars['d'] . "[o+1], _R16(" . $vars['d'] . ", o+2), " . $vars['d'] . "[o+4] end; ";
$lua .= "local " . $vars['v'] . " = function() ";
$lua .= "local " . $vars['stack'] . " = {}; local " . $vars['pc'] . " = 1; local " . $vars['seed'] . " = " . $this->seed . " + " . $vars['entropy'] . "(); ";
$lua .= "local " . $vars['rolling'] . " = " . $vars['entropy'] . "(); local " . $vars['corrupted'] . " = false; ";
$lua .= "local " . $vars['handlers'] . " = {}; ";
// Unstable Opcode Mapping - Context Sensitive
$lua .= "local function " . $vars['dispatcher'] . "(op, seed, pc) return bit32.bxor(op, bit32.band(seed, 0xFF), bit32.band(pc, 0xFF)) % 256 end; ";
foreach ($this->opMap as $name => $val) {
$lua .= $vars['handlers'] . "[" . $val . "] = function(a, b, c) ";
// Silent Failure logic
$lua .= "if " . $vars['corrupted'] . " then if math.random() > 0.5 then a = (a + 1) % 256 end if math.random() > 0.8 then return end end; ";
switch($name) {
case 'ENTROPY_SYNC':
$lua .= $vars['rolling'] . " = bit32.bxor(" . $vars['rolling'] . ", " . $vars['entropy'] . "()); ";
$lua .= "if " . $vars['rolling'] . " == 0 then " . $vars['corrupted'] . " = true end; ";
break;
case 'FETCH_ENV': $lua .= $vars['stack'] . "[a] = " . $vars['e'] . "; "; break;
case 'RESOLVE_SYMBOL': $lua .= $vars['stack'] . "[a] = " . $vars['stack'] . "[b][" . $vars['stack'] . "[c]]; "; break;
case 'LOADK': $lua .= "local v = " . $vars['c'] . "[b + 1]; if c == 1 then local f = loadstring('return ' .. v); if f then v = f()() end end; " . $vars['stack'] . "[a] = v; "; break;
case 'CALL': $lua .= "local f = " . $vars['stack'] . "[a]; local args = {}; for m = 1, b do args[m] = " . $vars['stack'] . "[a + m] end; if f then f((unpack or table.unpack)(args)) end; "; break;
case 'RETURN': $lua .= $vars['pc'] . " = -1; "; break;
case 'NEWTABLE': $lua .= $vars['stack'] . "[a] = {}; "; break;
case 'SETTABLE': $lua .= $vars['stack'] . "[a][" . $vars['stack'] . "[b]] = " . $vars['stack'] . "[c]; "; break;
case 'ADD': $lua .= "local v1, v2 = " . $vars['stack'] . "[b], " . $vars['stack'] . "[c]; if " . $vars['corrupted'] . " then " . $vars['stack'] . "[a] = (v1 or 0) + (v2 or 0) + math.random() else " . $vars['stack'] . "[a] = (v1 or 0) + (v2 or 0) end; "; break;
case 'MORPH_STATE': $lua .= $vars['seed'] . " = bit32.bxor(" . $vars['seed'] . ", a, b, c); "; break;
case 'GHOST_NOP': $lua .= $vars['seed'] . " = bit32.bxor(" . $vars['seed'] . ", " . $vars['rolling'] . ", " . $vars['pc'] . "); "; break;
case 'MUTATE_BYTECODE':
$lua .= "local target = 5 + (" . $vars['pc'] . " + a % 10) * 5; if target < # " . $vars['d'] . " then " . $vars['d'] . "[target] = bit32.bxor(" . $vars['d'] . "[target], b) end; ";
break;
case 'DECEPTIVE_TRAP':
$lua .= "local fake_crypto = function(d) local r = ''; for i=1,#d do r=r..string.char(bit32.bxor(d:byte(i), 0xAA)) end return r end; ";
$lua .= "local res = fake_crypto('ENCRYPTED_PAYLOAD_STUB'); ";
break;
case 'TAMPER_CHECK':
$lua .= "if debug.info(print, 's') ~= '=[C]' then " . $vars['corrupted'] . " = true end; ";
break;
default: break;
}
$lua .= $vars['seed'] . " = bit32.bxor(" . $vars['seed'] . ", " . $val . ", a or 0) + 1; ";
$lua .= "end; ";
}
$lua .= "while " . $vars['pc'] . " > 0 do ";
$lua .= "local raw_op, _a, _b, _c = " . $vars['fetch'] . "(" . $vars['pc'] . "); if not raw_op then break end; ";
$lua .= "local op = bit32.bxor(raw_op, (" . $this->polyKey . " + " . $vars['pc'] . " * 7) % 256); ";
// Operand Permutation evolves with seed and rolling entropy
$lua .= "local a, b, c; local " . $vars['perm'] . " = bit32.bxor(" . $vars['seed'] . ", " . $vars['rolling'] . ") % 3; ";
$lua .= "if " . $vars['perm'] . " == 0 then a,b,c = _a,_b,_c elseif " . $vars['perm'] . " == 1 then a,b,c = _b,_c,_a else a,b,c = _c,_a,_b end; ";
$lua .= "local h = " . $vars['handlers'] . "[op]; if h then h(a, b, c) end; ";
$lua .= "if " . $vars['pc'] . " > 0 then " . $vars['pc'] . " = " . $vars['pc'] . " + 1 end; ";
$lua .= "if " . $vars['pc'] . " % 50 == 0 then if task and task.wait then task.wait() elseif wait then wait() end end; ";
$lua .= "end; ";
$lua .= "end; ";
$lua .= "pcall(" . $vars['v'] . "); ";
return [
'success' => true,
'protected_code' => $lua,
'stats' => ['version' => 'V3.2 (Luartex)', 'poly_key' => $this->polyKey, 'seed' => $this->seed]
];
}
}
try {
$vm = new LuartexV3_2($code);
echo json_encode($vm->build());
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}