示例#1
0
def _read_class_members_meta(ctx, object_id):
    count = read_primitive(ctx.handle, PrimitiveType.Int32)
    names = [None] * count
    binary_types = [None] * count
    for i in range(count):
        names[i] = read_primitive(ctx.handle, PrimitiveType.String)
    for i in range(count):
        binary_types[i] = _read_binary_type(ctx)

    node = Node('MembersMeta')
    for i in range(count):
        member_node = Node('MemberMeta')
        member_node.add_leaf('Name', names[i])
        member_node.add_leaf('BinaryType', binary_types[i])
        if binary_types[i] in (BinaryType.Primitive, BinaryType.PrimitiveArray):
            member_node.add_leaf('PrimitiveType', _read_primitive_type(ctx))
        elif binary_types[i] == BinaryType.SystemClass:
            member_node.add_leaf(
                'ClassName', read_primitive(ctx.handle, PrimitiveType.String))
        elif binary_types[i] == BinaryType.Class:
            member_node.add_leaf(
                'ClassName', read_primitive(ctx.handle, PrimitiveType.String))
            member_node.add_leaf(
                'LibraryId', read_primitive(ctx.handle, PrimitiveType.Int32))
        node.add(member_node)
    return node
示例#2
0
def _read_serialized_stream_header(ctx):
    node = Node('SerializedStreamHeader')
    node.add_leaf('RootId', read_primitive(ctx.handle, PrimitiveType.Int32))
    node.add_leaf('HeaderId', read_primitive(ctx.handle, PrimitiveType.Int32))
    node.add_leaf('MajorVersion', read_primitive(ctx.handle, PrimitiveType.Int32))
    node.add_leaf('MinorVersion', read_primitive(ctx.handle, PrimitiveType.Int32))
    return node
示例#3
0
def _read_method_call(ctx):
    node = Node('BinaryMethodCall')

    flags = util.read_fmt(ctx.handle, '<L')
    node.add_leaf('Flags', flags)

    primitive_type = _read_primitive_type(ctx)
    node.add_leaf('MethodName', read_primitive(ctx.handle, primitive_type))

    primitive_type = _read_primitive_type(ctx)
    node.add_leaf('TypeName', read_primitive(ctx.handle, primitive_type))

    if (flags & MessageFlags.ContextInline.value) != 0:
        primitive_type = _read_primitive_type(ctx)
        node.add_leaf('CallContext', read_primitive(ctx.handle, primitive_type))

    if (flags & MessageFlags.ArgsInline.value) != 0:
        args_node = _read_array_of_value_with_code(ctx)
        args_node.name = 'Args'
        node.add(args_node)
    elif (flags & MessageFlags.NoArgs.value) == 0:
        record_type = _read_record_type(ctx)
        args_node = _read_record(ctx, record_type)
        args_node.name = 'Args'
        node.add(args_node)

    return node
示例#4
0
def _read_class_members_meta(ctx, object_id):
    count = read_primitive(ctx.handle, PrimitiveType.Int32)
    names = [None] * count
    binary_types = [None] * count
    for i in range(count):
        names[i] = read_primitive(ctx.handle, PrimitiveType.String)
    for i in range(count):
        binary_types[i] = _read_binary_type(ctx)

    node = Node('MembersMeta')
    for i in range(count):
        member_node = Node('MemberMeta')
        member_node.add_leaf('Name', names[i])
        member_node.add_leaf('BinaryType', binary_types[i])
        if binary_types[i] in (BinaryType.Primitive,
                               BinaryType.PrimitiveArray):
            member_node.add_leaf('PrimitiveType', _read_primitive_type(ctx))
        elif binary_types[i] == BinaryType.SystemClass:
            member_node.add_leaf(
                'ClassName', read_primitive(ctx.handle, PrimitiveType.String))
        elif binary_types[i] == BinaryType.Class:
            member_node.add_leaf(
                'ClassName', read_primitive(ctx.handle, PrimitiveType.String))
            member_node.add_leaf(
                'LibraryId', read_primitive(ctx.handle, PrimitiveType.Int32))
        node.add(member_node)
    return node
