Skip to content

Commit

Permalink
feat: gui rework
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalsin committed Dec 18, 2024
1 parent ab5c4bf commit 3b93ea6
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 37 deletions.
2 changes: 2 additions & 0 deletions dev.skidfuscator.client.standalone/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
implementation 'org.jline:jline:3.21.0'
implementation 'com.jgoodies:jgoodies-forms:1.9.0'
implementation 'com.github.vlsi.mxgraph:jgraphx:4.2.2'
implementation 'com.formdev:flatlaf:3.5.4'
implementation 'com.formdev:flatlaf-intellij-themes:3.5.4'

implementation project(':obfuscator')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.skidfuscator.obfuscator;

import com.formdev.flatlaf.intellijthemes.FlatDarkPurpleIJTheme;
import dev.skidfuscator.obfuscator.command.HelpCommand;
import dev.skidfuscator.obfuscator.command.MappingsCommand;
import dev.skidfuscator.obfuscator.command.ObfuscateCommand;
Expand All @@ -25,7 +26,7 @@ public static void main(String[] args) {
if (args.length == 0) {
SwingUtilities.invokeLater(() -> {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
FlatDarkPurpleIJTheme.setup();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// MainFrame.java
package dev.skidfuscator.obfuscator.gui;

import com.formdev.flatlaf.ui.FlatTabbedPaneUI;
import dev.skidfuscator.obfuscator.Skidfuscator;
import dev.skidfuscator.obfuscator.SkidfuscatorSession;
import lombok.Getter;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.InputStream;

@Getter
public class MainFrame extends JFrame {
Expand All @@ -17,29 +21,81 @@ public class MainFrame extends JFrame {
private TransformerPanel transformerPanel;
private ConsolePanel consolePanel;
private JButton startButton;
private JPanel headerPanel;

public MainFrame() {
setTitle("Skidfuscator Obfuscator");
setTitle("Skidfuscator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setPreferredSize(new Dimension(800, 600));
setPreferredSize(new Dimension(900, 700));

// Create main layout
setLayout(new BorderLayout(10, 10));
// Create main layout with increased padding
setLayout(new BorderLayout(15, 5));

// Initialize tabbed pane
tabbedPane = new JTabbedPane();
// Add header with logo

JPanel tabbedPanel = new JPanel(new BorderLayout());
tabbedPane = new JTabbedPane(JTabbedPane.LEFT) {
@Override
public void updateUI() {
super.updateUI();
setUI(new FlatTabbedPaneUI() {
@Override
protected Insets getTabAreaInsets(int tabPlacement) {
Insets insets = super.getTabAreaInsets(tabPlacement);
return new Insets(140, insets.left, insets.bottom, insets.right);
}

@Override
protected int calculateTabAreaWidth(int tabPlacement, int horizRunCount, int maxTabWidth) {
return 150;
}

@Override
protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
// Make tabs fill the entire width of the tab area
return 150;
}

@Override
protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex) {
try {
InputStream logoStream = getClass().getResourceAsStream("/images/logo.png");
if (logoStream != null) {
Image logo = ImageIO.read(logoStream);
Image scaledLogo = logo.getScaledInstance(150, 150, Image.SCALE_SMOOTH);
g.drawImage(scaledLogo, 5, 0, null);
}
} catch (Exception e) {
e.printStackTrace();
}
super.paintTabArea(g, tabPlacement, selectedIndex);
}
});
}
};
tabbedPane.setFont(new Font("Segoe UI", Font.PLAIN, 12));
initializeTabs();
tabbedPanel.add(tabbedPane);
add(tabbedPanel, BorderLayout.CENTER);

// Initialize action panel
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// Create a more polished button panel
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 15, 10));
startButton = new JButton("Start Obfuscation");
startButton.addActionListener(e -> startObfuscation());
startButton.setFont(new Font("Segoe UI", Font.PLAIN, 12));
startButton.setBackground(new Color(70, 130, 180));
startButton.setForeground(Color.WHITE);
startButton.setFocusPainted(false);
startButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == startButton) {
startObfuscation();
}
}
});
buttonPanel.add(startButton);
add(buttonPanel, BorderLayout.SOUTH);

// Add components to frame
add(tabbedPane, BorderLayout.CENTER);

// Set keyboard mnemonics
setupKeyboardShortcuts();

