Skip to content

Commit

Permalink
July Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisTestUser committed Jul 8, 2020
1 parent 6716e1d commit efa6d95
Show file tree
Hide file tree
Showing 18 changed files with 4,405 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,18 @@ private static <T> T execute(ClassNode classNode, MethodNode method, AbstractIns
Type type = Type.getType(cast.desc);
Class<?> clazz = PrimitiveUtils.getPrimitiveByName(type.getClassName());
Object provided = context.provider.getField(cast.owner, cast.name, cast.desc, null, context);
if(provided == null && type.getSort() != Type.OBJECT && type.getSort() != Type.ARRAY)
{
ClassNode fieldClass = null;
for(ClassNode cn : context.dictionary.values())
if(cn.name.equals(cast.owner))
{
fieldClass = cn;
break;
}
provided = fieldClass.fields.stream().filter(f -> f.name.equals(cast.name) && f.desc.equals(cast.desc)).findFirst().orElse(null).value;
context.provider.setField(cast.owner, cast.name, cast.desc, null, provided, context);
}

switch (type.getSort()) {
case Type.BOOLEAN:
Expand Down Expand Up @@ -1075,6 +1087,19 @@ else if(obj instanceof JavaObject)
Type type = Type.getType(cast.desc);
Class<?> clazz = PrimitiveUtils.getPrimitiveByName(type.getClassName());
Object provided = context.provider.getField(cast.owner, cast.name, cast.desc, obj, context);
if(provided == null && type.getSort() != Type.OBJECT && type.getSort() != Type.ARRAY)
{
ClassNode fieldClass = null;
for(ClassNode cn : context.dictionary.values())
if(cn.name.equals(cast.owner))
{
fieldClass = cn;
break;
}
provided = fieldClass.fields.stream().filter(f -> f.name.equals(cast.name) && f.desc.equals(cast.desc)).findFirst().orElse(null).value;
context.provider.setField(cast.owner, cast.name, cast.desc, obj, provided, context);
}

switch (type.getSort()) {
case Type.BOOLEAN:
stack.add(0, new JavaBoolean((Boolean) provided));
Expand Down Expand Up @@ -1216,10 +1241,13 @@ else if(obj instanceof JavaObject)
break;
}
} else {
throw new NoSuchMethodHandlerException("Could not find invoker for " + args.get(args.size() - 1).type() + " " + cast.name + cast.desc);
throw new NoSuchMethodHandlerException("Could not find invoker for " + args.get(args.size() - 1).type() + " " + cast.name + cast.desc).setThrownFromInvoke(true);
}
break;
} catch (NoSuchMethodHandlerException | IllegalArgumentException t) {
if(t instanceof NoSuchMethodHandlerException
&& !((NoSuchMethodHandlerException)t).isThrownFromInvoke())
throw t;
ClassNode ownerClass = context.dictionary.get(owner);
if (ownerClass != null) {
if (ownerClass.superName != null) {
Expand Down Expand Up @@ -1311,10 +1339,13 @@ else if(obj instanceof JavaObject)
break;
}
} else {
throw new NoSuchMethodHandlerException("Could not find invoker for " + cast.owner + " " + cast.name + cast.desc);
throw new NoSuchMethodHandlerException("Could not find invoker for " + cast.owner + " " + cast.name + cast.desc).setThrownFromInvoke(true);
}
break;
} catch (NoSuchMethodHandlerException | IllegalArgumentException t) {
if(t instanceof NoSuchMethodHandlerException
&& !((NoSuchMethodHandlerException)t).isThrownFromInvoke())
throw t;
ClassNode ownerClass = context.dictionary.get(owner);
if (ownerClass != null) {
if (ownerClass.superName != null) {
Expand Down Expand Up @@ -1404,7 +1435,7 @@ else if(obj instanceof JavaObject)
break;
}
} else {
throw new NoSuchMethodHandlerException("Could not find invoker for " + cast.owner + " " + cast.name + cast.desc);
throw new NoSuchMethodHandlerException("Could not find invoker for " + cast.owner + " " + cast.name + cast.desc).setThrownFromInvoke(true);
}
break;
}
Expand Down Expand Up @@ -1534,7 +1565,7 @@ else if(obj instanceof JavaObject)
break;
}
}else {
throw new NoSuchMethodHandlerException("Could not find invoker for " + args.get(args.size() - 1).type() + " " + cast.name + cast.desc);
throw new NoSuchMethodHandlerException("Could not find invoker for " + args.get(args.size() - 1).type() + " " + cast.name + cast.desc).setThrownFromInvoke(true);
}
break;
}
Expand Down Expand Up @@ -1796,6 +1827,8 @@ else if(argumentTypes[i + 3].getSort() == Type.DOUBLE)
e.clazz = classNode.name;
e.method = method.name + method.desc;
}
if(e instanceof NoSuchMethodHandlerException)
((NoSuchMethodHandlerException)e).setThrownFromInvoke(false);
throw e;
} catch (Throwable t) {
if (DEBUG_PRINT_EXCEPTIONS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.security.CodeSource;
import java.security.Key;
Expand Down Expand Up @@ -109,6 +110,10 @@ public class JVMMethodProvider extends MethodProvider {
put("java/nio/charset/Charset", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("availableCharsets()Ljava/util/SortedMap;", (targetObject, args, context) -> Charset.availableCharsets());
}});
put("java/nio/ByteBuffer", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("wrap([B)Ljava/nio/ByteBuffer;", (targetObject, args, context) -> ByteBuffer.wrap(args.get(0).as(byte[].class)));
put("getDouble()D", (targetObject, args, context) -> targetObject.as(ByteBuffer.class).getDouble());
}});
put("java/util/SortedMap", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("keySet()Ljava/util/Set;", (targetObject, args, context) -> targetObject.as(SortedMap.class).keySet());
}});
Expand Down Expand Up @@ -241,6 +246,11 @@ public class JVMMethodProvider extends MethodProvider {
targetObject.initialize(new String(args.get(0).as(byte[].class), args.get(1).intValue()));
return null;
});
put("<init>([BII)V", (targetObject, args, context) -> {
expect(targetObject, "java/lang/String");
targetObject.initialize(new String(args.get(0).as(byte[].class), args.get(1).intValue(), args.get(2).intValue()));
return null;
});
put("<init>([BLjava/lang/String;)V", (targetObject, args, context) -> {
expect(targetObject, "java/lang/String");
targetObject.initialize(new String(args.get(0).as(byte[].class), args.get(1).as(String.class)));
Expand Down Expand Up @@ -636,6 +646,14 @@ public class JVMMethodProvider extends MethodProvider {
put("getMethodName()Ljava/lang/String;", (targetObject, args, context) -> targetObject.as(StackTraceElement.class).getMethodName());
put("getFileName()Ljava/lang/String;", (targetObject, args, context) -> targetObject.as(StackTraceElement.class).getFileName());
}});
put("java/lang/Float", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("intBitsToFloat(I)F", (targetObject, args, context) -> Float.intBitsToFloat(args.get(0).intValue()));
put("valueOf(F)Ljava/lang/Float;", (targetObject, args, context) -> Float.valueOf(args.get(0).floatValue()));
}});
put("java/lang/Double", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("longBitsToDouble(J)D", (targetObject, args, context) -> Double.longBitsToDouble(args.get(0).longValue()));
put("valueOf(D)Ljava/lang/Double;", (targetObject, args, context) -> Double.valueOf(args.get(0).doubleValue()));
}});
put("java/lang/Long", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("<init>(J)V", (targetObject, args, context) -> {
expect(targetObject, "java/lang/Long");
Expand Down Expand Up @@ -672,6 +690,14 @@ public class JVMMethodProvider extends MethodProvider {
put("java/util/regex/Pattern", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("compile(Ljava/lang/String;)Ljava/util/regex/Pattern;", (targetObject, args, context) -> Pattern.compile(args.get(0).as(String.class)));
}});
put("java/util/Random", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("<init>(J)V", (targetObject, args, context) -> {
expect(targetObject, "java/util/Random");
targetObject.initialize(new Random(args.get(0).longValue()));
return null;
});
put("nextDouble()D", (targetObject, args, context) -> targetObject.as(Random.class).nextDouble());
}});
put("java/lang/BootstrapMethodError", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("<init>()V", (targetObject, args, context) -> {
expect(targetObject, "java/lang/BootstrapMethodError");
Expand All @@ -697,7 +723,7 @@ public class JVMMethodProvider extends MethodProvider {
targetObject.initialize(new HashMap<>(args.get(0).intValue()));
return null;
});
put("put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", (targetObject, args, context) -> targetObject.as(HashMap.class).put(args.get(0), args.get(1)));
put("put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", (targetObject, args, context) -> targetObject.as(HashMap.class).put(args.get(0).value(), args.get(1).value()));
put("get(Ljava/lang/Object;)Ljava/lang/Object;", (targetObject, args, context) -> targetObject.as(HashMap.class).get(args.get(0).value()));
put("containsKey(Ljava/lang/Object;)Z", (targetObject, args, context) -> targetObject.as(HashMap.class).containsKey(args.get(0).value()));
put("isEmpty()Z", (targetObject, args, context) -> targetObject.as(HashMap.class).isEmpty());
Expand Down Expand Up @@ -746,6 +772,7 @@ public class JVMMethodProvider extends MethodProvider {
}});
put("java/lang/Math", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("abs(J)J", (targetObject, args, context) -> Math.abs(args.get(0).longValue()));
put("round(D)J", (targetObject, args, context) -> Math.round(args.get(0).doubleValue()));
}});
put("java/math/BigInteger", new HashMap<String, Function3<JavaValue, List<JavaValue>, Context, Object>>() {{
put("<init>(Ljava/lang/String;I)V", (targetObject, args, context) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@
package com.javadeobfuscator.deobfuscator.executor.exceptions;

public class NoSuchMethodHandlerException extends NoSuchHandlerException {
private boolean isThrownFromInvoke;

public NoSuchMethodHandlerException(String msg) {
super(msg);
}

public NoSuchMethodHandlerException setThrownFromInvoke(boolean isThrownFromExe) {
this.isThrownFromInvoke = isThrownFromExe;
return this;
}

public boolean isThrownFromInvoke() {
return isThrownFromInvoke;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
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 Down
Loading

0 comments on commit efa6d95

Please sign in to comment.