探测简单的 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){ } } }
?