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; } }
protected MethodCollection getRemovedMethods() { var removedMethods = new MethodCollection(); removedMethods.add(getMethodsToRemove()); removedMethods.addAndNested(getTypesToRemove()); return(removedMethods); }
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); }
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; } } }