示例#1
0
        public static Type CreateStructType(Signature sig)
        {
            InitHack();

            var typeName = "DynamicType" + sig.ToString();
            var type     = asmBdef.GetType(typeName, false);

            if (type != null)
            {
                return(type);
            }

            var typeBuilder = modBdef.DefineType(typeName,
                                                 TypeAttributes.Class, typeof(DValue));

            int fieldCount = 0;

            foreach (var field in sig.GetFieldSignatures())
            {
                var fieldName = string.Format("field_{0}", fieldCount++);
                var t         = field.ToType();
                typeBuilder.DefineField(fieldName, t, FieldAttributes.Public);
            }
            return(typeBuilder.CreateType());
        }
示例#2
0
        public IEnumerable <Signature> StepInto(Signature sig)
        {
            if (sig == Signature.VariantSig)
            {
                Signature valueSig = ReadSignature();
                yield return(valueSig);

                yield break;
            }

            // No need to handle dicts specially. IsArray does the job
            if (sig.IsArray)
            {
                Signature elemSig = sig.GetElementSignature();
                uint      ln      = ReadUInt32();
                ReadPad(elemSig.Alignment);
                int endPos = pos + (int)ln;
                while (pos < endPos)
                {
                    yield return(elemSig);
                }
                yield break;
            }

            if (sig.IsDictEntry)
            {
                pos = Protocol.Padded(pos, sig.Alignment);
                Signature sigKey, sigValue;
                sig.GetDictEntrySignatures(out sigKey, out sigValue);
                yield return(sigKey);

                yield return(sigValue);

                yield break;
            }

            if (sig.IsStruct)
            {
                pos = Protocol.Padded(pos, sig.Alignment);
                foreach (Signature fieldSig in sig.GetFieldSignatures())
                {
                    yield return(fieldSig);
                }
                yield break;
            }

            throw new Exception("Can't step into '" + sig + "'");
            //yield break;
        }
        // Note: This method doesn't support aggregate signatures
        public bool StepOver(Signature sig)
        {
            if (sig == Signature.VariantSig) {
                Signature valueSig = ReadSignature ();
                return StepOver (valueSig);
            }

            if (sig == Signature.StringSig) {
                uint valueLength = ReadUInt32 ();
                pos += (int)valueLength;
                pos++;
                return true;
            }

            if (sig == Signature.SignatureSig) {
                byte valueLength = ReadByte ();
                pos += valueLength;
                pos++;
                return true;
            }

            // No need to handle dicts specially. IsArray does the job
            if (sig.IsArray) {
                Signature elemSig = sig.GetElementSignature ();
                uint ln = ReadUInt32 ();
                pos = Protocol.Padded (pos, elemSig.Alignment);
                pos += (int)ln;
                return true;
            }

            int endPos = pos;
            if (sig.GetFixedSize (ref endPos)) {
                pos = endPos;
                return true;
            }

            if (sig.IsDictEntry) {
                pos = Protocol.Padded (pos, sig.Alignment);
                Signature sigKey, sigValue;
                sig.GetDictEntrySignatures (out sigKey, out sigValue);
                if (!StepOver (sigKey))
                    return false;
                if (!StepOver (sigValue))
                    return false;
                return true;
            }

            if (sig.IsStruct) {
                pos = Protocol.Padded (pos, sig.Alignment);
                foreach (Signature fieldSig in sig.GetFieldSignatures ())
                    if (!StepOver (fieldSig))
                        return false;
                return true;
            }

            throw new Exception ("Can't step over '" + sig + "'");
            //return false;
        }
示例#4
0
        // Note: This method doesn't support aggregate signatures
        public bool StepOver(Signature sig)
        {
            if (sig == Signature.VariantSig)
            {
                Signature valueSig = ReadSignature();
                return(StepOver(valueSig));
            }

            if (sig == Signature.StringSig)
            {
                uint valueLength = ReadUInt32();
                pos += (int)valueLength;
                pos++;
                return(true);
            }

            if (sig == Signature.SignatureSig)
            {
                byte valueLength = ReadByte();
                pos += valueLength;
                pos++;
                return(true);
            }

            // No need to handle dicts specially. IsArray does the job
            if (sig.IsArray)
            {
                Signature elemSig = sig.GetElementSignature();
                uint      ln      = ReadUInt32();
                pos  = Protocol.Padded(pos, elemSig.Alignment);
                pos += (int)ln;
                return(true);
            }

            int endPos = pos;

            if (sig.GetFixedSize(ref endPos))
            {
                pos = endPos;
                return(true);
            }

            if (sig.IsDictEntry)
            {
                pos = Protocol.Padded(pos, sig.Alignment);
                Signature sigKey, sigValue;
                sig.GetDictEntrySignatures(out sigKey, out sigValue);
                if (!StepOver(sigKey))
                {
                    return(false);
                }
                if (!StepOver(sigValue))
                {
                    return(false);
                }
                return(true);
            }

            if (sig.IsStruct)
            {
                pos = Protocol.Padded(pos, sig.Alignment);
                foreach (Signature fieldSig in sig.GetFieldSignatures())
                {
                    if (!StepOver(fieldSig))
                    {
                        return(false);
                    }
                }
                return(true);
            }

            throw new Exception("Can't step over '" + sig + "'");
            //return false;
        }
        public IEnumerable<Signature> StepInto(Signature sig)
        {
            if (sig == Signature.VariantSig) {
                Signature valueSig = ReadSignature ();
                yield return valueSig;
                yield break;
            }

            // No need to handle dicts specially. IsArray does the job
            if (sig.IsArray) {
                Signature elemSig = sig.GetElementSignature ();
                uint ln = ReadUInt32 ();
                ReadPad (elemSig.Alignment);
                int endPos = pos + (int)ln;
                while (pos < endPos)
                    yield return elemSig;
                yield break;
            }

            if (sig.IsDictEntry) {
                pos = Protocol.Padded (pos, sig.Alignment);
                Signature sigKey, sigValue;
                sig.GetDictEntrySignatures (out sigKey, out sigValue);
                yield return sigKey;
                yield return sigValue;
                yield break;
            }

            if (sig.IsStruct) {
                pos = Protocol.Padded (pos, sig.Alignment);
                foreach (Signature fieldSig in sig.GetFieldSignatures ())
                    yield return fieldSig;
                yield break;
            }

            throw new Exception ("Can't step into '" + sig + "'");
            //yield break;
        }