@Throws(IOException::class) fun openInputFileAsZip(fileName: String): RandomAccessFile? { val zipFile: ZipFile try { zipFile = ZipFile(fileName) } catch (fnfe: FileNotFoundException) { System.err.println("Unable to open '" + fileName + "': " + fnfe.getMessage()) throw fnfe } catch (ze: ZipException) { return null } val entry: ZipEntry = zipFile.getEntry(CLASSES_DEX) if (entry == null) { System.err.println("Unable to find '" + CLASSES_DEX.toString() + "' in '" + fileName + "'") zipFile.close() throw ZipException() } val zis: InputStream = zipFile.getInputStream(entry) val tempFile: File = File.createTempFile("dexdeps", ".dex") val raf = RandomAccessFile(tempFile, "rw") tempFile.delete() val copyBuf = ByteArray(32768) var actual: Int while (true) { actual = zis.read(copyBuf) if (actual == -1) break raf.write(copyBuf, 0, actual) } zis.close() raf.seek(0) return raf }
Tries to open an input file as a Zip archive ( jar/apk ) with a `` classes.dex '' inside .