首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

探测容易的 rar 密码

2012-10-20 
探测简单的 rar 密码密码格式:年月日(yyyyMMdd)package org.demoimport java.io.BufferedReaderimport j

探测简单的 rar 密码

密码格式:年月日(yyyyMMdd)

package org.demo;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;/** * 探测 rar 压缩包的密码 * <p> * 针对密码格式为 yyyyMMdd 的 rar 压缩包,使用穷举法探测密码 * <p> *  */public class RarPasswordTest{    /**     *      * 探测 rar 压缩包的密码,密码格式为:yyyyMMdd     *      * @param args fileName startDate endDate     * @throws Exception     */    public static void main(String[] args) throws Exception    {        String path = "E:\\password_test.rar";        String cmd_prefix = ""C:\\Program Files\\WinRAR\\rar.exe" -y x -p";                // 分析入参        int start = 20110901;        int end = 20111231;if (args.length > 0){    path = args[0];}        if (args.length > 2){                        start = Integer.parseInt(args[1]);            end = Integer.parseInt(args[2]);        }                Runtime runtime = Runtime.getRuntime();        String cmd = null;        for (int i=start; i < end; i++){            // command            cmd = cmd_prefix + i + " " + path;                                    // execute command            Process proc = runtime.exec(cmd);                                    // out information (这里inputStream和errorStream 需要同时读,否则会发生死锁的情况)            new Thread(new OutTask(proc.getInputStream())).start();                        // error information            InputStream is = proc.getErrorStream();            BufferedReader br = new BufferedReader(new InputStreamReader(is, "gbk"));            String data = null;                        boolean finish = true;            while((data = br.readLine()) != null){                if (data.contains("errors") || data.contains("failed")){                    finish = false;                    break;                }            }            br.close();                        if (finish){                System.out.println("------- password -------");                System.out.println(i);                System.out.println("> finished");                System.exit(0);            }            System.out.println(i);        }                System.out.println("> exit");    }}class OutTask implements Runnable{    private InputStream is;        public OutTask(InputStream is){        this.is = is;    }        @Override    public void run()    {        try {            BufferedReader br = new BufferedReader(new InputStreamReader(is, "gbk"));            while(br.readLine() != null){                // ..            }            br.close();        } catch(Exception e){                    }            }    }   

?

热点排行