Search in sources :

Example 1 with JadxException

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

the class IntegrationTest method getClassNodeFromFile.

public ClassNode getClassNodeFromFile(File file, String clsName) {
    JadxDecompiler d = new JadxDecompiler(args);
    try {
        d.loadFile(file);
    } catch (JadxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    RootNode root = JadxInternalAccess.getRoot(d);
    root.getConstValues().getResourcesNames().putAll(resMap);
    ClassNode cls = root.searchClassByName(clsName);
    assertThat("Class not found: " + clsName, cls, notNullValue());
    assertThat(clsName, is(cls.getClassInfo().getFullName()));
    if (unloadCls) {
        decompile(d, cls);
    } else {
        decompileWithoutUnload(d, cls);
    }
    System.out.println("-----------------------------------------------------------");
    System.out.println(cls.getCode());
    System.out.println("-----------------------------------------------------------");
    checkCode(cls);
    compile(cls);
    runAutoCheck(clsName);
    return cls;
}
Also used : JadxException(jadx.core.utils.exceptions.JadxException) RootNode(jadx.core.dex.nodes.RootNode) ClassNode(jadx.core.dex.nodes.ClassNode) JadxDecompiler(jadx.api.JadxDecompiler)

Example 2 with JadxException

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

the class JadxCLIArgs method process.

private boolean process() {
    if (isPrintHelp()) {
        printUsage();
        return false;
    }
    try {
        if (threadsCount <= 0) {
            throw new JadxException("Threads count must be positive");
        }
        if (files != null) {
            for (String fileName : files) {
                File file = new File(fileName);
                if (file.exists()) {
                    input.add(file);
                } else {
                    throw new JadxException("File not found: " + file);
                }
            }
        }
        if (input.size() > 1) {
            throw new JadxException("Only one input file is supported");
        }
        if (outDirName != null) {
            outputDir = new File(outDirName);
        }
        if (isVerbose()) {
            ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
            // remove INFO ThresholdFilter
            Appender<ILoggingEvent> appender = rootLogger.getAppender("STDOUT");
            if (appender != null) {
                appender.clearAllFilters();
            }
        }
    } catch (JadxException e) {
        System.err.println("ERROR: " + e.getMessage());
        printUsage();
        return false;
    }
    return true;
}
Also used : JadxException(jadx.core.utils.exceptions.JadxException) Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) File(java.io.File)

Example 3 with JadxException

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

the class InputFile method loadFromJar.

private static Dex loadFromJar(File jarFile) throws DecodeException {
    try {
        LOG.info("converting to dex: {} ...", jarFile.getName());
        JavaToDex j2d = new JavaToDex();
        byte[] ba = j2d.convert(jarFile.getAbsolutePath());
        if (ba.length == 0) {
            throw new JadxException(j2d.isError() ? j2d.getDxErrors() : "Empty dx output");
        }
        if (j2d.isError()) {
            LOG.warn("dx message: {}", j2d.getDxErrors());
        }
        return new Dex(ba);
    } catch (Throwable e) {
        throw new DecodeException("java class to dex conversion error:\n " + e.getMessage(), e);
    }
}
Also used : JadxException(jadx.core.utils.exceptions.JadxException) Dex(com.android.dex.Dex) DecodeException(jadx.core.utils.exceptions.DecodeException)

Example 4 with JadxException

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

the class JavaToDex method convert.

public byte[] convert(String javaFile) throws JadxException {
    ByteArrayOutputStream errOut = new ByteArrayOutputStream();
    try {
        DxConsole.err = new PrintStream(errOut, true, CHARSET_NAME);
    } catch (UnsupportedEncodingException e) {
        throw new JadxException(e.getMessage(), e);
    }
    PrintStream oldOut = System.out;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        setOut(new PrintStream(baos, true, CHARSET_NAME));
        DxArgs args = new DxArgs("-", new String[] { javaFile });
        resetOutDexVar();
        run(args);
    } catch (Throwable e) {
        throw new JadxException("dx exception: " + e.getMessage(), e);
    } finally {
        close(baos);
        System.setOut(oldOut);
    }
    try {
        // errOut also contains warnings
        dxErrors = errOut.toString(CHARSET_NAME);
    } catch (UnsupportedEncodingException e) {
        throw new JadxException("Can't save error output", e);
    }
    return baos.toByteArray();
}
Also used : JadxException(jadx.core.utils.exceptions.JadxException) PrintStream(java.io.PrintStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with JadxException

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

the class JavaToDex method resetOutDexVar.

private void resetOutDexVar() throws JadxException {
    try {
        Field outputDex = Main.class.getDeclaredField("outputDex");
        outputDex.setAccessible(true);
        outputDex.set(null, null);
    } catch (Exception e) {
        throw new JadxException("Failed to reset outputDex field", e);
    }
}
Also used : JadxException(jadx.core.utils.exceptions.JadxException) Field(java.lang.reflect.Field) JadxException(jadx.core.utils.exceptions.JadxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

JadxException (jadx.core.utils.exceptions.JadxException)9 File (java.io.File)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 Dex (com.android.dex.Dex)1 JadxDecompiler (jadx.api.JadxDecompiler)1 ZipRef (jadx.api.ResourceFile.ZipRef)1 AccessInfo (jadx.core.dex.info.AccessInfo)1 ClassNode (jadx.core.dex.nodes.ClassNode)1 RootNode (jadx.core.dex.nodes.RootNode)1 DecodeException (jadx.core.utils.exceptions.DecodeException)1 InputFile (jadx.core.utils.files.InputFile)1 ResContainer (jadx.core.xmlgen.ResContainer)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 Field (java.lang.reflect.Field)1 ZipEntry (java.util.zip.ZipEntry)1