示例#5
0
def _read_method_call(ctx):
    node = Node('BinaryMethodCall')

    flags = util.read_fmt(ctx.handle, '<L')
    node.add_leaf('Flags', flags)

    primitive_type = _read_primitive_type(ctx)
    node.add_leaf('MethodName', read_primitive(ctx.handle, primitive_type))

    primitive_type = _read_primitive_type(ctx)
    node.add_leaf('TypeName', read_primitive(ctx.handle, primitive_type))

    if (flags & MessageFlags.ContextInline.value) != 0:
        primitive_type = _read_primitive_type(ctx)
        node.add_leaf('CallContext', read_primitive(ctx.handle,
                                                    primitive_type))

    if (flags & MessageFlags.ArgsInline.value) != 0:
        args_node = _read_array_of_value_with_code(ctx)
        args_node.name = 'Args'
        node.add(args_node)
    elif (flags & MessageFlags.NoArgs.value) == 0:
        record_type = _read_record_type(ctx)
        args_node = _read_record(ctx, record_type)
        args_node.name = 'Args'
        node.add(args_node)

    return node
示例#6
0
def _read_class_with_members_and_types(ctx):
    node, object_id = _read_create_object(ctx, 'ClassWithMembersAndTypes')
    node.add_leaf('ObjectName', read_primitive(ctx.handle, PrimitiveType.String))
    node.add(_read_class_members_meta(ctx, object_id))
    node.add_leaf('LibraryId', read_primitive(ctx.handle, PrimitiveType.Int32))
    node.add(_read_class_members(ctx, object_id))
    return node
示例#7
0
def _read_class_with_members_and_types(ctx):
    node, object_id = _read_create_object(ctx, 'ClassWithMembersAndTypes')
    node.add_leaf('ObjectName', read_primitive(ctx.handle,
                                               PrimitiveType.String))
    node.add(_read_class_members_meta(ctx, object_id))
    node.add_leaf('LibraryId', read_primitive(ctx.handle, PrimitiveType.Int32))
    node.add(_read_class_members(ctx, object_id))
    return node
示例#8
0
def _read_serialized_stream_header(ctx):
    node = Node('SerializedStreamHeader')
    node.add_leaf('RootId', read_primitive(ctx.handle, PrimitiveType.Int32))
    node.add_leaf('HeaderId', read_primitive(ctx.handle, PrimitiveType.Int32))
    node.add_leaf('MajorVersion',
                  read_primitive(ctx.handle, PrimitiveType.Int32))
    node.add_leaf('MinorVersion',
                  read_primitive(ctx.handle, PrimitiveType.Int32))
    return node
示例#9
0
def _read_binary_library(ctx):
    library_node = Node('BinaryLibrary')
    library_node.add_leaf('LibraryId', read_primitive(ctx.handle, PrimitiveType.Int32))
    library_node.add_leaf('LibraryName', read_primitive(ctx.handle, PrimitiveType.String))
    record_type = _read_record_type(ctx)
    if _is_class(record_type):
        library_node.add(_read_record(ctx, record_type))
        return library_node
    elif _is_array(record_type):
        library_node.add(_read_record(ctx, record_type))
        return library_node
    else:
        raise CorruptDataError(
            'Binary library followed with neither class or array')
示例#10
0
def _read_binary_library(ctx):
    library_node = Node('BinaryLibrary')
    library_node.add_leaf('LibraryId',
                          read_primitive(ctx.handle, PrimitiveType.Int32))
    library_node.add_leaf('LibraryName',
                          read_primitive(ctx.handle, PrimitiveType.String))
    record_type = _read_record_type(ctx)
    if _is_class(record_type):
        library_node.add(_read_record(ctx, record_type))
        return library_node
    elif _is_array(record_type):
        library_node.add(_read_record(ctx, record_type))
        return library_node
    else:
        raise CorruptDataError(
            'Binary library followed with neither class or array')
