Esempio n. 1
0
 public override void WriteTo(WriteFormatterInfo writeFormatterInfo)
 {
     writeFormatterInfo.Writer.Write((byte)MessageType.RpcRequest);
     if (MethodKey is int)
     {
         serviceByte |= 1 << 1;
     }
     if (ExpectResponse)
     {
         serviceByte |= 1 << 2;
     }
     if (ExpectAck)
     {
         serviceByte |= 1 << 3;
     }
     base.WriteTo(writeFormatterInfo);
     writeFormatterInfo.Writer.WriteVarInt(RequestId);
     if (MethodKey is int)
     {
         writeFormatterInfo.Writer.WriteVarInt((int)MethodKey);
     }
     else
     {
         writeFormatterInfo.Writer.Write(MethodKey.ToString());
     }
 }
Esempio n. 2
0
			public void GetMethodInfo(MethodKey key, out Parameter[] parameters, out Local[] locals, out ILVariable[] decLocals) {
				parameters = null;
				locals = null;
				decLocals = null;

				foreach (var textView in MainWindow.Instance.AllTextViews) {
					if (parameters != null && decLocals != null)
						break;

					var cm = textView.CodeMappings;
					if (cm == null)
						continue;
					MemberMapping mapping;
					if (!cm.TryGetValue(key, out mapping))
						continue;
					var method = mapping.MethodDefinition;
					if (mapping.LocalVariables != null && method.Body != null) {
						locals = method.Body.Variables.ToArray();
						decLocals = new ILVariable[method.Body.Variables.Count];
						foreach (var v in mapping.LocalVariables) {
							if (v.IsGenerated)
								continue;
							if (v.OriginalVariable == null)
								continue;
							if ((uint)v.OriginalVariable.Index >= decLocals.Length)
								continue;
							decLocals[v.OriginalVariable.Index] = v;
						}
					}

					parameters = method.Parameters.ToArray();
				}
			}
Esempio n. 3
0
 protected override IMethodNode CreateShadowConcreteMethodNode(MethodKey methodKey)
 {
     return(new ShadowConcreteMethodNode(methodKey.Method,
                                         MethodEntrypoint(
                                             methodKey.Method.GetCanonMethodTarget(CanonicalFormKind.Specific),
                                             methodKey.IsUnboxingStub)));
 }
Esempio n. 4
0
        public override bool SetBreakpoint(Module module)
        {
            bool okMod = MethodKey.IsSameModule(module.FullPath);

            Debug.Assert(okMod, "Trying to set a BP that belongs in another module");
            if (!okMod)
            {
                return(false);
            }
            SourcecodeSegment segment = SourcecodeSegment.CreateForIL(module, this.Location.Line, (int)MethodKey.Token, (int)ILOffset);

            if (segment == null)
            {
                return(false);
            }
            try {
                ICorDebugFunctionBreakpoint corBreakpoint = segment.CorFunction.GetILCode().CreateBreakpoint((uint)segment.ILStart);
                corBreakpoint.Activate(Enabled ? 1 : 0);

                corBreakpoints.Add(corBreakpoint);

                OnSet(new BreakpointEventArgs(this));

                return(true);
            } catch {
                return(false);
            }
        }
Esempio n. 5
0
 static string GetMethodAsString(string asmName, MethodKey key)
 {
     var loadedAsm = MainWindow.Instance.LoadAssembly(asmName, key.Module);
     var mod = loadedAsm.ModuleDefinition as ModuleDefMD;
     var method = mod == null ? null : mod.ResolveToken(key.Token) as MethodDef;
     return method == null ? null : method.ToString();
 }
