Esempio n. 1
0
        internal int?ParseRecord(SerialObject parentObject)
        {
            int?serialObjectReferenceID = null;

            if (PendingNullCounter == 0)
            {
                long                  startPosition  = reader.BaseStream.Position;
                SerialObject          si             = null;
                RecordTypeEnumeration nextRecordType = (RecordTypeEnumeration)reader.ReadByte();
                switch (nextRecordType)
                {
                case RecordTypeEnumeration.SerializedStreamHeader:
                    //header is 4 values that I wouldn't know what to do with (what type of message, what version, etc) - trash.
                    reader.ReadBytes(16);
                    break;

                case RecordTypeEnumeration.ClassWithID:
                    //just two ints, read directly
                    si = new ClassInfo().ReadObjectId(this);
                    int refObj = reader.ReadInt32();
                    //Use the referenced object definition for data retrieval rules
                    // -> this will overwrite the original values in the referenced object, but who cares - the values are trash anyway (for now).
                    ((ClassInfo)SerialObjectsFound[refObj]).ReadValues(this);
                    break;

                case RecordTypeEnumeration.SystemClassWithMembers:
                    si = new ClassInfo().ReadMembers(this).ReadValues(this);
                    break;

                case RecordTypeEnumeration.ClassWithMembers:
                    si = new ClassInfo().ReadMembers(this).ReadLibraryId(this).ReadValues(this);
                    break;

                case RecordTypeEnumeration.SystemClassWithMembersAndTypes:
                    si = new ClassInfo().ReadMembers(this).ReadTypeInfo(this).ReadValues(this);
                    break;

                case RecordTypeEnumeration.ClassWithMembersAndTypes:
                    si = new ClassInfo().ReadMembers(this).ReadTypeInfo(this).ReadLibraryId(this).ReadValues(this);
                    break;

                case RecordTypeEnumeration.BinaryObjectString:
                    si = new ObjectString().ReadObjectId(this).ReadString(this);
                    break;

                case RecordTypeEnumeration.BinaryArray:
                    si = new BinaryArray().ReadStruct(this).ReadValues(this);
                    break;

                case RecordTypeEnumeration.MemberPrimitiveTyped:
                    //Don't know how this can happen - I think it's for messages/remoting only
                    throw new NotImplementedException();

                case RecordTypeEnumeration.MemberReference:
                    //just return the ID that was referenced.
                    serialObjectReferenceID = reader.ReadInt32();
                    break;

                case RecordTypeEnumeration.ObjectNull:
                    //a single null; do nothing, as null is the default return value.
                    break;

                case RecordTypeEnumeration.MessageEnd:
                    //do nothing, quit. Wasn't that fun?
                    endRecordReached = true;
                    break;

                case RecordTypeEnumeration.BinaryLibrary:
                    int newLibraryID = reader.ReadInt32();
                    LibrariesFound.Add(newLibraryID, new BinaryLibrary {
                        LibraryID = newLibraryID, Name = ReadAssemblyName()
                    });
                    break;

                case RecordTypeEnumeration.ObjectNullMultiple256:
                    //a sequence of nulls; return null, and start a counter to continue returning N nulls over the next calls.
                    PendingNullCounter = reader.ReadByte() - 1;
                    break;

                case RecordTypeEnumeration.ObjectNullMultiple:
                    //a sequence of nulls; return null, and start a counter to continue returning N nulls over the next calls.
                    PendingNullCounter = reader.ReadInt32() - 1;
                    //not yet tested: if it happens, take a look around.
                    throw new NotImplementedException();

                case RecordTypeEnumeration.ArraySinglePrimitive:
                    si = new BinaryArray(BinaryTypeEnumeration.Primitive).ReadObjectId(this).ReadLengths(this).ReadPrimitiveType(this).ReadValues(this);
                    break;

                case RecordTypeEnumeration.ArraySingleObject:
                    si = new BinaryArray(BinaryTypeEnumeration.Object).ReadObjectId(this).ReadLengths(this).ReadValues(this);
                    //not yet tested: if it happens, take a look around.
                    throw new NotImplementedException();

                case RecordTypeEnumeration.ArraySingleString:
                    si = new BinaryArray(BinaryTypeEnumeration.String).ReadObjectId(this).ReadLengths(this).ReadValues(this);
                    //not yet tested: if it happens, take a look around.
                    throw new NotImplementedException();

                case RecordTypeEnumeration.MethodCall:
                    //messages/remoting functionality not implemented
                    throw new NotImplementedException();

                case RecordTypeEnumeration.MethodReturn:
                    //messages/remoting functionality not implemented
                    throw new NotImplementedException();

                default:
                    throw new Exception("Parsing appears to have failed dramatically. Unknown record type, we must be lost in the bytestream!");
                }

                //standard: if this was a serial object, add to list and record its length.
                if (si != null)
                {
                    if (parentObject != null)
                    {
                        si.ParentObjectID = parentObject.ObjectID;
                    }
                    SerialObjectsFound.Add(si.ObjectID, si);
                    return(si.ObjectID);
                }
            }
            else
            {
                PendingNullCounter--;
            }
            return(serialObjectReferenceID);
        }
