本文整理汇总了C#中Mono.Cecil.AssemblyDefinition类的典型用法代码示例。如果您正苦于以下问题:C# AssemblyDefinition类的具体用法?C# AssemblyDefinition怎么用?C# AssemblyDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssemblyDefinition类属于Mono.Cecil命名空间,在下文中一共展示了AssemblyDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindInstruction
public static Instruction FindInstruction(AssemblyDefinition assembly, string typeName, string testMethodName, OpCode testInstruction)
{
MethodDefinition testMethod = FindMethod(assembly, typeName, testMethodName);
Assert.IsNotNull(testMethod);
return FindInstruction(testMethod, testInstruction);
}
示例2: OutputAssembly
void OutputAssembly (AssemblyDefinition assembly)
{
string directory = Context.OutputDirectory;
CopyConfigFileIfNeeded (assembly, directory);
switch (Annotations.GetAction (assembly)) {
case AssemblyAction.Link:
assembly.Write (GetAssemblyFileName (assembly, directory), SaveSymbols (assembly));
break;
case AssemblyAction.Copy:
CloseSymbols (assembly);
CopyAssembly (GetOriginalAssemblyFileInfo (assembly), directory, Context.LinkSymbols);
break;
case AssemblyAction.Delete:
CloseSymbols (assembly);
var target = GetAssemblyFileName (assembly, directory);
if (File.Exists (target))
File.Delete (target);
break;
default:
CloseSymbols (assembly);
break;
}
}
示例3: SweepAssembly
void SweepAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
if (!IsMarkedAssembly (assembly)) {
RemoveAssembly (assembly);
return;
}
var types = new List<TypeDefinition> ();
foreach (TypeDefinition type in assembly.MainModule.Types) {
if (Annotations.IsMarked (type)) {
SweepType (type);
types.Add (type);
continue;
}
if (type.Name == "<Module>")
types.Add (type);
}
assembly.MainModule.Types.Clear ();
foreach (TypeDefinition type in types)
assembly.MainModule.Types.Add (type);
}
示例4: SetHook
public static void SetHook(
HookType hookType,
AssemblyDefinition targetAssembly, string targetTypeName, string targetMethodName,
AssemblyDefinition calleeAssembly, string calleeTypeName, string calleeMethodName)
{
#if DEBUG
Console.WriteLine("SetHook - {0}/{1}|{2} -> {3}/{4}|{5}", targetAssembly.Name.Name, targetTypeName, targetMethodName, calleeAssembly.Name.Name, calleeTypeName, calleeMethodName);
#endif
TypeDefinition calleeTypeDefinition = calleeAssembly.MainModule.GetType(calleeTypeName);
if (calleeTypeDefinition == null)
{
throw new Exception(string.Format("Error ({0}) : {1} is not found", calleeAssembly.Name, calleeTypeName));
}
MethodDefinition calleeMethod = GetMethod(calleeTypeDefinition, calleeMethodName);
if (calleeMethod == null)
{
throw new Exception(string.Format("Error ({0}) : {1}.{2} is not found", calleeAssembly.Name, calleeTypeName, calleeMethodName));
}
TypeDefinition targetTypeDefinition = targetAssembly.MainModule.GetType(targetTypeName);
if (targetTypeDefinition == null)
{
throw new Exception(string.Format("Error ({0}) : {1} is not found", targetAssembly.Name, targetTypeName));
}
MethodDefinition targetMethod = GetMethod(targetTypeDefinition, targetMethodName);
if (targetMethod == null)
{
throw new Exception(string.Format("Error ({0}) : {1}.{2} is not found", targetAssembly.Name, targetTypeName, targetMethodName));
}
HookMethod(hookType, targetAssembly.MainModule, targetMethod, calleeMethod);
}
示例5: Rewrite
private void Rewrite(AssemblyDefinition assemblyDefinition)
{
foreach (ModuleDefinition moduleDefinition in assemblyDefinition.Modules)
{
Rewrite(moduleDefinition);
}
}
示例6: ProcessAssembly
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
ProcessTypes (assembly.MainModule.Types);
}
示例7: SweepAssembly
void SweepAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
if (!IsMarkedAssembly (assembly)) {
RemoveAssembly (assembly);
return;
}
var types = assembly.MainModule.Types;
var cloned_types = Clone (types);
types.Clear ();
foreach (TypeDefinition type in cloned_types) {
if (Annotations.IsMarked (type)) {
SweepType (type);
types.Add (type);
continue;
}
SweepReferences (assembly, type);
}
}
示例8: ProcessAssembly
public AssemblyResult ProcessAssembly(AssemblyDefinition assembly, ModuleResult[] moduleResults)
{
AssemblyResult result = new AssemblyResult(assembly.Name.Name);
result.ModuleResults = moduleResults;
result.Result = moduleResults.Sum(r => r.Result);
return result;
}
示例9: VisitAssembly
public void VisitAssembly(AssemblyDefinition assembly)
{
Log.DebugLine(this, "-----------------------------------");
Log.DebugLine(this, "checking {0}", assembly.Name);
if (Aspell.Instance != null)
{
string details = string.Empty;
foreach (CustomAttribute attr in assembly.CustomAttributes)
{
foreach (object o in attr.ConstructorParameters)
{
string text = o.ToString();
Unused.Value = CheckSpelling.Text(text, ref details);
}
}
if (details.Length > 0)
{
details = "Words: " + details;
Log.DebugLine(this, details);
Reporter.AssemblyFailed(assembly, CheckID, details);
}
}
}
示例10: DiscoverTestsInAssembly
/// <summary>
/// Discovers the tests in the Assembly.
/// </summary>
/// <param name="dllPath">The path to the DLL.</param>
/// <param name="assembly">The loaded Assembly.</param>
/// <returns>Tests in the Assembly</returns>
protected override List<TestClass> DiscoverTestsInAssembly(string dll, AssemblyDefinition assembly)
{
var classes2 = new List<TestClass>();
foreach (var type in assembly.MainModule.Types)
{
bool isMSTest = false;
try
{
var customAttributes = type.CustomAttributes;
if (customAttributes != null)
{
isMSTest = customAttributes.Any(attribute => attribute.AttributeType.FullName == typeof(TestClassAttribute).FullName);
}
}
catch { }
if (isMSTest)
{
var TestClass = new TestClass
{
DLLPath = dll,
Name = type.Name,
Namespace = type.Namespace,
TestType = TestType.MSTest
};
TestClass.TestMethods = DiscoverTestsInClass(type, TestClass);
classes2.Add(TestClass);
}
}
return classes2;
}
示例11: JSAssembly
public JSAssembly(AssemblyDefinition assembly)
{
if (assembly == null)
throw new ArgumentNullException("assembly");
Assembly = assembly;
}
示例12: FindDecryptor
public static MethodDefinition FindDecryptor(AssemblyDefinition asmDef)
{
foreach (var modDef in asmDef.Modules)
foreach (var typeDef in modDef.Types)
foreach (var mDef in typeDef.Methods)
{
var signature = new ILSignature
{
Start = 1,
StartOpCode = OpCodes.Nop,
Instructions = new List<OpCode>
{
OpCodes.Callvirt,
OpCodes.Stloc_0,
OpCodes.Ldloc_0,
OpCodes.Newarr,
OpCodes.Stloc_1,
OpCodes.Ldc_I4_0,
OpCodes.Stloc_2
}
};
if (mDef.HasBody) {
if (SignatureFinder.IsMatch(mDef, signature))
return mDef;
}
}
return null;
}
示例13: Process
public bool Process(AssemblyDefinition def)
{
foreach (var type in def.MainModule.Types)
ProcessType(def, type);
return true;
}
示例14: AssemblyTypeInfoGenerator
public AssemblyTypeInfoGenerator(string assembly, string[] searchDirs)
{
this.assembly_ = AssemblyDefinition.ReadAssembly(assembly, new ReaderParameters
{
AssemblyResolver = AssemblyTypeInfoGenerator.AssemblyResolver.WithSearchDirs(searchDirs)
});
}
示例15: CheckAssembly
public RuleResult CheckAssembly (AssemblyDefinition assembly)
{
// assembly must have an entry point to be examined
MethodDefinition entry_point = assembly.EntryPoint;
if (entry_point == null)
return RuleResult.DoesNotApply;
// RULE APPLIES
// we have to check declaringType's visibility so
// if we can't get access to it (is this possible?) we abandon
// also, if it is not public, we don't have to continue our work
// - we can't reach Main () anyways
TypeDefinition type = entry_point.DeclaringType.Resolve ();
if (type == null || !type.IsPublic)
return RuleResult.Success;
// at last, if Main () is not public, then it's okay
if (!entry_point.IsPublic)
return RuleResult.Success;
if (assembly.References (VisualBasic)) {
Runner.Report (type, Severity.Medium, Confidence.High, "Reduce class or module visibility (from public).");
} else {
Runner.Report (entry_point, Severity.Medium, Confidence.Total, "Change method visibility to private or internal.");
}
return RuleResult.Failure;
}