Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zlataovce committed Aug 3, 2024
0 parents commit c4ee0a7
Show file tree
Hide file tree
Showing 21 changed files with 876 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store

obf-sample-test/
dist/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Matouš Kučera

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions LICENSE-JASM
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2023-2024 Justus Garbe

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# jasm

A JavaScript port of the [Jasm dis/assembler](https://github.com/jumanji144/Jasm).

## Example

```js
const fs = require("fs");
const { disassemble } = require("./jasm.js"); // get it from the dist/ directory or jsDelivr

const data = fs.readFileSync("./your/package/HelloWorld.class"); // read a class file
console.log(disassemble(data, {
indent: " ", // the string that should be used as the indent, defaults to 4 spaces
}));
```

Or see the browser-based proof-of-concept in the [docs](./docs) directory.

## Licensing

The supporting code for this project and the Jasm dis/assembler are licensed under the MIT License
([supporting code](./LICENSE), [Jasm](./LICENSE-JASM)).

_This project is not affiliated with, maintained or endorsed by the Jasm project in any way. Do NOT report issues with this project to the Jasm issue tracker._
67 changes: 67 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
plugins {
`java-library`
alias(libs.plugins.teavm) // order matters?
}

val thisVersion = "0.1.0"

group = "run.slicer"
version = "$thisVersion-${libs.versions.jasm.get()}"
description = "A JavaScript port of the Jasm dis/assembler."

repositories {
mavenCentral()
maven("https://jitpack.io")
}

dependencies {
api(libs.jasm.composition.jvm)
implementation("org.ow2.asm:asm:+") // override transitive dep scope
compileOnly(libs.teavm.core)
}

java.toolchain {
languageVersion = JavaLanguageVersion.of(21)
}

teavm.js {
mainClass = "run.slicer.jasm.Main"
moduleType = org.teavm.gradle.api.JSModuleType.ES2015
// obfuscated = false
// optimization = org.teavm.gradle.api.OptimizationLevel.NONE
}

tasks {
register<Copy>("copyDist") {
group = "build"

from("README.md", "LICENSE", "LICENSE-JASM", generateJavaScript, "jasm.d.ts")
into("dist")

doLast {
file("dist/package.json").writeText(
"""
{
"name": "@run-slicer/jasm",
"version": "${project.version}",
"description": "A JavaScript port of the Jasm dis/assembler (https://github.com/jumanji144/Jasm).",
"main": "jasm.js",
"types": "jasm.d.ts",
"keywords": [
"assembler",
"disassembler",
"java",
"bytecode"
],
"author": "run-slicer",
"license": "MIT"
}
""".trimIndent()
)
}
}

build {
dependsOn("copyDist")
}
}
81 changes: 81 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>Jasm in TeaVM</title>
<style>
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap");

body {
margin: 0;
padding: 0;
font-family: "JetBrains Mono", monospace;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: var(--bg-color);
color: var(--text-color);
transition: background-color 0.3s, color 0.3s;
}

:root {
--bg-color: #ffffff;
--text-color: #000000;
}

@media (prefers-color-scheme: dark) {
:root {
--bg-color: #1e1e1e;
--text-color: #cfcfcf;
}
}

#file-input {
margin-bottom: 20px;
}

#file-content {
width: 80%;
max-width: 1024px;
height: 60vh;
padding: 10px;
overflow-y: auto;
border: 1px solid var(--text-color);
border-radius: 5px;
background-color: var(--bg-color);
color: var(--text-color);
white-space: pre-wrap;
}
</style>
</head>
<body>
<input accept=".class" id="file-input" type="file">
<div id="file-content"></div>

<script type="module">
import { disassemble } from "https://cdn.jsdelivr.net/npm/@run-slicer/jasm/jasm.js";

const input = document.getElementById("file-input");
input.value = null; // clear file input
input.addEventListener("change", (e) => {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (evt) => {
const start = Date.now();
console.log(`Disassembling ${file.name}...`);

document.getElementById("file-content").textContent = disassemble(new Uint8Array(evt.target.result));

console.log(`Disassembled ${file.name} in ${Date.now() - start}ms.`);
};

reader.readAsArrayBuffer(file);
}
});
</script>
</body>
</html>
10 changes: 10 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[versions]
jasm = "2.5.0"
teavm = "0.10.0"

[libraries]
jasm-composition-jvm = { group = "com.github.jumanji144.Jasm", name = "jasm-composition-jvm", version.ref = "jasm" }
teavm-core = { group = "org.teavm", name = "teavm-core", version.ref = "teavm" }

[plugins]
teavm = { id = "org.teavm", version.ref = "teavm" }
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Jun 12 22:45:56 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit c4ee0a7

Please sign in to comment.