hexdump.java

Output from this program:

C:\ece538\WMF>java hexdump hex1.wmf
00000000: 01 00 09 00 00 03 36 00 00 00 02 00 0c 00 00 00
00000010: 00 00 08 00 00 00 fa 02 04 00 00 00 00 00 00 00
00000020: ff 00 04 00 00 00 2d 01 00 00 07 00 00 00 fc 02
00000030: 02 00 00 ff 00 ff 04 00 04 00 00 00 2c 01 01 00
00000040: 07 00 00 00 1b 04 46 00 3f 00 00 00 00 00 0c 00
00000050: 00 00 21 05 0c 00 48 65 6c 6c 6f 20 50 65 6f 70
00000060: 6c 65 0a 00 0a 00 03 00 00 00 00 00

Original hex file:

00000000: 01 00 09 00 00 03 36 00 00 00 02 00 0C 00 00 00 …...6......... 
00000010: 00 00 08 00 00 00 FA 02 04 00 00 00 00 00 00 00 ......ú......... 
00000020: FF 00 04 00 00 00 2D 01 00 00 07 00 00 00 FC 02 ÿ.....-.......ü. 
00000030: 02 00 00 FF 00 FF 04 00 04 00 00 00 2C 01 01 00 ...ÿ.ÿ......,... 
00000040: 07 00 00 00 1B 04 46 00 96 00 00 00 00 00 0C 00 ......F.–....... 
00000050: 00 00 21 05 0C 00 48 65 6C 6C 6F 20 50 65 6F 70 ..!...Hello Peop 
00000060: 6C 65 0A 00 0A 00 03 00 00 00 00 00             

The original file (hex1.txt) was converted to binary (hex1.wmf) and then dumped to text again by this program.


hexdump.java

import java.io.*;
import java.util.Arrays;


public class hexdump {

public static int get32(byte[] b) {
	int v;
	v  = (b[3]&0xff)<<24;
	v += (b[2]&0xff)<<16;
	v += (b[1]&0xff)<<8;
	v += (b[0]&0xff);
	return v;
}

public static int get16(byte[] b) {
	int v;
	v = (b[1]&0xff)<<8;
	v += (b[0]&0xff);
	return v;
}

public static void readFile(String filename) {

	try(BufferedInputStream in = new BufferedInputStream(new FileInputStream(filename))) {
		byte[] b = new byte[64];
		byte[] c;
		int eof, count, n, type;
		int v1,v2;
		count = 0;
		n = 0;
		while (in.read(b,0,1)>0) {
			if (n==0) {
				System.out.format("%08x:",count);
				count +=16;
			}
			n += 1;
			System.out.format(" %02x",b[0]);
			if (n==16) {
				n=0;
				System.out.println();
			}
		}
		in.close();

	}
	catch(Exception e) {
		System.err.println(e);
	}
}


public static void main(String [] args) {
	String filename = "hex1.wmf";
	if (args.length>0) filename = args[0];

	readFile(filename);
}

}


Maintained by John Loomis, updated Mon Mar 27 13:48:06 2017