Skip to content

Commit

Permalink
fix ClassCastException
Browse files Browse the repository at this point in the history
NewTransformer#findInvokeExpr attempts to cast InvokePolymorphicExpr to InvokeExpr under certain inputs, which causes a ClassCastException.

this patch is similar with

9c6cde4
9c0db1d
  • Loading branch information
pxb1988 committed Oct 30, 2021
1 parent 441d045 commit b004967
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import com.googlecode.dex2jar.ir.stmt.Stmt.E1Stmt;

/**
* Represent a void-return Invoke
* Represent a void-expr: the expr result is ignored.
* possible op type: AbstractInvokeExpr, FieldExpr, or others
*
* @see ST#VOID_INVOKE
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void replaceAST(IrMethod method) {
for (Iterator<Stmt> it = method.stmts.iterator(); it.hasNext(); ) {
Stmt p = it.next();

InvokeExpr ie = findInvokeExpr(p, null);
InvokeExpr ie = findInvokeExpr(p);

if (ie != null) {
if ("<init>".equals(ie.getName()) && "V".equals(ie.getRet())) {
Expand Down Expand Up @@ -153,7 +153,7 @@ void replace0(IrMethod method, Map<Local, TObject> init, int size) {
}
}
}
InvokeExpr ie = findInvokeExpr(obj.invokeStmt, null);
InvokeExpr ie = findInvokeExpr(obj.invokeStmt);
Value[] orgOps = ie.getOps();
Value[] nOps = Arrays.copyOfRange(orgOps, 1, orgOps.length);
InvokeExpr invokeNew = Exprs.nInvokeNew(nOps, ie.getArgs(), ie.getOwner());
Expand Down Expand Up @@ -352,13 +352,17 @@ void use(Local local) {
}
}

InvokeExpr findInvokeExpr(Stmt p, InvokeExpr ie) {
InvokeExpr findInvokeExpr(Stmt p) {
InvokeExpr ie = null;
if (p.st == ASSIGN) {
if (p.getOp2().vt == INVOKE_SPECIAL) {
ie = (InvokeExpr) p.getOp2();
}
} else if (p.st == VOID_INVOKE) {
ie = (InvokeExpr) p.getOp();
Value op = p.getOp();
if (op instanceof InvokeExpr) {
ie = (InvokeExpr) op;
}
}
return ie;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.googlecode.dex2jar.ir.ts;

import com.googlecode.dex2jar.ir.IrMethod;
import com.googlecode.dex2jar.ir.expr.AbstractInvokeExpr;
import com.googlecode.dex2jar.ir.expr.Local;
import com.googlecode.dex2jar.ir.expr.Value;
import com.googlecode.dex2jar.ir.stmt.Stmt;
Expand Down Expand Up @@ -49,20 +50,13 @@ public boolean transformReportChanged(IrMethod method) {
if (p.st == Stmt.ST.ASSIGN && p.getOp1().vt == Value.VT.LOCAL) {
Local left = (Local) p.getOp1();
if (reads[left._ls_index] == 0) {
switch (p.getOp2().vt) {
case INVOKE_INTERFACE:
case INVOKE_NEW:
case INVOKE_SPECIAL:
case INVOKE_STATIC:
case INVOKE_VIRTUAL:
Value op2 = p.getOp2();
if (op2 instanceof AbstractInvokeExpr) {
method.locals.remove(left);
Stmt nVoidInvoke = Stmts.nVoidInvoke(p.getOp2());
Stmt nVoidInvoke = Stmts.nVoidInvoke(op2);
method.stmts.replace(p, nVoidInvoke);
p = nVoidInvoke;
changed = true;
break;
default:
break;
}
}
}
Expand Down

0 comments on commit b004967

Please sign in to comment.