• Welcome to Valhalla Legends Archive.
 

byte limitations

Started by Orillion, December 01, 2003, 12:55 AM

Previous topic - Next topic

Orillion

After testing iago's binary packet buffer he wrote for his Javabot, it became apparent that adding bytes with high values seemed to be impossible so I ran some quick tests only to discover this error


*** Semantic Error: A byte value must be an integer value in the range of -128..127

NOTE: I achieved this error from just compiling a primitive byte with a value of 255.

From my understanding this means we'd never be able to add a byte with a decimal value higher than 127. This would make adding 0xff for example, impossible. Any thoughts on this problem?

iago

Hmm, I think a simple change can fix that.  Just store it as an integer or long until it gets put into a byte, then mask it to put it into the byte.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Etheran

Quote from: Orillion on December 01, 2003, 12:55 AM
After testing iago's binary packet buffer he wrote for his Javabot, it became apparent that adding bytes with high values seemed to be impossible so I ran some quick tests only to discover this error


*** Semantic Error: A byte value must be an integer value in the range of -128..127

NOTE: I achieved this error from just compiling a primitive byte with a value of 255.

From my understanding this means we'd never be able to add a byte with a decimal value higher than 127. This would make adding 0xff for example, impossible. Any thoughts on this problem?
why wouldn't 0xff work?  in a signed variable 0xff = -128 am I wrong?

Skywing

#3
Quote from: Etheran on December 01, 2003, 04:48 PM
Quote from: Orillion on December 01, 2003, 12:55 AM
After testing iago's binary packet buffer he wrote for his Javabot, it became apparent that adding bytes with high values seemed to be impossible so I ran some quick tests only to discover this error


*** Semantic Error: A byte value must be an integer value in the range of -128..127

NOTE: I achieved this error from just compiling a primitive byte with a value of 255.

From my understanding this means we'd never be able to add a byte with a decimal value higher than 127. This would make adding 0xff for example, impossible. Any thoughts on this problem?
why wouldn't 0xff work?  in a signed variable 0xff = -128 am I wrong?
I think the problem they are speaking of is having to use signed constants (this being inconvenient and a pain).

Kp

Quote from: Etheran on December 01, 2003, 04:48 PMin a signed variable 0xff = -128 am I wrong?

Yes.  0xff = 255 = -1.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Etheran

Quote from: Kp on December 01, 2003, 05:54 PM
Quote from: Etheran on December 01, 2003, 04:48 PMin a signed variable 0xff = -128 am I wrong?

Yes.  0xff = 255 = -1.
err yes of course, that would be 0x80 = -128 and 0x7F = 127

Orillion

Yeah the problem i think stems from the fact that java automatically signs everything. Although we have gotten around that to a certain extent

j0k3r

Er, sort of off topic, what part of '0x80' determines that it's negative 128?
QuoteAnyone attempting to generate random numbers by deterministic means is, of course, living in a state of sin
John Vo

Banana fanna fo fanna

The sign bit, or the first bit in the number.

iago

Quote from: St0rm.iD on December 08, 2003, 08:15 AM
The sign bit, or the first bit in the number.

Technically, it's the last bit.  I would call it the left-most bit :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Banana fanna fo fanna


Etheran

and to find your signed value if the sign bit is set, you take the two's complement of the number:
~x + 1

example:

1101 1001 = 0xC9

take the two's complement:

0010 0110 + 1 = 0010 0111 = 39
add the sign and you end up with -39

iago

hmm, I don't see what your problem was.  I just tested it out with the following code:

   public static void main(String args[])
   {
       Buffer buf = new Buffer();

       buf.add((byte)250);
       buf.add((byte)251);
       buf.add((byte)252);
       buf.add((byte)253);
       buf.add((byte)254);
       buf.add((byte)255);

       buf.add((byte)-1);
       buf.add((byte)-2);
       buf.add((byte)-3);
       buf.add((byte)-4);
       buf.add((byte)-5);

       System.out.println(buf.toText());
   }


And it came back with the (correct) results:
Buffer contents:
fa fb fc fd fe ff ff fe fd fc fb                        ...........
Length: 11
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*