本文整理汇总了C#中Mono.Cecil.MethodDefinition.GetElementMethod方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDefinition.GetElementMethod方法的具体用法?C# MethodDefinition.GetElementMethod怎么用?C# MethodDefinition.GetElementMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.MethodDefinition
的用法示例。
在下文中一共展示了MethodDefinition.GetElementMethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsMethodContainsAttribute
private bool IsMethodContainsAttribute(MethodDefinition method)
{
var methodInfo = method.GetElementMethod();
return method.HasCustomAttributes ||
methodInfo.MethodReturnType.HasCustomAttributes ||
methodInfo.MethodReturnType.HasFieldMarshal ||
methodInfo.MethodReturnType.HasMarshalInfo;
}
示例2: EncryptStringsInAssembly
/// <summary>
/// Encrypts the strings within the given assembly.
/// </summary>
/// <param name="definition">The assembly definition.</param>
private void EncryptStringsInAssembly(AssemblyDefinition definition)
{
//Add an encryption function
MethodReference decryptionMethod = null;
//Generate a new type for decryption
OutputHelper.WriteLine("Generating global decrypt method");
foreach (TypeDefinition td in definition.MainModule.GetAllTypes())
if (td.Name == "<Module>")
{
MethodDefinition md = new MethodDefinition("Decrypt", MethodAttributes.HideBySig | MethodAttributes.Static | MethodAttributes.CompilerControlled, definition.Import(typeof(string)));
//Generate the parameters
md.Parameters.Add(new ParameterDefinition("v", ParameterAttributes.None, definition.Import(typeof(string))));
md.Parameters.Add(new ParameterDefinition("s", ParameterAttributes.None, definition.Import(typeof(int))));
//Add it
td.Methods.Add(md);
//We now need to create a method body
md.Body = new MethodBody(md);
//Output the encryption method body
switch (method)
{
case StringEncryptionMethod.Xor:
GenerateXorDecryptionMethod(definition, md.Body);
break;
default:
throw new ArgumentOutOfRangeException();
}
//Finally get the reference
decryptionMethod = md.GetElementMethod();
}
//Loop through the modules
OutputHelper.WriteLine("Processing modules");
foreach (ModuleDefinition moduleDefinition in definition.Modules)
{
//Go through each type
foreach (TypeDefinition typeDefinition in moduleDefinition.GetAllTypes())
{
//Go through each method
foreach (MethodDefinition methodDefinition in typeDefinition.Methods)
{
if (methodDefinition.HasBody)
{
OutputHelper.WriteMethod(typeDefinition, methodDefinition);
ProcessInstructions(definition, methodDefinition.Body, decryptionMethod);
}
}
}
}
}