示例#11
0
def _read_binary_array(ctx):
    node, object_id = _read_create_object(ctx, 'BinaryArray')
    array_type = BinaryArrayType(util.read_fmt(ctx.handle, 'B'))
    node.add_leaf('BinaryArrayType', array_type)

    rank = util.read_fmt(ctx.handle, '<l')
    node.add_leaf('Rank', rank)

    dimensions_node = Node('Dimensions')
    element_count = 0
    for i in range(rank):
        dimension = util.read_fmt(ctx.handle, '<l')
        dimensions_node.add_leaf('Dimension', dimension)
        if i == 0:
            element_count = dimension
        else:
            element_count *= dimension
    node.add(dimensions_node)

    if array_type in (BinaryArrayType.SingleOffset,
                      BinaryArrayType.JaggedOffset,
                      BinaryArrayType.RectangularOffset):
        lower_bounds_node = Node('LowerBounds')
        for i in range(rank):
            lower_bounds_node.add_leaf('LowerBound',
                                       util.read_fmt(ctx.handle, '<l'))
        node.add(lower_bounds_node)

    binary_type = _read_binary_type(ctx)
    primitive_type = PrimitiveType.Invalid
    if binary_type in (BinaryType.Primitive, BinaryType.PrimitiveArray):
        primitive_type = _read_primitive_type(ctx)
    elif binary_type == BinaryType.SystemClass:
        node.add_leaf('ClassName',
                      read_primitive(ctx.handle, PrimitiveType.String))
    elif binary_type == BinaryType.Class:
        node.add_leaf('ClassName',
                      read_primitive(ctx.handle, PrimitiveType.String))
        node.add_leaf('LibraryId',
                      read_primitive(ctx.handle, PrimitiveType.Int32))

    elements_node = Node('Elements')
    for i in range(element_count):
        elements_node.add(
            _read_from_binary_type(ctx, binary_type, primitive_type))
    node.add(elements_node)
    return node
示例#12
0
def _read_array_single_primitive(ctx):
    node, object_id = _read_create_object(ctx, 'ArraySinglePrimitive')
    length = util.read_fmt(ctx.handle, '<l')
    primitive_type = _read_primitive_type(ctx)
    elements_node = Node('Elements')
    for i in range(length):
        elements_node.add_leaf('Element', read_primitive(ctx.handle, primitive_type))
    node.add(elements_node)
    return node
示例#13
0
def _read_binary_array(ctx):
    node, object_id = _read_create_object(ctx, 'BinaryArray')
    array_type = BinaryArrayType(util.read_fmt(ctx.handle, 'B'))
    node.add_leaf('BinaryArrayType', array_type)

    rank = util.read_fmt(ctx.handle, '<l')
    node.add_leaf('Rank', rank)

    dimensions_node = Node('Dimensions')
    element_count = 0
    for i in range(rank):
        dimension = util.read_fmt(ctx.handle, '<l')
        dimensions_node.add_leaf('Dimension', dimension)
        if i == 0:
            element_count = dimension
        else:
            element_count *= dimension
    node.add(dimensions_node)

    if array_type in (
            BinaryArrayType.SingleOffset,
            BinaryArrayType.JaggedOffset,
            BinaryArrayType.RectangularOffset):
        lower_bounds_node = Node('LowerBounds')
        for i in range(rank):
            lower_bounds_node.add_leaf(
                'LowerBound', util.read_fmt(ctx.handle, '<l'))
        node.add(lower_bounds_node)

    binary_type = _read_binary_type(ctx)
    primitive_type = PrimitiveType.Invalid
    if binary_type in (BinaryType.Primitive, BinaryType.PrimitiveArray):
        primitive_type = _read_primitive_type(ctx)
    elif binary_type == BinaryType.SystemClass:
        node.add_leaf('ClassName', read_primitive(ctx.handle, PrimitiveType.String))
    elif binary_type == BinaryType.Class:
        node.add_leaf('ClassName', read_primitive(ctx.handle, PrimitiveType.String))
        node.add_leaf('LibraryId', read_primitive(ctx.handle, PrimitiveType.Int32))

    elements_node = Node('Elements')
    for i in range(element_count):
        elements_node.add(_read_from_binary_type(ctx, binary_type, primitive_type))
    node.add(elements_node)
    return node
