Skip to content

Commit b004967

Browse files
committed
fix ClassCastException
NewTransformer#findInvokeExpr attempts to cast InvokePolymorphicExpr to InvokeExpr under certain inputs, which causes a ClassCastException. this patch is similar with 9c6cde4 9c0db1d
1 parent 441d045 commit b004967

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/VoidInvokeStmt.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import com.googlecode.dex2jar.ir.stmt.Stmt.E1Stmt;
2222

2323
/**
24-
* Represent a void-return Invoke
24+
* Represent a void-expr: the expr result is ignored.
25+
* possible op type: AbstractInvokeExpr, FieldExpr, or others
2526
*
2627
* @see ST#VOID_INVOKE
2728
*

dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/NewTransformer.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void replaceAST(IrMethod method) {
9595
for (Iterator<Stmt> it = method.stmts.iterator(); it.hasNext(); ) {
9696
Stmt p = it.next();
9797

98-
InvokeExpr ie = findInvokeExpr(p, null);
98+
InvokeExpr ie = findInvokeExpr(p);
9999

100100
if (ie != null) {
101101
if ("<init>".equals(ie.getName()) && "V".equals(ie.getRet())) {
@@ -153,7 +153,7 @@ void replace0(IrMethod method, Map<Local, TObject> init, int size) {
153153
}
154154
}
155155
}
156-
InvokeExpr ie = findInvokeExpr(obj.invokeStmt, null);
156+
InvokeExpr ie = findInvokeExpr(obj.invokeStmt);
157157
Value[] orgOps = ie.getOps();
158158
Value[] nOps = Arrays.copyOfRange(orgOps, 1, orgOps.length);
159159
InvokeExpr invokeNew = Exprs.nInvokeNew(nOps, ie.getArgs(), ie.getOwner());
@@ -352,13 +352,17 @@ void use(Local local) {
352352
}
353353
}
354354

355-
InvokeExpr findInvokeExpr(Stmt p, InvokeExpr ie) {
355+
InvokeExpr findInvokeExpr(Stmt p) {
356+
InvokeExpr ie = null;
356357
if (p.st == ASSIGN) {
357358
if (p.getOp2().vt == INVOKE_SPECIAL) {
358359
ie = (InvokeExpr) p.getOp2();
359360
}
360361
} else if (p.st == VOID_INVOKE) {
361-
ie = (InvokeExpr) p.getOp();
362+
Value op = p.getOp();
363+
if (op instanceof InvokeExpr) {
364+
ie = (InvokeExpr) op;
365+
}
362366
}
363367
return ie;
364368
}

dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/VoidInvokeTransformer.java

+4-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.googlecode.dex2jar.ir.ts;
1818

1919
import com.googlecode.dex2jar.ir.IrMethod;
20+
import com.googlecode.dex2jar.ir.expr.AbstractInvokeExpr;
2021
import com.googlecode.dex2jar.ir.expr.Local;
2122
import com.googlecode.dex2jar.ir.expr.Value;
2223
import com.googlecode.dex2jar.ir.stmt.Stmt;
@@ -49,20 +50,13 @@ public boolean transformReportChanged(IrMethod method) {
4950
if (p.st == Stmt.ST.ASSIGN && p.getOp1().vt == Value.VT.LOCAL) {
5051
Local left = (Local) p.getOp1();
5152
if (reads[left._ls_index] == 0) {
52-
switch (p.getOp2().vt) {
53-
case INVOKE_INTERFACE:
54-
case INVOKE_NEW:
55-
case INVOKE_SPECIAL:
56-
case INVOKE_STATIC:
57-
case INVOKE_VIRTUAL:
53+
Value op2 = p.getOp2();
54+
if (op2 instanceof AbstractInvokeExpr) {
5855
method.locals.remove(left);
59-
Stmt nVoidInvoke = Stmts.nVoidInvoke(p.getOp2());
56+
Stmt nVoidInvoke = Stmts.nVoidInvoke(op2);
6057
method.stmts.replace(p, nVoidInvoke);
6158
p = nVoidInvoke;
6259
changed = true;
63-
break;
64-
default:
65-
break;
6660
}
6761
}
6862
}

0 commit comments

Comments
 (0)