Search in sources :

Example 6 with SimpleCodeWriter

use of jadx.api.impl.SimpleCodeWriter in project jadx by skylot.

the class DebugUtils method printInsns.

private static void printInsns(MethodNode mth, ICodeWriter cw, String indent, IBlock block) {
    for (InsnNode insn : block.getInstructions()) {
        try {
            MethodGen mg = MethodGen.getFallbackMethodGen(mth);
            InsnGen ig = new InsnGen(mg, true);
            ICodeWriter code = new SimpleCodeWriter();
            ig.makeInsn(insn, code);
            String codeStr = code.getCodeStr();
            List<String> insnStrings = Stream.of(codeStr.split(ICodeWriter.NL)).filter(StringUtils::notBlank).map(s -> "|> " + s).collect(Collectors.toList());
            Iterator<String> it = insnStrings.iterator();
            while (true) {
                String insnStr = it.next();
                if (it.hasNext()) {
                    cw.startLine(indent).add(insnStr);
                } else {
                    printWithAttributes(cw, indent, insnStr, insn);
                    break;
                }
            }
        } catch (CodegenException e) {
            cw.startLine(indent).add(">!! ").add(insn.toString());
        }
    }
}
Also used : IDexTreeVisitor(jadx.core.dex.visitors.IDexTreeVisitor) IRegion(jadx.core.dex.nodes.IRegion) MethodNode(jadx.core.dex.nodes.MethodNode) AType(jadx.core.dex.attributes.AType) LoggerFactory(org.slf4j.LoggerFactory) RootNode(jadx.core.dex.nodes.RootNode) JadxException(jadx.core.utils.exceptions.JadxException) InsnGen(jadx.core.codegen.InsnGen) Function(java.util.function.Function) DepthRegionTraversal(jadx.core.dex.visitors.regions.DepthRegionTraversal) AbstractVisitor(jadx.core.dex.visitors.AbstractVisitor) Map(java.util.Map) InsnNode(jadx.core.dex.nodes.InsnNode) IfCondition(jadx.core.dex.regions.conditions.IfCondition) MethodOverrideAttr(jadx.core.dex.attributes.nodes.MethodOverrideAttr) CodegenException(jadx.core.utils.exceptions.CodegenException) LinkedHashSet(java.util.LinkedHashSet) SimpleCodeWriter(jadx.api.impl.SimpleCodeWriter) DotGraphVisitor(jadx.core.dex.visitors.DotGraphVisitor) Logger(org.slf4j.Logger) LoopRegion(jadx.core.dex.regions.loops.LoopRegion) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IAttributeNode(jadx.core.dex.attributes.IAttributeNode) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) BlockNode(jadx.core.dex.nodes.BlockNode) Stream(java.util.stream.Stream) Region(jadx.core.dex.regions.Region) IContainer(jadx.core.dex.nodes.IContainer) ConditionGen(jadx.core.codegen.ConditionGen) TracedRegionVisitor(jadx.core.dex.visitors.regions.TracedRegionVisitor) MethodGen(jadx.core.codegen.MethodGen) Comparator(java.util.Comparator) ICodeWriter(jadx.api.ICodeWriter) IBlock(jadx.core.dex.nodes.IBlock) InsnNode(jadx.core.dex.nodes.InsnNode) InsnGen(jadx.core.codegen.InsnGen) CodegenException(jadx.core.utils.exceptions.CodegenException) SimpleCodeWriter(jadx.api.impl.SimpleCodeWriter) ICodeWriter(jadx.api.ICodeWriter) MethodGen(jadx.core.codegen.MethodGen)

Example 7 with SimpleCodeWriter

use of jadx.api.impl.SimpleCodeWriter in project jadx by skylot.

the class DebugUtils method printRegion.

public static void printRegion(MethodNode mth, IRegion region, boolean printInsns) {
    ICodeWriter cw = new SimpleCodeWriter();
    cw.startLine('|').add(mth.toString());
    printRegion(mth, region, cw, "|  ", printInsns);
    LOG.debug("{}{}", ICodeWriter.NL, cw.finish().getCodeStr());
}
Also used : SimpleCodeWriter(jadx.api.impl.SimpleCodeWriter) ICodeWriter(jadx.api.ICodeWriter)

Aggregations

SimpleCodeWriter (jadx.api.impl.SimpleCodeWriter)7 ICodeWriter (jadx.api.ICodeWriter)6 InsnGen (jadx.core.codegen.InsnGen)2 MethodGen (jadx.core.codegen.MethodGen)2 InsnNode (jadx.core.dex.nodes.InsnNode)2 CodegenException (jadx.core.utils.exceptions.CodegenException)2 Map (java.util.Map)2 ICodeInfo (jadx.api.ICodeInfo)1 JadxArgs (jadx.api.JadxArgs)1 JadxDecompiler (jadx.api.JadxDecompiler)1 NoOpCodeCache (jadx.api.impl.NoOpCodeCache)1 ClassGen (jadx.core.codegen.ClassGen)1 ConditionGen (jadx.core.codegen.ConditionGen)1 JsonClass (jadx.core.codegen.json.cls.JsonClass)1 JsonField (jadx.core.codegen.json.cls.JsonField)1 AType (jadx.core.dex.attributes.AType)1 IAttributeNode (jadx.core.dex.attributes.IAttributeNode)1 MethodOverrideAttr (jadx.core.dex.attributes.nodes.MethodOverrideAttr)1 ClassInfo (jadx.core.dex.info.ClassInfo)1 BlockNode (jadx.core.dex.nodes.BlockNode)1