From 9576c62734d8e9039193d232cd5c0bf426481957 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Wed, 22 May 2024 17:15:24 +0800 Subject: [PATCH] NoReflect: Static functions, autoimports, sparse inclusion --- NoReflect/generate.js | 40 ++++++++++++++++++++++++++++++++------- NoReflect/index.html | 43 ++++++++++++++++++++++++++++++++++++------ NoReflect/javaRecon.js | 11 ++++++----- 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/NoReflect/generate.js b/NoReflect/generate.js index 81d58cc..fc6c04e 100644 --- a/NoReflect/generate.js +++ b/NoReflect/generate.js @@ -82,26 +82,26 @@ function process(file, reader, classDataDump, className) { reader.addEventListener("load", ()=>{ var output = reader.result; classDataDump[className] = (reconJ(output, className)); - console.log(classDataDump[className].usedClasses); res(output); }); reader.readAsText(file); }); } -function createManagerFile(managerTemplate, config, zip, dataDump) { +function createManagerFile(managerTemplate, config, zip, dataDump, classIdMap) { var manager = managerTemplate; var filePath = config.managerFile.replaceAll(".", "/") + ".java"; for (let i = 0; i < config.targetFiles.length; i++) { manager = `import ${config.targetFiles[i]}` + ";\n" + manager; } - manager = `package ${config.managerFile.match(/(.*)(?=\.[^.]*$)/g)[0]}` + ";\n" + manager; - + var imports = []; var classText = ""; var classes = Object.keys(dataDump); for (let i = 0; i < classes.length; i++) { const className = classes[i]; + imports = [...new Set(imports.concat(dataDump[className].usedClasses))]; + var tmpClassText = templateClassdef; tmpClassText = tmpClassText.replaceAll("%classname%", className); @@ -179,21 +179,39 @@ function createManagerFile(managerTemplate, config, zip, dataDump) { tmpMethodText = tmpMethodText.replaceAll("%methodimpl%", method.impl); methodText += tmpMethodText; } + tmpClassText = tmpClassText.replaceAll("%methoddefs%", methodText); classText += tmpClassText; } + for (let i = 0; i < config.imports.length; i++) { + manager = `import ${config.imports[i]}` + ";\n" + manager; + logTxt(`Force imported classid: ${config.imports[i]}`); + } + + if (config.attemptAutoImport) { + for (let i = 0; i < imports.length; i++) { + if (classIdMap.has(imports[i])) { + manager = `import ${classIdMap.get(imports[i])}` + ";\n" + manager; + logTxt(`Imported classid: ${classIdMap.get(imports[i])}`); + } + } + } + + manager = `package ${config.managerFile.match(/(.*)(?=\.[^.]*$)/g)[0]}` + ";\n" + manager; + manager = manager.replaceAll("%classdefs%", classText); zip.file(filePath, manager); } async function generate(fileList) { + var classToLocationMap = new Map(); var cfg; var output = new JSZip(); const reader = new FileReader(); var classDataDump = {}; logClear(); - logTxt("[LOG] Build @ "+(new Date())); + logTxt("[INIT] Build @ "+(new Date())); if (!fileList || fileList.length === 0) { logTxt("[ERROR] Filelist is empty.") return; @@ -212,14 +230,22 @@ async function generate(fileList) { if (file.webkitRelativePath.endsWith(".java")) { var classId = file.webkitRelativePath.replaceAll("java/", "").replaceAll(".java", "").replaceAll("/", "."); var className = classId.split(".")[classId.split(".").length - 1]; + classToLocationMap.set(className, classId); if (cfg.targetFiles.includes(classId)) { logTxt("Found "+classId+" ["+file.name+"], processing..."); - output.file(file.webkitRelativePath.replaceAll("java/", ""), await process(file, reader, classDataDump, className)); + var javaFileContent = await process(file, reader, classDataDump, className); + if (cfg.includeReadFiles) { + output.file(file.webkitRelativePath.replaceAll("java/", ""), javaFileContent); + } } } } + logTxt(`Creating manager file...`); + createManagerFile(templateManager, cfg, output, classDataDump, classToLocationMap); + + logTxt(`Writing log.txt...`); output.file("log.txt", document.querySelector("#logs").innerText); - createManagerFile(templateManager, cfg, output, classDataDump); + output.generateAsync({type:"blob"}).then(function(content) { saveAs(content, "patch.zip"); }); diff --git a/NoReflect/index.html b/NoReflect/index.html index 4f2b50a..f8155d2 100644 --- a/NoReflect/index.html +++ b/NoReflect/index.html @@ -21,6 +21,7 @@ text-shadow: 0px 0px 3px; min-height: 10rem; min-width: 50rem; + font-size: 0.8rem; } textarea:focus { outline: 0; @@ -56,22 +57,52 @@ color: orange; text-shadow: 0px 0px 2px; } + .crt::after { + content: " "; + display: block; + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + background: rgba(18, 16, 16, 0.1); + opacity: 0; + z-index: 2; + pointer-events: none; + } + + .crt::before { + content: " "; + display: block; + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06)); + z-index: 2; + background-size: 100% 2px, 3px 100%; + pointer-events: none; + } - +

> NoReflect Generator WebUI


Config
-

diff --git a/NoReflect/javaRecon.js b/NoReflect/javaRecon.js index 5e40c28..d59bfd4 100644 --- a/NoReflect/javaRecon.js +++ b/NoReflect/javaRecon.js @@ -103,22 +103,22 @@ function reconJ(java, className) { argStr += ", " } } - + let prefix = isStatic ? className : `((${className}) params.get("_self"))`; let impl; if (returnType === "void") { impl = `setCallbackVoidWithArgs("${methodName}", (BaseData params) -> { - ((${className}) params.get("_self")).${methodName}(${argStr}); + ${prefix}.${methodName}(${argStr}); }); `; } else if (callbackStatementsTypes.includes(returnType)) { impl = `${callbackStatements[returnType]}("${methodName}", (BaseData params) -> { - return (${returnType}) ((${className}) params.get("_self")).${methodName}(${argStr}); + return (${returnType}) ${prefix}.${methodName}(${argStr}); }); `; } else { usedClasses.push(returnType); impl = `setCallbackReflectiveWithArgs("${methodName}", (BaseData params) -> { - return (${returnType}) ((${className}) params.get("_self")).${methodName}(${argStr}); + return (${returnType}) ${prefix}.${methodName}(${argStr}); }); `; } @@ -129,7 +129,8 @@ function reconJ(java, className) { returnType: returnType, isStatic: isStatic, arguments: arguments, - impl: impl + impl: impl, + idx: methods.indexOf(method) }; }); return {