Search in sources :

Example 36 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class TextResMapFile method write.

public static void write(Path resMapFile, Map<Integer, String> inputResMap) {
    try {
        Map<Integer, String> resMap = new TreeMap<>(inputResMap);
        List<String> lines = new ArrayList<>(resMap.size());
        for (Map.Entry<Integer, String> entry : resMap.entrySet()) {
            lines.add(String.format("%08x=%s", entry.getKey(), entry.getValue()));
        }
        Files.write(resMapFile, lines, StandardCharsets.UTF_8);
    } catch (Exception e) {
        throw new JadxRuntimeException("Failed to write res-map file", e);
    }
}
Also used : ArrayList(java.util.ArrayList) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 37 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class ExportGradleProject method parseXml.

private Document parseXml(String xmlContent) {
    try {
        DocumentBuilder builder = XmlSecurity.getSecureDbf().newDocumentBuilder();
        Document document = builder.parse(new InputSource(new StringReader(xmlContent)));
        document.getDocumentElement().normalize();
        return document;
    } catch (Exception e) {
        throw new JadxRuntimeException("Can not parse xml content", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) Document(org.w3c.dom.Document) IOException(java.io.IOException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 38 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class FileUtils method createTempDir.

public static Path createTempDir(String prefix) {
    try {
        Path dir = Files.createTempDirectory(TEMP_ROOT_DIR, prefix);
        dir.toFile().deleteOnExit();
        return dir;
    } catch (Exception e) {
        throw new JadxRuntimeException("Failed to create temp directory with suffix: " + prefix, e);
    }
}
Also used : Path(java.nio.file.Path) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IOException(java.io.IOException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 39 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class RegionGen method makeLoop.

public void makeLoop(LoopRegion region, ICodeWriter code) throws CodegenException {
    code.startLineWithNum(region.getSourceLine());
    LoopLabelAttr labelAttr = region.getInfo().getStart().get(AType.LOOP_LABEL);
    if (labelAttr != null) {
        code.add(mgen.getNameGen().getLoopLabel(labelAttr)).add(": ");
    }
    IfCondition condition = region.getCondition();
    if (condition == null) {
        // infinite loop
        code.add("while (true) {");
        makeRegionIndent(code, region.getBody());
        code.startLine('}');
        return;
    }
    InsnNode condInsn = condition.getFirstInsn();
    InsnCodeOffset.attach(code, condInsn);
    ConditionGen conditionGen = new ConditionGen(this);
    LoopType type = region.getType();
    if (type != null) {
        if (type instanceof ForLoop) {
            ForLoop forLoop = (ForLoop) type;
            code.add("for (");
            makeInsn(forLoop.getInitInsn(), code, Flags.INLINE);
            code.add("; ");
            conditionGen.add(code, condition);
            code.add("; ");
            makeInsn(forLoop.getIncrInsn(), code, Flags.INLINE);
            code.add(") {");
            CodeGenUtils.addCodeComments(code, mth, condInsn);
            makeRegionIndent(code, region.getBody());
            code.startLine('}');
            return;
        }
        if (type instanceof ForEachLoop) {
            ForEachLoop forEachLoop = (ForEachLoop) type;
            code.add("for (");
            declareVar(code, forEachLoop.getVarArg());
            code.add(" : ");
            addArg(code, forEachLoop.getIterableArg(), false);
            code.add(") {");
            CodeGenUtils.addCodeComments(code, mth, condInsn);
            makeRegionIndent(code, region.getBody());
            code.startLine('}');
            return;
        }
        throw new JadxRuntimeException("Unknown loop type: " + type.getClass());
    }
    if (region.isConditionAtEnd()) {
        code.add("do {");
        CodeGenUtils.addCodeComments(code, mth, condInsn);
        makeRegionIndent(code, region.getBody());
        code.startLineWithNum(region.getSourceLine());
        code.add("} while (");
        conditionGen.add(code, condition);
        code.add(");");
    } else {
        code.add("while (");
        conditionGen.add(code, condition);
        code.add(") {");
        CodeGenUtils.addCodeComments(code, mth, condInsn);
        makeRegionIndent(code, region.getBody());
        code.startLine('}');
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) ForLoop(jadx.core.dex.regions.loops.ForLoop) LoopLabelAttr(jadx.core.dex.attributes.nodes.LoopLabelAttr) LoopType(jadx.core.dex.regions.loops.LoopType) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IfCondition(jadx.core.dex.regions.conditions.IfCondition) ForEachLoop(jadx.core.dex.regions.loops.ForEachLoop)

Example 40 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class InsnDecoder method invokeSpecial.

private InsnNode invokeSpecial(InsnData insn) {
    IMethodRef mthRef = InsnDataUtils.getMethodRef(insn);
    if (mthRef == null) {
        throw new JadxRuntimeException("Failed to load method reference for insn: " + insn);
    }
    MethodInfo mthInfo = MethodInfo.fromRef(root, mthRef);
    // convert 'special' to 'direct/super' same as dx
    InvokeType type;
    if (mthInfo.isConstructor() || Objects.equals(mthInfo.getDeclClass(), method.getParentClass().getClassInfo())) {
        type = InvokeType.DIRECT;
    } else {
        type = InvokeType.SUPER;
    }
    return new InvokeNode(mthInfo, insn, type, false);
}
Also used : IMethodRef(jadx.api.plugins.input.data.IMethodRef) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) MethodInfo(jadx.core.dex.info.MethodInfo)

Aggregations

JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)115 BlockNode (jadx.core.dex.nodes.BlockNode)25 ArrayList (java.util.ArrayList)25 InsnNode (jadx.core.dex.nodes.InsnNode)24 ArgType (jadx.core.dex.instructions.args.ArgType)20 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)17 BitSet (java.util.BitSet)11 ClassNode (jadx.core.dex.nodes.ClassNode)10 MethodNode (jadx.core.dex.nodes.MethodNode)9 InsnArg (jadx.core.dex.instructions.args.InsnArg)8 SSAVar (jadx.core.dex.instructions.args.SSAVar)8 IOException (java.io.IOException)8 List (java.util.List)8 File (java.io.File)7 IRegion (jadx.core.dex.nodes.IRegion)6 Path (java.nio.file.Path)6 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)5 PhiInsn (jadx.core.dex.instructions.PhiInsn)5 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)5 FieldNode (jadx.core.dex.nodes.FieldNode)5