Search in sources :

Example 11 with ICodeInfo

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

the class JsonCodeGen method fillMthCode.

private List<JsonCodeLine> fillMthCode(MethodNode mth, MethodGen mthGen) {
    if (mth.isNoCode()) {
        return Collections.emptyList();
    }
    ICodeWriter cw = mth.root().makeCodeWriter();
    try {
        mthGen.addInstructions(cw);
    } catch (Exception e) {
        throw new JadxRuntimeException("Method generation error", e);
    }
    ICodeInfo code = cw.finish();
    String codeStr = code.getCodeStr();
    if (codeStr.isEmpty()) {
        return Collections.emptyList();
    }
    String[] lines = codeStr.split(ICodeWriter.NL);
    Map<Integer, Integer> lineMapping = code.getLineMapping();
    Map<CodePosition, Object> annotations = code.getAnnotations();
    long mthCodeOffset = mth.getMethodCodeOffset() + 16;
    int linesCount = lines.length;
    List<JsonCodeLine> codeLines = new ArrayList<>(linesCount);
    for (int i = 0; i < linesCount; i++) {
        String codeLine = lines[i];
        int line = i + 2;
        JsonCodeLine jsonCodeLine = new JsonCodeLine();
        jsonCodeLine.setCode(codeLine);
        jsonCodeLine.setSourceLine(lineMapping.get(line));
        Object obj = annotations.get(new CodePosition(line));
        if (obj instanceof InsnCodeOffset) {
            long offset = ((InsnCodeOffset) obj).getOffset();
            jsonCodeLine.setOffset("0x" + Long.toHexString(mthCodeOffset + offset * 2));
        }
        codeLines.add(jsonCodeLine);
    }
    return codeLines;
}
Also used : ArrayList(java.util.ArrayList) InsnCodeOffset(jadx.api.data.annotations.InsnCodeOffset) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) CodePosition(jadx.api.CodePosition) ICodeInfo(jadx.api.ICodeInfo) JsonCodeLine(jadx.core.codegen.json.cls.JsonCodeLine) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) ICodeWriter(jadx.api.ICodeWriter)

Example 12 with ICodeInfo

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

the class JResource method loadSubNodes.

private void loadSubNodes(JResource root, ResContainer rc, int depth) {
    String resName = rc.getName();
    String[] path = resName.split("/");
    String resShortName = path.length == 0 ? resName : path[path.length - 1];
    ICodeInfo code = rc.getText();
    ResourceFileContent fileContent = new ResourceFileContent(resShortName, ResourceType.XML, code);
    addPath(path, root, new JResource(fileContent, resName, resShortName, JResType.FILE));
    for (ResContainer subFile : rc.getSubFiles()) {
        loadSubNodes(root, subFile, depth + 1);
    }
}
Also used : ResContainer(jadx.core.xmlgen.ResContainer) ResourceFileContent(jadx.api.ResourceFileContent) ICodeInfo(jadx.api.ICodeInfo)

Example 13 with ICodeInfo

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

the class BinaryXMLParser method parse.

public synchronized ICodeInfo parse(InputStream inputStream) throws IOException {
    is = new ParserStream(inputStream);
    if (!isBinaryXml()) {
        return ResourcesLoader.loadToCodeWriter(inputStream);
    }
    nsMapGenerated = new HashSet<>();
    nsMap = new HashMap<>();
    writer = rootNode.makeCodeWriter();
    writer.add("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    firstElement = true;
    decode();
    nsMap = null;
    ICodeInfo codeInfo = writer.finish();
    // reset class name cache
    this.classNameCache = null;
    return codeInfo;
}
Also used : ICodeInfo(jadx.api.ICodeInfo)

Example 14 with ICodeInfo

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

the class ResTableParser method decodeFiles.

public ResContainer decodeFiles(InputStream inputStream) throws IOException {
    decode(inputStream);
    ValuesParser vp = new ValuesParser(strings, resStorage.getResourcesNames());
    ResXmlGen resGen = new ResXmlGen(resStorage, vp);
    ICodeInfo content = XmlGenUtils.makeXmlDump(root.makeCodeWriter(), resStorage);
    List<ResContainer> xmlFiles = resGen.makeResourcesXml();
    return ResContainer.resourceTable("res", xmlFiles, content);
}
Also used : ICodeInfo(jadx.api.ICodeInfo) ValuesParser(jadx.core.xmlgen.entry.ValuesParser)

Example 15 with ICodeInfo

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

the class JadxClassNodeAssertions method code.

public JadxCodeAssertions code() {
    isNotNull();
    ICodeInfo code = actual.getCode();
    Assertions.assertThat(code).isNotNull();
    String codeStr = code.getCodeStr();
    assertThat(codeStr).isNotBlank();
    return new JadxCodeAssertions(codeStr);
}
Also used : ICodeInfo(jadx.api.ICodeInfo)

Aggregations

ICodeInfo (jadx.api.ICodeInfo)17 ClassNode (jadx.core.dex.nodes.ClassNode)3 ICodeCache (jadx.api.ICodeCache)2 ICodeWriter (jadx.api.ICodeWriter)2 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)2 ResContainer (jadx.core.xmlgen.ResContainer)2 ValuesParser (jadx.core.xmlgen.entry.ValuesParser)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 Package (com.android.aapt.Resources.Package)1 ResourceTable (com.android.aapt.Resources.ResourceTable)1 CodePosition (jadx.api.CodePosition)1 JadxDecompiler (jadx.api.JadxDecompiler)1 ResourceFile (jadx.api.ResourceFile)1 ResourceFileContent (jadx.api.ResourceFileContent)1 InsnCodeOffset (jadx.api.data.annotations.InsnCodeOffset)1 SimpleCodeWriter (jadx.api.impl.SimpleCodeWriter)1 JsonCodeLine (jadx.core.codegen.json.cls.JsonCodeLine)1 AFlag (jadx.core.dex.attributes.AFlag)1