Skip to content

Commit

Permalink
feat: bug fixes and library gui
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalsin committed Dec 25, 2024
1 parent 3b634cb commit 56cacc6
Show file tree
Hide file tree
Showing 10 changed files with 484 additions and 168 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Getter
public class MainFrame extends JFrame {
Expand All @@ -25,6 +29,7 @@ public class MainFrame extends JFrame {
private ConsolePanel consolePanel;
private LibrariesPanel librariesPanel;
private JButton startButton;
private JButton buyEnterpriseButton;
private JPanel headerPanel;

public MainFrame() {
Expand Down Expand Up @@ -119,11 +124,27 @@ protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex) {
}
});

buyEnterpriseButton = new JButton("Buy Enterprise");
buyEnterpriseButton.setFont(new Font("Segoe UI", Font.PLAIN, 12));
buyEnterpriseButton.setBackground(Color.DARK_GRAY);
buyEnterpriseButton.setForeground(Color.WHITE);
buyEnterpriseButton.setFocusPainted(false);
buyEnterpriseButton.setPreferredSize(new Dimension(160, 30));

buyEnterpriseButton.addActionListener(e -> {
try {
Desktop.getDesktop().browse(new URI("https://skidfuscator.dev/pricing"));
} catch (Exception ex) {
ex.printStackTrace();
}
});

int topSpace = 220;
int bottomPadding = this.getPreferredSize().height - 60*3;

JPanel buttonPanel = new JPanel(new BorderLayout());
buttonPanel.add(startButton, BorderLayout.NORTH);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(startButton);
buttonPanel.add(buyEnterpriseButton);

// Add copyright and website info
JPanel copyrightPanel = new JPanel();
Expand Down Expand Up @@ -299,14 +320,31 @@ public void startObfuscation() {
}

// Validate inputs
tabbedPane.setSelectedIndex(2);
tabbedPane.setSelectedIndex(3);

// Validate libs
// Initialize library folder
String configLibPath = configPanel.getLibraryPath();
Path libraryFolder;
if (configLibPath != null && !configLibPath.isEmpty()) {
libraryFolder = Paths.get(configLibPath);
} else {
libraryFolder = Paths.get(System.getProperty("user.home"), ".ssvm", "libs");
}

// Create library folder if it doesn't exist
try {
Files.createDirectories(libraryFolder);
} catch (IOException e) {
Skidfuscator.LOGGER.error("Failed to create library folder", e);
}

