Search in sources :

Example 6 with CodeWriter

use of jadx.core.codegen.CodeWriter in project jadx by skylot.

the class JavaClass method getCode.

public String getCode() {
    CodeWriter code = cls.getCode();
    if (code == null) {
        decompile();
        code = cls.getCode();
        if (code == null) {
            return "";
        }
    }
    return code.getCodeStr();
}
Also used : CodeWriter(jadx.core.codegen.CodeWriter)

Example 7 with CodeWriter

use of jadx.core.codegen.CodeWriter in project jadx by skylot.

the class ResourcesLoader method loadToCodeWriter.

public static CodeWriter loadToCodeWriter(InputStream is) throws IOException {
    CodeWriter cw = new CodeWriter();
    ByteArrayOutputStream baos = new ByteArrayOutputStream(READ_BUFFER_SIZE);
    copyStream(is, baos);
    cw.add(baos.toString("UTF-8"));
    return cw;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) CodeWriter(jadx.core.codegen.CodeWriter)

Example 8 with CodeWriter

use of jadx.core.codegen.CodeWriter in project jadx by skylot.

the class TestLineNumbers2 method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    CodeWriter codeWriter = cls.getCode();
    String code = codeWriter.toString();
    Map<Integer, Integer> lineMapping = codeWriter.getLineMapping();
    assertEquals("{8=18, 11=22, 12=23, 13=24, 14=28, 16=25, 17=26, 18=28, 21=31, 22=32}", lineMapping.toString());
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CodeWriter(jadx.core.codegen.CodeWriter) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 9 with CodeWriter

use of jadx.core.codegen.CodeWriter in project jadx by skylot.

the class TestReturnSourceLine method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    CodeWriter codeWriter = cls.getCode();
    String code = codeWriter.toString();
    String[] lines = code.split(CodeWriter.NL);
    MethodNode test1 = cls.searchMethodByName("test1(Z)I");
    checkLine(lines, codeWriter, test1, 3, "return 1;");
    MethodNode test2 = cls.searchMethodByName("test2(I)I");
    checkLine(lines, codeWriter, test2, 3, "return v - 1;");
//		TODO:
//		MethodNode test3 = cls.searchMethodByName("test3(I)I");
//		checkLine(lines, codeWriter, test3, 3, "return v;");
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) MethodNode(jadx.core.dex.nodes.MethodNode) CodeWriter(jadx.core.codegen.CodeWriter) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 10 with CodeWriter

use of jadx.core.codegen.CodeWriter in project jadx by skylot.

the class BinaryXMLParser method parse.

public synchronized CodeWriter parse(InputStream inputStream) throws IOException {
    is = new ParserStream(inputStream);
    if (!isBinaryXml()) {
        return ResourcesLoader.loadToCodeWriter(inputStream);
    }
    writer = new CodeWriter();
    writer.add("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    firstElement = true;
    decode();
    writer.finish();
    return writer;
}
Also used : CodeWriter(jadx.core.codegen.CodeWriter)

Aggregations

CodeWriter (jadx.core.codegen.CodeWriter)11 ClassNode (jadx.core.dex.nodes.ClassNode)2 ResourceEntry (jadx.core.xmlgen.entry.ResourceEntry)2 IntegrationTest (jadx.tests.api.IntegrationTest)2 Test (org.junit.Test)2 ResourceFile (jadx.api.ResourceFile)1 ResourceFileContent (jadx.api.ResourceFileContent)1 InsnGen (jadx.core.codegen.InsnGen)1 MethodGen (jadx.core.codegen.MethodGen)1 InsnNode (jadx.core.dex.nodes.InsnNode)1 MethodNode (jadx.core.dex.nodes.MethodNode)1 CodegenException (jadx.core.utils.exceptions.CodegenException)1 FileUtils.prepareFile (jadx.core.utils.files.FileUtils.prepareFile)1 ResContainer (jadx.core.xmlgen.ResContainer)1 ValuesParser (jadx.core.xmlgen.entry.ValuesParser)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1