Skip to content

Commit

Permalink
rename classpath correctly
Browse files Browse the repository at this point in the history
EpicPlayerA10 committed Sep 16, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 269f914 commit 2e4ee86
Showing 10 changed files with 52 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
import org.objectweb.asm.tree.*;
import uwu.narumi.deobfuscator.api.context.Context;
import uwu.narumi.deobfuscator.api.helper.ClassHelper;
import uwu.narumi.deobfuscator.api.classpath.ClassPathClassWriter;
import uwu.narumi.deobfuscator.api.classpath.ClasspathClassWriter;

public class ClassWrapper implements Cloneable {

@@ -131,7 +131,7 @@ public String canonicalName() {
*/
public byte[] compileToBytes(Context context) {
try {
ClassWriter classWriter = new ClassPathClassWriter(this.classWriterFlags, context.getClassPath());
ClassWriter classWriter = new ClasspathClassWriter(this.classWriterFlags, context.getClasspath());
this.classNode.accept(classWriter);

return classWriter.toByteArray();

This file was deleted.

Original file line number Diff line number Diff line change
@@ -16,16 +16,16 @@
/**
* All sources for deobfuscated jar
*/
public class ClassPath {
public class Classpath {

private static final Logger LOGGER = LogManager.getLogger(ClassPath.class);
private static final Logger LOGGER = LogManager.getLogger(Classpath.class);

private final Map<String, byte[]> files = new ConcurrentHashMap<>();
private final Map<String, byte[]> classes = new ConcurrentHashMap<>();

private final int classWriterFlags;

public ClassPath(int classWriterFlags) {
public Classpath(int classWriterFlags) {
this.classWriterFlags = classWriterFlags;
}

Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@
/**
* A {@link ClassLoader} that holds all classpath of the current deobfuscation context
*/
public class ClassPathClassLoader extends ClassLoader {
private final ClassPath classPath;
public class ClasspathClassLoader extends ClassLoader {
private final Classpath classpath;

public ClassPathClassLoader(ClassPath classPath) {
this.classPath = classPath;
public ClasspathClassLoader(Classpath classpath) {
this.classpath = classpath;
}

@Override
@@ -16,9 +16,9 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {

// Find class in classPath
byte[] classBytes = null;
if (this.classPath.getClasses().containsKey(internalName)) {
if (this.classpath.getClasses().containsKey(internalName)) {
// Find in normal classes
classBytes = this.classPath.getClasses().get(internalName);
classBytes = this.classpath.getClasses().get(internalName);
}

if (classBytes != null) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uwu.narumi.deobfuscator.api.classpath;

import org.objectweb.asm.ClassWriter;

public class ClasspathClassWriter extends ClassWriter {

private final ClasspathClassLoader loader;

public ClasspathClassWriter(int flags, Classpath classpath) {
super(flags);
this.loader = new ClasspathClassLoader(classpath);
}

@Override
protected ClassLoader getClassLoader() {
return loader;
}
}
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
import org.apache.logging.log4j.Logger;
import uwu.narumi.deobfuscator.api.asm.ClassWrapper;
import uwu.narumi.deobfuscator.api.execution.SandBox;
import uwu.narumi.deobfuscator.api.classpath.ClassPath;
import uwu.narumi.deobfuscator.api.classpath.Classpath;

public class Context {

@@ -20,13 +20,13 @@ public class Context {
private final Map<String, byte[]> files = new ConcurrentHashMap<>();

private final DeobfuscatorOptions options;
private final ClassPath classPath;
private final Classpath classpath;

private SandBox globalSandBox = null;

public Context(DeobfuscatorOptions options, ClassPath classPath) {
public Context(DeobfuscatorOptions options, Classpath classpath) {
this.options = options;
this.classPath = classPath;
this.classpath = classpath;
}

/**
@@ -44,8 +44,8 @@ public DeobfuscatorOptions getOptions() {
return options;
}

public ClassPath getClassPath() {
return classPath;
public Classpath getClasspath() {
return classpath;
}

public Collection<ClassWrapper> classes() {
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package uwu.narumi.deobfuscator.api.execution;

import dev.xdark.ssvm.classloading.SupplyingClassLoaderInstaller;
import uwu.narumi.deobfuscator.api.classpath.ClassPath;
import uwu.narumi.deobfuscator.api.classpath.Classpath;

public class ClassPathDataSupplier implements SupplyingClassLoaderInstaller.DataSupplier {
public class ClasspathDataSupplier implements SupplyingClassLoaderInstaller.DataSupplier {

private final ClassPath classPath;
private final Classpath classPath;

public ClassPathDataSupplier(ClassPath classPath) {
this.classPath = classPath;
public ClasspathDataSupplier(Classpath classpath) {
this.classPath = classpath;
}

@Override
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ public SandBox(Context context, VirtualMachine vm) {
this.vm.bootstrap();
this.memoryManager = vm.getMemoryManager();
// Install all classes from deobfuscator context
this.helper = SupplyingClassLoaderInstaller.install(vm, new ClassPathDataSupplier(context.getClassPath()));
this.helper = SupplyingClassLoaderInstaller.install(vm, new ClasspathDataSupplier(context.getClasspath()));
this.invocationUtil = InvocationUtil.create(vm);
patchVm();
} catch (Exception ex) {
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
import uwu.narumi.deobfuscator.api.context.DeobfuscatorOptions;
import uwu.narumi.deobfuscator.api.helper.ClassHelper;
import uwu.narumi.deobfuscator.api.helper.FileHelper;
import uwu.narumi.deobfuscator.api.classpath.ClassPath;
import uwu.narumi.deobfuscator.api.classpath.Classpath;
import uwu.narumi.deobfuscator.api.transformer.Transformer;

public class Deobfuscator {
@@ -45,26 +45,26 @@ private Deobfuscator(DeobfuscatorOptions options) {
LOGGER.warn("Output file already exist, data will be overwritten");
}

ClassPath classPath = this.buildClassPath();
Classpath classpath = this.buildClasspath();

this.context = new Context(options, classPath);
this.context = new Context(options, classpath);
}

private ClassPath buildClassPath() {
ClassPath classPath = new ClassPath(this.options.classWriterFlags());
private Classpath buildClasspath() {
Classpath classpath = new Classpath(this.options.classWriterFlags());

// Add libraries
options.libraries().forEach(classPath::addJar);
options.libraries().forEach(classpath::addJar);
// Add input jar as a library
if (options.inputJar() != null) {
classPath.addJar(options.inputJar());
classpath.addJar(options.inputJar());
}
// Add raw classes as a library
if (!options.classes().isEmpty()) {
options.classes().forEach(classPath::addExternalClass);
options.classes().forEach(classpath::addExternalClass);
}

return classPath;
return classpath;
}

public void start() {
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@ public class Main {
// Usage

public static void main(String[] args) {
// decrypterA must be decrypted first for decrypterB to be decrypted correctly. So there is specific decryption order:
// decrypterA -> decrypterB
ILongDecrypter decrypterA = SimpleLongDecrypter.buildNumberDecryptor(273921918217628048L, -8431841081763909460L, MethodHandles.lookup().lookupClass());
System.out.println(decrypterA);
long a = decrypterA.decrypt(36730249601911L);

0 comments on commit 2e4ee86

Please sign in to comment.