Search in sources :

Example 61 with JadxRuntimeException

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

the class ImagePanel method loadImage.

private BufferedImage loadImage(JResource res) {
    ResourceFile resFile = res.getResFile();
    ResContainer resContainer = resFile.loadContent();
    ResContainer.DataType dataType = resContainer.getDataType();
    if (dataType == ResContainer.DataType.DECODED_DATA) {
        try {
            return ImageIO.read(new ByteArrayInputStream(resContainer.getDecodedData()));
        } catch (Exception e) {
            throw new JadxRuntimeException("Failed to load image", e);
        }
    } else if (dataType == ResContainer.DataType.RES_LINK) {
        try {
            return ResourcesLoader.decodeStream(resFile, (size, is) -> ImageIO.read(is));
        } catch (Exception e) {
            throw new JadxRuntimeException("Failed to load image", e);
        }
    } else {
        throw new JadxRuntimeException("Unsupported resource image data type: " + resFile);
    }
}
Also used : ResourceFile(jadx.api.ResourceFile) BufferedImage(java.awt.image.BufferedImage) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) TabbedPane(jadx.gui.ui.TabbedPane) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) AbstractCodeArea(jadx.gui.ui.codearea.AbstractCodeArea) ResContainer(jadx.core.xmlgen.ResContainer) ResourcesLoader(jadx.api.ResourcesLoader) JResource(jadx.gui.treemodel.JResource) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageIO(javax.imageio.ImageIO) BorderLayout(java.awt.BorderLayout) ImageViewer(hu.kazocsaba.imageviewer.ImageViewer) ICodeWriter(jadx.api.ICodeWriter) Utils(jadx.core.utils.Utils) ResourceFile(jadx.api.ResourceFile) ResContainer(jadx.core.xmlgen.ResContainer) ByteArrayInputStream(java.io.ByteArrayInputStream) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 62 with JadxRuntimeException

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

the class TabbedPane method smaliJump.

public void smaliJump(JClass cls, int pos, boolean debugMode) {
    ContentPanel panel = getOpenTabs().get(cls);
    if (panel == null) {
        showCode(new JumpPosition(cls, 0, 1));
        panel = getOpenTabs().get(cls);
        if (panel == null) {
            throw new JadxRuntimeException("Failed to open panel for JClass: " + cls);
        }
    } else {
        selectTab(panel);
    }
    ClassCodeContentPanel codePane = ((ClassCodeContentPanel) panel);
    codePane.showSmaliPane();
    SmaliArea smaliArea = (SmaliArea) codePane.getSmaliCodeArea();
    if (debugMode) {
        smaliArea.scrollToDebugPos(pos);
    }
    smaliArea.scrollToPos(pos);
    smaliArea.requestFocus();
}
Also used : JumpPosition(jadx.gui.utils.JumpPosition) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) ClassCodeContentPanel(jadx.gui.ui.codearea.ClassCodeContentPanel) AbstractCodeContentPanel(jadx.gui.ui.codearea.AbstractCodeContentPanel) ClassCodeContentPanel(jadx.gui.ui.codearea.ClassCodeContentPanel) ContentPanel(jadx.gui.ui.panel.ContentPanel) SmaliArea(jadx.gui.ui.codearea.SmaliArea)

Example 63 with JadxRuntimeException

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

the class Utils method openIcon.

public static ImageIcon openIcon(String name) {
    String iconPath = "/icons-16/" + name + ".png";
    URL resource = Utils.class.getResource(iconPath);
    if (resource == null) {
        throw new JadxRuntimeException("Icon not found: " + iconPath);
    }
    return new ImageIcon(resource);
}
Also used : ImageIcon(javax.swing.ImageIcon) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) URL(java.net.URL)

Example 64 with JadxRuntimeException

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

the class RegionGen method makeSwitch.

