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;
}
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;
}
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);
}
}
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();
}
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);
}
}
Aggregations