Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- .adwind -file decoder
- 1st compile
- javac decoder.java
- 2nd find the password/key, usually found in the file ID
- 3rd run the decoder:
- java decoder password file [file2] [file3...]
- */
- import java.io.*;
- import java.util.zip.GZIPInputStream;
- public class decoder {
- private static String pass;
- public static void main (String[] args) {
- if (args.length < 2) {
- System.out.println("Usage: java decoder pass file1 [file2]...");
- return ;
- }
- pass = args[0];
- try{
- for (int i = 1; i<args.length; i++){
- String filename = args[i];
- String extension = filename.substring(filename.lastIndexOf("."));
- filename = filename.substring(0, filename.lastIndexOf("."));
- byte[] data = loadClassData(args[i]);
- FileOutputStream fos = new FileOutputStream(new File(filename + ".decompiled" + extension));
- BufferedOutputStream bos = new BufferedOutputStream(fos);
- bos.write(data);
- bos.close();
- System.out.println("Wrote output to "+ filename +".decompiled" + extension + "; data length: " + data.length);
- }
- }catch (Exception ex) {
- System.out.print(ex);
- }
- }
- public static byte[] loadClassData(String name) throws Exception
- {
- byte tmp[];
- tmp = null;
- try {
- InputStream m;
- ByteArrayOutputStream b;
- m = decoder.class.getClassLoader().getResourceAsStream(name);
- b = new ByteArrayOutputStream();
- byte buf[] = new byte[1024];
- int i;
- while((i = m.read(buf)) > -1) {
- b.write(buf, 0, i);
- }
- b.close();
- byte c[] = b.toByteArray();
- System.out.println("Decoding file " + name);
- tmp = decode(pass, b.toByteArray());
- System.out.println("Trying to decompress...");
- return decompress(tmp);
- } catch (IOException ioEx) {
- return tmp;
- } catch (Exception ex) {
- ex.printStackTrace();
- throw ex;
- }
- }
- public static byte[] decompress(byte tmp[]) throws Exception
- {
- try{
- ByteArrayOutputStream out;
- ByteArrayInputStream in = new ByteArrayInputStream(tmp);
- GZIPInputStream inn = new GZIPInputStream(in);
- out = new ByteArrayOutputStream();
- byte buf[] = new byte[1024];
- int i;
- while((i = inn.read(buf)) > -1)
- out.write(buf, 0, i);
- out.close();
- return out.toByteArray();
- }catch(Exception ex){
- System.out.println("Failed to decompress, maybe the file wasn't an archive");
- throw ex;
- }
- }
- public static byte[] decode(String key, byte inp[])
- {
- int Sbox[] = new int[257];
- int Sbox2[] = new int[257];
- int i = 0;
- int j = 0;
- char k = '\0';
- int t = 0;
- int x = 0;
- char temp = '\0';
- for(i = 0; i < 256; i++)
- Sbox[i] = i;
- j = 0;
- for(i = 0; i < 256; i++) {
- if(j == key.length())
- j = 0;
- Sbox2[i] = key.charAt(j++);
- }
- j = 0;
- for(i = 0; i < 256; i++) {
- j = (j + Sbox[i] + Sbox2[i]) % 256;
- temp = (char)Sbox[i];
- Sbox[i] = Sbox[j];
- Sbox[j] = temp;
- }
- i = j = 0;
- for(x = 0; x < inp.length; x++) {
- i = (i + 1) % 256;
- j = (j + Sbox[i]) % 256;
- temp = (char)Sbox[i];
- Sbox[i] = Sbox[j];
- Sbox[j] = temp;
- t = (Sbox[i] + Sbox[j]) % 256;
- k = (char)Sbox[t];
- inp[x] = (byte)(inp[x] ^ k);
- }
- return inp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement