コード例 #1
0
ファイル: MethodSpec.cs プロジェクト: BGCX261/zoompe-git
        public void Read(BinaryStreamReader signatureBlobReader)
        {
            byte genericInst = signatureBlobReader.ReadByte();
            if (genericInst != 0x0a)
                throw new BadImageFormatException("Invalid leading byte in MethodSpec: " + genericInst + ".");

            uint? genArgCount = signatureBlobReader.ReadCompressedUInt32();
            if(genArgCount==null)
                throw new BadImageFormatException("Null value for MethodSpec.GenArgCount is not supported.");

            this.GenArgs = new TypeReference[genArgCount.Value];
        }
コード例 #2
0
ファイル: MethodSig.cs プロジェクト: BGCX261/zoompe-git
 internal void ReadDetails(BinaryStreamReader reader)
 {
     this.GenParamCount = reader.ReadCompressedUInt32() ?? 0;
 }
コード例 #3
0
ファイル: Type.cs プロジェクト: BGCX261/zoompe-git
        public static Type Read(ElementType leadByte, BinaryStreamReader signatureBlobReader)
        {
            switch (leadByte)
            {
                case ElementType.End:
                    break;
                case ElementType.Void:
                    break;

                case ElementType.Boolean: return Boolean.Instance;
                case ElementType.Char: return Char.Instance;
                case ElementType.I1: return I1.Instance;
                case ElementType.U1: return U1.Instance;
                case ElementType.I2: return I2.Instance;
                case ElementType.U2: return U2.Instance;
                case ElementType.I4: return I4.Instance;
                case ElementType.U4: return U4.Instance;
                case ElementType.I8: return I8.Instance;
                case ElementType.U8: return U8.Instance;
                case ElementType.R4: return R4.Instance;
                case ElementType.R8: return R8.Instance;

                case ElementType.String: return String.Instance;

                case ElementType.Ptr:
                    ElementType ptrLeadByte;
                    var ptrCustomMod = CustomMod.ReadCustomModArray(out ptrLeadByte, signatureBlobReader);
                    Ptr resultPtr;
                    if (ptrLeadByte == ElementType.Void)
                    {
                        resultPtr = Ptr.Void.Instance;
                    }
                    else
                    {
                        Type ptrType = Type.Read(ptrLeadByte, signatureBlobReader);
                        resultPtr = new Ptr.Type
                        {
                            PtrType = ptrType
                        };
                    }
                    resultPtr.CustomMods = ptrCustomMod;
                    return resultPtr;

                case ElementType.ByRef:
                    break;

                case ElementType.ValueType:
                    var valueTypeTypeDefOrRefOrSpecEncoded = signatureBlobReader.ReadTypeDefOrRefOrSpecEncoded();
                    return new ValueType { TypeDefOrRefEncoded = valueTypeTypeDefOrRefOrSpecEncoded };

                case ElementType.Class:
                    var classTypeDefOrRefOrSpecEncoded = signatureBlobReader.ReadTypeDefOrRefOrSpecEncoded();
                    return new Class { TypeDefOrRefEncoded = classTypeDefOrRefOrSpecEncoded };

                case ElementType.Var:
                    uint? varNumber = signatureBlobReader.ReadCompressedUInt32();
                    return new Var
                    {
                        Number = varNumber
                    };

                case ElementType.Array:
                    // TODO: implement ArrayShape (ECMA-335 §23.2.13)
                    throw new NotImplementedException("TODO: implement ArrayShape (ECMA-335 §23.2.13).");

                case ElementType.GenericInst:
                    var genericLeadByte = (ElementType)signatureBlobReader.ReadByte();
                    GenericInst genericInst;
                    switch (genericLeadByte)
                    {
                        case ElementType.Class:
                            genericInst = new GenericInst.Class();
                            break;

                        case ElementType.ValueType:
                            genericInst = new GenericInst.ValueType();
                            break;

                        default:
                            throw new BadImageFormatException("Invalid lead byte for "+ElementType.GenericInst+" class/valuetype value.");
                    }

                    var typeDefOrRefOrSpecEncoded = signatureBlobReader.ReadTypeDefOrRefOrSpecEncoded();
                    genericInst.TypeDefOrRefOrSpecEncoded = typeDefOrRefOrSpecEncoded;

                    uint? genArgCount = signatureBlobReader.ReadCompressedUInt32();
                    if (genArgCount == null)
                        throw new BadImageFormatException("Invalid null value for GenArgCount value in " + ElementType.GenericInst+".");

                    var genericInstTypes = new Type[genArgCount.Value];
                    for(int i = 0; i<genericInstTypes.Length; i++)
                    {
                        var genericInstTypeLeadByte = (ElementType)signatureBlobReader.ReadByte();
                        genericInstTypes[i] = Type.Read(genericInstTypeLeadByte, signatureBlobReader);
                    }

                    genericInst.Types = genericInstTypes;
                    return genericInst;

                case ElementType.TypedByRef:
                    break;

                case ElementType.I: return I.Instance;
                case ElementType.U: return U.Instance;

                case ElementType.FnPtr:
                    var methodDefSig = MethodSig.Read(signatureBlobReader);
                    return new FnPtr
                    {
                        MethodDefSig = methodDefSig
                    };

                case ElementType.Object: return Object.Instance;

                case ElementType.SZArray:
                    ElementType szArrayLeadByte;
                    var szArrayCustomMod = CustomMod.ReadCustomModArray(out szArrayLeadByte, signatureBlobReader);
                    var szArrayType = Type.Read(szArrayLeadByte, signatureBlobReader);
                    return new SZArray
                    {
                        CustomMods = szArrayCustomMod,
                        Type = szArrayType
                    };

                case ElementType.MVar:
                    uint? mvarNumber = signatureBlobReader.ReadCompressedUInt32();
                    return new MVar
                    {
                        Number = mvarNumber
                    };

                case ElementType.CMod_ReqD:
                    break;

                case ElementType.CMod_Opt:
                    break;
                case ElementType.Internal:
                    break;
                case ElementType.Modifier:
                    break;
                case ElementType.Sentinel:
                    break;
                case ElementType.Pinned:
                    break;
                case ElementType.R4_Hfa:
                    break;
                case ElementType.R8_Hfa:
                    break;
                case ElementType.ArgumentType_:
                    break;
                case ElementType.CustomAttribute_BoxedObject_:
                    break;
                case ElementType.CustomAttribute_Field_:
                    break;
                case ElementType.CustomAttribute_Property_:
                    break;
                case ElementType.CustomAttribute_Enum_:
                    break;
                default:
                    break;
            }

            throw new BadImageFormatException("Invalid lead byte "+leadByte+".");
        }
コード例 #4
0
ファイル: MethodSig.cs プロジェクト: BGCX261/zoompe-git
        void ReadParameters(BinaryStreamReader signatureBlobReader)
        {
            uint parameterCount = signatureBlobReader.ReadCompressedUInt32() ?? 0;

            this.RefType = RefType.Read(signatureBlobReader);

            var paramList = new Param[parameterCount];
            for (int i = 0; i < paramList.Length; i++)
            {
                var p = Param.Read(signatureBlobReader);
                paramList[i] = p;
            }

            this.ParamList = paramList;
        }