Skip to content

Commit

Permalink
Fix issues with J2IRConverter
Browse files Browse the repository at this point in the history
Fixes #28
  • Loading branch information
ThexXTURBOXx committed Nov 1, 2022
1 parent 6f8b680 commit 09273cd
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
5 changes: 5 additions & 0 deletions dex-reader-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
description = 'Dex Reader API'

dependencies {
implementation fileTree(dir: '../libs', include: '*.jar')
// implementation group: 'org.ow2.asm', name: 'asm', version: '9.4' // Fixed MethodCodeTooLargeException
}
30 changes: 30 additions & 0 deletions dex-reader-api/src/main/java/com/googlecode/d2j/MethodHandle.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.googlecode.d2j;

import java.util.Objects;
import org.objectweb.asm.Opcodes;

public class MethodHandle {

Expand Down Expand Up @@ -84,4 +85,33 @@ public Method getMethod() {
return method;
}

public static int getTypeFromAsmOpcode(int opcode) {
switch (opcode) {
case Opcodes.H_GETFIELD:
return INSTANCE_GET;
case Opcodes.H_GETSTATIC:
return STATIC_GET;
case Opcodes.H_PUTFIELD:
return INSTANCE_PUT;
case Opcodes.H_PUTSTATIC:
return STATIC_PUT;

case Opcodes.H_INVOKEVIRTUAL:
return INVOKE_INSTANCE; // ?

case Opcodes.H_INVOKESTATIC:
return INVOKE_STATIC;

case Opcodes.H_INVOKESPECIAL:
return INVOKE_DIRECT; // ?

case Opcodes.H_NEWINVOKESPECIAL:
return INVOKE_CONSTRUCTOR;
case Opcodes.H_INVOKEINTERFACE:
return INVOKE_INTERFACE;
default:
throw new RuntimeException("Not supported yet.");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

// CHECKSTYLE:OFF

import com.googlecode.d2j.Method;
import com.googlecode.d2j.MethodHandle;
import com.googlecode.d2j.Proto;
import com.googlecode.dex2jar.ir.IrMethod;
import com.googlecode.dex2jar.ir.Trap;
import com.googlecode.dex2jar.ir.expr.Exprs;
import com.googlecode.dex2jar.ir.expr.InvokeCustomExpr;
import com.googlecode.dex2jar.ir.expr.Local;
import com.googlecode.dex2jar.ir.expr.NewMutiArrayExpr;
import com.googlecode.dex2jar.ir.stmt.AssignStmt;
import com.googlecode.dex2jar.ir.stmt.LabelStmt;
import com.googlecode.dex2jar.ir.stmt.Stmt;
Expand All @@ -31,12 +36,14 @@
import org.objectweb.asm.tree.IincInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.IntInsnNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.LookupSwitchInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.MultiANewArrayInsnNode;
import org.objectweb.asm.tree.TableSwitchInsnNode;
import org.objectweb.asm.tree.TryCatchBlockNode;
import org.objectweb.asm.tree.TypeInsnNode;
Expand Down Expand Up @@ -561,7 +568,7 @@ public JvmValue unaryOperation(AbstractInsnNode insn, JvmValue value0) throws An
case T_DOUBLE:
return b(1, Exprs.nNewArray("D", local));
case T_LONG:
return b(1, Exprs.nNewArray("D", local));
return b(1, Exprs.nNewArray("J", local));
default:
throw new AnalyzerException(insn, "Invalid array type");
}
Expand Down Expand Up @@ -802,14 +809,34 @@ public String[] toDescArray(Type[] ts) {

@Override
public JvmValue naryOperation(AbstractInsnNode insn, List<? extends JvmValue> xvalues) {

com.googlecode.dex2jar.ir.expr.Value[] values =
new com.googlecode.dex2jar.ir.expr.Value[xvalues.size()];
for (int i = 0; i < xvalues.size(); i++) {
values[i] = getLocal(xvalues.get(i));
}
if (insn.getOpcode() == MULTIANEWARRAY) {
throw new UnsupportedOperationException("Not supported yet.");
MultiANewArrayInsnNode multi = (MultiANewArrayInsnNode) insn;
NewMutiArrayExpr n = Exprs.nNewMutiArray(multi.desc.replaceAll("\\[+", ""), multi.dims, values);
return b(Type.getType(multi.desc).getSize(), n);
} else if (insn.getOpcode() == INVOKEDYNAMIC) {
InvokeDynamicInsnNode mi = (InvokeDynamicInsnNode) insn;
Handle bsm = mi.bsm;
Type[] a = Type.getArgumentTypes(bsm.getDesc());
String[] params = new String[a.length];
for (int i = 0; i < a.length; i += 1) {
params[i] = a[i].getDescriptor();
}
Method method = new Method("L" + bsm.getOwner() + ";", bsm.getName(), params,
Type.getReturnType(bsm.getDesc()).getDescriptor());
MethodHandle mh = new MethodHandle(MethodHandle.getTypeFromAsmOpcode(bsm.getTag()), method);
Type[] t = Type.getArgumentTypes(mi.desc);
String[] paramDesc = new String[t.length];
for (int i = 0; i < t.length; i += 1) {
paramDesc[i] = t[i].getDescriptor();
}
InvokeCustomExpr d = Exprs.nInvokeCustom(values, mi.name, new Proto(paramDesc,
Type.getReturnType(mi.desc).getDescriptor()), mh, mi.bsmArgs);
return b(Type.getReturnType(mi.desc).getSize(), d);
} else {
MethodInsnNode mi = (MethodInsnNode) insn;
com.googlecode.dex2jar.ir.expr.Value v = null;
Expand All @@ -829,8 +856,6 @@ public JvmValue naryOperation(AbstractInsnNode insn, List<? extends JvmValue> xv
case INVOKEINTERFACE:
v = Exprs.nInvokeInterface(values, owner, mi.name, ps, ret);
break;
case INVOKEDYNAMIC:
throw new UnsupportedOperationException("Not supported yet.");
default:
break;
}
Expand Down

0 comments on commit 09273cd

Please sign in to comment.