예제 #1
0
def read_data(input, context=None):
    amf.utils.logger().debug("read_data()")
    if not context:
        context=amf.AMFMessageBodyContext()
    if not hasattr(input, 'read'):
        input = StringIO(input)

    type = amf0.read_byte(input)
    if type == amf0.AMF3_DATA_TYPE:
        type = amf0.read_byte(input)
    amf.utils.logger().debug("AMF3 Type='%d'", type)
    if type not in read_func_map:
        amf.logger.error("Unsupported Type [type='%s']", type)
        raise Exception("Unsupported type [type='%s']" % (type,))
    func_name = read_func_map[type]
    if func_name is not None:
        func = eval(func_name)
        if callable(func):
            return func(input, context)
    return None
예제 #2
0
def read_integer(input, context=None):
    amf.utils.logger().debug("amf3.read_integer()")
    n = 0
    b = amf0.read_byte(input)
    result = 0
    while (b & 0x80) != 0 and n < 3: # Check the first bit of the byte is 1 or not
        result <<= 7
        result |= (b & 0x7F)
        b = amf0.read_byte(input)
        n += 1
    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 # This doesn't work
            result -= 0x20000000 # TODO 
    amf.utils.logger().debug("amf3.read_integer() -- result='%s'", repr(result))
    return result