FileDocCategorySizeDatePackage
PasswordDumper5.javaAPI DocExample5043Sun Mar 28 07:21:06 BST 1999None

FileDumper5

public class FileDumper5 extends Object

Fields Summary
public static final int
ASC
public static final int
DEC
public static final int
HEX
public static final int
SHORT
public static final int
INT
public static final int
LONG
public static final int
FLOAT
public static final int
DOUBLE
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

  

       

    if (args.length < 1) {
      System.err.println(
       "Usage: java FileDumper2 [-ahdsilfx] [-little] [-gzip|-deflated] [-password password] file1...");
    }

    boolean bigEndian = true; 
    int firstFile = 0;
    int mode = ASC;
    boolean deflated = false;
    boolean gzipped = false;
    String password = null;
    
    // process command line switches
    for (firstFile = 0; firstFile < args.length; firstFile++) {
      if (!args[firstFile].startsWith("-")) break;
      if (args[firstFile].equals("-h")) mode = HEX;
      else if (args[firstFile].equals("-d")) mode = DEC;
      else if (args[firstFile].equals("-s")) mode = SHORT;
      else if (args[firstFile].equals("-i")) mode = INT;
      else if (args[firstFile].equals("-l")) mode = LONG;
      else if (args[firstFile].equals("-f")) mode = FLOAT;
      else if (args[firstFile].equals("-x")) mode = DOUBLE;
      else if (args[firstFile].equals("-little")) bigEndian = false;
      else if (args[firstFile].equals("-deflated") && !gzipped) deflated = true;
      else if (args[firstFile].equals("-gzip") && !deflated) gzipped = true;
      else if (args[firstFile].equals("-password")) {
        password = args[firstFile+1];
        firstFile++;
      }
    }
    
    for (int i = firstFile; i < args.length; i++) {
      try {
        InputStream in = new FileInputStream(args[i]);

        // Note that the reference variable in
        // may point to several different objects
        // within the space of the next few lines
        
        // other than the command line arguments
        // the following lines are the only real addition        
        if (password != null) {
          PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray());
          SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
          SecretKey pbeKey = keyFactory.generateSecret(pbeKeySpec);
          Cipher pbe = Cipher.getInstance("PBEWithMD5AndDES");
          byte[] salt = { (byte) 0x9C, (byte) 0x8A, (byte) 0xFF, (byte) 0xEF, 
           (byte) 0x76, (byte) 0x23, (byte) 0x29, (byte) 0x02, };
          PBEParameterSpec paramspec = new PBEParameterSpec(salt, 20);
          pbe.init(Cipher.DECRYPT_MODE, pbeKey, paramspec);
          in = new CipherInputStream(in, pbe);
        }
        
        if (deflated) {
          in = new InflaterInputStream(in);
        }
        else if (gzipped) {
          in = new GZIPInputStream(in);
        }
        
        if (bigEndian) {
          DataInputStream din = new DataInputStream(in);
          switch (mode) {
            case HEX: 
              in = new HexFilter(in);
              break;
            case DEC: 
              in = new DecimalFilter(in);
              break;
            case INT: 
              in = new IntFilter(din);
              break;
            case SHORT: 
              in = new ShortFilter(din);
              break;
            case LONG: 
              in = new LongFilter(din);
              break;
            case DOUBLE: 
              in = new DoubleFilter(din);
              break;
            case FLOAT: 
              in = new FloatFilter(din);
              break;
            default:
          }
        }
        else {
          LittleEndianInputStream lin = new LittleEndianInputStream(in);
          switch (mode) {
            case HEX: 
              in = new HexFilter(in);
              break;
            case DEC: 
              in = new DecimalFilter(in);
              break;
            case INT: 
              in = new LEIntFilter(lin);
              break;
            case SHORT: 
              in = new LEShortFilter(lin);
              break;
            case LONG: 
              in = new LELongFilter(lin);
              break;
            case DOUBLE: 
              in = new LEDoubleFilter(lin);
              break;
            case FLOAT: 
              in = new LEFloatFilter(lin);
              break;
            default:  
          }
        }
        
        StreamCopier.copy(in, System.out);
        in.close();
        
        if (i < args.length-1) {  // more files to dump
          System.out.println();
          System.out.println("--------------------------------------");
          System.out.println();
        }
        
      }
      catch (Exception e) {
        System.err.println(e);
        e.printStackTrace();
      }
        
    }