Skip to content

Commit

Permalink
Add M1 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
sotasan committed May 16, 2022
1 parent a9c8fe7 commit 4c6d573
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 106 deletions.
14 changes: 7 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "net.pryoscode"
version = "0.2.2"
version = "0.2.3"

kotlin {
jvmToolchain {
Expand All @@ -13,15 +13,15 @@ kotlin {
}

javafx {
version = JavaVersion.VERSION_17.toString()
version = JavaVersion.VERSION_18.toString()
modules("javafx.base", "javafx.controls", "javafx.graphics", "javafx.swing")
}

tasks.jar {
archiveBaseName.set(project.name.toLowerCase())
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest.attributes["Specification-Version"] = project.version
manifest.attributes["Main-Class"] = "${project.group}.${project.name.toLowerCase()}.Main"
manifest.attributes["Main-Class"] = "${project.group}.${project.name.toLowerCase()}.Decompiler"
from(configurations.compileClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
}

Expand All @@ -40,15 +40,15 @@ dependencies {
implementation("org.fxmisc.richtext:richtextfx:0.10.9")
implementation("com.github.sommeri:less4j:1.17.2")
implementation("org.openjfx:javafx-base:${javafx.version}:win")
implementation("org.openjfx:javafx-base:${javafx.version}:mac")
implementation("org.openjfx:javafx-base:${javafx.version}:mac-aarch64")
implementation("org.openjfx:javafx-base:${javafx.version}:linux")
implementation("org.openjfx:javafx-controls:${javafx.version}:win")
implementation("org.openjfx:javafx-controls:${javafx.version}:mac")
implementation("org.openjfx:javafx-controls:${javafx.version}:mac-aarch64")
implementation("org.openjfx:javafx-controls:${javafx.version}:linux")
implementation("org.openjfx:javafx-graphics:${javafx.version}:win")
implementation("org.openjfx:javafx-graphics:${javafx.version}:mac")
implementation("org.openjfx:javafx-graphics:${javafx.version}:mac-aarch64")
implementation("org.openjfx:javafx-graphics:${javafx.version}:linux")
implementation("org.openjfx:javafx-swing:${javafx.version}:win")
implementation("org.openjfx:javafx-swing:${javafx.version}:mac")
implementation("org.openjfx:javafx-swing:${javafx.version}:mac-aarch64")
implementation("org.openjfx:javafx-swing:${javafx.version}:linux")
}
75 changes: 7 additions & 68 deletions src/main/kotlin/net/pryoscode/decompiler/Decompiler.kt
Original file line number Diff line number Diff line change
@@ -1,72 +1,11 @@
@file:JvmName("Decompiler")
package net.pryoscode.decompiler

import net.pryoscode.decompiler.window.container.Code
import net.pryoscode.decompiler.window.sidebar.Entry
import org.jetbrains.java.decompiler.main.Fernflower
import org.jetbrains.java.decompiler.main.extern.IBytecodeProvider
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences
import org.jetbrains.java.decompiler.main.extern.IResultSaver
import org.jetbrains.java.decompiler.struct.ContextUnit
import org.jetbrains.java.decompiler.struct.StructClass
import org.jetbrains.java.decompiler.struct.StructContext
import org.jetbrains.java.decompiler.struct.lazy.LazyLoader
import org.jetbrains.java.decompiler.util.DataInputFullStream
import org.jetbrains.java.decompiler.util.InterpreterUtil
import java.io.File
import java.util.jar.Manifest

class Decompiler(private val entry: Entry) : IBytecodeProvider, IResultSaver, IFernflowerLogger() {

private val bytes = InterpreterUtil.getBytes(entry.file, entry.entry)

init {
val fernflower = Fernflower(this, this, IFernflowerPreferences.DEFAULTS, this)
fernflower.addLibrary(File("null.class"))

val structContextField = fernflower.javaClass.getDeclaredField("structContext")
structContextField.isAccessible = true
val structContext = structContextField.get(fernflower) as StructContext

val loaderField = structContext.javaClass.getDeclaredField("loader")
loaderField.isAccessible = true
val loader = loaderField.get(structContext) as LazyLoader

val structClass = StructClass.create(DataInputFullStream(bytes), true, loader)
structContext.classes.put(entry.name, structClass)

val path = File("null.class").absolutePath
val contextUnit = ContextUnit(ContextUnit.TYPE_FOLDER, null, path, true, this, fernflower)
contextUnit.addClass(structClass, "null.class")

val unitsField = structContext.javaClass.getDeclaredField("units")
unitsField.isAccessible = true
val units = unitsField.get(structContext) as HashMap<String, ContextUnit>

units[path] = contextUnit
loader.addClassLink(entry.name, LazyLoader.Link(path, null))

fernflower.decompileContext()
}

override fun getBytecode(externalPath: String?, internalPath: String?): ByteArray {
return bytes
}

override fun saveClassFile(path: String?, qualifiedName: String?, entryName: String?, content: String?, mapping: IntArray?) {
content?.let {
Code(entry, it)
}
}

override fun saveFolder(path: String?) {}
override fun copyFile(source: String?, path: String?, entryName: String?) {}
override fun createArchive(path: String?, archiveName: String?, manifest: Manifest?) {}
override fun saveDirEntry(path: String?, archiveName: String?, entryName: String?) {}
override fun copyEntry(source: String?, path: String?, archiveName: String?, entry: String?) {}
override fun saveClassEntry(path: String?, archiveName: String?, qualifiedName: String?, entryName: String?, content: String?) {}
override fun closeArchive(path: String?, archiveName: String?) {}
override fun writeMessage(message: String?, severity: Severity?) {}
override fun writeMessage(message: String?, severity: Severity?, t: Throwable?) {}
import net.pryoscode.decompiler.window.Window
import javax.swing.UIManager

fun main(args: Array<String>) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
Window.run(args)
}
72 changes: 72 additions & 0 deletions src/main/kotlin/net/pryoscode/decompiler/Fernflower.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package net.pryoscode.decompiler

import net.pryoscode.decompiler.window.container.Code
import net.pryoscode.decompiler.window.sidebar.Entry
import org.jetbrains.java.decompiler.main.Fernflower
import org.jetbrains.java.decompiler.main.extern.IBytecodeProvider
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences
import org.jetbrains.java.decompiler.main.extern.IResultSaver
import org.jetbrains.java.decompiler.struct.ContextUnit
import org.jetbrains.java.decompiler.struct.StructClass
import org.jetbrains.java.decompiler.struct.StructContext
import org.jetbrains.java.decompiler.struct.lazy.LazyLoader
import org.jetbrains.java.decompiler.util.DataInputFullStream
import org.jetbrains.java.decompiler.util.InterpreterUtil
import java.io.File
import java.util.jar.Manifest

class Fernflower(private val entry: Entry) : IBytecodeProvider, IResultSaver, IFernflowerLogger() {

private val bytes = InterpreterUtil.getBytes(entry.file, entry.entry)

init {
val fernflower = Fernflower(this, this, IFernflowerPreferences.DEFAULTS, this)
fernflower.addLibrary(File("null.class"))

val structContextField = fernflower.javaClass.getDeclaredField("structContext")
structContextField.isAccessible = true
val structContext = structContextField.get(fernflower) as StructContext

val loaderField = structContext.javaClass.getDeclaredField("loader")
loaderField.isAccessible = true
val loader = loaderField.get(structContext) as LazyLoader

val structClass = StructClass.create(DataInputFullStream(bytes), true, loader)
structContext.classes.put(entry.name, structClass)

val path = File("null.class").absolutePath
val contextUnit = ContextUnit(ContextUnit.TYPE_FOLDER, null, path, true, this, fernflower)
contextUnit.addClass(structClass, "null.class")

val unitsField = structContext.javaClass.getDeclaredField("units")
unitsField.isAccessible = true
val units = unitsField.get(structContext) as HashMap<String, ContextUnit>

units[path] = contextUnit
loader.addClassLink(entry.name, LazyLoader.Link(path, null))

fernflower.decompileContext()
}

override fun getBytecode(externalPath: String?, internalPath: String?): ByteArray {
return bytes
}

override fun saveClassFile(path: String?, qualifiedName: String?, entryName: String?, content: String?, mapping: IntArray?) {
content?.let {
Code(entry, it)
}
}

override fun saveFolder(path: String?) {}
override fun copyFile(source: String?, path: String?, entryName: String?) {}
override fun createArchive(path: String?, archiveName: String?, manifest: Manifest?) {}
override fun saveDirEntry(path: String?, archiveName: String?, entryName: String?) {}
override fun copyEntry(source: String?, path: String?, archiveName: String?, entry: String?) {}
override fun saveClassEntry(path: String?, archiveName: String?, qualifiedName: String?, entryName: String?, content: String?) {}
override fun closeArchive(path: String?, archiveName: String?) {}
override fun writeMessage(message: String?, severity: Severity?) {}
override fun writeMessage(message: String?, severity: Severity?, t: Throwable?) {}

}
11 changes: 0 additions & 11 deletions src/main/kotlin/net/pryoscode/decompiler/Main.kt

This file was deleted.

32 changes: 14 additions & 18 deletions src/main/kotlin/net/pryoscode/decompiler/window/Window.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import net.pryoscode.decompiler.window.container.Container
import net.pryoscode.decompiler.window.sidebar.Sidebar
import net.pryoscode.decompiler.window.popup.About
import net.pryoscode.decompiler.window.utils.style
import java.awt.Taskbar
import java.awt.datatransfer.DataFlavor
import java.awt.dnd.*
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.io.File
import javax.swing.*

Expand All @@ -36,6 +35,12 @@ object Window : JFrame() {
)

init {
title = "Decompiler"
defaultCloseOperation = DISPOSE_ON_CLOSE
val icon = ImageIcon(javaClass.classLoader.getResourceAsStream("icons/logo.png")?.readAllBytes()).image
Taskbar.getTaskbar().iconImage = icon
iconImage = icon

val panel = JFXPanel()
val root = BorderPane()
root.center = Container
Expand All @@ -45,8 +50,6 @@ object Window : JFrame() {
Font.loadFont(javaClass.classLoader.getResourceAsStream("fonts/${font.split("-")[0]}/$font.ttf"), Toolkit.getToolkit().fontLoader.systemFontSize.toDouble())
root.stylesheets.add(style("base.less"))

panel.scene = Scene(root, 896.0, 560.0)

jMenuBar = JMenuBar()
val file = JMenu("File")
val fileOpen = JMenuItem("Open")
Expand All @@ -66,17 +69,11 @@ object Window : JFrame() {
file.add(fileClose)
file.add(fileExit)
jMenuBar.add(file)
val search = JMenu("Search")
search.isEnabled = false
jMenuBar.add(search)
val about = JMenu("About")
about.addMouseListener(object : MouseAdapter() {
override fun mousePressed(e: MouseEvent?) {
about.isSelected = false
About()
}
})
jMenuBar.add(about)
val help = JMenu("Help")
val helpAbout = JMenuItem("About")
helpAbout.addActionListener { About() }
help.add(helpAbout)
jMenuBar.add(help)

dropTarget = DropTarget(panel, object : DropTargetListener {
override fun dropActionChanged(event: DropTargetDragEvent?) {}
Expand All @@ -102,9 +99,8 @@ object Window : JFrame() {
}
})

title = "Decompiler"
iconImage = ImageIcon(javaClass.classLoader.getResourceAsStream("icons/logo.png")?.readAllBytes()).image
defaultCloseOperation = DISPOSE_ON_CLOSE
panel.scene = Scene(root, 896.0, 560.0)

add(panel)
pack()
setLocationRelativeTo(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.pryoscode.decompiler.window.container

import javafx.scene.control.TabPane
import net.pryoscode.decompiler.Decompiler
import net.pryoscode.decompiler.Fernflower
import net.pryoscode.decompiler.window.sidebar.Entry
import net.pryoscode.decompiler.window.sidebar.Type
import org.jetbrains.java.decompiler.util.InterpreterUtil
Expand All @@ -23,7 +23,7 @@ object Container : TabPane() {
}
if (tab == null) {
if (entry.type == Type.CLASS)
Decompiler(entry)
Fernflower(entry)
else
Code(entry, String(InterpreterUtil.getBytes(entry.file, entry.entry)))
} else
Expand Down

0 comments on commit 4c6d573

Please sign in to comment.