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