import jp.hishidama.zip.ZipCloak; import jp.hishidama.zip.ZipEntry; import jp.hishidama.zip.ZipFile; import java.io.File; import java.nio.charset.Charset; import java.io.UnsupportedEncodingException; import java.util.*; import java.io.*; class ZipDecrypt { static byte begin = '!'; // 対象文字列の始まり static byte end = '~'; // 対象文字列の終わり static int MaxPwLength=5; // 探索するパスワードの長さ //public static String bruteforce(ZipCloak zip, File dst) { public static String bruteforce(File src, File dst) throws Exception{ System.out.println("bruteforce called"); for(int pwlength=1; pwlength<=MaxPwLength; pwlength++) { // 文字数が変わったら作り直す byte[] passwd = new byte[pwlength]; for(int i=0; i= 0; i--) { if(passwd[i] == end+1) { passwd[i] = begin; if(i > 0) { passwd[i-1]++; } carry = true; } else { carry = false; } } } } return ""; } public static boolean challange(ZipCloak zip, File dst, byte[] pw) { try { //System.out.println("Trying '" + new String(pw, 0, pw.length) + "'..."); zip.decrypt(dst, pw); } catch (java.util.zip.ZipException e) { return false; } catch (java.io.IOException e) { System.out.println("IOException!!!"); return false; } return true; } /* public static boolean challange(File src, byte[] pw) { try { ZipFile zf = new ZipFile(src); zf.setPassword(pw); zf.setCheckCrc(true); for(Iterator i=zf.getEntriesIterator(); i.hasNext();) { ZipEntry ze = i.next(); InputStream is = zf.getInputStream(ze); for(;;) { int c = is.read(); if (c == -1) break; } System.out.println("***DEBUG*** Trying.. " + new String(pw,0,pw.length)); } zf.close(); } catch (jp.hishidama.zip.ZipPasswordException e) { return false; } catch (jp.hishidama.zip.ZipCrcException e) { return false; } catch (java.util.zip.ZipException e) { return false; } catch (java.io.IOException e) { return false; / } catch (Exception e) { return false; } return true; }*/ public static boolean challange(File src, byte[] pw) throws Exception{ ZipFile zf = null; //InputStream is = new InputStream(); try { zf = new ZipFile(src); zf.setPassword(pw); zf.setCheckCrc(true); for(Iterator i=zf.getEntriesIterator(); i.hasNext();) { ZipEntry ze = i.next(); InputStream is = zf.getInputStream(ze); ByteArrayOutputStream bos = new ByteArrayOutputStream(); for(;;) { int c = is.read(); if (c == -1) break; bos.write(c); } System.out.println("***DEBUG*** Trying.. " + new String(pw,0,pw.length)); } } catch (jp.hishidama.zip.ZipPasswordException e) { return false; } catch (jp.hishidama.zip.ZipCrcException e) { return false; } catch (java.util.zip.ZipException e) { return false; //} catch (java.io.IOException e) { // return false; } catch (Exception e) { //System.out.println(new String(pw,0,pw.length)); e.printStackTrace(); return false; } finally { //if (is != null) is.close(); if (zf != null) zf.close(); } return true; } public static void main(String[] args) throws Exception { File src = new File(args[0]); File dst = new File(args[1]); ZipCloak zip = new ZipCloak(src); //System.out.println(bruteforce(zip,dst)); System.out.println(bruteforce(src,dst)); } }