Advertisement
Guest User

.adwind file decoder

a guest
May 27th, 2013
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.96 KB | None | 0 0
  1. /*
  2.  .adwind -file decoder
  3.  1st compile
  4.     javac decoder.java
  5.  2nd find the password/key, usually found in the file ID
  6.  3rd run the decoder:
  7.     java decoder password file [file2] [file3...]
  8. */
  9.  
  10. import java.io.*;
  11. import java.util.zip.GZIPInputStream;
  12.  
  13.  
  14. public class decoder {
  15.     private static String pass;
  16.     public static void main (String[] args) {
  17.         if (args.length < 2) {
  18.             System.out.println("Usage: java decoder pass file1 [file2]...");
  19.             return ;
  20.         }
  21.         pass = args[0];
  22.         try{
  23.             for (int i = 1; i<args.length; i++){
  24.                 String filename = args[i];
  25.                 String extension = filename.substring(filename.lastIndexOf("."));
  26.                 filename = filename.substring(0, filename.lastIndexOf("."));
  27.                 byte[] data = loadClassData(args[i]);
  28.                 FileOutputStream fos = new FileOutputStream(new File(filename + ".decompiled" + extension));
  29.                 BufferedOutputStream bos = new BufferedOutputStream(fos);
  30.                 bos.write(data);
  31.                 bos.close();
  32.                 System.out.println("Wrote output to "+ filename +".decompiled" + extension + "; data length: " + data.length);
  33.             }
  34.         }catch (Exception ex) {
  35.             System.out.print(ex);
  36.         }
  37.     }
  38.    
  39.     public static byte[] loadClassData(String name) throws Exception
  40.     {
  41.         byte tmp[];
  42.         tmp = null;
  43.         try {
  44.             InputStream m;
  45.             ByteArrayOutputStream b;
  46.             m = decoder.class.getClassLoader().getResourceAsStream(name);
  47.             b = new ByteArrayOutputStream();
  48.             byte buf[] = new byte[1024];
  49.             int i;
  50.             while((i = m.read(buf)) > -1) {
  51.                 b.write(buf, 0, i);
  52.             }
  53.             b.close();
  54.             byte c[] = b.toByteArray();
  55.             System.out.println("Decoding file " + name);
  56.             tmp = decode(pass, b.toByteArray());
  57.             System.out.println("Trying to decompress...");
  58.             return decompress(tmp);
  59.         } catch (IOException ioEx) {
  60.             return tmp;
  61.         } catch (Exception ex) {
  62.             ex.printStackTrace();
  63.             throw ex;
  64.         }
  65.  
  66.     }
  67.    
  68.     public static byte[] decompress(byte tmp[]) throws Exception
  69.     {
  70.         try{
  71.             ByteArrayOutputStream out;
  72.             ByteArrayInputStream in = new ByteArrayInputStream(tmp);
  73.             GZIPInputStream inn = new GZIPInputStream(in);
  74.             out = new ByteArrayOutputStream();
  75.             byte buf[] = new byte[1024];
  76.             int i;
  77.             while((i = inn.read(buf)) > -1)
  78.                 out.write(buf, 0, i);
  79.             out.close();
  80.             return out.toByteArray();
  81.         }catch(Exception ex){
  82.             System.out.println("Failed to decompress, maybe the file wasn't an archive");
  83.             throw ex;
  84.         }
  85.     }
  86.    
  87.     public static byte[] decode(String key, byte inp[])
  88.     {
  89.         int Sbox[] = new int[257];
  90.         int Sbox2[] = new int[257];
  91.         int i = 0;
  92.         int j = 0;
  93.         char k = '\0';
  94.         int t = 0;
  95.         int x = 0;
  96.         char temp = '\0';
  97.         for(i = 0; i < 256; i++)
  98.             Sbox[i] = i;
  99.  
  100.         j = 0;
  101.         for(i = 0; i < 256; i++) {
  102.             if(j == key.length())
  103.                 j = 0;
  104.             Sbox2[i] = key.charAt(j++);
  105.         }
  106.         j = 0;
  107.         for(i = 0; i < 256; i++) {
  108.             j = (j + Sbox[i] + Sbox2[i]) % 256;
  109.             temp = (char)Sbox[i];
  110.             Sbox[i] = Sbox[j];
  111.             Sbox[j] = temp;
  112.         }
  113.  
  114.         i = j = 0;
  115.         for(x = 0; x < inp.length; x++) {
  116.             i = (i + 1) % 256;
  117.             j = (j + Sbox[i]) % 256;
  118.             temp = (char)Sbox[i];
  119.             Sbox[i] = Sbox[j];
  120.             Sbox[j] = temp;
  121.             t = (Sbox[i] + Sbox[j]) % 256;
  122.             k = (char)Sbox[t];
  123.             inp[x] = (byte)(inp[x] ^ k);
  124.         }
  125.  
  126.         return inp;
  127.     }
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement