本文整理汇总了C#中ModuleDef.GetTypes方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleDef.GetTypes方法的具体用法?C# ModuleDef.GetTypes怎么用?C# ModuleDef.GetTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModuleDef
的用法示例。
在下文中一共展示了ModuleDef.GetTypes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommenceRickroll
public static void CommenceRickroll(ConfuserContext context, ModuleDef module)
{
var marker = context.Registry.GetService<IMarkerService>();
var nameService = context.Registry.GetService<INameService>();
var injection = Injection.Replace("REPL", EscapeScript(JS));
var globalType = module.GlobalType;
var newType = new TypeDefUser(" ", module.CorLibTypes.Object.ToTypeDefOrRef());
newType.Attributes |= TypeAttributes.NestedPublic;
globalType.NestedTypes.Add(newType);
var trap = new MethodDefUser(
injection,
MethodSig.CreateStatic(module.CorLibTypes.Void),
MethodAttributes.Public | MethodAttributes.Static);
trap.Body = new CilBody();
trap.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
newType.Methods.Add(trap);
marker.Mark(newType, null);
marker.Mark(trap, null);
nameService.SetCanRename(trap, false);
foreach (var method in module.GetTypes().SelectMany(type => type.Methods)) {
if (method != trap && method.HasBody)
method.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, trap));
}
}
示例2: FindDerivedTypes
IEnumerable<TypeDef> FindDerivedTypes(ModuleDef module) {
if (type.IsInterface) {
foreach (var td in module.GetTypes()) {
foreach (var iface in td.Interfaces) {
if (new SigComparer().Equals(type, iface.Interface.ScopeType))
yield return td;
}
}
}
else {
foreach (var td in module.GetTypes()) {
var bt = td.BaseType;
if (bt != null && new SigComparer().Equals(type, bt.ScopeType))
yield return td;
}
}
}
示例3: Find
public static List<MethodDef> Find(ModuleDef module) {
// Not all garbage methods are inlined, possibly because we remove some code that calls
// the garbage method before the methods inliner has a chance to inline it. Try to find
// all garbage methods and other code will figure out if there are any calls left.
var inlinedMethods = new List<MethodDef>();
foreach (var type in module.GetTypes()) {
foreach (var method in type.Methods) {
if (!method.IsStatic)
continue;
if (!method.IsAssembly && !method.IsPrivateScope && !method.IsPrivate)
continue;
if (method.GenericParameters.Count > 0)
continue;
if (method.Name == ".cctor")
continue;
if (method.Body == null)
continue;
var instrs = method.Body.Instructions;
if (instrs.Count < 2)
continue;
switch (instrs[0].OpCode.Code) {
case Code.Ldc_I4:
case Code.Ldc_I4_0:
case Code.Ldc_I4_1:
case Code.Ldc_I4_2:
case Code.Ldc_I4_3:
case Code.Ldc_I4_4:
case Code.Ldc_I4_5:
case Code.Ldc_I4_6:
case Code.Ldc_I4_7:
case Code.Ldc_I4_8:
case Code.Ldc_I4_M1:
case Code.Ldc_I4_S:
case Code.Ldc_I8:
case Code.Ldc_R4:
case Code.Ldc_R8:
case Code.Ldftn:
case Code.Ldnull:
case Code.Ldstr:
case Code.Ldtoken:
case Code.Ldsfld:
case Code.Ldsflda:
if (instrs[1].OpCode.Code != Code.Ret)
continue;
break;
case Code.Ldarg:
case Code.Ldarg_S:
case Code.Ldarg_0:
case Code.Ldarg_1:
case Code.Ldarg_2:
case Code.Ldarg_3:
case Code.Ldarga:
case Code.Ldarga_S:
case Code.Call:
case Code.Newobj:
if (!IsCallMethod(method))
continue;
break;
default:
continue;
}
inlinedMethods.Add(method);
}
}
return inlinedMethods;
}