/* BtoI.java by Mark D. LaDue */

/* June 24, 1997 */

/* Copyright (c) 1997 Mark D. LaDue
   You may study, use, modify, and distribute this example for any purpose.
   This example is provided WITHOUT WARRANTY either expressed or implied.  */

/* This Java application reads an input file and converts each byte to its
   corresponding unsigned integer value, with each such integer appearing
   on its own line.  When the input file is a Java class file, the output
   file may be thought of as the array of integers representing that class
   file.  When combined with the output of the "javap" utility and the
   application Inspector.java, this allows one to hack the class file's code
   arrays. The application ItoB.java converts the resulting array of
   integers back to bytes.  While decompilers and disassemblers allow one
   to do this in a much more elegant fashion, such tools are not always
   reliable and effective. */


import java.io.*;

class BtoI {
    public static void main(String[] argv) {

// How on earth do I use this thing?
        if (argv.length != 2) {
            System.out.println("Try \"java BtoI input_file output_file\"");
            System.exit(1);
        }

        try {

// Open the specified input file for reading
            FileInputStream inner = new FileInputStream(argv[0]);

// Open the specified output file for writing
            PrintStream outer = new PrintStream(new FileOutputStream(argv[1]));

// Read each byte and convert it to an unsigned integer
            int b;
            while ((b=inner.read()) >= 0) {
                outer.println(b);
            }
            inner.close();
            outer.close();
        } catch (IOException ioe) {}
    }
}