private CodeWriter makeSwitch(SwitchRegion sw, CodeWriter code) throws CodegenException {
    SwitchNode insn = (SwitchNode) sw.getHeader().getInstructions().get(0);
    InsnArg arg = insn.getArg(0);
    code.startLine("switch (");
    addArg(code, arg, false);
    code.add(") {");
    code.incIndent();
    int size = sw.getKeys().size();
    for (int i = 0; i < size; i++) {
        List<Object> keys = sw.getKeys().get(i);
        IContainer c = sw.getCases().get(i);
        for (Object k : keys) {
            code.startLine("case ");
            if (k instanceof FieldNode) {
                FieldNode fn = (FieldNode) k;
                if (fn.getParentClass().isEnum()) {
                    code.add(fn.getAlias());
                } else {
                    staticField(code, fn.getFieldInfo());
                    // print original value, sometimes replace with incorrect field
                    FieldInitAttr valueAttr = fn.get(AType.FIELD_INIT);
                    if (valueAttr != null && valueAttr.getValue() != null) {
                        code.add(" /*").add(valueAttr.getValue().toString()).add("*/");
                    }
                }
            } else if (k instanceof Integer) {
                code.add(TypeGen.literalToString((Integer) k, arg.getType(), mth));
            } else {
                throw new JadxRuntimeException("Unexpected key in switch: " + (k != null ? k.getClass() : null));
            }
            code.add(':');
        }
        makeRegionIndent(code, c);
    }
    if (sw.getDefaultCase() != null) {
        code.startLine("default:");
        makeRegionIndent(code, sw.getDefaultCase());
    }
    code.decIndent();
    code.startLine('}');
    return code;
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IContainer(jadx.core.dex.nodes.IContainer) SwitchNode(jadx.core.dex.instructions.SwitchNode) FieldInitAttr(jadx.core.dex.nodes.parser.FieldInitAttr)

Example 65 with JadxRuntimeException

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

the class RegionGen method makeLoop.

private CodeWriter makeLoop(LoopRegion region, CodeWriter code) throws CodegenException {
    BlockNode header = region.getHeader();
    if (header != null) {
        List<InsnNode> headerInsns = header.getInstructions();
        if (headerInsns.size() > 1) {
            ErrorsCounter.methodError(mth, "Found not inlined instructions from loop header");
            int last = headerInsns.size() - 1;
            for (int i = 0; i < last; i++) {
                InsnNode insn = headerInsns.get(i);
                makeInsn(insn, code);
            }
        }
    }
    LoopLabelAttr labelAttr = region.getInfo().getStart().get(AType.LOOP_LABEL);
    if (labelAttr != null) {
        code.startLine(mgen.getNameGen().getLoopLabel(labelAttr)).add(':');
    }
    IfCondition condition = region.getCondition();
    if (condition == null) {
        // infinite loop
        code.startLine("while (true) {");
        makeRegionIndent(code, region.getBody());
        code.startLine('}');
        return code;
    }
    ConditionGen conditionGen = new ConditionGen(this);
    LoopType type = region.getType();
    if (type != null) {
        if (type instanceof ForLoop) {
            ForLoop forLoop = (ForLoop) type;
            code.startLine("for (");
            makeInsn(forLoop.getInitInsn(), code, Flags.INLINE);
            code.add("; ");
            conditionGen.add(code, condition);
            code.add("; ");
            makeInsn(forLoop.getIncrInsn(), code, Flags.INLINE);
            code.add(") {");
            makeRegionIndent(code, region.getBody());
            code.startLine('}');
            return code;
        }
        if (type instanceof ForEachLoop) {
            ForEachLoop forEachLoop = (ForEachLoop) type;
            code.startLine("for (");
            declareVar(code, forEachLoop.getVarArg());
            code.add(" : ");
            addArg(code, forEachLoop.getIterableArg(), false);
            code.add(") {");
            makeRegionIndent(code, region.getBody());
            code.startLine('}');
            return code;
        }
        throw new JadxRuntimeException("Unknown loop type: " + type.getClass());
    }
    if (region.isConditionAtEnd()) {
        code.startLine("do {");
        makeRegionIndent(code, region.getBody());
        code.startLine("} while (");
        conditionGen.add(code, condition);
        code.add(");");
    } else {
        code.startLine("while (");
        conditionGen.add(code, condition);
        code.add(") {");
        makeRegionIndent(code, region.getBody());
        code.startLine('}');
    }
    return code;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) 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)

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