private void find9patchChunk(DataInput di) throws JadxException, IOException { di.skipBytes(8); while (true) { int size; try { size = di.readInt(); } catch (IOException ex) { throw new JadxException("Cant find nine patch chunk", ex); } if (di.readInt() == NP_CHUNK_TYPE) { return; } di.skipBytes(size + 4); } }
private boolean process(JCommanderWrapper jcw) { if (printHelp) { jcw.printUsage(); return false; } if (printVersion) { System.out.println(JadxDecompiler.getVersion()); return false; } try { if (threadsCount <= 0) { throw new JadxException("Threads count must be positive, got: " + threadsCount); } if (verbose) { 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()); jcw.printUsage(); return false; } return true; }
private List<IDexTreeVisitor> getPassesList(JadxDecompiler jadx) { RootNode root = JadxInternalAccess.getRoot(jadx); List<IDexTreeVisitor> passesList = Jadx.getPassesList(jadx.getArgs()); passesList.forEach(pass -> { try { pass.init(root); } catch (JadxException e) { e.printStackTrace(); fail(e.getMessage()); } }); return passesList; }
static ResContainer loadContent(JadxDecompiler jadxRef, ResourceFile rf) { try { return decodeStream(rf, (size, is) -> loadContent(jadxRef, rf, is)); } catch (JadxException e) { LOG.error("Decode error", e); CodeWriter cw = new CodeWriter(); cw.add("Error decode ").add(rf.getType().toString().toLowerCase()); cw.startLine(Utils.getStackTrace(e.getCause())); return ResContainer.textResource(rf.getName(), cw); } }
public byte[] convert(String javaFile) throws JadxException { try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream errOut = new ByteArrayOutputStream()) { DxContext context = new DxContext(out, errOut); DxArgs args = new DxArgs(context, "-", new String[]{javaFile}); int result = (new Main(context)).runDx(args); dxErrors = errOut.toString(CHARSET_NAME); if (result != 0) { throw new JadxException("Java to dex conversion error, code: " + result); } return out.toByteArray(); } catch (Exception e) { throw new JadxException("dx exception: " + e.getMessage(), e); } }
public void decode(InputStream in, OutputStream out) throws JadxException { try { byte[] data = IOUtils.toByteArray(in); BufferedImage im = ImageIO.read(new ByteArrayInputStream(data)); int w = im.getWidth(); int h = im.getHeight(); BufferedImage im2 = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB); im2.createGraphics().drawImage(im, 1, 1, w, h, null); NinePatch np = getNinePatch(data); drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight); drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom); int[] xDivs = np.xDivs; for (int i = 0; i < xDivs.length; i += 2) { drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]); } int[] yDivs = np.yDivs; for (int i = 0; i < yDivs.length; i += 2) { drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]); } ImageIO.write(im2, "png", out); } catch (IOException | NullPointerException ex) { throw new JadxException(ex.toString()); } }
private static Dex loadFromJar(File jarFile) throws DecodeException { JavaToDex j2d = new JavaToDex(); try { LOG.info("converting to dex: {} ...", jarFile.getName()); byte[] ba = j2d.convert(jarFile.getAbsolutePath()); if (ba.length == 0) { throw new JadxException("Empty dx output"); } return new Dex(ba); } catch (Exception e) { throw new DecodeException("java class to dex conversion error:\n " + e.getMessage(), e); } finally { if (j2d.isError()) { LOG.warn("dx message: {}", j2d.getDxErrors()); } } }
public static <T> T decodeStream(ResourceFile rf, ResourceDecoder<T> decoder) throws JadxException { try { ZipRef zipRef = rf.getZipRef(); if (zipRef == null) { File file = new File(rf.getName()); try (InputStream inputStream = new BufferedInputStream(new FileInputStream(file))) { return decoder.decode(file.length(), inputStream); } } else { try (ZipFile zipFile = new ZipFile(zipRef.getZipFile())) { ZipEntry entry = zipFile.getEntry(zipRef.getEntryName()); if (entry == null) { throw new IOException("Zip entry not found: " + zipRef); } if (!ZipSecurity.isValidZipEntry(entry)) { return null; } try (InputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry))) { return decoder.decode(entry.getSize(), inputStream); } } } } catch (Exception e) { throw new JadxException("Error decode: " + rf.getName(), e); } }