Search in sources :

Example 1 with ICodeWriter

use of jadx.api.ICodeWriter in project jadx by skylot.

the class CheckRegions method getBlockInsnStr.

private static String getBlockInsnStr(MethodNode mth, IBlock block) {
    ICodeWriter code = new SimpleCodeWriter();
    code.incIndent();
    code.newLine();
    MethodGen mg = MethodGen.getFallbackMethodGen(mth);
    InsnGen ig = new InsnGen(mg, true);
    for (InsnNode insn : block.getInstructions()) {
        try {
            ig.makeInsn(insn, code);
        } catch (CodegenException e) {
        // ignore
        }
    }
    code.newLine();
    return code.getCodeStr();
}
Also used : 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 2 with ICodeWriter

use of jadx.api.ICodeWriter in project jadx by skylot.

the class MethodGen method addOverrideAnnotation.

private void addOverrideAnnotation(ICodeWriter code, MethodNode mth) {
    MethodOverrideAttr overrideAttr = mth.get(AType.METHOD_OVERRIDE);
    if (overrideAttr == null) {
        return;
    }
    if (!overrideAttr.getBaseMethods().contains(mth)) {
        code.startLine("@Override");
        if (mth.checkCommentsLevel(CommentsLevel.INFO)) {
            code.add(" // ");
            code.add(Utils.listToString(overrideAttr.getOverrideList(), ", ", md -> md.getMethodInfo().getDeclClass().getAliasFullName()));
        }
    }
    if (Consts.DEBUG) {
        code.startLine("// related by override: ");
        code.add(Utils.listToString(overrideAttr.getRelatedMthNodes(), ", ", m -> m.getParentClass().getFullName()));
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) CodeVar(jadx.core.dex.instructions.args.CodeVar) IDexTreeVisitor(jadx.core.dex.visitors.IDexTreeVisitor) JumpInfo(jadx.core.dex.attributes.nodes.JumpInfo) MethodNode(jadx.core.dex.nodes.MethodNode) Consts(jadx.core.Consts) AType(jadx.core.dex.attributes.AType) AFlag(jadx.core.dex.attributes.AFlag) LoggerFactory(org.slf4j.LoggerFactory) InsnType(jadx.core.dex.instructions.InsnType) CatchAttr(jadx.core.dex.trycatch.CatchAttr) JadxOverflowException(jadx.core.utils.exceptions.JadxOverflowException) AccessInfo(jadx.core.dex.info.AccessInfo) InsnCodeOffset(jadx.api.data.annotations.InsnCodeOffset) IfNode(jadx.core.dex.instructions.IfNode) InsnUtils(jadx.core.utils.InsnUtils) CodeGenUtils(jadx.core.utils.CodeGenUtils) CommentsLevel(jadx.api.CommentsLevel) InsnNode(jadx.core.dex.nodes.InsnNode) SSAVar(jadx.core.dex.instructions.args.SSAVar) VarDeclareRef(jadx.api.data.annotations.VarDeclareRef) MethodOverrideAttr(jadx.core.dex.attributes.nodes.MethodOverrideAttr) CodegenException(jadx.core.utils.exceptions.CodegenException) Jadx(jadx.core.Jadx) EncodedValue(jadx.api.plugins.input.data.annotations.EncodedValue) JadxAttrType(jadx.api.plugins.input.data.attributes.JadxAttrType) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DepthTraversal(jadx.core.dex.visitors.DepthTraversal) BLOCK_DUMP(jadx.core.codegen.MethodGen.FallbackOption.BLOCK_DUMP) AnnotationMethodParamsAttr(jadx.api.plugins.input.data.attributes.types.AnnotationMethodParamsAttr) ConstStringNode(jadx.core.dex.instructions.ConstStringNode) FALLBACK_MODE(jadx.core.codegen.MethodGen.FallbackOption.FALLBACK_MODE) Objects(java.util.Objects) JadxError(jadx.core.dex.attributes.nodes.JadxError) List(java.util.List) Stream(java.util.stream.Stream) AccessFlags(jadx.api.plugins.input.data.AccessFlags) COMMENTED_DUMP(jadx.core.codegen.MethodGen.FallbackOption.COMMENTED_DUMP) Collections(java.util.Collections) ICodeWriter(jadx.api.ICodeWriter) Utils(jadx.core.utils.Utils) MethodOverrideAttr(jadx.core.dex.attributes.nodes.MethodOverrideAttr)

Example 3 with ICodeWriter

use of jadx.api.ICodeWriter in project jadx by skylot.

the class JsonCodeGen method addMethods.

private void addMethods(ClassNode cls, JsonClass jsonCls, ClassGen classGen) {
    jsonCls.setMethods(new ArrayList<>());
    for (MethodNode mth : cls.getMethods()) {
        if (mth.contains(AFlag.DONT_GENERATE)) {
            continue;
        }
        JsonMethod jsonMth = new JsonMethod();
        jsonMth.setName(mth.getName());
        if (mth.getMethodInfo().hasAlias()) {
            jsonMth.setAlias(mth.getAlias());
        }
        jsonMth.setSignature(mth.getMethodInfo().getShortId());
        jsonMth.setReturnType(getTypeAlias(mth.getReturnType()));
        jsonMth.setArguments(Utils.collectionMap(mth.getMethodInfo().getArgumentsTypes(), this::getTypeAlias));
        MethodGen mthGen = new MethodGen(classGen, mth);
        ICodeWriter cw = new AnnotatedCodeWriter();
        mthGen.addDefinition(cw);
        jsonMth.setDeclaration(cw.getCodeStr());
        jsonMth.setAccessFlags(mth.getAccessFlags().rawValue());
        jsonMth.setLines(fillMthCode(mth, mthGen));
        jsonMth.setOffset("0x" + Long.toHexString(mth.getMethodCodeOffset()));
        jsonCls.getMethods().add(jsonMth);
    }
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) AnnotatedCodeWriter(jadx.api.impl.AnnotatedCodeWriter) JsonMethod(jadx.core.codegen.json.cls.JsonMethod) ICodeWriter(jadx.api.ICodeWriter) MethodGen(jadx.core.codegen.MethodGen)

Example 4 with ICodeWriter

use of jadx.api.ICodeWriter in project jadx by skylot.

the class JsonCodeGen method addFields.

private void addFields(ClassNode cls, JsonClass jsonCls, ClassGen classGen) {
    jsonCls.setFields(new ArrayList<>());
    for (FieldNode field : cls.getFields()) {
        if (field.contains(AFlag.DONT_GENERATE)) {
            continue;
        }
        JsonField jsonField = new JsonField();
        jsonField.setName(field.getName());
        if (field.getFieldInfo().hasAlias()) {
            jsonField.setAlias(field.getAlias());
        }
        ICodeWriter cw = new SimpleCodeWriter();
        classGen.addField(cw, field);
        jsonField.setDeclaration(cw.getCodeStr());
        jsonField.setAccessFlags(field.getAccessFlags().rawValue());
        jsonCls.getFields().add(jsonField);
    }
}
Also used : JsonField(jadx.core.codegen.json.cls.JsonField) FieldNode(jadx.core.dex.nodes.FieldNode) SimpleCodeWriter(jadx.api.impl.SimpleCodeWriter) ICodeWriter(jadx.api.ICodeWriter)

Example 5 with ICodeWriter

use of jadx.api.ICodeWriter in project jadx by skylot.

the class ResXmlGen method makeResourcesXml.

public List<ResContainer> makeResourcesXml() {
    Map<String, ICodeWriter> contMap = new HashMap<>();
    for (ResourceEntry ri : resStorage.getResources()) {
        if (SKIP_RES_TYPES.contains(ri.getTypeName())) {
            continue;
        }
        String fn = getFileName(ri);
        ICodeWriter cw = contMap.get(fn);
        if (cw == null) {
            cw = new SimpleCodeWriter();
            cw.add("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            cw.startLine("<resources>");
            cw.incIndent();
            contMap.put(fn, cw);
        }
        addValue(cw, ri);
    }
    List<ResContainer> files = new ArrayList<>(contMap.size());
    for (Map.Entry<String, ICodeWriter> entry : contMap.entrySet()) {
        String fileName = entry.getKey();
        ICodeWriter content = entry.getValue();
        content.decIndent();
        content.startLine("</resources>");
        ICodeInfo codeInfo = content.finish();
        files.add(ResContainer.textResource(fileName, codeInfo));
    }
    Collections.sort(files);
    return files;
}
Also used : HashMap(java.util.HashMap) ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) SimpleCodeWriter(jadx.api.impl.SimpleCodeWriter) ArrayList(java.util.ArrayList) ICodeInfo(jadx.api.ICodeInfo) ICodeWriter(jadx.api.ICodeWriter) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ICodeWriter (jadx.api.ICodeWriter)11 SimpleCodeWriter (jadx.api.impl.SimpleCodeWriter)6 InsnNode (jadx.core.dex.nodes.InsnNode)4 MethodNode (jadx.core.dex.nodes.MethodNode)4 CodegenException (jadx.core.utils.exceptions.CodegenException)4 InsnCodeOffset (jadx.api.data.annotations.InsnCodeOffset)3 MethodGen (jadx.core.codegen.MethodGen)3 AType (jadx.core.dex.attributes.AType)3 MethodOverrideAttr (jadx.core.dex.attributes.nodes.MethodOverrideAttr)3 IDexTreeVisitor (jadx.core.dex.visitors.IDexTreeVisitor)3 CommentsLevel (jadx.api.CommentsLevel)2 ICodeInfo (jadx.api.ICodeInfo)2 VarDeclareRef (jadx.api.data.annotations.VarDeclareRef)2 AccessFlags (jadx.api.plugins.input.data.AccessFlags)2 EncodedValue (jadx.api.plugins.input.data.annotations.EncodedValue)2 JadxAttrType (jadx.api.plugins.input.data.attributes.JadxAttrType)2 AnnotationMethodParamsAttr (jadx.api.plugins.input.data.attributes.types.AnnotationMethodParamsAttr)2 Consts (jadx.core.Consts)2 Jadx (jadx.core.Jadx)2 InsnGen (jadx.core.codegen.InsnGen)2