Skip to content

Commit

Permalink
Merge pull request pxb1988#7 from nick-botticelli/main
Browse files Browse the repository at this point in the history
Fix inheritance issue in InvokePolymorphicExpr causing ClassCastException
  • Loading branch information
ThexXTURBOXx authored Sep 6, 2021
2 parents f1da047 + 9c0db1d commit 43238bf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
3 changes: 3 additions & 0 deletions dex-ir/src/main/java/com/googlecode/dex2jar/ir/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public static void appendString(final StringBuffer buf, final String s) {
}

public static String toShortClassName(String desc) {
if (desc == null || desc.isEmpty()) {
return "";
}
switch (desc.charAt(0)) {
case 'Z':
return "boolean";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.googlecode.d2j.Proto;
import com.googlecode.dex2jar.ir.LabelAndLocalMapper;

public class InvokeCustomExpr extends AbstractInvokeExpr {
public class InvokeCustomExpr extends InvokeExpr {

public String name;

Expand All @@ -30,20 +30,20 @@ public Proto getProto() {

public InvokeCustomExpr(VT type, Value[] args, String methodName, Proto proto, MethodHandle handle,
Object[] bsmArgs) {
super(type, args);
super(type, args, handle == null ? null : handle.getMethod());
this.proto = proto;
this.name = methodName;
this.handle = handle;
this.bsmArgs = bsmArgs;
}

@Override
public Value clone() {
public InvokeCustomExpr clone() {
return new InvokeCustomExpr(vt, cloneOps(), name, proto, handle, bsmArgs);
}

@Override
public Value clone(LabelAndLocalMapper mapper) {
public InvokeCustomExpr clone(LabelAndLocalMapper mapper) {
return new InvokeCustomExpr(vt, cloneOps(mapper), name, proto, handle, bsmArgs);
}

Expand Down
29 changes: 14 additions & 15 deletions dex-ir/src/main/java/com/googlecode/dex2jar/ir/expr/InvokeExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ protected void releaseMemory() {

@Override
public Proto getProto() {
return method.getProto();
return method == null ? null : method.getProto();
}

public InvokeExpr(VT type, Value[] args, String ownerType, String methodName, String[] argmentTypes,
String returnType) {
super(type, args);
this.method = new Method(ownerType, methodName, argmentTypes, returnType);
this(type, args, new Method(ownerType, methodName, argmentTypes, returnType));
}

public InvokeExpr(VT type, Value[] args, Method method) {
Expand All @@ -45,12 +44,12 @@ public InvokeExpr(VT type, Value[] args, Method method) {
}

@Override
public Value clone() {
public InvokeExpr clone() {
return new InvokeExpr(vt, cloneOps(), method);
}

@Override
public Value clone(LabelAndLocalMapper mapper) {
public InvokeExpr clone(LabelAndLocalMapper mapper) {
return new InvokeExpr(vt, cloneOps(mapper), method);
}

Expand All @@ -59,13 +58,13 @@ public String toString0() {
StringBuilder sb = new StringBuilder();

int i = 0;
if (super.vt == VT.INVOKE_NEW) {
sb.append("new ").append(Util.toShortClassName(method.getOwner()));
} else if (super.vt == VT.INVOKE_STATIC) {
sb.append(Util.toShortClassName(method.getOwner())).append('.')
.append(this.method.getName());
if (vt == VT.INVOKE_NEW) {
sb.append("new ").append(Util.toShortClassName(getOwner()));
} else if (vt == VT.INVOKE_STATIC) {
sb.append(Util.toShortClassName(getOwner())).append('.')
.append(getName());
} else {
sb.append(ops[i++]).append('.').append(this.method.getName());
sb.append(ops[i++]).append('.').append(getName());
}
sb.append('(');
boolean first = true;
Expand All @@ -82,19 +81,19 @@ public String toString0() {
}

public String getOwner() {
return method.getOwner();
return method == null ? null : method.getOwner();
}

public String getRet() {
return method.getReturnType();
return method == null ? null : method.getReturnType();
}

public String getName() {
return method.getName();
return method == null ? null : method.getName();
}

public String[] getArgs() {
return method.getParameterTypes();
return method == null ? null : method.getParameterTypes();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
import com.googlecode.dex2jar.ir.LabelAndLocalMapper;
import com.googlecode.dex2jar.ir.Util;

public class InvokePolymorphicExpr extends AbstractInvokeExpr {
public class InvokePolymorphicExpr extends InvokeExpr {

public Proto proto;

public Method method;

@Override
protected void releaseMemory() {
method = null;
proto = null;
super.releaseMemory();
}
Expand All @@ -24,18 +21,17 @@ public Proto getProto() {
}

public InvokePolymorphicExpr(VT type, Value[] args, Proto proto, Method method) {
super(type, args);
super(type, args, method);
this.proto = proto;
this.method = method;
}

@Override
public Value clone() {
public InvokePolymorphicExpr clone() {
return new InvokePolymorphicExpr(vt, cloneOps(), proto, method);
}

@Override
public Value clone(LabelAndLocalMapper mapper) {
public InvokePolymorphicExpr clone(LabelAndLocalMapper mapper) {
return new InvokePolymorphicExpr(vt, cloneOps(mapper), proto, method);
}

Expand Down

0 comments on commit 43238bf

Please sign in to comment.