Esempio n. 6
0
        /// <summary>Gets the collection of Dto instances from API.</summary>
        /// <typeparam name="T">Type on behalf of which the request is being called.</typeparam>
        /// <param name="methodKey">Relevant method key.</param>
        /// <param name="pagination">Pagination object.</param>
        /// <param name="entitiesId">Entities identifier.</param>
        /// <param name="sort">Sort.</param>
        /// <param name="additionalUrlParams">Collection of key-value pairs of request parameters.</param>
        /// <returns>Collection of Dto instances returned from API.</returns>
        protected async Task <ListPaginated <T> > GetListAsync <T>(MethodKey methodKey, Pagination pagination, Sort sort, Dictionary <String, String> additionalUrlParams, params string[] entitiesId)
            where T : EntityBase, new()
        {
            var endPoint = GetApiEndPoint(methodKey);

            endPoint.SetParameters(entitiesId);

            if (pagination == null)
            {
                pagination = new Pagination();
            }

            if (sort != null && sort.IsSet)
            {
                if (additionalUrlParams == null)
                {
                    additionalUrlParams = new Dictionary <string, string>();
                }

                additionalUrlParams.Add(Constants.SORT_URL_PARAMETER_NAME, sort.GetFields());
            }

            var restTool = new RestTool(this._root, true);

            return(await restTool.RequestListAsync <T>(endPoint, additionalUrlParams, pagination));
        }
        /// <summary>Gets the collection of Dto instances from API.</summary>
        /// <typeparam name="T">Type on behalf of which the request is being called.</typeparam>
        /// <param name="methodKey">Relevant method key.</param>
        /// <param name="pagination">Pagination object.</param>
        /// <param name="entityId">Entity identifier.</param>
        /// <param name="sort">Sort.</param>
        /// <param name="additionalUrlParams">Collection of key-value pairs of request parameters.</param>
        /// <returns>Collection of Dto instances returned from API.</returns>
        protected ListPaginated <T> GetList <T>(MethodKey methodKey, Pagination pagination, string entityId, Sort sort, Dictionary <String, String> additionalUrlParams)
            where T : EntityBase, new()
        {
            string urlMethod = "";

            if (!String.IsNullOrEmpty(entityId))
            {
                urlMethod = String.Format(this.GetRequestUrl(methodKey), entityId);
            }
            else
            {
                urlMethod = this.GetRequestUrl(methodKey);
            }

            if (pagination == null)
            {
                pagination = new Pagination();
            }

            if (sort != null && sort.IsSet)
            {
                if (additionalUrlParams == null)
                {
                    additionalUrlParams = new Dictionary <string, string>();
                }

                additionalUrlParams.Add(Constants.SORT_URL_PARAMETER_NAME, sort.GetFields());
            }

            RestTool restTool = new RestTool(this._root, true);

            return(restTool.RequestList <T>(urlMethod, this.GetRequestType(methodKey), additionalUrlParams, pagination));
        }
Esempio n. 8
0
        public bool GetLocation(DecompilerTextView textView, out TextLocation location, out TextLocation endLocation)
        {
            var           cm = textView == null ? null : textView.CodeMappings;
            MemberMapping mapping;
            var           key = MethodKey.Create(MemberReference);

            if (cm == null || key == null || !cm.TryGetValue(key.Value, out mapping))
            {
                location = endLocation = new TextLocation();
                return(false);
            }

            bool isMatch;
            SourceCodeMapping map = mapping.GetInstructionByOffset(ilOffset, out isMatch);

            if (map == null)
            {
                location = endLocation = new TextLocation();
                return(false);
            }

            location    = map.StartLocation;
            endLocation = map.EndLocation;
            return(true);
        }
Esempio n. 9
0
        public static void Toggle(DecompilerTextView textView, int line, int column)
        {
            var bps  = SourceCodeMappingUtils.Find(textView, line, column);
            var bpms = GetBreakpointBookmarks(textView, bps);

            if (bpms.Count > 0)
            {
                if (bpms.IsEnabled())
                {
                    foreach (var bpm in bpms)
                    {
                        BookmarkManager.RemoveMark(bpm);
                    }
                }
                else
                {
                    foreach (var bpm in bpms)
                    {
                        bpm.IsEnabled = true;
                    }
                }
            }
            else if (bps.Count > 0)
            {
                foreach (var bp in bps)
                {
                    if (MethodKey.Create(bp.MemberMapping.MethodDefinition) == null)
                    {
                        continue;
                    }
                    BookmarkManager.AddMark(new BreakpointBookmark(bp.MemberMapping.MethodDefinition, bp.StartLocation, bp.EndLocation, bp.ILInstructionOffset));
                }
                textView.ScrollAndMoveCaretTo(bps[0].StartLocation.Line, bps[0].StartLocation.Column);
            }
        }
Esempio n. 10
0
 public override bool Equals(MethodKey other)
 {
     MethodSpecMethodKey tOther = other as MethodSpecMethodKey;
     if (tOther == null)
         return false;
     return m_methodSpec == tOther.m_methodSpec;
 }
Esempio n. 11
0
 public bool ShouldVisit(MethodKey methodKey)
 {
   if (_methods == null)
   {
     return true;
   }
   return _methods.Contains(methodKey);
 }
        public override bool Equals(MethodKey other)
        {
            GMDelegateConvertToMulticast tOther = other as GMDelegateConvertToMulticast;
            if (tOther == null)
                return false;

            return m_dt == tOther.m_dt;
        }
Esempio n. 13
0
        static string GetMethodAsString(string asmName, MethodKey key)
        {
            var loadedAsm = MainWindow.Instance.LoadAssembly(asmName, key.Module);
            var mod       = loadedAsm.ModuleDefinition as ModuleDefMD;
            var method    = mod == null ? null : mod.ResolveToken(key.Token) as MethodDef;

            return(method == null ? null : method.ToString());
        }
Esempio n. 14
0
        public override bool Equals(MethodKey other)
        {
            GMMulticastDelegateInvoke tOther = other as GMMulticastDelegateInvoke;
            if (tOther == null)
                return false;

            return m_dt == tOther.m_dt;
        }
