I wanted to make a program that deals with the editing of hex files, but I'm not sure how I would go about doing this. Normally I can just input a file into a Java program, read it into a String, then do what I please with it.

If any of you are familiar with it, I wish to edit .gct files, files used to hold codes for Wii games. The only problem I imagine I would have is that you can't open gct files in notepad or something to see the codes, it's all a garbled mess. To view the contents you have to use a hex editor program. Contents of a gct file are normally something like this:

00 D0 C0 DE 00 D0 C0 DE 24 49 4A 98 80 00 00 00
20 52 33 00 00 00 00 00 04 52 33 00 DE AD BE EF
42 00 00 00 90 00 00 00 04 17 F3 60 00 00 01 04
04 17 F3 64 04 02 0A 00 04 17 F3 68 08 01 01 01
04 17 F3 6C 01 00 00 00 E0 00 00 00 80 00 80 00
22 56 64 EC 00 00 00 00 04 01 BF E0 48 58 BE 20
06 5A 7E 00 00 00 00 70 38 A0 00 67 38 81 00 20
3C E0 80 5A 60 E3 7C 18 4B E5 25 31 38 A0 00 7F
38 83 FF E8 38 61 00 20 4B E5 25 21 38 A0 00 68
60 E4 7C 18 38 61 00 20 94 21 FF 80 BC 41 00 08
38 61 00 88 4B A7 4D B9 7C 7C 1B 78 2C 03 00 00
40 82 00 0C 38 21 00 80 48 00 00 1C B8 41 00 08
38 21 00 80 4B E5 24 E5 38 61 00 08 4B A7 42 E1
7C 7C 1B 78 4B A7 41 E8 04 01 CD 0C 48 58 B1 F4
06 5A 7F 00 00 00 00 18 2C 03 00 00 41 82 00 0C
4B A7 DD 51 48 00 00 08 80 78 00 0C 4B A7 4D FC
04 3E E9 D8 48 00 00 14 04 3E EB D4 48 00 00 14
04 3D 8B 9C 48 00 00 18 04 3E 9B 4C 38 60 00 00
04 3E 9D 38 38 60 00 00 04 3D 8C 80 60 00 00 00
80 00 00 00 80 40 69 20 80 00 00 01 80 5A 7C 00
8A 00 10 01 00 00 00 00 04 5A 7C 10 2F 52 53 42
04 5A 7C 14 45 2F 70 66 E0 00 00 00 80 00 80 00
04 0A 7D 60 4E 80 00 20 04 10 9D 88 38 80 00 01
F0 00 00 00 00 00 00 00

Does anyone know of a way I can read in a gct file like this, move all that data into a String (even if its all with no spaces and such) so I can edit it how I wish using methods I'm familiar with, then output it back to a gct?

I would think there's some kind of Java library out there I could get to do this, but I've tried searching around google and had no luck.

More info on the contents of gcts are here:
http://www.smashboards.com/showthread.php?t=246810

You can read the file as a byte array, then convert each byte to a standard hex String representation with something like

String byteToHex(byte b) {
                // coded for clarity - could be a lot shorter
		char[] chars = { ' ', ' ' };
		chars[0] = "0123456789ABCDEF".charAt((b >> 4) & 0x0F);
		chars[1] = "0123456789ABCDEF".charAt(b & 0x0F);
		return new String(chars);
	}

You can then display/edit the contents in hex, and use something like the reverse of the above code to convert back to bytes and save the file

how can i match 00 01 00 02 (hex, byte) in a image file and get next byte as character

This is an old thread. Start a new thread and explain what you need in more detail (with examples if possible).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.