2.0版のリソースライブラリを解読するファイルアルゴリズム

22593 ワード

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
 
public class CopyFile {
    
    public static void DecodeRes2ByFile(File inFile) throws Exception
    {
        String m_strKey1 = "E5BCB9C350916554349299514FB2B8F8D6B6F38685A7D1971962BDD2F5E0CACDE944D93CA34D0874AB6807F3BD60571A2FAAC7DA2E282324C105F4F23C575810F324E80BE542462782BADE04889A57C0C599911C6E652E6CD5BFD7FF3E6B782E10798621F04D98606B73BAA3F4AE20DEE196851AD1DE44994D108E9F90F0483";
        String m_strKey2 = "1F4057E499C8143031D80E7C3305F74A0AE2BBB1EE77AEB61788883C18E94FCE6DB1176D5B8C3F8345953CFBA30D0503C1924CC48EF4B9530E0FA68900C09E705026F5EC9EDAAF8D69249CFFC303982734976FF92A515DA58B3261B70303D82D63153ACEE65BC9DA2EF09B55F6D24DE9E1276F4D9E574E018D3B2BA4F9520856";

        int key1Len = m_strKey1.length();
        int key2Len = m_strKey2.length();
                       
        File tmp_dir=new File("c:\\temp");
        if(!tmp_dir.exists())
        {
            tmp_dir.mkdir();
        }
        
        String targetFile=tmp_dir+"\\"+inFile.getName();
        File out = new File(targetFile);
        FileInputStream fin=new FileInputStream(inFile);
        FileOutputStream fout=new FileOutputStream(out);
     
        int length=2097152;//2m  
        byte[] buffer=new byte[length];
         
        int     curLength = 0;
        while(true)
        {
            int ins=fin.read(buffer);
            
            
            if(ins==-1)
            {
                fin.close();
                fout.flush();
                fout.close();
                break;                 
            }
            else
            {
                for(int i=0;i<ins;i++)
                {
                    buffer[i]^=m_strKey1.substring(curLength%key1Len,curLength%key1Len+1).getBytes("UTF8")[0];
                    buffer[i]^=m_strKey2.substring(curLength%key2Len,curLength%key2Len+1).getBytes("UTF8")[0];
                    
                    curLength++;
                }
                fout.write(buffer,0,ins);
            }             
        }
        //      
        inFile.delete();  
        //       
        out.renameTo(inFile);
    }
    
    /**
     *   :       ,    
     *   :  
     *   :2014-06-19
     * @param file
     * @throws Exception
     */
    public static void DecodeRes2ByPath(File file) throws Exception
    {
        if (file.isDirectory()) {
            File[] filearry = file.listFiles();
            for (File f : filearry) {
                if (f.isDirectory()) 
                {
                    System.out.println(f.getAbsoluteFile());
                } 
                else 
                {
                     DecodeRes2ByFile(new File(f.getAbsolutePath()));
                     System.out.println(""+f.getAbsolutePath());
                }
                
                DecodeRes2ByPath(f);
            }
        }
    }
    static public void main(String args[]) throws Exception 
    {
                 
         //      ,          ,      ,   
         //File root = new File("C:\\Old");
         //DecodeRes2ByPath(root);
                  
        
         //      ,        .    
         String filepath="C:\\Old\\image\\200810";
         File f=new File(filepath);
         File flist[] = f.listFiles();
        
         
         //                 ,    。
         ThreadPool threadPool = new ThreadPool(4); //      4          
         Thread.sleep(400); //  400  ,                  
         //      
         for (int i = 0; i <flist.length; i++) 
         { //  N     
             threadPool.execute(DecodeFileMultiThread(flist[i]));  
         }  
         threadPool.waitFinish(); //            
         threadPool.closePool(); //       
    }
    
    private static Runnable DecodeFileMultiThread(final File taskID) 
    {  
        return new Runnable() 
        {  
            public void run() 
            {
                try 
                {
                    DecodeRes2ByFile(taskID);
                }
                catch (Exception e) 
                {
                    e.printStackTrace();
                }
            }  
        };  
    }  
}
import java.util.LinkedList;
  
/** 
 * @project LocationGateway 
 * @author sunnylocus    
 * @verson 1.0.0 
 * @date   Aug 2, 2008 
 * @jdk    1.4.2 
 */  
public class ThreadPool extends ThreadGroup {  
    private boolean isClosed = false;  //          
    private LinkedList workQueue;      //      
    private static int threadPoolID = 1;  //    id  
    public ThreadPool(int poolSize) {  //poolSize                 
  
        super(threadPoolID + "");      //  ThreadGroup     
        setDaemon(true);               //
        workQueue = new LinkedList();  //        
        for(int i = 0; i < poolSize; i++) {  
            new WorkThread(i).start();   //         ,                    
        }  
    }  
      
    /**              ,           */  
    public synchronized void execute(Runnable task) {  
        if(isClosed) {  
            throw new IllegalStateException();  
        }  
        if(task != null) {  
            workQueue.add(task);//            
            notify();           //      getTask()             
        }  
    }  
      
    /**             ,          */  
    private synchronized Runnable getTask(int threadid) throws InterruptedException {  
        while(workQueue.size() == 0) {  
            if(isClosed) return null;  
            System.out.println("    "+threadid+"    ...");  
            wait();             //           ,       
        }  
        System.out.println("    "+threadid+"      ...");  
        return (Runnable) workQueue.removeFirst(); //          ,         
    }  
      
    /**       */  
    public synchronized void closePool() {  
        if(! isClosed) {  
            waitFinish();        //            
            isClosed = true;  
            workQueue.clear();  //        
            interrupt();        //              ,      ThreadGroup   
        }  
    }  
      
    /**                */  
    public void waitFinish() {  
        synchronized (this) {  
            isClosed = true;  
            notifyAll();            //      getTask()              
        }  
        Thread[] threads = new Thread[activeCount()]; //activeCount()                。  
        int count = enumerate(threads); //enumerate()     ThreadGroup ,                             
        for(int i =0; i < count; i++) { //            
            try {  
                threads[i].join();  //          
            }catch(InterruptedException ex) {  
                ex.printStackTrace();  
            }  
        }  
    }  
  
    /** 
     *    ,    ,            ,    
     * @author sunnylocus 
     */  
    private class WorkThread extends Thread {  
        private int id;  
        public WorkThread(int id) {  
            //      ,        ThreadPool      
            super(ThreadPool.this,id+"");  
            this.id =id;  
        }  
        public void run() {  
            while(! isInterrupted()) {  //isInterrupted()     Thread ,           
                Runnable task = null;  
                try {  
                    task = getTask(id);     //      
                }catch(InterruptedException ex) {  
                    ex.printStackTrace();  
                }  
                //  getTask()  null      getTask()    ,        
                if(task == null) return;  
                  
                try {  
                    task.run();  //      
                }catch(Throwable t) {  
                    t.printStackTrace();  
                }  
            }//  end while  
        }//  end run  
    }// end workThread  
}