Esempio n. 2
0
        internal int? ParseRecord(SerialObject parentObject)
        {
            int? serialObjectReferenceID = null;
            if (PendingNullCounter == 0)
            {
                long startPosition = reader.BaseStream.Position;
                SerialObject si = null;
                RecordTypeEnumeration nextRecordType = (RecordTypeEnumeration)reader.ReadByte();
                switch (nextRecordType)
                {
                    case RecordTypeEnumeration.SerializedStreamHeader:
                        //header is 4 values that I wouldn't know what to do with (what type of message, what version, etc) - trash.
                        reader.ReadBytes(16);
                        break;
                    case RecordTypeEnumeration.ClassWithID:
                        //just two ints, read directly
                        si = new ClassInfo().ReadObjectId(this);
                        int refObj = reader.ReadInt32();
                        //Use the referenced object definition for data retrieval rules
                        // -> this will overwrite the original values in the referenced object, but who cares - the values are trash anyway (for now).
                        ((ClassInfo)SerialObjectsFound[refObj]).ReadValues(this);
                        break;
                    case RecordTypeEnumeration.SystemClassWithMembers:
                        si = new ClassInfo().ReadMembers(this).ReadValues(this);
                        break;
                    case RecordTypeEnumeration.ClassWithMembers:
                        si = new ClassInfo().ReadMembers(this).ReadLibraryId(this).ReadValues(this);
                        break;
                    case RecordTypeEnumeration.SystemClassWithMembersAndTypes:
                        si = new ClassInfo().ReadMembers(this).ReadTypeInfo(this).ReadValues(this);
                        break;
                    case RecordTypeEnumeration.ClassWithMembersAndTypes:
                        si = new ClassInfo().ReadMembers(this).ReadTypeInfo(this).ReadLibraryId(this).ReadValues(this);
                        break;
                    case RecordTypeEnumeration.BinaryObjectString:
                        si = new ObjectString().ReadObjectId(this).ReadString(this);
                        break;
                    case RecordTypeEnumeration.BinaryArray:
                        si = new BinaryArray().ReadStruct(this).ReadValues(this);
                        break;
                    case RecordTypeEnumeration.MemberPrimitiveTyped:
                        //Don't know how this can happen - I think it's for messages/remoting only
                        throw new NotImplementedException();
                    case RecordTypeEnumeration.MemberReference:
                        //just return the ID that was referenced.
                        serialObjectReferenceID = reader.ReadInt32();
                        break;
                    case RecordTypeEnumeration.ObjectNull:
                        //a single null; do nothing, as null is the default return value.
                        break;
                    case RecordTypeEnumeration.MessageEnd:
                        //do nothing, quit. Wasn't that fun?
                        endRecordReached = true;
                        break;
                    case RecordTypeEnumeration.BinaryLibrary:
                        int newLibraryID = reader.ReadInt32();
                        LibrariesFound.Add(newLibraryID, new BinaryLibrary { LibraryID = newLibraryID, Name = ReadAssemblyName() });
                        break;
                    case RecordTypeEnumeration.ObjectNullMultiple256:
                        //a sequence of nulls; return null, and start a counter to continue returning N nulls over the next calls.
                        PendingNullCounter = reader.ReadByte() - 1;
                        break;
                    case RecordTypeEnumeration.ObjectNullMultiple:
                        //a sequence of nulls; return null, and start a counter to continue returning N nulls over the next calls.
                        PendingNullCounter = reader.ReadInt32() - 1;
                        //not yet tested: if it happens, take a look around.
                        throw new NotImplementedException();
                    case RecordTypeEnumeration.ArraySinglePrimitive:
                        si = new BinaryArray(BinaryTypeEnumeration.Primitive).ReadObjectId(this).ReadLengths(this).ReadPrimitiveType(this).ReadValues(this);
                        break;
                    case RecordTypeEnumeration.ArraySingleObject:
                        si = new BinaryArray(BinaryTypeEnumeration.Object).ReadObjectId(this).ReadLengths(this).ReadValues(this);
                        //not yet tested: if it happens, take a look around.
                        throw new NotImplementedException();
                    case RecordTypeEnumeration.ArraySingleString:
                        si = new BinaryArray(BinaryTypeEnumeration.String).ReadObjectId(this).ReadLengths(this).ReadValues(this);
                        //not yet tested: if it happens, take a look around.
                        throw new NotImplementedException();
                    case RecordTypeEnumeration.MethodCall:
                        //messages/remoting functionality not implemented
                        throw new NotImplementedException();
                    case RecordTypeEnumeration.MethodReturn:
                        //messages/remoting functionality not implemented
                        throw new NotImplementedException();
                    default:
                        throw new Exception("Parsing appears to have failed dramatically. Unknown record type, we must be lost in the bytestream!");

                }

                //standard: if this was a serial object, add to list and record its length.
                if (si != null)
                {
                    if (parentObject != null)
                        si.ParentObjectID = parentObject.ObjectID;
                    SerialObjectsFound.Add(si.ObjectID, si);
                    return si.ObjectID;
                }
            }
            else
                PendingNullCounter--;
            return serialObjectReferenceID;
        }