Skip to content

Commit 4c41bfb

Browse files
committed
Improved GUI and compatibility
1 parent c348dcf commit 4c41bfb

23 files changed

+324
-245
lines changed

grunt-main/src/main/kotlin/net/spartanb312/grunt/Grunt.kt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import kotlin.system.measureTimeMillis
1010

1111
/**
1212
* Gruntpocalypse
13-
* A continuation of Grunt witch is a lightweight java bytecode obfuscator
13+
* A java bytecode obfuscator
1414
*/
15-
const val VERSION = "2.0.2"
16-
const val SUBTITLE = "build 240717"
15+
const val VERSION = "2.1.0"
16+
const val SUBTITLE = "build 240721"
1717
const val GITHUB = "https://github.com/SpartanB312/Grunt"
1818

1919
fun main(args: Array<String>) {
@@ -34,38 +34,40 @@ fun main(args: Array<String>) {
3434

3535
Logger.info("Initializing Grunt Obfuscator...")
3636

37-
val needGui = args.contains("-gui")
38-
val config = args.firstOrNull { it.endsWith(".json") } ?: "config.json"
37+
var guiMode = false
38+
val config = args.firstOrNull { it.endsWith(".json") } ?: run {
39+
guiMode = true
40+
"config.json"
41+
} // If config is provided, use console mode
3942

4043
Logger.info("Using config $config")
4144

42-
if (needGui) {
43-
if (GraphicsEnvironment.isHeadless()){
44-
println("Gui is not allowed in your environment. pls remove [-gui]")
45-
return
46-
}
45+
if (GraphicsEnvironment.isHeadless()) {
46+
Logger.error("Gui is not allowed in your environment. Switching to console mode.")
47+
guiMode = false
48+
}
4749

50+
if (guiMode) {
4851
try {
4952
Configs.loadConfig(config)
53+
Configs.saveConfig(config) // Clean up the config
5054
} catch (ignore: Exception) {
55+
Logger.info("Failed to read config $config! But we generated a new one.")
5156
Configs.saveConfig(config)
5257
}
53-
5458
GuiFrame.loadConfig(config)
5559
GuiFrame.view()
5660
} else {
57-
5861
try {
5962
Configs.resetConfig()
6063
Configs.loadConfig(config)
61-
Configs.saveConfig(config)
64+
Configs.saveConfig(config) // Clean up the config
6265
} catch (ignore: Exception) {
6366
Logger.info("Failed to read config $config! But we generated a new one.")
6467
Configs.saveConfig(config)
6568
Logger.info("Type (Y/N) if you want to continue")
6669
if (readlnOrNull()?.lowercase() == "n") return
6770
}
68-
6971
runProcess()
7072
}
7173
}
@@ -77,7 +79,7 @@ fun runProcess() {
7779
readJar()
7880
val obfTime = measureTimeMillis {
7981
Logger.info("Processing...")
80-
Transformers.forEach { if (it.enabled) with(it) { transform() } }
82+
Transformers.sortedBy { it.order }.forEach { if (it.enabled) with(it) { transform() } }
8183
}
8284
Logger.info("Took $obfTime ms to process!")
8385
Logger.info("Dumping to ${Configs.Settings.output}")

grunt-main/src/main/kotlin/net/spartanb312/grunt/gui/GuiFrame.kt

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import net.spartanb312.grunt.VERSION
1010
import net.spartanb312.grunt.config.Configs
1111
import net.spartanb312.grunt.gui.panel.BasicPanel
1212
import net.spartanb312.grunt.gui.panel.GeneralPanel
13-
import net.spartanb312.grunt.gui.panel.LoggerPanel
13+
import net.spartanb312.grunt.gui.panel.ConsolePanel
1414
import net.spartanb312.grunt.gui.panel.TransformerPanel
15-
import net.spartanb312.grunt.gui.util.LoggerCapture
15+
import net.spartanb312.grunt.gui.util.LoggerPrinter
1616
import net.spartanb312.grunt.runProcess
1717
import net.spartanb312.grunt.utils.logging.SimpleLogger
1818
import java.awt.BorderLayout
1919
import java.awt.Dimension
20+
import java.awt.Image
2021
import java.io.PrintWriter
2122
import java.io.StringWriter
2223
import javax.swing.*
@@ -25,29 +26,34 @@ import javax.swing.border.EmptyBorder
2526
import kotlin.concurrent.thread
2627

2728
object GuiFrame {
28-
val logger = SimpleLogger("Grunt Gui")
29+
30+
val logger = SimpleLogger("Grunt-UI")
2931

3032
private val mainFrame = JFrame("")
3133
private val frameSize = Dimension(755, 535)
3234

3335
var currentConfig: String = "config.json"
3436

35-
//Page
37+
// Page
3638
val tabbedPanel = JTabbedPane()
3739

38-
//Config
40+
// Config
3941
val basicPanel = BasicPanel()
4042
val generalPanel = GeneralPanel()
4143
val transformerPanel = TransformerPanel()
4244

43-
//Logger
44-
var loggerPanel = LoggerPanel()
45-
val captureInfo = LoggerCapture(System.out) { loggerPanel.info(it) }
45+
// Console
46+
var consolePanel = ConsolePanel()
47+
val captureInfo = LoggerPrinter(System.out) { consolePanel.info(it) }
48+
4649
init {
4750
System.setOut(captureInfo)
4851
}
4952

5053
init {
54+
val imageIcon = ImageIcon(GuiFrame::class.java.getResource("/logo.png"))
55+
mainFrame.iconImage = imageIcon.image.getScaledInstance(40, 40, Image.SCALE_DEFAULT)
56+
5157
mainFrame.title = "Gruntpocalypse v$VERSION | $SUBTITLE"
5258
mainFrame.defaultCloseOperation = EXIT_ON_CLOSE
5359
mainFrame.size = frameSize
@@ -58,8 +64,8 @@ object GuiFrame {
5864
)
5965

6066
tabbedPanel.addTab("General", JScrollPane(generalPanel).apply { verticalScrollBar.unitIncrement = 16 })
61-
tabbedPanel.addTab("Transformer", transformerPanel)
62-
tabbedPanel.addTab("Logger", loggerPanel)
67+
tabbedPanel.addTab("Obfuscation", transformerPanel)
68+
tabbedPanel.addTab("Console", consolePanel)
6369

6470
mainFrame.add(tabbedPanel, CC().cell(0, 0))
6571
mainFrame.add(basicPanel, CC().cell(0, 1))
@@ -71,22 +77,22 @@ object GuiFrame {
7177
fun startObf() {
7278
setValues()
7379
thread(
74-
name = "Grunt Process",
80+
name = "process",
7581
priority = Thread.MAX_PRIORITY
7682
) {
7783
disableAll()
7884
tabbedPanel.selectedIndex = 2
7985
try {
80-
runProcess()
86+
runProcess()
8187
} catch (e: Exception) {
8288
e.printStackTrace()
8389

8490
val stacktrace = StringWriter().also {
8591
e.printStackTrace(PrintWriter(it))
8692
}.toString()
8793

88-
//Send To Gui Logger
89-
loggerPanel.err(stacktrace)
94+
// Send To Gui Logger
95+
consolePanel.err(stacktrace)
9096

9197
val panel = JPanel().apply {
9298
border = EmptyBorder(5, 5, 5, 5)
@@ -95,7 +101,12 @@ object GuiFrame {
95101

96102
panel.add(JScrollPane(JTextArea(stacktrace).also { it.isEditable = false }))
97103

98-
JOptionPane.showMessageDialog(this.mainFrame, panel, "ERROR encountered at " + e.stackTrace[0].className, JOptionPane.ERROR_MESSAGE)
104+
JOptionPane.showMessageDialog(
105+
this.mainFrame,
106+
panel,
107+
"ERROR encountered at " + e.stackTrace[0].className,
108+
JOptionPane.ERROR_MESSAGE
109+
)
99110
}
100111
enableAll()
101112
}
@@ -122,21 +133,21 @@ object GuiFrame {
122133

123134
fun loadConfig(path: String) {
124135
currentConfig = path
125-
logger.info("Load Config $currentConfig")
136+
logger.info("Loading config $currentConfig")
126137
Configs.loadConfig(currentConfig)
127138
refreshElement()
128139
}
129140

130141
fun saveConfig(path: String) {
131142
currentConfig = path
132143

133-
logger.info("Save Config $currentConfig")
144+
logger.info("Saving config $currentConfig")
134145
setValues()
135146
Configs.saveConfig(currentConfig)
136147
}
137148

138149
fun resetValue() {
139-
logger.info("Reset Value")
150+
logger.info("Reset all settings")
140151
Configs.resetConfig()
141152
refreshElement()
142153
}
@@ -156,4 +167,5 @@ object GuiFrame {
156167
fun view() {
157168
mainFrame.isVisible = true
158169
}
170+
159171
}

grunt-main/src/main/kotlin/net/spartanb312/grunt/gui/panel/BasicPanel.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import java.io.File
1111
import javax.swing.*
1212
import javax.swing.border.TitledBorder
1313

14-
1514
class BasicPanel : JPanel() {
15+
1616
val input = JTextField()
1717
val output = JTextField()
1818
private val inputBrowse = JButton("Browse")
@@ -28,8 +28,8 @@ class BasicPanel : JPanel() {
2828

2929
val loadButton = JButton("Load Config")
3030
val saveButton = JButton("Save Config")
31-
val resetButton = JButton("Reset Value")
32-
val startSave = JCheckBox("Save when start obfuscate", true)
31+
val resetButton = JButton("Reset Values")
32+
val startSave = JCheckBox("Save when obfuscation starts", true)
3333

3434
init {
3535
layout = MigLayout(
@@ -56,7 +56,8 @@ class BasicPanel : JPanel() {
5656
GuiFrame.loadConfig(file)
5757
}
5858
saveButton.addActionListener {
59-
val file = FileChooseUtils.choosePathSaveJsonFile(parent, File(GuiFrame.currentConfig)) ?: return@addActionListener
59+
val file =
60+
FileChooseUtils.choosePathSaveJsonFile(parent, File(GuiFrame.currentConfig)) ?: return@addActionListener
6061
GuiFrame.saveConfig(file.removeSuffix(".json").plus(".json"))
6162
}
6263
resetButton.addActionListener {
@@ -120,4 +121,5 @@ class BasicPanel : JPanel() {
120121
Settings.corruptOutput = this.corruptOutput.isSelected
121122
Settings.generateRemap = this.dumpMappings.isSelected
122123
}
124+
123125
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package net.spartanb312.grunt.gui.panel
2+
3+
import java.awt.BorderLayout
4+
import java.awt.Color
5+
import javax.swing.JPanel
6+
import javax.swing.JScrollPane
7+
import javax.swing.JTextPane
8+
import javax.swing.text.SimpleAttributeSet
9+
import javax.swing.text.StyleConstants
10+
import javax.swing.text.StyleContext
11+
12+
class ConsolePanel : JPanel() {
13+
14+
private val loggerPanel = JTextPane().apply { isEditable = false }
15+
private val printLayout: JPanel
16+
private val scrollPane: JScrollPane
17+
18+
init {
19+
layout = BorderLayout()
20+
printLayout = JPanel(BorderLayout())
21+
printLayout.add(loggerPanel)
22+
scrollPane = JScrollPane(printLayout).apply {
23+
verticalScrollBar.unitIncrement = 16
24+
}
25+
add(scrollPane, BorderLayout.CENTER)
26+
}
27+
28+
private val scrollBar = scrollPane.verticalScrollBar
29+
30+
fun info(str: String) {
31+
appendToPane(loggerPanel, "$str\n", Color.BLACK)
32+
}
33+
34+
fun err(str: String) {
35+
appendToPane(loggerPanel, "$str\n", Color.RED)
36+
}
37+
38+
private fun appendToPane(text: JTextPane, msg: String, c: Color) {
39+
scrollBar.value = scrollBar.maximum
40+
text.document.insertString(
41+
text.document.length,
42+
msg,
43+
StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c)
44+
)
45+
}
46+
47+
}

0 commit comments

Comments
 (0)