Skip to content

Commit

Permalink
Publish some transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisTestUser committed May 11, 2020
1 parent 47d3327 commit aaff183
Show file tree
Hide file tree
Showing 29 changed files with 1,938 additions and 174 deletions.
39 changes: 33 additions & 6 deletions src/main/java/com/javadeobfuscator/deobfuscator/Deobfuscator.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public Deobfuscator(Configuration configuration) {
* Must enable for paramorphism obfuscated files.
*/
private static final boolean PARAMORPHISM = false;

public List<String> junkFiles = new ArrayList<>();

/**
* Must enable for paramorphism v2 obfuscated files.
*/
private static final boolean PARAMORPHISM_V2 = false;

public ConstantPool getConstantPool(ClassNode classNode) {
return this.constantPools.get(classNode);
Expand Down Expand Up @@ -168,7 +175,21 @@ private boolean isClassIgnored(ClassNode classNode) {
}

private void loadInput() throws IOException {
if(PARAMORPHISM)
if(PARAMORPHISM_V2)
{
//Load folder "classes"
try(ZipFile zipIn = new ZipFile(configuration.getInput())) {
Enumeration<? extends ZipEntry> e = zipIn.entries();
while(e.hasMoreElements()) {
ZipEntry next = e.nextElement();
if(next.isDirectory() && next.getName().endsWith(".class/")) {
byte[] data = IOUtils.toByteArray(zipIn.getInputStream(next));
loadInput(next.getName().substring(0, next.getName().length() - 1), data);
}else if(!next.isDirectory() && next.getName().contains(".class/"))
junkFiles.add(next.getName());
}
}
}else if(PARAMORPHISM)
{
Map<String, String> classNameToName = new HashMap<>();
Map<String, byte[]> entries = new HashMap<>();
Expand Down Expand Up @@ -255,13 +276,19 @@ public void loadInput(String name, byte[] data) {
classpath.put(node.name, node);
}
} catch (IllegalArgumentException x) {
logger.error("Could not parse {} (is it a class file?)", name, x);
if(PARAMORPHISM_V2)
invaildClasses.put(name, data);
else
logger.error("Could not parse {} (is it a class file?)", name, x);
} catch (ArrayIndexOutOfBoundsException x) {
logger.error("Could not parse {} (is it a class file?)", name, x);
if(PARAMORPHISM_V2)
invaildClasses.put(name, data);
else
logger.error("Could not parse {} (is it a class file?)", name, x);
}
}

if (passthrough) {
if (passthrough && !junkFiles.contains(name)) {
inputPassthrough.put(name, data);
}
}
Expand Down Expand Up @@ -316,11 +343,11 @@ public void start() throws Throwable {
logger.info("\t{}", message);
logger.info("Recommend transformers:");

Collection<Class<? extends Transformer>> recommended = rule.getRecommendTransformers();
Collection<Class<? extends Transformer<?>>> recommended = rule.getRecommendTransformers();
if (recommended == null) {
logger.info("\tNone");
} else {
for (Class<? extends Transformer> transformer : recommended) {
for (Class<? extends Transformer<?>> transformer : recommended) {
logger.info("\t{}", transformer.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.javadeobfuscator.deobfuscator.executor.defined.types;

public class JavaMethodHandle {
public class JavaMethodHandle extends JavaHandle {
public final String clazz;
public final String name;
public final String desc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@

import com.google.common.primitives.Primitives;
import com.javadeobfuscator.deobfuscator.executor.MethodExecutor;
import com.javadeobfuscator.deobfuscator.executor.defined.types.JavaClass;
import com.javadeobfuscator.deobfuscator.executor.defined.types.JavaConstantPool;
import com.javadeobfuscator.deobfuscator.executor.defined.types.JavaConstructor;
import com.javadeobfuscator.deobfuscator.executor.defined.types.JavaField;
import com.javadeobfuscator.deobfuscator.executor.defined.types.JavaMethod;
import com.javadeobfuscator.deobfuscator.executor.defined.types.JavaMethodHandle;
import com.javadeobfuscator.deobfuscator.executor.defined.types.JavaThread;
import com.javadeobfuscator.deobfuscator.executor.defined.types.*;
import com.javadeobfuscator.deobfuscator.executor.exceptions.ExecutionException;

public abstract class JavaValue {
public boolean booleanValue() {
throw new ExecutionException(new UnsupportedOperationException());

public boolean booleanValue() {
throw new ExecutionException(new UnsupportedOperationException());
}

public int intValue() {
Expand All @@ -56,6 +50,9 @@ public Object value() {
}

public <T> T as(Class<T> clazz) {
//TODO: Fix this
if(value() instanceof JavaValue)
return ((JavaValue)value()).as(clazz);
if (Primitives.unwrap(clazz) != clazz) {
throw new ExecutionException("Cannot call as(Class<T> clazz) with a primitive class");
}
Expand Down Expand Up @@ -88,7 +85,7 @@ else if(cst.getClass().isArray())
return new JavaObject(cst, "java/lang/Object");
else if(cst instanceof JavaThread)
return new JavaObject(cst, "java/lang/Thread");
else if(cst instanceof JavaMethodHandle)
else if(cst instanceof JavaHandle)
return new JavaObject(cst, "java/lang/invoke/MethodHandle");
else if(cst instanceof JavaMethod)
return new JavaObject(cst, "java/lang/reflect/Method");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public interface Rule extends Opcodes {

String test(Deobfuscator deobfuscator);

Collection<Class<? extends Transformer>> getRecommendTransformers();
Collection<Class<? extends Transformer<?>>> getRecommendTransformers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(EncryptionTransformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(EncryptionTransformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singleton(StringEncryptionTransformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(IllegalSignatureRemover.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(SourceFileClassNormalizer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(Invokedynamic1Transformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(Invokedynamic2Transformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(StringEncryptionTransformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singleton(StringEncryptionTransformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(StringEncryptionTransformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(EnhancedStringEncryptionTransformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(ReflectionObfuscationTransformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return Collections.singletonList(SimpleStringEncryptionTransformer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public String test(Deobfuscator deobfuscator) {
}

@Override
public Collection<Class<? extends Transformer>> getRecommendTransformers() {
public Collection<Class<? extends Transformer<?>>> getRecommendTransformers() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.javadeobfuscator.deobfuscator.transformers.dasho;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.TryCatchBlockNode;

import com.javadeobfuscator.deobfuscator.config.TransformerConfig;
import com.javadeobfuscator.deobfuscator.transformers.Transformer;
import com.javadeobfuscator.deobfuscator.utils.Utils;

public class FakeExceptionTransformer extends Transformer<TransformerConfig>
{
@Override
public boolean transform() throws Throwable {
System.out.println("[DashO] [FakeExceptionTransformer] Starting");
AtomicInteger counter = new AtomicInteger();
Set<String> fakeExceptionClass = new HashSet<>();

classNodes().forEach(classNode -> {
classNode.methods.stream().filter(Utils::notAbstractOrNative).forEach(methodNode -> {
List<TryCatchBlockNode> remove = new ArrayList<>();
for(TryCatchBlockNode tcbn : methodNode.tryCatchBlocks)
{
String handler = tcbn.type;
if(handler != null && classes.containsKey(handler))
{
ClassNode handlerClass = classes.get(handler);
if(handlerClass.methods.size() == 0 && handlerClass.superName.equals("java/lang/RuntimeException"))
{
remove.add(tcbn);
fakeExceptionClass.add(handler);
counter.incrementAndGet();
}
}
}
methodNode.tryCatchBlocks.removeIf(remove::contains);
});
});

fakeExceptionClass.forEach(str -> {
classes.remove(str);
classpath.remove(str);
});

System.out.println("[DashO] [FakeExceptionTransformer] Removed " + counter.get() + " fake try-catch blocks");
System.out.println("[DashO] [FakeExceptionTransformer] Removed " + fakeExceptionClass.size() + " fake exception classes");
System.out.println("[DashO] [FakeExceptionTransformer] Done");
return counter.get() > 0;
}
}
Loading

0 comments on commit aaff183

Please sign in to comment.