Beispiel #1
0
		void Initialize() {
			var callCounter = new CallCounter();
			int count = 0;
			foreach (var type in module.GetTypes()) {
				if (count >= 40)
					break;
				foreach (var method in type.Methods) {
					if (method.Name != ".ctor" && method.Name != ".cctor" && module.EntryPoint != method)
						continue;
					foreach (var calledMethod in DotNetUtils.GetCalledMethods(module, method)) {
						if (!calledMethod.IsStatic || calledMethod.Body == null)
							continue;
						if (!DotNetUtils.IsMethod(calledMethod, "System.Void", "()"))
							continue;
						if (IsEmptyClass(calledMethod)) {
							callCounter.Add(calledMethod);
							count++;
						}
					}
				}
			}

			int numCalls;
			var theMethod = (MethodDef)callCounter.Most(out numCalls);
			if (numCalls >= 10)
				emptyMethod = theMethod;
		}
		public void Find() {
			var additionalTypes = new string[] {
				"System.IntPtr",
//				"System.Reflection.Assembly",		//TODO: Not in unknown DNR version with jitter support
			};
			var checkedMethods = new Dictionary<IMethod, bool>(MethodEqualityComparer.CompareDeclaringTypes);
			var callCounter = new CallCounter();
			int typesLeft = 30;
			foreach (var type in module.GetTypes()) {
				var cctor = type.FindStaticConstructor();
				if (cctor == null || cctor.Body == null)
					continue;
				if (typesLeft-- <= 0)
					break;

				foreach (var method in DotNetUtils.GetCalledMethods(module, cctor)) {
					if (!checkedMethods.ContainsKey(method)) {
						checkedMethods[method] = false;
						if (method.DeclaringType.BaseType == null || method.DeclaringType.BaseType.FullName != "System.Object")
							continue;
						if (!DotNetUtils.IsMethod(method, "System.Void", "()"))
							continue;
						if (!encryptedResource.CouldBeResourceDecrypter(method, additionalTypes))
							continue;
						checkedMethods[method] = true;
					}
					else if (!checkedMethods[method])
						continue;
					callCounter.Add(method);
				}
			}

			encryptedResource.Method = (MethodDef)callCounter.Most();
		}
Beispiel #3
0
        void init()
        {
            var callCounter = new CallCounter();
            int count = 0;
            foreach (var type in module.GetTypes()) {
                if (count >= 40)
                    break;
                foreach (var method in type.Methods) {
                    if (method.Name != ".ctor")
                        continue;
                    foreach (var tuple in DotNetUtils.getCalledMethods(module, method)) {
                        var calledMethod = tuple.Item2;
                        if (!calledMethod.IsStatic || calledMethod.Body == null)
                            continue;
                        if (!DotNetUtils.isMethod(calledMethod, "System.Void", "()"))
                            continue;
                        if (isEmptyClass(calledMethod)) {
                            callCounter.add(calledMethod);
                            count++;
                        }
                    }
                }
            }

            emptyMethod = (MethodDefinition)callCounter.most();
        }
        public void findDelegateCreator(ModuleDefMD module)
        {
            var callCounter = new CallCounter();
            foreach (var type in module.Types) {
                if (type.Namespace != "" || !DotNetUtils.derivesFromDelegate(type))
                    continue;
                var cctor = type.FindStaticConstructor();
                if (cctor == null)
                    continue;
                foreach (var method in DotNetUtils.getMethodCalls(cctor))
                    callCounter.add(method);
            }

            var mostCalls = callCounter.most();
            if (mostCalls == null)
                return;

            setDelegateCreatorMethod(DotNetUtils.getMethod(module, mostCalls));
        }
Beispiel #5
0
        public void findDelegateCreator(ModuleDefinition module)
        {
            var callCounter = new CallCounter();
            foreach (var type in module.Types) {
                if (type.Namespace != "" || !DotNetUtils.isDelegateType(type))
                    continue;
                var cctor = DotNetUtils.getMethod(type, ".cctor");
                if (cctor == null)
                    continue;
                foreach (var method in DotNetUtils.getMethodCalls(cctor))
                    callCounter.add(method);
            }

            var mostCalls = callCounter.most();
            if (mostCalls == null)
                return;

            setDelegateCreatorMethod(DotNetUtils.getMethod(DotNetUtils.getType(module, mostCalls.DeclaringType), mostCalls));
        }
Beispiel #6
0
        public void find()
        {
            var additionalTypes = new string[] {
                "System.IntPtr",
            //				"System.Reflection.Assembly",		//TODO: Not in unknown DNR version with jitter support
            };
            var checkedMethods = new Dictionary<MethodReferenceAndDeclaringTypeKey, bool>();
            var callCounter = new CallCounter();
            int typesLeft = 30;
            foreach (var type in module.GetTypes()) {
                var cctor = DotNetUtils.getMethod(type, ".cctor");
                if (cctor == null || cctor.Body == null)
                    continue;
                if (typesLeft-- <= 0)
                    break;

                foreach (var info in DotNetUtils.getCalledMethods(module, cctor)) {
                    var method = info.Item2;
                    var key = new MethodReferenceAndDeclaringTypeKey(method);
                    if (!checkedMethods.ContainsKey(key)) {
                        checkedMethods[key] = false;
                        if (info.Item1.BaseType == null || info.Item1.BaseType.FullName != "System.Object")
                            continue;
                        if (!DotNetUtils.isMethod(method, "System.Void", "()"))
                            continue;
                        if (!encryptedResource.couldBeResourceDecrypter(method, additionalTypes))
                            continue;
                        checkedMethods[key] = true;
                    }
                    else if (!checkedMethods[key])
                        continue;
                    callCounter.add(method);
                }
            }

            encryptedResource.Method = (MethodDefinition)callCounter.most();
        }