Exemple #1
0
 internal VariableInfo ResolveVariable(VariableReference parent, string name)
 {
     return(null);
 }
Exemple #2
0
        internal unsafe VariableInfo ResolveVariable(int threadHashCode, VariableReference variable, out object res)
        {
            ILIntepreter intepreter;

            res = null;
            if (AppDomain.Intepreters.TryGetValue(threadHashCode, out intepreter))
            {
                if (variable != null)
                {
                    switch (variable.Type)
                    {
                    case VariableTypes.Normal:
                    {
                        StackObject *ptr = (StackObject *)variable.Address;
                        object       obj = StackObject.ToObject(ptr, AppDomain, intepreter.Stack.ManagedStack);
                        if (obj != null)
                        {
                            //return ResolveMember(obj, name, out res);
                            res = obj;
                            return(null);
                        }
                        else
                        {
                            return(VariableInfo.Null);
                        }
                    }

                    case VariableTypes.FieldReference:
                    case VariableTypes.PropertyReference:
                    {
                        object obj;
                        if (variable.Parent != null)
                        {
                            var info = ResolveVariable(threadHashCode, variable.Parent, out obj);
                            if (obj != null)
                            {
                                return(ResolveMember(obj, variable.Name, out res));
                            }
                            else
                            {
                                return(VariableInfo.NullReferenceExeption);
                            }
                        }
                        else
                        {
                            var frame = intepreter.Stack.Frames.Peek();
                            var m     = frame.Method;
                            if (m.HasThis)
                            {
                                var addr = Minus(frame.LocalVarPointer, m.ParameterCount + 1);
                                var v    = StackObject.ToObject(addr, intepreter.AppDomain, intepreter.Stack.ManagedStack);
                                return(ResolveMember(v, variable.Name, out res));
                            }
                            else
                            {
                                return(VariableInfo.GetCannotFind(variable.Name));
                            }
                        }
                    }

                    case VariableTypes.IndexAccess:
                    {
                        return(ResolveIndexAccess(threadHashCode, variable.Parent, variable.Parameters[0], out res));
                    }

                    case VariableTypes.Integer:
                    {
                        res = variable.Offset;
                        return(VariableInfo.GetInteger(variable.Offset));
                    }

                    case VariableTypes.String:
                    {
                        res = variable.Name;
                        return(VariableInfo.GetString(variable.Name));
                    }

                    case VariableTypes.Boolean:
                    {
                        if (variable.Offset == 1)
                        {
                            res = true;
                            return(VariableInfo.True);
                        }
                        else
                        {
                            res = false;
                            return(VariableInfo.False);
                        }
                    }

                    case VariableTypes.Null:
                    {
                        res = null;
                        return(VariableInfo.Null);
                    }

                    default:
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    return(VariableInfo.NullReferenceExeption);
                }
            }
            else
            {
                return(VariableInfo.NullReferenceExeption);
            }
        }
Exemple #3
0
        internal unsafe VariableInfo[] EnumChildren(int threadHashCode, VariableReference parent)
        {
            ILIntepreter intepreter;

            if (AppDomain.Intepreters.TryGetValue(threadHashCode, out intepreter))
            {
                object obj;
                var    info = ResolveVariable(threadHashCode, parent, out obj);
                if (obj != null)
                {
                    if (obj is Array)
                    {
                        return(EnumArray((Array)obj, intepreter));
                    }
                    else if (obj is IList)
                    {
                        return(EnumList((IList)obj, intepreter));
                    }
                    else if (obj is IDictionary)
                    {
                        return(EnumDictionary((IDictionary)obj, intepreter));
                    }
                    else if (obj is ILTypeInstance)
                    {
                        return(EnumILTypeInstance((ILTypeInstance)obj, intepreter));
                    }
                    else if (obj is ILRuntime.Runtime.Enviorment.CrossBindingAdaptorType)
                    {
                        return(EnumILTypeInstance(((Enviorment.CrossBindingAdaptorType)obj).ILInstance, intepreter));
                    }
                    else
                    {
                        return(EnumCLRObject(obj, intepreter));
                    }
                }
                else
                {
                    return new VariableInfo[] { VariableInfo.NullReferenceExeption }
                };
            }
            else
            {
                return new VariableInfo[] { VariableInfo.NullReferenceExeption }
            };
        }

        VariableInfo[] EnumArray(Array arr, ILIntepreter intepreter)
        {
            VariableInfo[] res = new VariableInfo[arr.Length];

            for (int i = 0; i < arr.Length; i++)
            {
                try
                {
                    var obj = arr.GetValue(i);

                    VariableInfo info = VariableInfo.FromObject(obj, true);
                    info.Name   = string.Format("[{0}]", i);
                    info.Offset = i;
                    info.Type   = VariableTypes.IndexAccess;
                    res[i]      = info;
                }
                catch (Exception ex)
                {
                    var info = VariableInfo.GetException(ex);
                    info.Name = string.Format("[{0}]", i);
                    res[i]    = info;
                }
            }

            return(res);
        }

        VariableInfo[] EnumList(IList lst, ILIntepreter intepreter)
        {
            VariableInfo[] res = new VariableInfo[lst.Count];

            for (int i = 0; i < lst.Count; i++)
            {
                try
                {
                    var obj = lst[i];

                    VariableInfo info = VariableInfo.FromObject(obj, true);
                    info.Name   = string.Format("[{0}]", i);
                    info.Offset = i;
                    info.Type   = VariableTypes.IndexAccess;

                    res[i] = info;
                }
                catch (Exception ex)
                {
                    var info = VariableInfo.GetException(ex);
                    info.Name = string.Format("[{0}]", i);
                    res[i]    = info;
                }
            }

            return(res);
        }

        VariableInfo[] EnumDictionary(IDictionary lst, ILIntepreter intepreter)
        {
            VariableInfo[] res = new VariableInfo[lst.Count];

            var keys   = GetArray(lst.Keys);
            var values = GetArray(lst.Values);

            for (int i = 0; i < lst.Count; i++)
            {
                try
                {
                    var          obj  = values[i];
                    VariableInfo info = VariableInfo.FromObject(obj, true);
                    info.Name       = string.Format("[{0}]", i);
                    info.Type       = VariableTypes.IndexAccess;
                    info.Offset     = i;
                    info.Value      = string.Format("{0},{1}", SafeToString(keys[i]), SafeToString(values[i]));
                    info.Expandable = true;
                    res[i]          = info;
                }
                catch (Exception ex)
                {
                    var info = VariableInfo.GetException(ex);
                    info.Name = string.Format("[{0}]", i);
                    res[i]    = info;
                }
            }
            return(res);
        }

        string SafeToString(object obj)
        {
            if (obj != null)
            {
                return(obj.ToString());
            }
            else
            {
                return("null");
            }
        }

        object[] GetArray(ICollection lst)
        {
            object[] res = new object[lst.Count];
            int      idx = 0;

            foreach (var i in lst)
            {
                res[idx++] = i;
            }
            return(res);
        }

        VariableInfo[] EnumILTypeInstance(ILTypeInstance obj, ILIntepreter intepreter)
        {
            return(EnumObject(obj, obj.Type.ReflectionType));
        }

        VariableInfo[] EnumCLRObject(object obj, ILIntepreter intepreter)
        {
            return(EnumObject(obj, obj.GetType()));
        }

        VariableInfo[] EnumObject(object obj, Type t)
        {
            List <VariableInfo> lst = new List <VariableInfo>();

            foreach (var i in t.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance))
            {
                try
                {
                    if (i.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false).Length > 0)
                    {
                        continue;
                    }
                    var          val  = i.GetValue(obj);
                    VariableInfo info = VariableInfo.FromObject(val);
                    info.Type        = VariableTypes.FieldReference;
                    info.TypeName    = i.FieldType.FullName;
                    info.Name        = i.Name;
                    info.Expandable  = !i.FieldType.IsPrimitive && val != null;
                    info.IsPrivate   = i.IsPrivate;
                    info.IsProtected = i.IsFamily;

                    lst.Add(info);
                }
                catch (Exception ex)
                {
                    var info = VariableInfo.GetException(ex);
                    info.Name = i.Name;
                    lst.Add(info);
                }
            }

            foreach (var i in t.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance))
            {
                try
                {
                    if (i.GetIndexParameters().Length > 0)
                    {
                        continue;
                    }
                    var          val  = i.GetValue(obj, null);
                    VariableInfo info = VariableInfo.FromObject(val);
                    info.Type        = VariableTypes.PropertyReference;
                    info.TypeName    = i.PropertyType.FullName;
                    info.Name        = i.Name;
                    info.Expandable  = !i.PropertyType.IsPrimitive && val != null;
                    info.IsPrivate   = i.GetGetMethod(true).IsPrivate;
                    info.IsProtected = i.GetGetMethod(true).IsFamily;

                    lst.Add(info);
                }
                catch (Exception ex)
                {
                    var info = VariableInfo.GetException(ex);
                    info.Name = i.Name;
                    lst.Add(info);
                }
            }

            return(lst.ToArray());
        }