// Create session
SkidfuscatorSession session = SkidfuscatorSession.builder()
.input(new File(config.getInputPath()))
.output(new File(config.getOutputPath()))
.libs(config.getLibsPath().isEmpty()
? new File[0]
? libraryFolder.toFile().listFiles()
: new File(config.getLibsPath()).listFiles()
)
.runtime(config.getRuntimePath().isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ApplicationClassSource getLibraryClassSource(final Logger logger, final b
public ApplicationClassSource importFile(final Logger logger, final boolean fuckit, final GhostLibrary library) {
/* Create a new library class source with superior to default priority */
final ApplicationClassSource libraryClassSource = new ApplicationClassSource(
"libraries",
library.getName(),
fuckit,
library.getContents()
.getClasses()
Expand Down Expand Up @@ -140,6 +140,7 @@ public GhostLibrary createFromLibraryFile(final Logger logger, final File file)

final GhostContents ghostContents = new GhostContents();
final GhostLibrary ghostLibrary = new GhostLibrary();
ghostLibrary.setName(file.getName());
ghostLibrary.setContents(ghostContents);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public Skidfuscator(SkidfuscatorSession session) {

/* Builder */
.build();
this.config = new DefaultSkidConfig(tsConfig, "");
}

/**
Expand Down Expand Up @@ -429,7 +430,7 @@ protected void _verifyEnvironment() {
}
}

protected void _importConfig() {
public void _importConfig() {
LOGGER.post("Loading config...");

try (final ProgressWrapper progressBar = ProgressUtil.progressCheck(
Expand Down Expand Up @@ -552,7 +553,7 @@ public Set<LibraryClassSource> _importJvm() {
return sources;
}

protected void _importClasspath() {
public SkidApplicationClassSource _importClasspath() {
LOGGER.post("Importing jar...");

final String path = session.getInput().getPath();
Expand Down Expand Up @@ -673,6 +674,8 @@ protected void _importClasspath() {
1
));*/
LOGGER.log("Finished importing classpath!");

return classSource;
}

protected List<Transformer> _loadTransformer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

public class SkidApplicationClassSource extends ApplicationClassSource {
Expand Down Expand Up @@ -57,25 +54,7 @@ public void importLibrary(File file) throws IOException {
));
}

public Set<String> getMissingClassNames() {
Set<String> missingClasses = new HashSet<>();
for (String className : nodeMap.keySet()) {
ClassNode node = nodeMap.get(className);
if (node != null) {
String superName = node.getName();
if (superName != null && !contains(superName)) {
missingClasses.add(superName.replace('/', '.'));
}
Collection<String> interfaces = node.getInterfaces();
if (interfaces != null) {
for (String iface : interfaces) {
if (!contains(iface)) {
missingClasses.add(iface.replace('/', '.'));
}
}
}
}
}
return missingClasses;
public List<String> getMissingClassNames() {
return classTree.getMissingClasses();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -371,12 +372,49 @@ private void setupInvoke() {
if (!(targetClass instanceof SkidClassNode))
return;

assert targetClass.getMethods().size() == 1 : "Implicit Function must be single method!";
final SkidMethodNode methodNode = (SkidMethodNode) targetClass.getMethods().get(0);

methodNode.getGroup().setImplicitFunction(true);
SkidMethodNode methodNode = null;

// [resolution] step 1: check if current class has method
ClassNode node;

for (node = targetClass;
node instanceof SkidClassNode;
node = skidfuscator.getClassSource().findClassNode(targetClass.getSuperName())) {
if (!node.getMethods().isEmpty()) {

// [validation] cannot have more than one method in implicit function
if (node.getMethods().size() > 1) {
throw new IllegalStateException(String.format(
"""
-----------------------------------------------------
/!\\ Skidfuscator failed to verify a lambda call!
Please report this to the developer...
-----------------------------------------------------
Bound: %s
Target: %s
Target Methods: %s
-----------------------------------------------------
""",
boundFunc,
node.getDisplayName(),
node.getMethods().stream()
.map(MethodNode::toString)
.reduce("\n- ", (s, s2) -> s + "\n- " + s2)

));
}

// must be correct
methodNode = (SkidMethodNode) node.getMethods().get(0);
break;
}
}

if (methodNode != null) {
methodNode.getGroup().setImplicitFunction(true);
return;
}
//System.out.println("Found implicit function: " + methodNode.toString());
return;
}

target = new ClassMethodHash(boundFunc.getName(), boundFunc.getDesc(), boundFunc.getOwner());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ public SkiddedHash hash(int starting, BasicBlock vertex, PredicateFlowGetter cal

this.selectRandomMethod();

System.out.println("Hashed: " + hashed + " Expr: " + hashExpr);

return new SkiddedHash(hashExpr, hashed);
} catch (VMException | PanicException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected boolean matchesExpression(Expr expr) {
final boolean valid = expr instanceof InstanceofExpr;

if (valid) {
System.out.println("Checking instanceof expression: " + expr);
//System.out.println("Checking instanceof expression: " + expr);
}

return valid;
Expand All @@ -46,7 +46,7 @@ protected boolean transformExpression(Expr expr, ControlFlowGraph cfg) {
Type checkType = instanceofExpr.getCheckType();
Expr object = instanceofExpr.getExpression();

System.out.println("Checking instanceof expression: " + expr);
//System.out.println("Checking instanceof expression: " + expr);

// Skip primitive types and arrays
if (checkType.getSort() != Type.OBJECT || checkType.getDescriptor().startsWith("[")) {
Expand All @@ -69,7 +69,7 @@ protected boolean transformExpression(Expr expr, ControlFlowGraph cfg) {
"(Ljava/lang/Object;Ljava/lang/String;I)Z"
);

System.out.println("Transformed instanceof expression: " + expr + " to " + replacement);
//System.out.println("Transformed instanceof expression: " + expr + " to " + replacement);
expr.getParent().overwrite(expr, replacement);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void _importExempt() {
}

@Override
protected void _importJvm() {
public Set<LibraryClassSource> _importJvm() {
LOGGER.post("Beginning to import JVM...");
if (!cached) {
_cacheJvm(this);
Expand All @@ -72,10 +72,12 @@ protected void _importJvm() {
));
}
LOGGER.log("Finished importing JVM!");

return new HashSet<>();
}

@Override
protected void _importClasspath() {
public SkidApplicationClassSource _importClasspath() {
LOGGER.post("Beginning to import classpath...");
this.jarContents = new JarContents();

Expand Down Expand Up @@ -133,6 +135,8 @@ protected void _importClasspath() {
this
);
LOGGER.log("Finished importing classpath!");

return classSource;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public LibraryClassSource(ApplicationClassSource parent, int priority) {
this(Collections.emptySet(), parent, priority);
}

public ApplicationClassSource getParent() {
return parent;
}

/* public lookup method, polls parent first (which can
* call its children to look for the */
@Override
Expand Down

0 comments on commit 56cacc6

Please sign in to comment.