Expand Down Expand Up @@ -194,4 +250,24 @@ protected void done() {
};
worker.execute();
}

private JPanel createHeaderPanel() {
JPanel header = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 10));

try {
// Load logo from resources
InputStream logoStream = getClass().getResourceAsStream("/images/logo.png");
if (logoStream != null) {
Image logo = ImageIO.read(logoStream);
Image scaledLogo = logo.getScaledInstance(120, 120, Image.SCALE_DEFAULT);
JLabel logoLabel = new JLabel(new ImageIcon(scaledLogo));
header.add(logoLabel);
}
// Add title label
} catch (Exception e) {
e.printStackTrace();
}

return header;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ protected void _importExempt() {

try(final ProgressWrapper progressBar = ProgressUtil.progressCheck(
config.getExemptionsv2().size(),
"Imported " + config.getExemptions().size() + " exclusions v2"
"Imported " + config.getExemptionsv2().size() + " exclusions v2"
)) {
for (String s : config.getExemptionsv2()) {
exemptAnalysis.add(ExclusionParser.parsePatternExclusion(s));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@Builder
public class Exclusion {
private final ExclusionMap testers;
private final boolean include;

/**
* Test if a class is to be excluded
Expand All @@ -25,8 +24,7 @@ public class Exclusion {
public boolean test(final ClassNode classNode) {
assert testers.containsKey(ExclusionType.CLASS) : "Trying to test with null class tester";

boolean result = testers.poll(ExclusionType.CLASS).test(classNode);
return include ? !result : result;
return testers.poll(ExclusionType.CLASS).test(classNode);
}

/**
Expand All @@ -36,12 +34,11 @@ public boolean test(final ClassNode classNode) {
* @return the boolean
*/
public boolean test(final MethodNode methodNode) {
if (test(methodNode.getOwnerClass()) != include)
if (test(methodNode.getOwnerClass()))
return true;

assert testers.containsKey(ExclusionType.METHOD) : "Trying to test with null method tester";
boolean result = testers.poll(ExclusionType.METHOD).test(methodNode);
return include != result;
return testers.poll(ExclusionType.METHOD).test(methodNode);
}

/**
Expand All @@ -51,12 +48,11 @@ public boolean test(final MethodNode methodNode) {
* @return the boolean
*/
public boolean test(final FieldNode fieldNode) {
if (test(fieldNode.getOwnerClass()) != include)
if (test(fieldNode.getOwnerClass()))
return true;

assert testers.containsKey(ExclusionType.FIELD) : "Trying to test with null field tester";
boolean result = testers.poll(ExclusionType.FIELD).test(fieldNode);
return include != result;
return testers.poll(ExclusionType.FIELD).test(fieldNode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,6 @@ public String toString() {
});
}

return new Exclusion(map, false);
return new Exclusion(map);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static class ParsedClass {
private final String extendsClass; // extended class
private final Set<String> interfaces; // implemented interfaces
private final List<ParsedMember> members; // class members
private final boolean isInclude; // whether this class is an inclusion
private final boolean include; // whether this class is an inclusion
}

/**
Expand Down Expand Up @@ -102,8 +102,9 @@ private ParsedClass parseClass(String input) {
}

// Check for inclusion prefix
boolean isInclusion = header.startsWith("!");
if (isInclusion) {
boolean include = header.startsWith("!");
if (include) {
System.out.println("include: " + include);
header = header.substring(1);
}

Expand Down Expand Up @@ -181,7 +182,7 @@ private ParsedClass parseClass(String input) {
}
}

return new ParsedClass(classType, modifiers, className, extendsClass, interfaces, members, isInclusion);
return new ParsedClass(classType, modifiers, className, extendsClass, interfaces, members, include);
}

private static class MemberParserState {
Expand Down Expand Up @@ -653,7 +654,6 @@ public boolean test(ClassNode var) {
.matcher(var.getName())
.find();


if (match) {
initialNameMatch = match != member.isInclusion();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void handle(final InitSkidTransformEvent event) {
*
* @param event Method initializer event
*/
@Listen(EventPriority.HIGHEST)
@Listen(EventPriority.LOWEST)
void handle(final InitMethodTransformEvent event) {
final SkidMethodNode methodNode = event.getMethodNode();
final BlockOpaquePredicate flowPredicate = methodNode.getFlowPredicate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void handle(final InitGroupTransformEvent event) {
* If the skid group is an entry point (it has no direct invocation)
* or in the future when we support reflection calls
*/
if (entryPoint) {
if (entryPoint || skidGroup.isStatical()) {
stackHeight = OpcodeUtil.getArgumentsSizes(skidGroup.getDesc());

if (skidGroup.isStatical())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.skidfuscator.obfuscator.util;

import dev.skidfuscator.obfuscator.util.progress.ProgressWrapper;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
Expand Down Expand Up @@ -60,7 +61,7 @@ public static Path getJdkHome() throws IOException {

Path jdkPath = CACHE_DIR.resolve(cacheName);
if (Files.exists(jdkPath)) {
System.out.println("JDK 17 already downloaded to " + jdkPath);
//System.out.println("JDK 17 already downloaded to " + jdkPath);
switch (OS) {
case "mac os x":
case "mac":
Expand All @@ -75,7 +76,8 @@ public static Path getJdkHome() throws IOException {
System.out.println("Downloading JDK 17...");

if (JDK_URL.endsWith(".zip")) {
try (ZipInputStream zis = new ZipInputStream(new URL(JDK_URL).openStream())) {
try (ProgressWrapper wrapper = ProgressUtil.progress(1, "Downloaded JDK 17");
ZipInputStream zis = new ZipInputStream(new URL(JDK_URL).openStream())) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
Path destPath = CACHE_DIR.resolve(entry.getName());
Expand All @@ -86,12 +88,15 @@ public static Path getJdkHome() throws IOException {
Files.copy(zis, destPath);
}
}
wrapper.tick();
wrapper.succeed();
} catch (IOException e) {
Files.deleteIfExists(jdkPath);
throw e;
}
} else {
try (TarArchiveInputStream tis = new TarArchiveInputStream(
try (ProgressWrapper wrapper = ProgressUtil.progress(1, "Downloaded JDK 17");
TarArchiveInputStream tis = new TarArchiveInputStream(
new GzipCompressorInputStream(
new URL(JDK_URL).openStream()
))) {
Expand All @@ -105,14 +110,14 @@ public static Path getJdkHome() throws IOException {
Files.copy(tis, destPath);
}
}
wrapper.tick();
wrapper.succeed();
} catch (IOException e) {
Files.deleteIfExists(jdkPath);
throw e;
}
}

System.out.println("JDK 17 downloaded to " + jdkPath);

switch (OS) {
case "mac os x":
case "mac":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public void test2() throws Exception {
.input(input)
.output(output)
.runtime(runtime)
.config(new File(TestSkidfuscator.class.getResource("/config/runtime.hocon").getFile()))
.config(new File(TestSkidfuscator.class.getResource("/config/new.hocon").getFile()))
.jmod(MiscUtil.getJavaVersion() > 8)
.phantom(true)
.analytics(false)
.debug(true)
.build();

final Skidfuscator skidfuscator = new Skidfuscator(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,32 @@ void testComplexInheritance() {
assertTrue(classTester.test(mockClassNode));
}

@Test
@DisplayName("Test class exclusion, ross#1")
void testEvaluatorNestedClass() {
String input = """
@class dev.sim0n.evaluator.* {
!@class util.*
!@class Main
}
""";

ClassNode dev_sim0n_evaluator_Main = mock(ClassNode.class);
when(dev_sim0n_evaluator_Main.getName()).thenReturn("dev/sim0n/evaluator/Main");

ClassNode dev_sim0n_evaluator_util_Util = mock(ClassNode.class);
when(dev_sim0n_evaluator_util_Util.getName()).thenReturn("dev/sim0n/evaluator/util/Util");

ClassNode dev_sim0n_evaluator_operation_Operation = mock(ClassNode.class);
when(dev_sim0n_evaluator_operation_Operation.getName()).thenReturn("dev/sim0n/evaluator/operation/Operation");

Exclusion exclusion = ExclusionParser.parsePatternExclusion(input);

assertFalse(exclusion.test(dev_sim0n_evaluator_Main));
assertFalse(exclusion.test(dev_sim0n_evaluator_util_Util));
assertTrue(exclusion.test(dev_sim0n_evaluator_operation_Operation));
}

@Test
@DisplayName("Test method parameter matching")
void testMethodParameters() {
Expand Down
Loading

0 comments on commit 3b93ea6

Please sign in to comment.