generated from run-slicer/script-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
969 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
.idea/ | ||
dist/ | ||
node_modules/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "Krakatau"] | ||
path = Krakatau | ||
url = https://github.com/run-slicer/Krakatau.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
pnpm-lock.yaml | ||
dist/ | ||
Krakatau/ | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# script-template | ||
# script-krak | ||
|
||
A Rollup+TypeScript template for a project based on the slicer scripting API. | ||
A slicer script binding for the Krakatau Java decompiler. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const krakScript = `from pyodide.http import pyfetch | ||
response = await pyfetch("https://cdn.jsdelivr.net/gh/run-slicer/script-krak@${"1.0.0"}/dist/krak.zip") | ||
await response.unpack_archive() | ||
from Krakatau.java.visitor import DefaultVisitor | ||
from Krakatau.java.javaclass import generateAST | ||
from Krakatau.ssa import ssaFromVerified | ||
from Krakatau.verifier.inference_verifier import verifyBytecode | ||
from Krakatau.java.stringescape import escapeString | ||
from Krakatau.environment import Environment | ||
from Krakatau.classfile import ClassFile | ||
from Krakatau.classfileformat.reader import Reader | ||
def makeGraph(m): | ||
v = verifyBytecode(m.code) | ||
s = ssaFromVerified(m.code, v, opts=False) | ||
if s.procs: | ||
s.inlineSubprocs() | ||
s.condenseBlocks() | ||
s.mergeSingleSuccessorBlocks() | ||
s.removeUnusedVariables() | ||
s.copyPropagation() | ||
s.abstractInterpert() | ||
s.disconnectConstantVariables() | ||
s.simplifyThrows() | ||
s.simplifyCatchIgnored() | ||
s.mergeSingleSuccessorBlocks() | ||
s.mergeSingleSuccessorBlocks() | ||
s.removeUnusedVariables() | ||
return s | ||
def decompile(data): | ||
e = Environment() | ||
c = ClassFile(Reader(data=bytes(data.to_py()))) | ||
c.env = e | ||
e.classes[c.name] = c | ||
c.loadElements() | ||
printer = DefaultVisitor() | ||
source = printer.visit(generateAST(c, makeGraph, skip_errors=True)) | ||
if '/' in c.name: | ||
return f'package {escapeString(c.name.replace('/','.').rpartition('.')[0])};\\n\\n{source}' | ||
return source | ||
decompile`; | ||
let decompileFunc = null; | ||
const krak = { | ||
id: "krak", | ||
label: "Krakatau", | ||
language: "java", | ||
async run(data) { | ||
if (!decompileFunc) { | ||
decompileFunc = await import('https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.mjs') | ||
.then(({ loadPyodide }) => loadPyodide()) | ||
.then((pyodide) => pyodide.runPythonAsync(krakScript)); | ||
} | ||
return decompileFunc(data); | ||
}, | ||
}; | ||
var index = { | ||
name: "script-krak", | ||
description: "A script binding for the Krakatau Java decompiler.", | ||
version: "1.0.0", | ||
load(context) { | ||
context.disasm.add(krak); | ||
}, | ||
unload(context) { | ||
context.disasm.remove(krak.id); | ||
}, | ||
}; | ||
|
||
export { index as default }; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
{ | ||
"name": "script-template", | ||
"name": "script-krak", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"author": "", | ||
"license": "Unlicense", | ||
"description": "A Rollup+TypeScript template for a project based on the slicer scripting API.", | ||
"author": "run-slicer", | ||
"license": "GPL-3.0-only", | ||
"description": "A slicer script binding for the Krakatau Java decompiler.", | ||
"scripts": { | ||
"build": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript", | ||
"prepare": "mkdir -p dist; cd Krakatau; find Krakatau LICENSE.TXT -name \"*.py\" -o -name \"LICENSE.TXT\" | zip -FS -@ ../dist/krak.zip", | ||
"build": "pnpm prepare && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript", | ||
"format": "prettier . --write" | ||
}, | ||
"dependencies": { | ||
"@run-slicer/script": "^0.3.0" | ||
"@run-slicer/script": "^0.8.1" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@rollup/plugin-replace": "^5.0.7", | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@types/node": "^22.4.0", | ||
"@types/node": "^22.5.2", | ||
"prettier": "^3.3.3", | ||
"rollup": "^4.21.0", | ||
"tslib": "^2.6.3", | ||
"rollup": "^4.21.2", | ||
"tslib": "^2.7.0", | ||
"typescript": "^5.5.4" | ||
}, | ||
"packageManager": "[email protected]+sha512.faf344af2d6ca65c4c5c8c2224ea77a81a5e8859cbc4e06b1511ddce2f0151512431dd19e6aff31f2c6a8f5f2aced9bd2273e1fed7dd4de1868984059d2c4247" | ||
|
Oops, something went wrong.