예제 #1
0
		public UnusedMethodsFinder(ModuleDef module, IEnumerable<MethodDef> possiblyUnusedMethods, MethodCollection removedMethods) {
			this.module = module;
			this.removedMethods = removedMethods;
			foreach (var method in possiblyUnusedMethods) {
				if (method != module.ManagedEntryPoint && !removedMethods.Exists(method))
					this.possiblyUnusedMethods[method] = true;
			}
		}
예제 #2
0
        protected MethodCollection getRemovedMethods()
        {
            var removedMethods = new MethodCollection();

            removedMethods.add(getMethodsToRemove());
            removedMethods.addAndNested(getTypesToRemove());
            return(removedMethods);
        }
예제 #3
0
        protected bool isTypeCalled(TypeDef decrypterType)
        {
            if (decrypterType == null)
            {
                return(false);
            }

            var decrypterMethods = new MethodCollection();

            decrypterMethods.addAndNested(decrypterType);

            var removedMethods = getRemovedMethods();

            foreach (var type in module.GetTypes())
            {
                foreach (var method in type.Methods)
                {
                    if (method.Body == null)
                    {
                        continue;
                    }
                    if (decrypterMethods.exists(method))
                    {
                        break;                          // decrypter type / nested type method
                    }
                    if (removedMethods.exists(method))
                    {
                        continue;
                    }

                    foreach (var instr in method.Body.Instructions)
                    {
                        switch (instr.OpCode.Code)
                        {
                        case Code.Call:
                        case Code.Callvirt:
                        case Code.Newobj:
                            var calledMethod = instr.Operand as IMethod;
                            if (calledMethod == null)
                            {
                                break;
                            }
                            if (decrypterMethods.exists(calledMethod))
                            {
                                return(true);
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            return(false);
        }
예제 #4
0
 public UnusedMethodsFinder(ModuleDef module, IEnumerable <MethodDef> possiblyUnusedMethods, MethodCollection removedMethods)
 {
     this.module         = module;
     this.removedMethods = removedMethods;
     foreach (var method in possiblyUnusedMethods)
     {
         if (method != module.ManagedEntryPoint && !removedMethods.Exists(method))
         {
             this.possiblyUnusedMethods[method] = true;
         }
     }
 }