Search in sources :

Example 96 with JadxRuntimeException

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

the class RegionUtils method getFirstInsn.

public static InsnNode getFirstInsn(IContainer container) {
    if (container instanceof IBlock) {
        IBlock block = (IBlock) container;
        List<InsnNode> insnList = block.getInstructions();
        if (insnList.isEmpty()) {
            return null;
        }
        return insnList.get(0);
    } else if (container instanceof IBranchRegion) {
        return null;
    } else if (container instanceof IRegion) {
        IRegion region = (IRegion) container;
        List<IContainer> blocks = region.getSubBlocks();
        if (blocks.isEmpty()) {
            return null;
        }
        return getFirstInsn(blocks.get(0));
    } else {
        throw new JadxRuntimeException(unknownContainerType(container));
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) IBlock(jadx.core.dex.nodes.IBlock) IBranchRegion(jadx.core.dex.nodes.IBranchRegion) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IContainer(jadx.core.dex.nodes.IContainer) IRegion(jadx.core.dex.nodes.IRegion)

Example 97 with JadxRuntimeException

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

the class RegionUtils method getLastInsn.

public static InsnNode getLastInsn(IContainer container) {
    if (container instanceof IBlock) {
        IBlock block = (IBlock) container;
        List<InsnNode> insnList = block.getInstructions();
        if (insnList.isEmpty()) {
            return null;
        }
        return insnList.get(insnList.size() - 1);
    } else if (container instanceof IBranchRegion) {
        return null;
    } else if (container instanceof IRegion) {
        IRegion region = (IRegion) container;
        List<IContainer> blocks = region.getSubBlocks();
        if (blocks.isEmpty()) {
            return null;
        }
        return getLastInsn(blocks.get(blocks.size() - 1));
    } else {
        throw new JadxRuntimeException(unknownContainerType(container));
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) IBlock(jadx.core.dex.nodes.IBlock) IBranchRegion(jadx.core.dex.nodes.IBranchRegion) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IContainer(jadx.core.dex.nodes.IContainer) IRegion(jadx.core.dex.nodes.IRegion)

Example 98 with JadxRuntimeException

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

the class Res9patchStreamDecoder method decode.

public boolean decode(InputStream in, OutputStream out) {
    try {
        BufferedImage im = ImageIO.read(in);
        NinePatch np = getNinePatch(in);
        if (np == null) {
            return false;
        }
        int w = im.getWidth();
        int h = im.getHeight();
        BufferedImage im2 = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB);
        im2.createGraphics().drawImage(im, 1, 1, w, h, null);
        drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight);
        drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom);
        int[] xDivs = np.xDivs;
        for (int i = 0; i < xDivs.length - 1; i += 2) {
            drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]);
        }
        int[] yDivs = np.yDivs;
        for (int i = 0; i < yDivs.length - 1; i += 2) {
            drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]);
        }
        ImageIO.write(im2, "png", out);
        return true;
    } catch (Exception e) {
        throw new JadxRuntimeException("9patch image decode error", e);
    }
}
Also used : JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 99 with JadxRuntimeException

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

the class ManifestAttributes method loadXML.

private Document loadXML(String xml) {
    Document doc;
    try (InputStream xmlStream = ManifestAttributes.class.getResourceAsStream(xml)) {
        if (xmlStream == null) {
            throw new JadxRuntimeException(xml + " not found in classpath");
        }
        DocumentBuilder dBuilder = XmlSecurity.getSecureDbf().newDocumentBuilder();
        doc = dBuilder.parse(xmlStream);
    } catch (Exception e) {
        throw new JadxRuntimeException("Xml load error, file: " + xml, e);
    }
    return doc;
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) InputStream(java.io.InputStream) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) Document(org.w3c.dom.Document) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 100 with JadxRuntimeException

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

the class InsnRemover method removeSsaVar.

private static void removeSsaVar(MethodNode mth, SSAVar ssaVar) {
    int useCount = ssaVar.getUseCount();
    if (useCount == 0) {
        mth.removeSVar(ssaVar);
        return;
    }
    // check if all usage only in PHI insns
    boolean allPhis = true;
    for (RegisterArg arg : ssaVar.getUseList()) {
        InsnNode parentInsn = arg.getParentInsn();
        if (parentInsn == null || parentInsn.getType() != InsnType.PHI) {
            allPhis = false;
            break;
        }
    }
    if (allPhis) {
        for (RegisterArg arg : new ArrayList<>(ssaVar.getUseList())) {
            InsnNode parentInsn = arg.getParentInsn();
            if (parentInsn != null) {
                ((PhiInsn) parentInsn).removeArg(arg);
            }
        }
        mth.removeSVar(ssaVar);
        return;
    }
    if (Consts.DEBUG_WITH_ERRORS) {
        throw new JadxRuntimeException("Can't remove SSA var, still in use, count: " + useCount + ", list:" + ICodeWriter.NL + "  " + ssaVar.getUseList().stream().map(arg -> arg + " from " + arg.getParentInsn()).collect(Collectors.joining(ICodeWriter.NL + "  ")));
    }
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) MethodNode(jadx.core.dex.nodes.MethodNode) Consts(jadx.core.Consts) Iterator(java.util.Iterator) AFlag(jadx.core.dex.attributes.AFlag) InsnType(jadx.core.dex.instructions.InsnType) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) BlockNode(jadx.core.dex.nodes.BlockNode) PhiInsn(jadx.core.dex.instructions.PhiInsn) InsnNode(jadx.core.dex.nodes.InsnNode) SSAVar(jadx.core.dex.instructions.args.SSAVar) InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) ICodeWriter(jadx.api.ICodeWriter) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) PhiInsn(jadx.core.dex.instructions.PhiInsn) ArrayList(java.util.ArrayList) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

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