Esempio n. 15
0
 public static bool JumpTo(DecompilerTextView textView, IMemberRef mr, MethodKey key, int ilOffset)
 {
     return MainWindow.Instance.JumpToReference(textView, mr, (success, hasMovedCaret) => {
         if (success)
             return MoveCaretTo(textView, key, ilOffset);
         return false;
     });
 }
        public override bool Equals(MethodKey other)
        {
            GMBoxedValueTypeGetHashCode tOther = other as GMBoxedValueTypeGetHashCode;
            if (tOther == null)
                return false;

            return m_bt == tOther.m_bt;
        }
Esempio n. 17
0
        public void Complex()
        {
            MethodParameter p    = MethodParameter.Create <int>();
            var             code = p.GetHashCode();

            MethodKey mk     = new MethodKey(typeof(AppContext), "test", null, null, false);
            var       mkCode = mk.GetHashCode();
        }
Esempio n. 18
0
        /// <summary>Gets an instance of <see cref="ApiEndPoint"/> for given method key</summary>
        /// <param name="key">The method key to get the end point details for</param>
        /// <returns></returns>
        protected ApiEndPoint GetApiEndPoint(MethodKey key)
        {
            if (!_methods.ContainsKey(key))
            {
                throw new Exception("Unknown method key: " + key);
            }

            return((ApiEndPoint)_methods[key].Clone());
        }
Esempio n. 19
0
        public BreakpointBookmark(IMemberRef member, TextLocation location, TextLocation endLocation, ILRange range, bool isEnabled = true)
            : base(member, range.From, location, endLocation)
        {
            var key = MethodKey.Create(member);

            Debug.Assert(key != null, "Caller must verify that MethodKey.Create() won't fail");
            this.MethodKey = key.Value;
            this.ILRange   = range;
            this.isEnabled = isEnabled;
        }
Esempio n. 20
0
        /// <summary>Gets the DTO instance from API.</summary>
        /// <typeparam name="T">Type on behalf of which the request is being called.</typeparam>
        /// <param name="methodKey">Relevant method key.</param>
        /// <param name="entityId">Entity identifier.</param>
        /// <param name="secondEntityId">Second entity identifier.</param>
        /// <returns>The DTO instance returned from API.</returns>
        protected T GetObject <T>(MethodKey methodKey, string entityId, string secondEntityId)
            where T : EntityBase, new()
        {
            string urlMethod = String.Format(this.GetRequestUrl(methodKey), entityId, secondEntityId);

            RestTool rest     = new RestTool(this._root, true);
            T        response = rest.Request <T, T>(urlMethod, this.GetRequestType(methodKey));

            return(response);
        }
Esempio n. 21
0
 public Method FindMethod(MethodKey key)
 {
   Type type = FindType(key);
   Method member = type.FindMethod(key);
   if (member == null)
   {
     member = type.AddMethod(key);
   }
   return member;
 }
Esempio n. 22
0
        /// <summary>Gets the DTO instance from API.</summary>
        /// <typeparam name="T">Type on behalf of which the request is being called.</typeparam>
        /// <param name="methodKey">Relevant method key.</param>
        /// <param name="entitiesId">Entities identifier.</param>
        /// <returns>The DTO instance returned from API.</returns>
        protected async Task <T> GetObjectAsync <T>(MethodKey methodKey, params string[] entitiesId) where T : EntityBase, new()
        {
            var endPoint = GetApiEndPoint(methodKey);

            endPoint.SetParameters(entitiesId);

            var rest = new RestTool(this._root, true);

            return(await rest.RequestAsync <T, T>(endPoint));
        }
Esempio n. 23
0
        public RangeMenuItem(string i_ItemName, GameScreen i_GameScreen, int i_Value, int i_Min, int i_Max, int i_Jump, MethodKey i_DecreaseMethod, MethodKey i_IncreaseMethod)
            : base(i_ItemName, i_GameScreen, Color.White, GameMenuItem.eFontSize.Medium, new MethodKey[] { i_DecreaseMethod, i_IncreaseMethod })
        {
            float x = this.Text.Width + this.Text.Position.X + 20;

            m_Range = new Range(i_GameScreen, i_Value, i_Min, i_Max, i_Jump);
            m_Range.Initialize();
            m_Range.Position = new Vector2(x, this.Position.Y);
            m_DecreaseMethod = i_DecreaseMethod;
            m_IncreaseMethod = i_IncreaseMethod;
        }
Esempio n. 24
0
        /// <summary>Gets the DTO instance from API.</summary>
        /// <typeparam name="T">Type on behalf of which the request is being called.</typeparam>
        /// <param name="methodKey">Relevant method key.</param>
        /// <param name="entitiesId">Entities identifier.</param>
        /// <returns>The DTO instance returned from API.</returns>
        protected T GetObject <T>(MethodKey methodKey, params string[] entitiesId) where T : EntityBase, new()
        {
            var endPoint = GetApiEndPoint(methodKey);

            endPoint.SetParameters(entitiesId);

            RestTool rest     = new RestTool(this._root, true);
            T        response = rest.Request <T, T>(endPoint);

            return(response);
        }
            public TypeMetadata AddMethodParameterAttributes(MethodKey method, int parameterIndex, IEnumerable <Attribute> attributes)
            {
                if (parameterIndex == -1)
                {
                    return(AddMethodReturnParameterAttributes(method, attributes));
                }

                var methodMetadata = GetMethodMetadata(method).AddParameterAttributes(parameterIndex, attributes);

                return(new TypeMetadata(TypeAttributes, MemberAttributes, MethodAttributes.SetItem(method, methodMetadata)));
            }
            private MethodMetadata GetMethodMetadata(MethodKey key)
            {
                MethodMetadata metadata;

                if (!MethodAttributes.TryGetValue(key, out metadata))
                {
                    metadata = new MethodMetadata(key.Parameters.Count);
                }

                return(metadata);
            }
Esempio n. 27
0
        /// <summary>Creates the DTO instance.</summary>
        /// <typeparam name="U">Return type.</typeparam>
        /// <typeparam name="T">Type on behalf of which the request is being called.</typeparam>
        /// <param name="idempotencyKey">Idempotency key for this request.</param>
        /// <param name="methodKey">Relevant method key.</param>
        /// <param name="entity">DTO instance that is going to be sent.</param>
        /// <param name="entitiesId">Entity identifier.</param>
        /// <returns>The DTO instance returned from API.</returns>
        protected U CreateObject <U, T>(String idempotencyKey, MethodKey methodKey, T entity, params string[] entitiesId)
            where U : EntityBase, new()
            where T : EntityPostBase
        {
            var endPoint = GetApiEndPoint(methodKey);

            endPoint.SetParameters(entitiesId);

            var restTool = new RestTool(this._root, true);

            return(restTool.Request <U, T>(idempotencyKey, endPoint, null, null, entity));
        }
Esempio n. 28
0
 public ToggleMenuItem(string i_ItemName, GameScreen i_GameScreen, string i_SelectedOption, List <string> i_Options, Keys i_ActivateItemKey, MethodKey i_ToggleRightMethod, MethodKey i_ToggleLeftMethod)
     : base(i_ItemName, i_GameScreen, Color.White, GameMenuItem.eFontSize.Medium, new MethodKey[] { i_ToggleRightMethod, i_ToggleLeftMethod })
 {
     if (i_Options.Count > 0)
     {
         m_SelectedOption = i_SelectedOption;
         initOptions(i_Options);
         m_Options[m_SelectedOptionIndex].TintColor = Color.Aqua;
         m_ToggleRightMethod = i_ToggleRightMethod;
         m_ToggleLeftMethod  = i_ToggleLeftMethod;
     }
 }
Esempio n. 29
0
        /// <summary>Gets the DTO instance from API.</summary>
        /// <typeparam name="T">Type on behalf of which the request is being called.</typeparam>
        /// <param name="methodKey">Relevant method key.</param>
        /// <param name="entityId">Entity identifier.</param>
        /// <param name="secondEntityId">Second entity identifier.</param>
        /// <returns>The DTO instance returned from API.</returns>
        protected async Task <T> GetObject <T>(MethodKey methodKey, string entityId, string secondEntityId)
            where T : EntityBase, new()
        {
            var endPoint = GetApiEndPoint(methodKey);

            endPoint.SetParameters(entityId, secondEntityId);

            RestTool rest     = new RestTool(this._root, true);
            T        response = await rest.Request <T, T>(endPoint);

            return(response);
        }
Esempio n. 30
0
        /// <summary>Saves the Dto instance.</summary>
        /// <typeparam name="U">Return type.</typeparam>
        /// <typeparam name="T">Type on behalf of which the request is being called.</typeparam>
        /// <param name="methodKey">Relevant method key.</param>
        /// <param name="entity">Dto instance that is going to be sent.</param>
        /// <param name="entitiesId">Entities identifier.</param>
        /// <returns>The Dto instance returned from API.</returns>
        protected async Task <U> UpdateObjectAsync <U, T>(MethodKey methodKey, T entity, params string[] entitiesId)
            where U : EntityBase, new()
            where T : EntityPutBase
        {
            var endPoint = GetApiEndPoint(methodKey);

            endPoint.SetParameters(entitiesId);

            var restTool = new RestTool(this._root, true);

            return(await restTool.RequestAsync <U, T>(null, endPoint, null, null, entity));
        }
Esempio n. 31
0
        /// <summary>Creates the DTO instance.</summary>
        /// <typeparam name="U">Return type.</typeparam>
        /// <typeparam name="T">Type on behalf of which the request is being called.</typeparam>
        /// <param name="idempotencyKey">Idempotency key for this request.</param>
        /// <param name="methodKey">Relevant method key.</param>
        /// <param name="entity">DTO instance that is going to be sent.</param>
        /// <param name="entityId">Entity identifier.</param>
        /// <param name="secondEntityId">Second entity identifier.</param>
        /// <returns>The DTO instance returned from API.</returns>
        protected async Task <U> CreateObject <U, T>(String idempotencyKey, MethodKey methodKey, T entity, String entityId, String secondEntityId)
            where U : EntityBase, new()
            where T : EntityPostBase
        {
            var endPoint = GetApiEndPoint(methodKey);

            endPoint.SetParameters(entityId, secondEntityId);

            RestTool restTool = new RestTool(this._root, true);
            U        result   = await restTool.Request <U, T>(idempotencyKey, endPoint, null, null, entity);

            return(result);
        }
Esempio n. 32
0
        /// <summary>Gets the URL of REST Mango Pay API.</summary>
        /// <param name="key">The method key to get URL of.</param>
        /// <returns>The URL string of given method.</returns>
        protected String GetRequestUrl(MethodKey key)
        {
            String result = "";

            try
            {
                result = this._methods[key][0];
            }
            catch
            {
                throw new Exception("Unknown method key: " + key);
            }
            return(result);
        }
Esempio n. 33
0
        private void CreatePropertyInvocations(Type implType, Property prop, string methodPrefix, string invocationType)
        {
            var key = new MethodKey(prop.ObjectClass.Module.Namespace, prop.ObjectClass.Name, string.Format("{0}{1}", methodPrefix, prop.Name));

            if (_reflectedMethods.ContainsKey(key))
            {
                var methodInfos = _reflectedMethods[key];
                foreach (var mi in methodInfos)
                {
                    CreateInvokeInfo(implType, mi, string.Format(CultureInfo.InvariantCulture, "On{0}_{1}", prop.Name, invocationType));
                }
                _attachedMethods[key] = true;
            }
        }
Esempio n. 34
0
        /// <summary>
        /// Creates and caches a fast method invoker.
        /// </summary>
        /// <param name="method">Method info instance to create an invoker for.</param>
        /// <returns>The fast method invoker.</returns>
        public static FastInvoker GetInvoker(MethodInfo method)
        {
            Guard.NotNull(method, nameof(method));

            var cacheKey = MethodKey.Create(method);

            if (!_invokersCache.TryGetValue(cacheKey, out var invoker))
            {
                invoker = new FastInvoker(method);
                _invokersCache.TryAdd(cacheKey, invoker);
            }

            return(invoker);
        }
Esempio n. 35
0
        private void CreateDefaultMethodInvocations(Type implType, DataType dt, string methodName)
        {
            var key = new MethodKey(dt.Module.Namespace, dt.Name, methodName);

            if (_reflectedMethods.ContainsKey(key))
            {
                var methodInfos = _reflectedMethods[key];
                foreach (var mi in methodInfos)
                {
                    CreateInvokeInfo(implType, mi, string.Format(CultureInfo.InvariantCulture, "On{0}_{1}", methodName, dt.Name));
                }
                _attachedMethods[key] = true;
            }
        }
Esempio n. 36
0
            public void GetMethodInfo(MethodKey key, out Parameter[] parameters, out Local[] locals, out ILVariable[] decLocals)
            {
                parameters = null;
                locals     = null;
                decLocals  = null;

                foreach (var textView in MainWindow.Instance.AllTextViews)
                {
                    if (parameters != null && decLocals != null)
                    {
                        break;
                    }

                    var cm = textView.CodeMappings;
                    if (cm == null)
                    {
                        continue;
                    }
                    MemberMapping mapping;
                    if (!cm.TryGetValue(key, out mapping))
                    {
                        continue;
                    }
                    var method = mapping.MethodDefinition;
                    if (mapping.LocalVariables != null && method.Body != null)
                    {
                        locals    = method.Body.Variables.ToArray();
                        decLocals = new ILVariable[method.Body.Variables.Count];
                        foreach (var v in mapping.LocalVariables)
                        {
                            if (v.IsGenerated)
                            {
                                continue;
                            }
                            if (v.OriginalVariable == null)
                            {
                                continue;
                            }
                            if ((uint)v.OriginalVariable.Index >= decLocals.Length)
                            {
                                continue;
                            }
                            decLocals[v.OriginalVariable.Index] = v;
                        }
                    }

                    parameters = method.Parameters.ToArray();
                }
            }
Esempio n. 37
0
        void LoadInternal()
        {
            DNSpySettings settings = DNSpySettings.Load();
            var           bpsx     = settings[SETTINGS_NAME];

            BreakpointManager.Instance.Clear();
            foreach (var bpx in bpsx.Elements("Breakpoint"))
            {
                uint?  token            = (uint?)bpx.Attribute("Token");
                string assemblyFullPath = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullPath"));
                string moduleFullPath   = SessionSettings.Unescape((string)bpx.Attribute("ModuleFullPath"));
                bool   isDynamic        = (bool?)bpx.Attribute("IsDynamic") ?? false;
                bool   isInMemory       = (bool?)bpx.Attribute("IsInMemory") ?? false;
                uint?  ilOffset         = (uint?)bpx.Attribute("ILOffset") ?? (uint?)bpx.Attribute("From");       //TODO: Remove "From" some time after this commit
                bool?  isEnabled        = (bool?)bpx.Attribute("IsEnabled");

                if (token == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(moduleFullPath))
                {
                    continue;
                }
                if (ilOffset == null)
                {
                    continue;
                }
                if (isEnabled == null)
                {
                    continue;
                }

                var snModule = new SerializedDnModule(moduleFullPath, isDynamic, isInMemory);
                var key      = MethodKey.Create(token.Value, snModule);

                if (!isInMemory)
                {
                    var s = SessionSettings.Unescape((string)bpx.Attribute("Method"));
                    if (s == null || s != GetMethodAsString(assemblyFullPath, key))
                    {
                        continue;
                    }
                }

                var bp = new ILCodeBreakpoint(assemblyFullPath, key, ilOffset.Value, isEnabled.Value);
                BreakpointManager.Instance.Add(bp);
            }
        }
Esempio n. 38
0
		public static bool MoveCaretTo(DecompilerTextView textView, MethodKey key, uint ilOffset) {
			if (textView == null)
				return false;
			TextLocation location, endLocation;
			var cm = textView.CodeMappings;
			if (cm == null || !cm.ContainsKey(key))
				return false;
			if (!cm[key].GetInstructionByTokenAndOffset(ilOffset, out location, out endLocation)) {
				//TODO: Missing IL ranges
				return false;
			}
			else {
				textView.ScrollAndMoveCaretTo(location.Line, location.Column);
				return true;
			}
		}
Esempio n. 39
0
        public void Register(object instance)
        {
            if (instance == null)
            {
                throw new ArgumentException("instance cannot be null");
            }

            if (_instanceDict.ContainsKey(instance.GetType()))
            {
                return;
            }

            var methodDict = new Dictionary <MethodKey, IList <MethodValue> >();

            foreach (var method in instance.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                var customAttributes = method.GetCustomAttributes(typeof(SubscribeAttribute), true);
                if (customAttributes.Length <= 0)
                {
                    continue;
                }
                if (customAttributes.Length > 1)
                {
                    throw new InvalidProgramException(
                              "The attribute for subscribing can exists only one times per method; method: " +
                              method.DeclaringType?.FullName + "#" + method.Name);
                }
                if (method.GetParameters().Length != 1)
                {
                    throw new InvalidProgramException("A subscribe method must have only one parameter; method: " +
                                                      method.DeclaringType?.FullName + "#" + method.Name);
                }

                var subscribe = (SubscribeAttribute)customAttributes[0];

                var key = new MethodKey(subscribe.Name, method.GetParameters()[0].ParameterType);
                if (!methodDict.ContainsKey(key))
                {
                    methodDict.Add(key, new List <MethodValue>());
                }

                methodDict[key].Add(new MethodValue(method, subscribe));
            }

            _instanceDict.Add(instance, methodDict);
        }
Esempio n. 40
0
        public override bool IsVisible(DecompilerTextView textView)
        {
            var          key = MethodKey.Create(MemberReference);
            uint         ilOffset = ILRange.From;
            TextLocation location, endLocation;
            var          cm = textView == null ? null : textView.CodeMappings;

            if (cm == null || key == null || !cm.ContainsKey(key.Value))
            {
                return(false);
            }
            if (!cm[key.Value].GetInstructionByTokenAndOffset((uint)ilOffset, out location, out endLocation))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 41
0
 public ILBreakpoint(NDebugger debugger, TextLocation location, TextLocation endLocation, MethodKey methodKey, uint offset, bool enabled)
 {
     this.Debugger = debugger;
     this.Location = location;
     this.EndLocation = endLocation;
     this.MethodKey = methodKey;
     this.ILOffset = offset;
     this.Enabled = enabled;
 }
Esempio n. 42
0
        public bool ShouldSkipStringHiding(MethodKey method, InheritMap map, bool projectHideStrings)
        {
            if (method.DeclaringType.IsResourcesType () && method.Method.ReturnType.FullName == "System.Resources.ResourceManager")
                return true; // IMPORTANT: avoid hiding resource type name, as it might be renamed later.

            if (ShouldForce (method.TypeKey, TypeAffectFlags.AffectString, map))
                return false;

            if (forceStringHiding.IsMatch (method, map))
                return false;

            if (ShouldSkip (method.TypeKey, TypeAffectFlags.AffectString, map))
                return true;

            if (skipStringHiding.IsMatch (method, map))
                return true;

            return !projectHideStrings;
        }
Esempio n. 43
0
        public bool ShouldSkipParams(MethodKey method, InheritMap map, bool keepPublicApi, bool hidePrivateApi, bool markedOnly, out string message)
        {
            var attribute = method.Method.MarkedToRename ();
            // skip runtime methods
            if (attribute != null) {
                message = "attribute";
                return !attribute.Value;
            }

            var parent = method.DeclaringType.MarkedToRename ();
            if (parent != null) {
                message = "type attribute";
                return !parent.Value;
            }

            if (markedOnly) {
                message = "MarkedOnly option in configuration";
                return true;
            }

            if (ShouldForce (method.TypeKey, TypeAffectFlags.AffectMethod, map)) {
                message = "type rule in configuration";
                return false;
            }

            if (forceMethods.IsMatch (method, map)) {
                message = "method rule in configuration";
                return false;
            }

            if (ShouldSkip (method.TypeKey, TypeAffectFlags.AffectMethod, map)) {
                message = "type rule in configuration";
                return true;
            }

            if (skipMethods.IsMatch (method, map)) {
                message = "method rule in configuration";
                return true;
            }

            if (method.DeclaringType.IsTypePublic () && method.Method.IsPublic ()) {
                message = "KeepPublicApi option in configuration";
                return keepPublicApi;
            }

            message = "HidePrivateApi option in configuration";
            return !hidePrivateApi;
        }
Esempio n. 44
0
 public void SetPropertySetter(PropertyKey propertyKey, MethodKey methodKey)
 {
   if (propertyKey == null) throw new ArgumentNullException("propertyKey");
   if (methodKey == null) throw new ArgumentNullException("methodKey");
   Property property = _memberRepository.FindProperty(propertyKey);
   property.Setter = _memberRepository.FindMethod(methodKey);
 }
		internal IKVM.Internal.MapXml.InstructionList GetMethodPrologue(MethodKey method)
		{
			if(mapxml_MethodPrologues == null)
			{
				return null;
			}
			IKVM.Internal.MapXml.InstructionList prologue;
			mapxml_MethodPrologues.TryGetValue(method, out prologue);
			return prologue;
		}
Esempio n. 46
0
 public void UseMethod(MethodKey key)
 {
   if (key == null) throw new ArgumentNullException("key");
   UseInCurrentContext(_memberRepository.FindMethod(key));
 }
Esempio n. 47
0
 public void SetEventRemover(EventKey eventKey, MethodKey methodKey)
 {
   if (eventKey == null) throw new ArgumentNullException("eventKey");
   if (methodKey == null) throw new ArgumentNullException("methodKey");
   Event theEvent = _memberRepository.FindEvent(eventKey);
   theEvent.Remover = _memberRepository.FindMethod(methodKey);
 }
Esempio n. 48
0
        private void DumpMethod( MethodKey key, ObfuscatedThing info )
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("{0}(", info.Name );
            for ( int i = 0; i < key.Count; i++ )
            {
                if ( i > 0 )
                    sb.Append( "," );

                sb.Append(key.ParamTypes[i]);
            }

            sb.Append(")");

            if (info.Status == ObfuscationStatus.Renamed)
            {
                writer.WriteStartElement("renamedMethod");
                writer.WriteAttributeString("oldName", sb.ToString());
                writer.WriteAttributeString("newName", info.StatusText);
                writer.WriteEndElement();
                writer.WriteString("\r\n");
            }
            else
            {
                writer.WriteStartElement("skippedMethod");
                writer.WriteAttributeString("name", sb.ToString());
                writer.WriteAttributeString("reason", info.StatusText);
                writer.WriteEndElement();
                writer.WriteString("\r\n");
            }
        }
Esempio n. 49
0
 static bool MethodsMatch(MethodKey[] methods, int i, int j)
 {
     return methods [i].Equals ((NameParamSig) methods [j]);
 }
Esempio n. 50
0
		public ObfuscatedThing GetMethod(MethodKey key)
		{
			ObfuscatedClass c = GetClass(key.TypeKey);

			ObfuscatedThing t;
			if (!c.Methods.TryGetValue(key, out t))
			{
				t = new ObfuscatedThing(key.ToString());
				c.Methods[key] = t;
			}

			return t;
		}
Esempio n. 51
0
		public void UpdateMethod(MethodKey key, ObfuscationStatus status, string text)
		{
			ObfuscatedThing m = GetMethod(key);

			m.Update(status, text);
		}
		private static bool GatherAllInterfaceMethods(TypeWrapper tw, ClassFile.ConstantPoolItemMethodType[] bridges, Dictionary<MethodKey, MethodWrapper> methods,
			ref int abstractMethodCount, ref int bridgeMethodCount)
		{
			foreach (MethodWrapper mw in tw.GetMethods())
			{
				if (mw.IsVirtual)
				{
					MirandaMethodWrapper mmw = mw as MirandaMethodWrapper;
					if (mmw != null)
					{
						if (mmw.Error != null)
						{
							return false;
						}
						continue;
					}
					MethodKey key = new MethodKey("", mw.Name, mw.Signature);
					MethodWrapper current;
					if (methods.TryGetValue(key, out current))
					{
						if (!MatchSignatures(mw, current))
						{
							// linkage error (or unloadable type)
							return false;
						}
					}
					else
					{
						methods.Add(key, mw);
						if (mw.IsAbstract && !IsObjectMethod(mw))
						{
							if (bridges != null && IsBridge(mw, bridges))
							{
								bridgeMethodCount++;
							}
							else
							{
								abstractMethodCount++;
							}
						}
					}
					mw.Link();
					if (mw.GetMethod() == null)
					{
						return false;
					}
					if (current != null && mw.RealName != current.RealName)
					{
						return false;
					}
				}
			}
			foreach (TypeWrapper tw1 in tw.Interfaces)
			{
				if (!GatherAllInterfaceMethods(tw1, bridges, methods, ref abstractMethodCount, ref bridgeMethodCount))
				{
					return false;
				}
			}
			return true;
		}
Esempio n. 53
0
        /// <summary>
        /// Gets the current debugged method
        /// </summary>
        /// <param name="info"></param>
        /// <param name="currentKey"></param>
        /// <param name="codeMappings"></param>
        /// <returns></returns>
        public static bool VerifyAndGetCurrentDebuggedMethod(DecompilerTextView textView, out Tuple<MethodKey, int, IMemberRef> info, out MethodKey currentKey, out Dictionary<MethodKey, MemberMapping> codeMappings)
        {
            currentKey = default(MethodKey);
            codeMappings = textView == null ? null : textView.CodeMappings;
            info = DebugInformation.DebugStepInformation;

            if (info == null)
                return false;

            currentKey = info.Item1;
            if (codeMappings == null || !codeMappings.ContainsKey(currentKey))
                return false;

            return true;
        }
Esempio n. 54
0
 public void StartMethod(MethodKey key)
 {
   if (key == null) throw new ArgumentNullException("key");
   _methods.Push(key);
   GetCurrentMethod();
 }
Esempio n. 55
0
        MethodGroup AddToGroup(MethodGroup group, MethodKey methodKey)
        {
            // add the method to the group
            group.Methods.Add (methodKey);

            // point the method at the group
            MethodGroup group2;
            if (methodGroups.TryGetValue (methodKey, out group2) && group2 != group) {
                // we have a problem; two unrelated groups come together; merge them
                if (group.Methods.Count > group2.Methods.Count) {
                    group.Name = group.Name ?? group2.Name;
                    group.External = group.External | group2.External;
                    foreach (MethodKey mk in group2.Methods) {
                        methodGroups [mk] = group;
                        group.Methods.Add (mk);

                    }
                    return group;
                } else {
                    group2.Name = group2.Name ?? group.Name;
                    group2.External = group2.External | group.External;
                    foreach (MethodKey mk in group.Methods) {
                        methodGroups [mk] = group2;
                        group2.Methods.Add (mk);

                    }
                    return group2;
                }
            }
            methodGroups [methodKey] = group;

            return group;
        }
Esempio n. 56
0
        public bool ShouldSkip(MethodKey method, InheritMap map, bool keepPublicApi, bool hidePrivateApi, bool markedOnly, out string message)
        {
            if (method.Method.IsRuntime) {
                message = "runtime method";
                return true;
            }

            if (method.Method.IsSpecialName) {
                switch (method.Method.SemanticsAttributes) {
                case MethodSemanticsAttributes.Getter:
                case MethodSemanticsAttributes.Setter:
                    message = "skipping properties";
                    return !project.Settings.RenameProperties;
                case MethodSemanticsAttributes.AddOn:
                case MethodSemanticsAttributes.RemoveOn:
                    message = "skipping events";
                    return !project.Settings.RenameEvents;
                default:
                    message = "special name";
                    return true;
                }
            }

            return ShouldSkipParams (method, map, keepPublicApi, hidePrivateApi, markedOnly, out message);
        }
Esempio n. 57
0
		public bool ShouldSkipStringHiding(MethodKey method, InheritMap map)
		{
			if (ShouldSkip(method.TypeKey, TypeSkipFlags.SkipStringHiding, map))
				return true;

			return skipStringHiding.IsMatch(method, map);
		}
Esempio n. 58
0
		public StackFrameLine(StackFrameLineType type, DecompilerTextView decompilerTextView, MethodKey methodKey, uint ilOffset)
			: base(methodKey, ilOffset) {
			this.type = type;
			this.decompilerTextView = decompilerTextView;
		}
Esempio n. 59
0
        private void DumpMethod( MethodKey key, ObfuscatedThing info )
        {
            writer.Write( "\t{0}(", info.Name );
            for ( int i = 0; i < key.Count; i++ )
            {
                if ( i > 0 )
                    writer.Write( ", " );
                else
                    writer.Write( " " );

                writer.Write( key.ParamTypes[i] );
            }

            if ( info.Status == ObfuscationStatus.Renamed )
                writer.WriteLine( " ) -> {0}", info.StatusText );
            else
            {
                Debug.Assert( info.Status == ObfuscationStatus.Skipped,
                    "Status is expected to be either Renamed or Skipped." );

                writer.WriteLine( " ) skipped:  {0}", info.StatusText );
            }
        }
Esempio n. 60
0
 public MethodGroup GetMethodGroup(MethodKey methodKey)
 {
     MethodGroup group;
     if (methodGroups.TryGetValue (methodKey, out group))
         return group;
     else
         return null;
 }