37722-vm/process.php
2026-01-24 18:40:43 +00:00

303 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'];
/**
* Hyperion V10.0 - Dynamic Instruction Polymorphism
* Features:
* - Dynamic Opcode Mapping (Seed-based)
* - Operand Permutation (A, B, C swap roles)
* - Instruction Ghosting & Seed Evolution
* - Semantic Flattening & Environmental Entanglement (inherited)
*/
class LuartexHyperionV10_0 {
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, 200);
$this->seed = rand(1000, 9999);
for ($i = 0; $i < 32; $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'
];
shuffle($ops);
foreach ($ops as $op) {
$this->opMap[$op] = rand(0, 255);
}
}
private function genVar($len = 24) {
$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, 100);
$b = rand(1, 100);
$op = rand(0, 2);
if ($op == 0) { $x = $char - ($a + $b); $res[] = "($x + $a + $b)"; }
elseif ($op == 1) { $x = $char + ($a - $b); $res[] = "($x - $a + $b)"; }
else { $x = $char ^ $a ^ $b; $res[] = "bit32.bxor($x, $a, $b)"; }
}
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("Hyperion V10.0 - DIP Engine Active");
$cleanCode = preg_replace('/--[[]*.*?[]]*--/s', '', $this->rawCode);
$cleanCode = preg_replace('/--.*$/m', '', $cleanCode);
$tokens = preg_split('/[;\n]+/', $cleanCode);
foreach ($tokens as $token) {
$token = trim($token);
if (empty($token)) continue;
// Randomly inject Ghost NOPs to evolve the state
if (rand(0, 5) == 0) {
$this->instructions[] = [$this->opMap['GHOST_NOP'], 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*\{\}$/', $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*\((.*?)\)$/', $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 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) % 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));
}
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'] as $v) {
$vars[$v] = $this->genVar();
}
$k_str = implode(",", $this->keys);
$lua = "-- [[ Hyperion Engine V10.0 - DIP ]] --\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) % 32) + 1; o[i] = bit32.bxor(b[i], " . $vars['k'] . "[k], ((i - 1) * 31) % 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, 0x1337) 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 . "; ";
$lua .= "local " . $vars['rolling'] . " = " . $vars['entropy'] . "(); local " . $vars['handlers'] . " = {}; ";
// Morphing Function
$lua .= "local function " . $vars['morph'] . "(op, seed, pc) return bit32.bxor(op, bit32.band(seed, 0xFF), bit32.band(pc, 0xFF)) % 256 end; ";
// Dynamic Handler Population
foreach ($this->opMap as $name => $val) {
$lua .= $vars['handlers'] . "[" . $val . "] = function(a, b, c) ";
switch($name) {
case 'ENTROPY_SYNC': $lua .= $vars['rolling'] . " = bit32.bxor(" . $vars['rolling'] . ", " . $vars['entropy'] . "()); "; 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 .= $vars['stack'] . "[a] = " . $vars['stack'] . "[b] + " . $vars['stack'] . "[c]; "; 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'] . "); "; break;
default: break;
}
// Evolution of seed after every instruction
$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'] . ") % 256); ";
// Operand Permutation based on seed
$lua .= "local a, b, c; local " . $vars['perm'] . " = " . $vars['seed'] . " % 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'] . " % 100 == 0 then if task and task.wait then task.wait() elseif wait then wait() end end; ";
$lua .= "end; ";
$lua .= "pcall(" . $vars['v'] . "); ";
return [
'success' => true,
'protected_code' => $lua,
'stats' => ['version' => '10.0-DIP', 'poly_key' => $this->polyKey, 'seed' => $this->seed]
];
}
}
try {
$vm = new LuartexHyperionV10_0($code);
echo json_encode($vm->build());
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}