AMF3 integer parsing
Martin Schnabel has done some work on further reverse engineering the integer format in AMF 3, and discovering the undefined type. I have updated my reference AMF 3 implementation accordingly. Including a simpler parse integer algorithm, which I’ve pasted below:
private int readAMF3Integer() throws IOException {
int n = 0;
int b = in.readUnsignedByte();
int result = 0;
while ((b & 0x80) != 0 && n < 3) {
result <<= 7;
result |= (b & 0x7f);
b = in.readUnsignedByte();
n++;
}
if (n < 3) {
result <<= 7;
result |= b;
} else {
/* Use all 8 bits from the 4th byte */
result <<= 8;
result |= b;
/* Check if the integer should be negative */
if ((result & 0x10000000) != 0) {
/* and extend the sign bit */
result |= 0xe0000000;
}
}
return result;
}