tags:

views:

1020

answers:

3

I'm working on a project fuzzing a media player. I wrote the file generator in Java and converted the CRC generator from the original compression code written in C. I can write data fine with DataOutputStream, but I can't figure out how to send the data as an unsigned character array in java. In C this is a very straightforward process. I have searched for a solution pretty thoroughly, and the best solution I've found is to just send the data to C and let C return a CRC. I may just not be searching correctly as I'm pretty unfamiliar with this stuff. Thank you very much for any help.

+1  A: 

I doubt that you want to do anything with characters. I can't see anything in your description which suggests text manipulation, which is what you'd do with characters.

You want to use a byte array. It's a bit of a pain that bytes are signed in Java, but a byte array is what you've got - just work with the bit patterns rather than thinking of them as actual numbers, and check each operation carefully.

Jon Skeet
It sounds more like he's struggling with the signedness aspect, not what the Java equivalent to a C char is, no? The bit pattern advice is solid, though.
Matt J
Matt: While I suspect the OP struggling with the signedness, the fact that "byte" doesn't appear once in the description makes it pretty unclear that they know they should be using a byte array.
Jon Skeet
A: 

Most CRC operators use mostly bitwise shifts and XORs. These should work fine on Java, which does not support unsigned integer primitives. If you need other arithmetic to work properly, you could try casting to a short.

Matt J
+5  A: 

You definitely want a byte[]. A 'byte' is equivalent to a signed char in C. Java's "char" is a 16-bit unicode value and not really equivalent at all.

If it's for fuzzing, unless there's something special about the CRC function you're using, I imagine you could simply use:

import java.util.Random;
Random randgen = new Random();

byte[] fuzzbytes = new byte[numbytes];
randgen.nextBytes(fuzzbytes);
outstream.write(fuzzbytes, 0, numbytes);
I am definitely using random bytes for the actual audio data, but right now I am trying to create legitimate headers and seek points and such. Thank you though, I will definitely try the byte array.
grossmae