Exemple #4
0
        internal unsafe VariableInfo ResolveIndexAccess(int threadHashCode, VariableReference body, VariableReference idx, out object res)
        {
            ILIntepreter intepreter;

            res = null;
            if (AppDomain.Intepreters.TryGetValue(threadHashCode, out intepreter))
            {
                object obj;
                var    info = ResolveVariable(threadHashCode, body, out obj);
                if (obj != null)
                {
                    object idxObj;
                    info = ResolveVariable(threadHashCode, idx, out idxObj);
                    if (obj is Array)
                    {
                        res             = ((Array)obj).GetValue((int)idxObj);
                        info            = VariableInfo.FromObject(res);
                        info.Type       = VariableTypes.IndexAccess;
                        info.TypeName   = obj.GetType().GetElementType().FullName;
                        info.Expandable = res != null && !obj.GetType().GetElementType().IsPrimitive;

                        return(info);
                    }
                    else
                    {
                        if (obj is ILTypeInstance)
                        {
                            var m = ((ILTypeInstance)obj).Type.GetMethod("get_Item");
                            if (m != null)
                            {
                                res             = intepreter.AppDomain.Invoke(m, obj, idxObj);
                                info            = VariableInfo.FromObject(res);
                                info.Type       = VariableTypes.IndexAccess;
                                info.TypeName   = m.ReturnType.FullName;
                                info.Expandable = res != null && !m.ReturnType.IsPrimitive;

                                return(info);
                            }
                            else
                            {
                                return(VariableInfo.NullReferenceExeption);
                            }
                        }
                        else
                        {
                            if (obj is ILRuntime.Runtime.Enviorment.CrossBindingAdaptorType)
                            {
                                throw new NotImplementedException();
                            }
                            else
                            {
                                if (obj is IDictionary && idxObj is int)
                                {
                                    IDictionary dic  = (IDictionary)obj;
                                    var         keys = GetArray(dic.Keys);
                                    if (keys[0].GetType() != typeof(int))
                                    {
                                        int index  = (int)idxObj;
                                        var values = GetArray(dic.Values);
                                        var t      = typeof(KeyValuePair <,>).MakeGenericType(keys[index].GetType(), values[index].GetType());
                                        var ctor   = t.GetConstructor(new Type[] { keys[index].GetType(), values[index].GetType() });
                                        res             = ctor.Invoke(new object[] { keys[index], values[index] });
                                        info            = VariableInfo.FromObject(res);
                                        info.Type       = VariableTypes.IndexAccess;
                                        info.Offset     = index;
                                        info.TypeName   = t.FullName;
                                        info.Expandable = true;

                                        return(info);
                                    }
                                }
                                var pi = obj.GetType().GetProperty("Item");
                                if (pi != null)
                                {
                                    res             = pi.GetValue(obj, new object[] { idxObj });
                                    info            = VariableInfo.FromObject(res);
                                    info.Type       = VariableTypes.IndexAccess;
                                    info.TypeName   = pi.PropertyType.FullName;
                                    info.Expandable = res != null && !pi.PropertyType.IsPrimitive;

                                    return(info);
                                }
                                else
                                {
                                    return(VariableInfo.NullReferenceExeption);
                                }
                            }
                        }
                    }
                }
                else
                {
                    return(VariableInfo.NullReferenceExeption);
                }
            }
            else
            {
                return(VariableInfo.NullReferenceExeption);
            }
        }
        internal unsafe VariableInfo ResolveVariable(int threadHashCode, VariableReference parent, string name)
        {
            ILIntepreter intepreter;

            if (AppDomain.Intepreters.TryGetValue(threadHashCode, out intepreter))
            {
                switch (parent.Type)
                {
                case VariableTypes.Normal:
                {
                    StackObject *ptr = (StackObject *)parent.Address;
                    object       obj = StackObject.ToObject(ptr, AppDomain, intepreter.Stack.ManagedStack);
                    if (obj != null)
                    {
                        if (obj is ILTypeInstance)
                        {
                            var type = ((ILTypeInstance)obj).Type.ReflectionType;
                            var fi   = type.GetField(name);
                            if (fi != null)
                            {
                                var          res  = fi.GetValue(obj);
                                var          rt   = res.GetType();
                                VariableInfo info = new VariableInfo();

                                info.Address  = 0;
                                info.Name     = name;
                                info.Type     = VariableTypes.FieldReference;
                                info.TypeName = fi.FieldType.FullName;
                                info.Value    = res != null?res.ToString() : "null";

                                return(info);
                            }
                            else
                            {
                                var pi = type.GetProperty(name);
                                if (pi != null)
                                {
                                    var          res  = pi.GetValue(obj, null);
                                    var          rt   = res.GetType();
                                    VariableInfo info = new VariableInfo();

                                    info.Address  = 0;
                                    info.Name     = name;
                                    info.Type     = VariableTypes.PropertyReference;
                                    info.TypeName = pi.PropertyType.FullName;
                                    info.Value    = res != null?res.ToString() : "null";

                                    info.Expandable = res != null && !pi.PropertyType.IsPrimitive;
                                    return(info);
                                }
                            }
                        }
                    }
                    else
                    {
                        VariableInfo info = new VariableInfo();
                        info.Type     = VariableTypes.Error;
                        info.Name     = "";
                        info.TypeName = "";
                        info.Value    = "NullReferenceException";
                        return(info);
                    }
                    return(null);
                }

                default:
                    throw new NotImplementedException();
                }
            }
            else
            {
                return(null);
            }
        }