Commit a324376e authored by Skylot's avatar Skylot

core: replace assertions with jadx exceptions throw

parent 04e50afa
...@@ -31,7 +31,6 @@ import jadx.core.dex.visitors.ssa.EliminatePhiNodes; ...@@ -31,7 +31,6 @@ import jadx.core.dex.visitors.ssa.EliminatePhiNodes;
import jadx.core.dex.visitors.ssa.SSATransform; import jadx.core.dex.visitors.ssa.SSATransform;
import jadx.core.dex.visitors.typeinference.FinishTypeInference; import jadx.core.dex.visitors.typeinference.FinishTypeInference;
import jadx.core.dex.visitors.typeinference.TypeInference; import jadx.core.dex.visitors.typeinference.TypeInference;
import jadx.core.utils.Utils;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
...@@ -50,9 +49,6 @@ public class Jadx { ...@@ -50,9 +49,6 @@ public class Jadx {
if (Consts.DEBUG) { if (Consts.DEBUG) {
LOG.info("debug enabled"); LOG.info("debug enabled");
} }
if (Jadx.class.desiredAssertionStatus()) {
LOG.info("assertions enabled");
}
} }
public static List<IDexTreeVisitor> getPassesList(IJadxArgs args, File outDir) { public static List<IDexTreeVisitor> getPassesList(IJadxArgs args, File outDir) {
...@@ -115,7 +111,7 @@ public class Jadx { ...@@ -115,7 +111,7 @@ public class Jadx {
public static String getVersion() { public static String getVersion() {
try { try {
ClassLoader classLoader = Utils.class.getClassLoader(); ClassLoader classLoader = Jadx.class.getClassLoader();
if (classLoader != null) { if (classLoader != null) {
Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF"); Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) { while (resources.hasMoreElements()) {
......
...@@ -450,7 +450,7 @@ public class InsnGen { ...@@ -450,7 +450,7 @@ public class InsnGen {
/* fallback mode instructions */ /* fallback mode instructions */
case IF: case IF:
assert isFallback() : "if insn in not fallback mode"; fallbackOnlyInsn(insn);
IfNode ifInsn = (IfNode) insn; IfNode ifInsn = (IfNode) insn;
code.add("if ("); code.add("if (");
addArg(code, insn.getArg(0)); addArg(code, insn.getArg(0));
...@@ -461,17 +461,17 @@ public class InsnGen { ...@@ -461,17 +461,17 @@ public class InsnGen {
break; break;
case GOTO: case GOTO:
assert isFallback(); fallbackOnlyInsn(insn);
code.add("goto ").add(MethodGen.getLabelName(((GotoNode) insn).getTarget())); code.add("goto ").add(MethodGen.getLabelName(((GotoNode) insn).getTarget()));
break; break;
case MOVE_EXCEPTION: case MOVE_EXCEPTION:
assert isFallback(); fallbackOnlyInsn(insn);
code.add("move-exception"); code.add("move-exception");
break; break;
case SWITCH: case SWITCH:
assert isFallback(); fallbackOnlyInsn(insn);
SwitchNode sw = (SwitchNode) insn; SwitchNode sw = (SwitchNode) insn;
code.add("switch("); code.add("switch(");
addArg(code, insn.getArg(0)); addArg(code, insn.getArg(0));
...@@ -489,7 +489,7 @@ public class InsnGen { ...@@ -489,7 +489,7 @@ public class InsnGen {
break; break;
case FILL_ARRAY: case FILL_ARRAY:
assert isFallback(); fallbackOnlyInsn(insn);
FillArrayNode arrayNode = (FillArrayNode) insn; FillArrayNode arrayNode = (FillArrayNode) insn;
Object data = arrayNode.getData(); Object data = arrayNode.getData();
String arrStr; String arrStr;
...@@ -509,7 +509,7 @@ public class InsnGen { ...@@ -509,7 +509,7 @@ public class InsnGen {
case NEW_INSTANCE: case NEW_INSTANCE:
// only fallback - make new instance in constructor invoke // only fallback - make new instance in constructor invoke
assert isFallback(); fallbackOnlyInsn(insn);
code.add("new " + insn.getResult().getType()); code.add("new " + insn.getResult().getType());
break; break;
...@@ -518,6 +518,12 @@ public class InsnGen { ...@@ -518,6 +518,12 @@ public class InsnGen {
} }
} }
private void fallbackOnlyInsn(InsnNode insn) throws CodegenException {
if (!fallback) {
throw new CodegenException(insn.getType() + " can be used only in fallback mode");
}
}
private void filledNewArray(FilledNewArrayNode insn, CodeWriter code) throws CodegenException { private void filledNewArray(FilledNewArrayNode insn, CodeWriter code) throws CodegenException {
code.add("new "); code.add("new ");
useType(code, insn.getArrayType()); useType(code, insn.getArrayType());
......
...@@ -40,7 +40,6 @@ public class ArithNode extends InsnNode { ...@@ -40,7 +40,6 @@ public class ArithNode extends InsnNode {
addReg(insn, 2, type); addReg(insn, 2, type);
} }
} }
assert getArgsCount() == 2;
} }
public ArithNode(ArithOp op, RegisterArg res, InsnArg a, InsnArg b) { public ArithNode(ArithOp op, RegisterArg res, InsnArg a, InsnArg b) {
......
package jadx.core.dex.instructions.args; package jadx.core.dex.instructions.args;
import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.InsnNode;
import jadx.core.utils.exceptions.JadxRuntimeException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
...@@ -20,7 +21,9 @@ public final class InsnWrapArg extends InsnArg { ...@@ -20,7 +21,9 @@ public final class InsnWrapArg extends InsnArg {
@Override @Override
public void setParentInsn(InsnNode parentInsn) { public void setParentInsn(InsnNode parentInsn) {
assert parentInsn != wrappedInsn : "Can't wrap instruction info itself: " + parentInsn; if (parentInsn == wrappedInsn) {
throw new JadxRuntimeException("Can't wrap instruction info itself: " + parentInsn);
}
this.parentInsn = parentInsn; this.parentInsn = parentInsn;
} }
......
...@@ -11,10 +11,14 @@ import jadx.core.utils.exceptions.DecodeException; ...@@ -11,10 +11,14 @@ import jadx.core.utils.exceptions.DecodeException;
import java.util.List; import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.android.dex.Dex.Section; import com.android.dex.Dex.Section;
public class DebugInfoParser { public class DebugInfoParser {
private static final Logger LOG = LoggerFactory.getLogger(DebugInfoParser.class);
private static final int DBG_END_SEQUENCE = 0x00; private static final int DBG_END_SEQUENCE = 0x00;
private static final int DBG_ADVANCE_PC = 0x01; private static final int DBG_ADVANCE_PC = 0x01;
private static final int DBG_ADVANCE_LINE = 0x02; private static final int DBG_ADVANCE_LINE = 0x02;
...@@ -58,13 +62,13 @@ public class DebugInfoParser { ...@@ -58,13 +62,13 @@ public class DebugInfoParser {
int paramsCount = section.readUleb128(); int paramsCount = section.readUleb128();
List<RegisterArg> mthArgs = mth.getArguments(false); List<RegisterArg> mthArgs = mth.getArguments(false);
assert paramsCount == mthArgs.size();
for (int i = 0; i < paramsCount; i++) { for (int i = 0; i < paramsCount; i++) {
int id = section.readUleb128() - 1; int id = section.readUleb128() - 1;
if (id != DexNode.NO_INDEX) { if (id != DexNode.NO_INDEX) {
String name = dex.getString(id); String name = dex.getString(id);
mthArgs.get(i).setName(name); if (i < mthArgs.size()) {
mthArgs.get(i).setName(name);
}
} }
} }
......
...@@ -5,6 +5,7 @@ import jadx.core.dex.nodes.IBranchRegion; ...@@ -5,6 +5,7 @@ import jadx.core.dex.nodes.IBranchRegion;
import jadx.core.dex.nodes.IContainer; import jadx.core.dex.nodes.IContainer;
import jadx.core.dex.nodes.IRegion; import jadx.core.dex.nodes.IRegion;
import jadx.core.dex.regions.AbstractRegion; import jadx.core.dex.regions.AbstractRegion;
import jadx.core.utils.exceptions.JadxRuntimeException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -20,7 +21,9 @@ public final class IfRegion extends AbstractRegion implements IBranchRegion { ...@@ -20,7 +21,9 @@ public final class IfRegion extends AbstractRegion implements IBranchRegion {
public IfRegion(IRegion parent, BlockNode header) { public IfRegion(IRegion parent, BlockNode header) {
super(parent); super(parent);
assert header.getInstructions().size() == 1; if (header.getInstructions().size() != 1) {
throw new JadxRuntimeException("Expected only one instruction in 'if' header");
}
this.header = header; this.header = header;
this.condition = IfCondition.fromIfBlock(header); this.condition = IfCondition.fromIfBlock(header);
} }
......
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