示例#14
0
def _read_array_single_primitive(ctx):
    node, object_id = _read_create_object(ctx, 'ArraySinglePrimitive')
    length = util.read_fmt(ctx.handle, '<l')
    primitive_type = _read_primitive_type(ctx)
    elements_node = Node('Elements')
    for i in range(length):
        elements_node.add_leaf('Element',
                               read_primitive(ctx.handle, primitive_type))
    node.add(elements_node)
    return node
示例#15
0
def _read_from_binary_type(ctx, binary_type, primitive_type):
    if binary_type == BinaryType.Primitive:
        return LeafNode('Value', read_primitive(ctx.handle, primitive_type))

    if binary_type in (BinaryType.String, BinaryType.Object,
                       BinaryType.PrimitiveArray, BinaryType.StringArray,
                       BinaryType.ObjectArray, BinaryType.Class,
                       BinaryType.SystemClass):
        record_type = _read_record_type(ctx)
        return _read_record(ctx, record_type)

    raise NotImplementedError(
        'Unimplemented binary type: {0}'.format(binary_type))
示例#16
0
def _read_from_binary_type(ctx, binary_type, primitive_type):
    if binary_type == BinaryType.Primitive:
        return LeafNode('Value', read_primitive(ctx.handle, primitive_type))

    if binary_type in (
            BinaryType.String,
            BinaryType.Object,
            BinaryType.PrimitiveArray,
            BinaryType.StringArray,
            BinaryType.ObjectArray,
            BinaryType.Class,
            BinaryType.SystemClass):
        record_type = _read_record_type(ctx)
        return _read_record(ctx, record_type)

    raise NotImplementedError(
        'Unimplemented binary type: {0}'.format(binary_type))
示例#17
0
def _read_create_object(ctx, name):
    object_id = read_primitive(ctx.handle, PrimitiveType.Int32)
    node = Node(name)
    ctx.objects[object_id] = node
    node.add_leaf('ObjectId', object_id)
    return node, object_id
示例#18
0
def _read_member_primitive_typed(ctx):
    primitive_type = _read_primitive_type(ctx)
    return LeafNode('MemberPrimitiveTyped',
                    read_primitive(ctx.handle, primitive_type))
示例#19
0
def _read_binary_object_string(ctx):
    node, object_id = _read_create_object(ctx, 'BinaryObjectString')
    node.add_leaf('Value', read_primitive(ctx.handle, PrimitiveType.String))
    return node
示例#20
0
def _read_member_reference(ctx):
    return LeafNode('MemberReference',
                    read_primitive(ctx.handle, PrimitiveType.Int32))
示例#21
0
def _read_member_reference(ctx):
    return LeafNode(
        'MemberReference',
        read_primitive(ctx.handle, PrimitiveType.Int32))
示例#22
0
def _read_member_primitive_typed(ctx):
    primitive_type = _read_primitive_type(ctx)
    return LeafNode(
        'MemberPrimitiveTyped',
        read_primitive(ctx.handle, primitive_type))
示例#23
0
def _read_create_object(ctx, name):
    object_id = read_primitive(ctx.handle, PrimitiveType.Int32)
    node = Node(name)
    ctx.objects[object_id] = node
    node.add_leaf('ObjectId', object_id)
    return node, object_id
示例#24
0
def _read_binary_object_string(ctx):
    node, object_id = _read_create_object(ctx, 'BinaryObjectString')
    node.add_leaf('Value', read_primitive(ctx.handle, PrimitiveType.String))
    return node