public virtual void Deserialize(IBinaryAccessor accessor)
        {
            _count = accessor.Read7BitEncodedInt();
            int bufferLength = accessor.Read7BitEncodedInt();

            if (_count > 0)
            {
                _buckets = new int[_count];
                for (int i = 0; i < _count; i++)
                {
                    _buckets[i] = -1;
                }

                _entries = new Entry[_count];

                for (int i = 0; i < _count; i++)
                {
                    var entry = new Entry();
                    entry.Offset   = accessor.Read7BitEncodedInt();
                    entry.HashCode = accessor.Read7BitEncodedInt();

                    int hashIndex = entry.HashCode % _buckets.Length;
                    entry.Next          = _buckets[hashIndex];
                    _buckets[hashIndex] = i;

                    _entries[i] = entry;
                }
            }

            _blob = new Blob(accessor.ReadBytes(bufferLength));
        }
Пример #2
0
        public void Deserialize(IBinaryAccessor accessor)
        {
            _count        = _capacity = accessor.Read7BitEncodedInt();
            _bufferLength = accessor.Read7BitEncodedInt();

            if (_capacity > 0)
            {
                _entries = new Entry[_capacity];

                for (int i = 0; i < _capacity; i++)
                {
                    var entry = new Entry();
                    entry.Offset = accessor.Read7BitEncodedInt();
                    entry.Size   = accessor.Read7BitEncodedInt();
                    _entries[i]  = entry;
                }

                _lastValidIndex = _capacity - 1;
            }

            if (_bufferLength > 0)
            {
                _buffer = accessor.ReadBytes(_bufferLength);
            }
        }
Пример #3
0
        protected internal override void Read(IBinaryAccessor accessor)
        {
            _methodID                 = accessor.Read7BitEncodedInt();
            _invokeMethodRID          = accessor.Read7BitEncodedInt();
            _delegateGenericArguments = ReadSignatures <TypeSignature>(accessor);
            _invokeGenericArguments   = ReadSignatures <TypeSignature>(accessor);

            base.Read(accessor);
        }
        protected internal override void Read(IBinaryAccessor accessor)
        {
            _genericParameterCount = accessor.Read7BitEncodedInt();
            _parameterFlags        = ReadIntArray(accessor);
            _callSite        = (CallSite)ReadSignature(accessor);
            _delegateTypeRID = accessor.Read7BitEncodedInt();
            _ownerTypeRID    = accessor.Read7BitEncodedInt();

            base.Read(accessor);
        }
        protected internal override void Read(IBinaryAccessor accessor)
        {
            _genericParameterCount = accessor.Read7BitEncodedInt();
            _methodCount           = accessor.Read7BitEncodedInt();
            _typeName            = ReadString(accessor);
            _invokeMethodName    = ReadString(accessor);
            _invokeMethodListRID = accessor.Read7BitEncodedInt();

            base.Read(accessor);
        }
        protected int[] ReadIntArray(IBinaryAccessor accessor)
        {
            int count = accessor.Read7BitEncodedInt();

            int[] value = new int[count];
            for (int i = 0; i < count; i++)
            {
                value[i] = accessor.Read7BitEncodedInt();
            }

            return(value);
        }
Пример #7
0
        protected internal override void Read(IBinaryAccessor accessor)
        {
            var count = accessor.Read7BitEncodedInt();

            _list.Capacity = count;

            for (int i = 0; i < count; i++)
            {
                _list.Add(accessor.Read7BitEncodedInt());
            }

            base.Read(accessor);
        }
        internal void Read(IBinaryAccessor accessor, ProjectReadState state)
        {
            _flags  = accessor.ReadInt32();
            _flags2 = accessor.ReadInt32();

            if (NameChanged)
            {
                _name = state.GetString(accessor.Read7BitEncodedInt());
            }

            if (NamespaceChanged)
            {
                _namespace = state.GetString(accessor.Read7BitEncodedInt());
            }
        }
Пример #9
0
        private void ReadSignatures(IBinaryAccessor accessor, ProjectReadState state)
        {
            int blobSize = accessor.Read7BitEncodedInt();
            var blob     = new Blob(accessor.ReadBytes(blobSize));

            state.Signatures = new ReadSignatureSerializer(new BlobAccessor(blob), state.Strings);
        }
        private void ReadResources(IBinaryAccessor accessor, ProjectReadState state)
        {
            int count = accessor.Read7BitEncodedInt();

            if (count == 0)
            {
                return;
            }

            _resources = new Dictionary <string, ProjectResource>(count, StringComparer.OrdinalIgnoreCase);

            for (int i = 0; i < count; i++)
            {
                string name = state.GetString(accessor.Read7BitEncodedInt());
                _resources.Add(name, new ProjectResource(accessor, state));
            }
        }
        private void ReadEvents(IBinaryAccessor accessor, ProjectReadState state)
        {
            int count = accessor.Read7BitEncodedInt();

            if (count == 0)
            {
                return;
            }

            _events = new Dictionary <IEventSignature, ProjectEvent>(count, SignatureComparer.IgnoreTypeOwner_IgnoreAssemblyStrongName);

            for (int i = 0; i < count; i++)
            {
                var eventSig = (EventReference)state.Signatures[accessor.Read7BitEncodedInt()];
                _events.Add(eventSig, new ProjectEvent(accessor, state));
            }
        }
        private void ReadProperties(IBinaryAccessor accessor, ProjectReadState state)
        {
            int count = accessor.Read7BitEncodedInt();

            if (count == 0)
            {
                return;
            }

            _properties = new Dictionary <IPropertySignature, ProjectProperty>(count, SignatureComparer.IgnoreTypeOwner_IgnoreAssemblyStrongName);

            for (int i = 0; i < count; i++)
            {
                var propertySig = (PropertyReference)state.Signatures[accessor.Read7BitEncodedInt()];
                _properties.Add(propertySig, new ProjectProperty(accessor, state));
            }
        }
        private void ReadNamespaces(IBinaryAccessor accessor, ProjectReadState state)
        {
            int count = accessor.Read7BitEncodedInt();

            if (count == 0)
            {
                return;
            }

            _namespaces = new Dictionary <string, ProjectNamespace>(count);

            for (int i = 0; i < count; i++)
            {
                string name = state.GetString(accessor.Read7BitEncodedInt());
                _namespaces.Add(name, new ProjectNamespace(accessor, state));
            }
        }
        private void ReadMethods(IBinaryAccessor accessor, ProjectReadState state)
        {
            int count = accessor.Read7BitEncodedInt();

            if (count == 0)
            {
                return;
            }

            _methods = new Dictionary <IMethodSignature, ProjectMethod>(count, SignatureComparer.IgnoreTypeOwner_IgnoreAssemblyStrongName);

            for (int i = 0; i < count; i++)
            {
                var methodSig = (MethodSignature)state.Signatures[accessor.Read7BitEncodedInt()];
                _methods.Add(methodSig, new ProjectMethod(accessor, state));
            }
        }
        protected internal override void Read(IBinaryAccessor accessor)
        {
            _genericParameterCount = accessor.Read7BitEncodedInt();
            _invokeParameterFlags  = ReadIntArray(accessor);
            _invokeCallSite        = (CallSite)ReadSignature(accessor);
            _declaringType         = (TypeReference)ReadSignature(accessor);

            base.Read(accessor);
        }
        protected T[] ReadSignatures <T>(IBinaryAccessor accessor)
            where T : Signature
        {
            int count = accessor.Read7BitEncodedInt();

            if (count == 0)
            {
                return(null);
            }

            var signatures = new T[count];

            for (int i = 0; i < count; i++)
            {
                signatures[i] = (T)_state.GetSignature(accessor.Read7BitEncodedInt());
            }

            return(signatures);
        }
        private void StateLoadExceptionHandlers(IBinaryAccessor accessor, Module module)
        {
            int count = accessor.Read7BitEncodedInt();

            _exceptionHandlers = new List <ExceptionHandler>(count);

            for (int i = 0; i < count; i++)
            {
                StateLoadExceptionHandler(accessor, module);
            }
        }
        private void StateLoadLocalVariables(IBinaryAccessor accessor, Module module)
        {
            int count = accessor.Read7BitEncodedInt();

            _localVariables = new List <TypeSignature>(count);

            for (int i = 0; i < count; i++)
            {
                int token = accessor.ReadInt32();
                _localVariables.Add(module.GetSignature <TypeSignature>(token));
            }
        }
        private void StateLoad(IBinaryAccessor accessor, Module module)
        {
            _maxStackSize = accessor.Read7BitEncodedInt();

            _initLocals = accessor.ReadBoolean();

            _localVarToken = accessor.ReadInt32();

            StateLoadInstructions(accessor, module);

            StateLoadLocalVariables(accessor, module);

            StateLoadExceptionHandlers(accessor, module);
        }
Пример #20
0
        private void Deserialize(IBinaryAccessor accessor)
        {
            _count   = accessor.Read7BitEncodedInt();
            _entries = new Entry[_count];
            _items   = new StateObject[Math.Max(_count, 0x10)];

            for (int i = 0; i < _count; i++)
            {
                _entries[i] =
                    new Entry()
                {
                    Offset = accessor.Read7BitEncodedInt(),
                    Size   = accessor.Read7BitEncodedInt(),
                };
            }

            int bufferLength = accessor.Read7BitEncodedInt();

            if (bufferLength > 0)
            {
                _buffer = accessor.ReadBytes(bufferLength);
            }
        }
Пример #21
0
        public void Deserialize(IBinaryAccessor accessor)
        {
            _count          = accessor.Read7BitEncodedInt();
            _bufferLength   = accessor.Read7BitEncodedInt();
            _lastValidIndex = _count - 1;
            _entries        = new Entry[_count];

            for (int i = 0; i < _count; i++)
            {
                var entry = new Entry();
                entry.Offset = accessor.Read7BitEncodedInt();
                entry.Size   = accessor.Read7BitEncodedInt();
                _entries[i]  = entry;
            }

            if (_bufferLength > 0)
            {
                _buffer = accessor.ReadBytes(_bufferLength);
            }
            else
            {
                _buffer = BufferUtils.EmptyArray;
            }
        }
        internal void Read(IBinaryAccessor accessor, ProjectReadState state)
        {
            _flags = accessor.ReadInt32();

            if (NameChanged)
            {
                _name = state.GetString(accessor.Read7BitEncodedInt());
            }

            ReadNamespaces(accessor, state);
            ReadTypes(accessor, state);
            ReadMethods(accessor, state);
            ReadFields(accessor, state);
            ReadProperties(accessor, state);
            ReadEvents(accessor, state);
        }
Пример #23
0
        private void ReadAssemblies(IBinaryAccessor accessor, ProjectReadState state)
        {
            int count = accessor.Read7BitEncodedInt();

            if (count > 0)
            {
                _assemblies = new List <ProjectAssembly>(count);

                for (int i = 0; i < count; i++)
                {
                    _assemblies.Add(new ProjectAssembly(accessor, state));
                }
            }
            else
            {
                _assemblies = new List <ProjectAssembly>();
            }
        }
Пример #24
0
        private void ReadStrings(IBinaryAccessor accessor, ProjectReadState state)
        {
            int blobSize = accessor.Read7BitEncodedInt();

            byte[] buffer = accessor.ReadBytes(blobSize);
            StrongCryptoUtils.Decrypt(buffer, 0, blobSize);

            var blob = new Blob(buffer);
            int pos  = 0;

            int count    = blob.Read7BitEncodedInt(ref pos);
            var strings  = new string[count];
            var encoding = Encoding.UTF8;

            for (int i = 0; i < count; i++)
            {
                strings[i] = blob.ReadLengthPrefixedString(ref pos, encoding);
            }

            state.Strings = strings;
        }
 protected ISignature ReadSignature(IBinaryAccessor accessor)
 {
     return(_state.GetSignature(accessor.Read7BitEncodedInt()));
 }
 protected string ReadString(IBinaryAccessor accessor)
 {
     return(_state.GetString(accessor.Read7BitEncodedInt()));
 }
 public override void Deserialize(IBinaryAccessor accessor)
 {
     _bindable  = accessor.ReadBoolean();
     _direction = (BindingDirection)accessor.Read7BitEncodedInt();
 }
        private void StateLoadInstructions(IBinaryAccessor accessor, Module module)
        {
            int instructionCount = accessor.Read7BitEncodedInt();

            _instructions = new List <Instruction>(instructionCount);

            for (int i = 0; i < instructionCount; i++)
            {
                OpCode opCode;
                byte   opByte = accessor.ReadByte();
                if (opByte == 0xFE)
                {
                    opByte = accessor.ReadByte();
                    opCode = OpCodes.OpCodeArray[256 + opByte];
                }
                else
                {
                    opCode = OpCodes.OpCodeArray[opByte];
                }

                object value;
                switch (opCode.OperandType)
                {
                case OperandType.InlineBrTarget:
                {
                    value = accessor.ReadInt32();
                }
                break;

                case OperandType.InlineField:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineI:
                {
                    value = accessor.ReadInt32();
                }
                break;

                case OperandType.InlineI8:
                {
                    value = accessor.ReadInt64();
                }
                break;

                case OperandType.InlineMethod:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineR:
                {
                    value = accessor.ReadDouble();
                }
                break;

                case OperandType.InlineSig:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineString:
                {
                    // Token of a userdefined string, whose RID portion is actually an offset in the #US blob stream.
                    value = accessor.ReadLengthPrefixedString(Encoding.Unicode);
                }
                break;

                case OperandType.InlineSwitch:
                {
                    int   count   = accessor.ReadInt32();
                    int[] targets = new int[count];
                    for (int j = 0; j < count; j++)
                    {
                        targets[j] = accessor.ReadInt32();
                    }

                    value = targets;
                }
                break;

                case OperandType.InlineTok:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineType:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineVar:
                {
                    value = accessor.ReadInt16();
                }
                break;

                case OperandType.ShortInlineBrTarget:
                {
                    value = accessor.ReadSByte();
                }
                break;

                case OperandType.ShortInlineI:
                {
                    value = accessor.ReadByte();
                }
                break;

                case OperandType.ShortInlineR:
                {
                    value = accessor.ReadSingle();
                }
                break;

                case OperandType.ShortInlineVar:
                {
                    value = accessor.ReadByte();
                }
                break;

                default:
                {
                    value = null;
                }
                break;
                }

                _instructions.Add(new Instruction(opCode, value));
            }
        }
        internal void Read(IBinaryAccessor accessor, ProjectReadState state)
        {
            _filePath   = ProjectHelper.MakeAbsolutePath(state.GetString(accessor.Read7BitEncodedInt()), state.BasePath);
            _outputPath = ProjectHelper.MakeAbsolutePath(state.GetString(accessor.Read7BitEncodedInt()), state.BasePath);
            _flags      = accessor.ReadInt32();
            _flags2     = accessor.ReadInt32();
            _flags3     = accessor.ReadInt32();

            if (NameChanged)
            {
                _name = state.GetString(accessor.Read7BitEncodedInt());
            }

            if (CultureChanged)
            {
                _culture = state.GetString(accessor.Read7BitEncodedInt());
            }

            if (VersionChanged)
            {
                _version = new Version(accessor.ReadUInt16(), accessor.ReadUInt16(), accessor.ReadUInt16(), accessor.ReadUInt16());
            }

            if (TitleChanged)
            {
                _title = state.GetString(accessor.Read7BitEncodedInt());
            }

            if (DescriptionChanged)
            {
                _description = state.GetString(accessor.Read7BitEncodedInt());
            }

            if (CompanyChanged)
            {
                _company = state.GetString(accessor.Read7BitEncodedInt());
            }

            if (ProductChanged)
            {
                _product = state.GetString(accessor.Read7BitEncodedInt());
            }

            if (CopyrightChanged)
            {
                _copyright = state.GetString(accessor.Read7BitEncodedInt());
            }

            if (TrademarkChanged)
            {
                _trademark = state.GetString(accessor.Read7BitEncodedInt());
            }

            if (accessor.ReadBoolean())
            {
                _sign = new ProjectAssemblySign(accessor, state);
            }

            ReadModules(accessor, state);
            ReadResources(accessor, state);
        }
Пример #30
0
 public override void Deserialize(IBinaryAccessor accessor)
 {
     _debuggingModes = accessor.Read7BitEncodedInt();
 }