bool AMF0Serializer::ReadShortString(IOBuffer &buffer, Variant &variant, bool readType) { if (readType) { AMF_CHECK_BOUNDARIES(buffer, 1); if (GETIBPOINTER(buffer)[0] != AMF0_SHORT_STRING) { FATAL("AMF type not valid: want: %hhu; got: %hhu", AMF0_SHORT_STRING, GETIBPOINTER(buffer)[0]); return false; } if (!buffer.Ignore(1)) { FATAL("Unable to ignore 1 bytes"); return false; } } AMF_CHECK_BOUNDARIES(buffer, 2); uint16_t length = ENTOHSP(GETIBPOINTER(buffer)); //----MARKED-SHORT---- if (!buffer.Ignore(2)) { FATAL("Unable to ignore 2 bytes"); return false; } AMF_CHECK_BOUNDARIES(buffer, length); variant = string((char *) (GETIBPOINTER(buffer)), length); if (!buffer.Ignore(length)) { FATAL("Unable to ignore %hu bytes", length); return false; } return true; }
bool AMF0Serializer::ReadDouble(IOBuffer &buffer, Variant &variant, bool readType) { if (readType) { AMF_CHECK_BOUNDARIES(buffer, 1); if (GETIBPOINTER(buffer)[0] != AMF0_NUMBER) { FATAL("AMF type not valid: want: %hhu; got: %hhu", AMF0_NUMBER, GETIBPOINTER(buffer)[0]); return false; } if (!buffer.Ignore(1)) { FATAL("Unable to ignore 1 bytes"); return false; } } AMF_CHECK_BOUNDARIES(buffer, 8); double temp = 0; ENTOHDP(GETIBPOINTER(buffer), temp); variant = (double) temp; if (!buffer.Ignore(8)) { FATAL("Unable to ignore 8 bytes"); return false; } return true; }
bool AMF0Serializer::ReadLongString(IOBuffer &buffer, Variant &variant, bool readType) { if (readType) { AMF_CHECK_BOUNDARIES(buffer, 1); if (GETIBPOINTER(buffer)[0] != AMF0_LONG_STRING) { FATAL("AMF type not valid: want: %"PRIu8"; got: %"PRIu8, AMF0_LONG_STRING, GETIBPOINTER(buffer)[0]); return false; } if (!buffer.Ignore(1)) { FATAL("Unable to ignore 1 bytes"); return false; } } AMF_CHECK_BOUNDARIES(buffer, 4); uint32_t length = ENTOHLP(GETIBPOINTER(buffer)); //----MARKED-LONG--- if (!buffer.Ignore(4)) { FATAL("Unable to ignore 4 bytes"); return false; } AMF_CHECK_BOUNDARIES(buffer, length); variant = string((char *) (GETIBPOINTER(buffer)), length); if (!buffer.Ignore(length)) { FATAL("Unable to ignore %"PRIu32" bytes", length); return false; } return true; }
bool AMF0Serializer::ReadObject(IOBuffer &buffer, Variant &variant, bool readType) { if (readType) { AMF_CHECK_BOUNDARIES(buffer, 1); if (GETIBPOINTER(buffer)[0] != AMF0_OBJECT) { FATAL("AMF type not valid: want: %"PRIu8"; got: %"PRIu8, AMF0_OBJECT, GETIBPOINTER(buffer)[0]); return false; } if (!buffer.Ignore(1)) { FATAL("Unable to ignore 1 bytes"); return false; } } AMF_CHECK_BOUNDARIES(buffer, 3); while (!((GETIBPOINTER(buffer)[0] == 0) && (GETIBPOINTER(buffer)[1] == 0) && (GETIBPOINTER(buffer)[2] == 9))) { Variant key; Variant value; if (!ReadShortString(buffer, key, false)) { FATAL("Unable to read key"); return false; } if (!Read(buffer, value)) { FATAL("Unable to read value"); return false; } variant[key] = value; } AMF_CHECK_BOUNDARIES(buffer, 3); if (!buffer.Ignore(3)) { FATAL("Unable to ignore 3 bytes"); return false; } variant.IsArray(false); return true; }