Commit 7f4da306 authored by Skylot's avatar Skylot

refactor: remove cloning library dependency

parent 424a8ffa
......@@ -7,7 +7,6 @@ dependencies {
compile 'org.ow2.asm:asm:7.1'
compile 'org.jetbrains:annotations:17.0.0'
compile 'uk.com.robust-it:cloning:1.9.12'
compile 'com.google.code.gson:gson:2.8.5'
compile 'org.smali:baksmali:2.2.7'
......
......@@ -72,6 +72,11 @@ public class ArithNode extends InsnNode {
}
@Override
public InsnNode copy() {
return copyCommonParams(new ArithNode(op, getResult(), getArg(0), getArg(1)));
}
@Override
public String toString() {
return InsnUtils.formatOffset(offset) + ": "
+ InsnUtils.insnTypeToString(insnType)
......
......@@ -25,13 +25,15 @@ public final class FillArrayNode extends InsnNode {
private ArgType elemType;
public FillArrayNode(int resReg, FillArrayDataPayloadDecodedInstruction payload) {
super(InsnType.FILL_ARRAY, 1);
ArgType elType = getElementType(payload.getElementWidthUnit());
addArg(InsnArg.reg(resReg, ArgType.array(elType)));
this(payload.getData(), payload.getSize(), getElementType(payload.getElementWidthUnit()));
addArg(InsnArg.reg(resReg, ArgType.array(elemType)));
}
this.data = payload.getData();
this.size = payload.getSize();
this.elemType = elType;
private FillArrayNode(Object data, int size, ArgType elemType) {
super(InsnType.FILL_ARRAY, 1);
this.data = data;
this.size = size;
this.elemType = elemType;
}
private static ArgType getElementType(short elementWidthUnit) {
......@@ -98,6 +100,11 @@ public final class FillArrayNode extends InsnNode {
return elemType.equals(other.elemType) && data == other.data;
}
@Override
public InsnNode copy() {
return copyCommonParams(new FillArrayNode(data, size, elemType));
}
public String dataToString() {
if (data instanceof int[]) {
return Arrays.toString((int[]) data);
......
......@@ -35,6 +35,11 @@ public class FilledNewArrayNode extends InsnNode {
}
@Override
public InsnNode copy() {
return copyCommonParams(new FilledNewArrayNode(elemType, getArgsCount()));
}
@Override
public String toString() {
return super.toString() + " elemType: " + elemType;
}
......
package jadx.core.dex.instructions;
import jadx.core.dex.nodes.InsnNode;
import jadx.core.utils.InsnUtils;
public class GotoNode extends TargetInsnNode {
......@@ -20,6 +21,11 @@ public class GotoNode extends TargetInsnNode {
}
@Override
public InsnNode copy() {
return copyCommonParams(new GotoNode(target));
}
@Override
public String toString() {
return super.toString() + "-> " + InsnUtils.formatOffset(target);
}
......
......@@ -34,12 +34,16 @@ public class IfNode extends GotoNode {
}
public IfNode(IfOp op, int targetOffset, InsnArg arg1, InsnArg arg2) {
super(InsnType.IF, targetOffset, 2);
this.op = op;
this(op, targetOffset);
addArg(arg1);
addArg(arg2);
}
private IfNode(IfOp op, int targetOffset) {
super(InsnType.IF, targetOffset, 2);
this.op = op;
}
// change default types priority
private static final ArgType WIDE_TYPE = ArgType.unknown(
PrimitiveType.INT, PrimitiveType.BOOLEAN,
......@@ -124,6 +128,14 @@ public class IfNode extends GotoNode {
}
@Override
public InsnNode copy() {
IfNode copy = new IfNode(op, target);
copy.thenBlock = thenBlock;
copy.elseBlock = elseBlock;
return copyCommonParams(copy);
}
@Override
public String toString() {
return InsnUtils.formatOffset(offset) + ": "
+ InsnUtils.insnTypeToString(insnType)
......
......@@ -12,12 +12,16 @@ public class NewArrayNode extends InsnNode {
private final ArgType arrType;
public NewArrayNode(@NotNull ArgType arrType, RegisterArg res, InsnArg size) {
super(InsnType.NEW_ARRAY, 1);
this.arrType = arrType;
this(arrType);
setResult(res);
addArg(size);
}
private NewArrayNode(ArgType arrType) {
super(InsnType.NEW_ARRAY, 1);
this.arrType = arrType;
}
public ArgType getArrayType() {
return arrType;
}
......@@ -35,6 +39,11 @@ public class NewArrayNode extends InsnNode {
}
@Override
public InsnNode copy() {
return copyCommonParams(new NewArrayNode(arrType));
}
@Override
public String toString() {
return super.toString() + " type: " + arrType;
}
......
......@@ -21,13 +21,17 @@ public final class PhiInsn extends InsnNode {
private final List<BlockNode> blockBinds;
public PhiInsn(int regNum, int predecessors) {
super(InsnType.PHI, predecessors);
this.blockBinds = new ArrayList<>(predecessors);
this(predecessors);
setResult(InsnArg.reg(regNum, ArgType.UNKNOWN));
add(AFlag.DONT_INLINE);
add(AFlag.DONT_GENERATE);
}
private PhiInsn(int argsCount) {
super(InsnType.PHI, argsCount);
this.blockBinds = new ArrayList<>(argsCount);
}
public RegisterArg bindArg(BlockNode pred) {
RegisterArg arg = InsnArg.reg(getResult().getRegNum(), getResult().getInitType());
bindArg(arg, pred);
......@@ -112,6 +116,11 @@ public final class PhiInsn extends InsnNode {
}
@Override
public InsnNode copy() {
return copyCommonParams(new PhiInsn(getArgsCount()));
}
@Override
public String toString() {
return "PHI: " + getResult() + " = " + Utils.listToString(getArguments())
+ " binds: " + blockBinds;
......
......@@ -20,11 +20,15 @@ public class SwitchNode extends TargetInsnNode {
private BlockNode defTargetBlock;
public SwitchNode(InsnArg arg, Object[] keys, int[] targets, int def) {
this(keys, targets, def);
addArg(arg);
}
private SwitchNode(Object[] keys, int[] targets, int def) {
super(InsnType.SWITCH, 1);
this.keys = keys;
this.targets = targets;
this.def = def;
addArg(arg);
}
public int getCasesCount() {
......@@ -97,6 +101,14 @@ public class SwitchNode extends TargetInsnNode {
}
@Override
public InsnNode copy() {
SwitchNode copy = new SwitchNode(keys, targets, def);
copy.targetBlocks = targetBlocks;
copy.defTargetBlock = defTargetBlock;
return copyCommonParams(copy);
}
@Override
public String toString() {
StringBuilder targ = new StringBuilder();
targ.append('[');
......
......@@ -105,6 +105,11 @@ public class ConstructorInsn extends InsnNode implements CallMthInterface {
}
@Override
public InsnNode copy() {
return copyCommonParams(new ConstructorInsn(callMth, callType, instanceArg));
}
@Override
public String toString() {
return super.toString() + ' ' + callMth + ' ' + callType;
}
......
......@@ -16,7 +16,7 @@ public final class TernaryInsn extends InsnNode {
private IfCondition condition;
public TernaryInsn(IfCondition condition, RegisterArg result, InsnArg th, InsnArg els) {
super(InsnType.TERNARY, 2);
this();
setResult(result);
if (th.equals(LiteralArg.FALSE) && els.equals(LiteralArg.TRUE)) {
......@@ -31,6 +31,10 @@ public final class TernaryInsn extends InsnNode {
}
}
private TernaryInsn() {
super(InsnType.TERNARY, 2);
}
public IfCondition getCondition() {
return condition;
}
......@@ -68,6 +72,13 @@ public final class TernaryInsn extends InsnNode {
}
@Override
public InsnNode copy() {
TernaryInsn copy = new TernaryInsn();
copy.condition = condition;
return copyCommonParams(copy);
}
@Override
public String toString() {
return InsnUtils.formatOffset(offset) + ": TERNARY"
+ getResult() + " = "
......
......@@ -9,7 +9,6 @@ import java.util.Objects;
import org.jetbrains.annotations.Nullable;
import com.android.dx.io.instructions.DecodedInstruction;
import com.rits.cloning.Cloner;
import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.attributes.nodes.LineAttrNode;
......@@ -17,23 +16,14 @@ import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.InsnWrapArg;
import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.instructions.args.NamedArg;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.instructions.args.SSAVar;
import jadx.core.utils.InsnRemover;
import jadx.core.utils.InsnUtils;
import jadx.core.utils.Utils;
import jadx.core.utils.exceptions.JadxRuntimeException;
public class InsnNode extends LineAttrNode {
private static final Cloner INSN_CLONER = new Cloner();
static {
INSN_CLONER.dontClone(ArgType.class, SSAVar.class, LiteralArg.class, NamedArg.class);
INSN_CLONER.dontCloneInstanceOf(RegisterArg.class);
}
protected final InsnType insnType;
private RegisterArg result;
......@@ -324,7 +314,7 @@ public class InsnNode extends LineAttrNode {
&& Objects.equals(arguments, other.arguments);
}
protected <T extends InsnNode> T copyCommonParams(T copy) {
protected final <T extends InsnNode> T copyCommonParams(T copy) {
copy.setResult(result);
if (copy.getArgsCount() == 0) {
for (InsnArg arg : this.getArguments()) {
......@@ -346,10 +336,10 @@ public class InsnNode extends LineAttrNode {
* Make copy of InsnNode object.
*/
public InsnNode copy() {
if (this.getClass() == InsnNode.class) {
return copyCommonParams(new InsnNode(insnType, getArgsCount()));
if (this.getClass() != InsnNode.class) {
throw new JadxRuntimeException("Copy method not implemented in insn class " + this.getClass().getSimpleName());
}
return INSN_CLONER.deepClone(this);
return copyCommonParams(new InsnNode(insnType, getArgsCount()));
}
public boolean canThrowException() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment