示例#1
0
 public BasicBlockChunk(VMRuntime rt, MethodDef method, ILBlock block)
 {
     this.rt     = rt;
     this.method = method;
     Block       = block;
     Length      = rt.serializer.ComputeLength(block);
 }
示例#2
0
        uint ComputeLength(VMRuntime rt)
        {
            uint len = 16;

            foreach (var reference in rt.Descriptor.Data.refMap)
            {
                len += Utils.GetCompressedUIntLength(reference.Value) + GetCodedLen(reference.Key.MDToken);
            }
            foreach (var str in rt.Descriptor.Data.strMap)
            {
                len += Utils.GetCompressedUIntLength(str.Value);
                len += Utils.GetCompressedUIntLength((uint)str.Key.Length);
                len += (uint)str.Key.Length * 2;
            }
            foreach (var sig in rt.Descriptor.Data.sigs)
            {
                len += Utils.GetCompressedUIntLength(sig.Id);
                len += 4;
                if (sig.Method != null)
                {
                    len += 4;
                }
                var paramCount = (uint)sig.FuncSig.ParamSigs.Length;
                len += 1 + Utils.GetCompressedUIntLength(paramCount);

                foreach (var param in sig.FuncSig.ParamSigs)
                {
                    len += GetCodedLen(param.MDToken);
                }
                len += GetCodedLen(sig.FuncSig.RetType.MDToken);
            }
            return(len);
        }
示例#3
0
        internal void WriteData(VMRuntime rt)
        {
            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);

            writer.Write((uint)0x68736966);
            writer.Write(rt.Descriptor.Data.refMap.Count);
            writer.Write(rt.Descriptor.Data.strMap.Count);
            writer.Write(rt.Descriptor.Data.sigs.Count);

            foreach (var refer in rt.Descriptor.Data.refMap)
            {
                writer.WriteCompressedUInt(refer.Value);
                writer.WriteCompressedUInt(GetCodedToken(refer.Key.MDToken));
            }

            foreach (var str in rt.Descriptor.Data.strMap)
            {
                writer.WriteCompressedUInt(str.Value);
                writer.WriteCompressedUInt((uint)str.Key.Length);
                foreach (var chr in str.Key)
                {
                    writer.Write((ushort)chr);
                }
            }

            foreach (var sig in rt.Descriptor.Data.sigs)
            {
                writer.WriteCompressedUInt(sig.Id);
                if (sig.Method != null)
                {
                    var entry       = rt.methodMap[sig.Method].Item2;
                    var entryOffset = entry.Content[0].Offset;
                    Debug.Assert(entryOffset != 0);
                    writer.Write(entryOffset);

                    var key = (uint)rt.Descriptor.Random.Next();
                    key = (key << 8) | rt.Descriptor.Data.LookupInfo(sig.Method).EntryKey;
                    writer.Write(key);
                }
                else
                {
                    writer.Write(0u);
                }

                writer.Write(sig.FuncSig.Flags);
                writer.WriteCompressedUInt((uint)sig.FuncSig.ParamSigs.Length);
                foreach (var paramType in sig.FuncSig.ParamSigs)
                {
                    writer.WriteCompressedUInt(GetCodedToken(paramType.MDToken));
                }
                writer.WriteCompressedUInt(GetCodedToken(sig.FuncSig.RetType.MDToken));
            }

            data = stream.ToArray();
            Debug.Assert(data.Length == Length);
        }
示例#4
0
 public HeaderChunk(VMRuntime rt)
 {
     Length = ComputeLength(rt);
 }
示例#5
0
 public BasicBlockSerializer(VMRuntime rt)
 {
     this.rt = rt;
 }