js解析php语言goto混淆完整实例,已经成功解析短小12KB的代码; 包括代码顺序恢复,后}补全,if反转等。耗费太多时间暂时放弃更新。
仅供恢复可读性用于安全分析和本js功能代码学习交流(很多语言chatgpt提供有学习价值)
不得用于非法目的,不得出售他人劳动成果和侵犯他人知识产权。
有遗憾待大家完善:
- \x开头和\数字的编码解析失败,代码应该正确,你可以尝试其他编程语言转。
- 大代码解析异常(浏览器奔溃): 可能编码ascii转UTF-8无效所以无法正常处理。
<!DOCTYPE html><html><head><meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>gotoencode</title> <style> *{margin:0;font-size:16px;} body{font-family:Arial,sans-serif;background-color:#f2f2f2;} .container{width:97.5%;margin:10px auto;padding:20px;background-color:#fff;border-radius:5px;box-shadow:0 0 10px rgba(0,0,0,0.3);max-width:1200px;min-width:300px;} result{margin:0px auto;padding-top:30px;} h1{margin:10px auto;font-size:20px;text-align:center;} p{margin-bottom:20px;text-align:left;} input,textarea{display:block;position:relative;background:none;border:2px solid #acacac;border-radius:5px;width:calc(99% - 20px);padding:0 10px;height:235px;z-index:1;} label{display:inline-block;position:relative;top:-32px;left:10px;color:#acacac;z-index:2;transition:all 0.2s ease-out;} textarea:focus,textarea:valid{outline:none;border:2px solid #4CAF50;} textarea:focus + label,textarea:valid + label{top:-255px;color:#4CAF50;background-color:#fff;} button{display:inline;padding:8px 15px;background-color:#4CAF50;color:#fff;border:none;border-radius:5px;cursor:pointer;} button:hover{background-color:#3e8e41;} table {border-top:3px solid #4CAF50;width:99.9%; margin:10px auto;} .r{font-weight:bold;text-align:center;} table tr:nth-child(2n){background:#FAFAFA;} </style> <script> function $(objId){ return document.getElementById(objId); } function loadcha(xxx) { $("res"+xxx).value = "???..."; // Step 1@read code const coda = $("xid").value; // Step 2@get all xxx const labelRegex = /goto\s+(\w+);/g; const labels = coda.match(labelRegex).map(label => label.replace(/goto\s+|;/g, '')); console.log("Step 2:all goto",labels); // Step 3.1 const gotoRegex = /goto\s+(\w+);\s+}\s+goto\s+(\w+);/g; const gotosMatch = coda.match(gotoRegex); const gotos = gotosMatch ? gotosMatch.map(goto => { const [_, from, to] = goto.match(/goto\s+(\w+);\s+}\s+goto\s+(\w+);/); return { [from]: to }; }) : []; console.log("Step 3.1:goto } goto",gotos); // Step 3.2 let code = coda.replace(gotoRegex, (match, from, to) => `goto ${to}; } goto ${from};`); console.log("Step 3.2: replace goto } goto"); let matches = code.match(/(\w+):(\s+(\w+):)+/g); for (let i = 0; i < matches.length; i++) { let index = matches[i].match(/(\w+):/g); for (let j = 0; j < index.length; j++) { let x = index[j]; let z = x.replace(":",""); let y = "goto "+z+"; "+z+": "; code = code.replace(x, y); } } console.log("Step 3.3: replace xxx: xxx:"); // Step 4.1 const labelCodex = /(\w+):(.*?)goto\s+(\w+);/g; const labelCodes = code.match(labelCodex).map(labelCode => { const [_, from, codeline, to] = labelCode.match(/(\w+):(.*?)goto\s+(\w+);/); return { [from]: codeline }; }); console.log("Step 4.1:list label==>code",labelCodes); // Step 4.2 const labelgogox = /(\w+):(.*?)goto\s+(\w+);/g; const labelgogok = code.match(labelgogox).map(gogoCode => { const [_, from, codeline, to] = gogoCode.match(/(\w+):(.*?)goto\s+(\w+);/); return { [from]: to }; }); const labelgogos = Object.assign({}, ...labelgogok); console.log("Step 4.2:label==>gogo"+labelgogok.length,labelgogos); // Step 5 const labelCodez = /(\w+):(.*?)goto\s+(\w+);/g; const labelGotoContents = code.match(labelCodez).map(labelCode => { const [_, from, codeline, to] = labelCode.match(/(\w+):(.*?)goto\s+(\w+);/); return { [from]: codeline.trim() }; }); console.log("Step 5:label:code2",labelGotoContents); // Step 6.1 let current = labels[0]; const t6 = []; while (current && labelgogos[current]) { t6.push(current); current = labelgogos[current] ? labelgogos[current] : "//kong.bai.1"; } console.log("Step 6.1:list order1",t6); //step 6.2 const tbs = []; for (let i = 0; i < gotos.length; i++) { const tr = []; let current = Object.keys(gotos[i])[0]; while (current && labelgogos[current] ) { tr.push(current); current = labelgogos[current] ? labelgogos[current] : "//kong.bai.2"; //if (Object.values(t6).includes(current)) continue; //t6 //if (t6.find(current)) continue; //t6 } const commonPoint = t6.find(point => tr.includes(point)); let index1 = tr.indexOf(commonPoint); let td = tr.slice(0, index1 + 1); if(td.length>0) tbs.push(td); } console.log("Step 6.2:list order2",tbs); for (let k = 0; k < tbs.length; k++) { const tdb = tbs[k]; const c = t6.indexOf(tdb[tdb.length - 1]); tdb[tdb.length - 1] = "ChaLiDe"; t6.splice(c, 0, ...tdb); console.log("Step 6.3:tdb=>+"+tbs[k].length+"=>"+t6.length); } // Step 7.1 const labelCodeMap = Object.assign({}, ...labelCodes); console.log("Step 7.1:label:code map",labelCodeMap); // Step 7.2 const t6LabelCodes = t6.map(label => ({ [label]: labelCodeMap[label] })); console.log("Step 7.2:t6 label:code",t6LabelCodes); // Step 9 const codenew = t6LabelCodes.reduce((acc, obj) => { const label = Object.keys(obj)[0]; const content = obj[label]; if (content) { acc += `${content}//${label}\n`; }else{acc += `//${label}\n`;} return acc; }, ''); codenow = codenew.replace(/\/\/ChaLiDe/g, '}'); console.log("Step 9","new.size:"+codenew.length); $("res"+xxx).value = codenow; /* // Step 10 居然解码无效供大家完善 const asciiRegex = /(\\\\d{1,3}|\\\\x[a-fA-F0-9]{1,2})/; const codenewReadable = codenow.replace(asciiRegex, (_, code) => String.fromCharCode(parseInt(code, 8))); console.log("Step 10",codenewReadable); */ } // ok </script> </head> <body> <h1>webtitle</h1> <div class="container"> <textarea type="text" name="xid" id="xid" required> <?php echo htmlspecialchars(file_get_contents("code.txt"));?> </textarea> <label for="xid">php code</label> <p><button onclick="loadcha('cha');">goto</button></p> <div id="result"><textarea id="rescha"></textarea></div> <div id="resalt"> 仅供恢复可读性用于安全分析和本js功能代码学习交流(很多语言chatgpt提供有学习价值)<br> 不得用于非法目的,不得出售他人劳动成果和侵犯他人知识产权。<br> 有遗憾待大家完善:<br> 1. \x开头和\数字的编码解析失败,代码应该正确<br> 2. 可能编码ascii转UTF-8无效所以大代码解析异常<br> </div> </div> </body> </html>