Skip to content

Commit

Permalink
Add Support for .MF + .TXT
Browse files Browse the repository at this point in the history
  • Loading branch information
sotasan committed May 13, 2022
1 parent 6e91f7c commit a9c8fe7
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 91 deletions.
2 changes: 1 addition & 1 deletion 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.1"
version = "0.2.2"

kotlin {
jvmToolchain {
Expand Down
10 changes: 4 additions & 6 deletions src/main/kotlin/net/pryoscode/decompiler/Decompiler.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package net.pryoscode.decompiler

import javafx.scene.control.TabPane
import net.pryoscode.decompiler.window.components.container.Code
import net.pryoscode.decompiler.window.components.sidebar.Entry
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
Expand All @@ -15,10 +14,9 @@ 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.HashMap
import java.util.jar.Manifest

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

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

Expand Down Expand Up @@ -57,7 +55,7 @@ class Decompiler(private val tabPane: TabPane, private val entry: Entry) : IByte

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/net/pryoscode/decompiler/Main.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@file:JvmName("Main")
package net.pryoscode.decompiler

import net.pryoscode.decompiler.window.windows.Window
import net.pryoscode.decompiler.window.Window
import javax.swing.UIManager

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.pryoscode.decompiler.window.windows
package net.pryoscode.decompiler.window

import com.sun.javafx.tk.Toolkit
import javafx.application.Platform
Expand All @@ -8,9 +8,10 @@ import javafx.scene.layout.BorderPane
import javafx.scene.text.Font
import javafx.stage.FileChooser
import javafx.stage.FileChooser.ExtensionFilter
import net.pryoscode.decompiler.window.components.container.Container
import net.pryoscode.decompiler.window.components.sidebar.Sidebar
import net.pryoscode.decompiler.window.style
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.datatransfer.DataFlavor
import java.awt.dnd.*
import java.awt.event.MouseAdapter
Expand All @@ -20,7 +21,7 @@ import javax.swing.*

object Window : JFrame() {

private val FONTS = arrayOf(
private val fonts = arrayOf(
"JetBrainsMono-Bold", "JetBrainsMono-BoldItalic", "JetBrainsMono-ExtraBold", "JetBrainsMono-ExtraBoldItalic",
"JetBrainsMono-ExtraLight", "JetBrainsMono-ExtraLightItalic", "JetBrainsMono-Italic", "JetBrainsMono-Light",
"JetBrainsMono-LightItalic", "JetBrainsMono-Medium", "JetBrainsMono-MediumItalic", "JetBrainsMono-Regular",
Expand All @@ -34,17 +35,13 @@ object Window : JFrame() {
"OpenSans-SemiBold", "OpenSans-SemiBoldItalic"
)

private val sidebar: Sidebar

init {
val panel = JFXPanel()
val root = BorderPane()
val container = Container()
sidebar = Sidebar(container)
root.center = container
root.left = sidebar
root.center = Container
root.left = Sidebar

for (font in FONTS)
for (font in fonts)
Font.loadFont(javaClass.classLoader.getResourceAsStream("fonts/${font.split("-")[0]}/$font.ttf"), Toolkit.getToolkit().fontLoader.systemFontSize.toDouble())
root.stylesheets.add(style("base.less"))

Expand All @@ -60,7 +57,7 @@ object Window : JFrame() {
val fileChooser = FileChooser()
fileChooser.extensionFilters.add(ExtensionFilter("Java Archive", "*.jar"))
val file = fileChooser.showOpenDialog(panel.scene.window)
sidebar.open(file)
Sidebar.open(file)
}
}
fileClose.isEnabled = false
Expand Down Expand Up @@ -101,7 +98,7 @@ object Window : JFrame() {
event?.acceptDrop(DnDConstants.ACTION_MOVE)
val files = event?.transferable?.getTransferData(DataFlavor.javaFileListFlavor) as List<File>
if (files[0].extension.equals("jar", true))
Platform.runLater { sidebar.open(files[0]) }
Platform.runLater { Sidebar.open(files[0]) }
}
})

Expand All @@ -117,7 +114,7 @@ object Window : JFrame() {
isVisible = true
Platform.runLater {
if (args.isNotEmpty())
sidebar.open(File(args[0]))
Sidebar.open(File(args[0]))
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package net.pryoscode.decompiler.window.components.container
package net.pryoscode.decompiler.window.container

import javafx.collections.ListChangeListener
import javafx.scene.control.ContextMenu
import javafx.scene.control.MenuItem
import javafx.scene.control.Tab
import javafx.scene.control.TabPane
import javafx.scene.image.ImageView
import net.pryoscode.decompiler.window.components.sidebar.Entry
import net.pryoscode.decompiler.window.sidebar.Entry
import org.fxmisc.flowless.VirtualizedScrollPane
import org.fxmisc.richtext.CodeArea
import org.fxmisc.richtext.LineNumberFactory

class Code(tabPane: TabPane, val entry: Entry, code: String) : Tab() {
class Code(val entry: Entry, code: String) : Tab() {

init {
text = entry.name
Expand All @@ -26,25 +25,25 @@ class Code(tabPane: TabPane, val entry: Entry, code: String) : Tab() {
val close = MenuItem("Close")
val closeOthers = MenuItem("Close Others")
val closeAll = MenuItem("Close All")
tabPane.tabs.addListener(ListChangeListener {
val multiple = tabPane.tabs.size == 1
Container.tabs.addListener(ListChangeListener {
val multiple = Container.tabs.size == 1
closeOthers.isDisable = multiple
closeAll.isDisable = multiple
})
close.setOnAction { tabPane.tabs.remove(this) }
close.setOnAction { Container.tabs.remove(this) }
closeOthers.setOnAction {
val tabs = tabPane.tabs.iterator()
val tabs = Container.tabs.iterator()
while (tabs.hasNext()) {
if (!tabs.next().equals(this))
tabs.remove()
}
}
closeAll.setOnAction { tabPane.tabs.clear() }
closeAll.setOnAction { Container.tabs.clear() }
menu.items.addAll(close, closeOthers, closeAll)
contextMenu = menu

tabPane.tabs.add(this)
tabPane.selectionModel.select(this)
Container.tabs.add(this)
Container.selectionModel.select(this)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.pryoscode.decompiler.window.container

import javafx.scene.control.TabPane
import net.pryoscode.decompiler.Decompiler
import net.pryoscode.decompiler.window.sidebar.Entry
import net.pryoscode.decompiler.window.sidebar.Type
import org.jetbrains.java.decompiler.util.InterpreterUtil

object Container : TabPane() {

init {
tabDragPolicy = TabDragPolicy.REORDER
tabClosingPolicy = TabClosingPolicy.ALL_TABS
}

fun open(entry: Entry) {
var tab: Code? = null
for (t in tabs) {
if ((t as Code).entry == entry) {
tab = t
break
}
}
if (tab == null) {
if (entry.type == Type.CLASS)
Decompiler(entry)
else
Code(entry, String(InterpreterUtil.getBytes(entry.file, entry.entry)))
} else
selectionModel.select(tab)
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package net.pryoscode.decompiler.window.windows
package net.pryoscode.decompiler.window.popup

import javafx.geometry.Pos
import javafx.scene.control.Button
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import net.pryoscode.decompiler.window.Popup
import net.pryoscode.decompiler.window.components.Link
import net.pryoscode.decompiler.window.utils.Link

class About : Popup("About") {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package net.pryoscode.decompiler.window.popup

class Importer
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package net.pryoscode.decompiler.window
package net.pryoscode.decompiler.window.popup

import javafx.embed.swing.JFXPanel
import javafx.scene.Parent
import javafx.scene.Scene
import net.pryoscode.decompiler.window.windows.Window
import net.pryoscode.decompiler.window.Window
import net.pryoscode.decompiler.window.utils.style
import java.awt.event.KeyEvent
import javax.swing.ImageIcon
import javax.swing.JComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package net.pryoscode.decompiler.window.popup

class Search
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.pryoscode.decompiler.window.components.sidebar
package net.pryoscode.decompiler.window.sidebar

import javafx.scene.Cursor
import javafx.scene.control.TreeView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package net.pryoscode.decompiler.window.components.sidebar
package net.pryoscode.decompiler.window.sidebar

import javafx.scene.control.TreeCell
import javafx.scene.image.ImageView
import javafx.scene.input.MouseButton
import javafx.scene.input.MouseEvent
import net.pryoscode.decompiler.window.components.container.Container
import net.pryoscode.decompiler.window.container.Container

class Cell(private val container: Container) : TreeCell<Entry>() {
class Cell : TreeCell<Entry>() {

init {
addEventHandler(MouseEvent.MOUSE_CLICKED, ::mouseClicked)
Expand All @@ -26,8 +26,8 @@ class Cell(private val container: Container) : TreeCell<Entry>() {

private fun mouseClicked(event: MouseEvent) {
if (item != null && event.button == MouseButton.PRIMARY) {
if (item.type == Type.CLASS)
container.open(item)
if (item.type != Type.ARCHIVE && item.type != Type.PACKAGE && item.type != Type.FILE)
Container.open(item)
if (item.type == Type.PACKAGE)
treeItem.isExpanded = !treeItem.isExpanded
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.pryoscode.decompiler.window.components.sidebar
package net.pryoscode.decompiler.window.sidebar

import java.util.jar.JarEntry
import java.util.jar.JarFile
Expand All @@ -14,7 +14,11 @@ class Entry(val file: JarFile?, val entry: JarEntry?) {
val base = if (entry.isDirectory) entry.name.substringBeforeLast("/") else entry.name
name = base.substringAfterLast("/")
path = entry.name
type = if (entry.isDirectory) Type.PACKAGE else if (entry.name.endsWith(".class", true)) Type.CLASS else Type.FILE
type = if (entry.isDirectory) Type.PACKAGE
else if (entry.name.endsWith(".class", true)) Type.CLASS
else if (entry.name.endsWith(".txt", true)) Type.TEXT
else if (entry.name.endsWith(".mf", true)) Type.MANIFEST
else Type.FILE
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.pryoscode.decompiler.window.components.sidebar
package net.pryoscode.decompiler.window.sidebar

import javafx.scene.control.TreeItem
import java.util.jar.JarEntry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package net.pryoscode.decompiler.window.components.sidebar
package net.pryoscode.decompiler.window.sidebar

import javafx.scene.control.TreeView
import javafx.scene.layout.BorderPane
import net.pryoscode.decompiler.window.components.container.Container
import net.pryoscode.decompiler.window.container.Container
import java.io.File
import java.util.jar.JarEntry
import java.util.jar.JarFile

class Sidebar(private val container: Container) : BorderPane() {
object Sidebar : BorderPane() {

private val tree = TreeView<Entry>()

init {
tree.setCellFactory { Cell(container) }
tree.setCellFactory { Cell() }
center = tree
tree.minWidth = 50.0
right = Bar(tree)
}

fun open(file: File?) {
if (file == null || !file.exists()) return
container.tabs.clear()
Container.tabs.clear()
val entries = ArrayList<JarEntry>()
val jar = JarFile(file)
val jarEntries = jar.entries()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.pryoscode.decompiler.window.components.sidebar
package net.pryoscode.decompiler.window.sidebar

import javafx.scene.image.Image

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.pryoscode.decompiler.window.components
package net.pryoscode.decompiler.window.utils

import javafx.scene.control.Hyperlink
import java.awt.Desktop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.pryoscode.decompiler.window
package net.pryoscode.decompiler.window.utils

import com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler
import net.pryoscode.decompiler.window.windows.Window
import net.pryoscode.decompiler.window.Window
import java.util.*

fun style(file: String): String {
Expand Down
Loading

0 comments on commit a9c8fe7

Please sign in to comment.