本文整理汇总了C#中Mono.Cecil.AssemblyDefinition类的典型用法代码示例。如果您正苦于以下问题:C# AssemblyDefinition类的具体用法?C# AssemblyDefinition怎么用?C# AssemblyDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssemblyDefinition类属于Mono.Cecil命名空间,在下文中一共展示了AssemblyDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:erdincay,项目名称:db4o,代码行数:7,代码来源:ReflectionServices.cs
示例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;
}
}
开发者ID:nzaugg,项目名称:mono,代码行数:25,代码来源:OutputStep.cs
示例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);
}
开发者ID:psni,项目名称:mono,代码行数:27,代码来源:SweepStep.cs
示例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);
}
开发者ID:neguse11,项目名称:CM3D2.ShaderWorkbench,代码行数:33,代码来源:PatcherHelper.cs
示例5: Rewrite
private void Rewrite(AssemblyDefinition assemblyDefinition)
{
foreach (ModuleDefinition moduleDefinition in assemblyDefinition.Modules)
{
Rewrite(moduleDefinition);
}
}
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:7,代码来源:StaticInstrumentor.cs
示例6: ProcessAssembly
protected override void ProcessAssembly (AssemblyDefinition assembly)
{
if (Annotations.GetAction (assembly) != AssemblyAction.Link)
return;
ProcessTypes (assembly.MainModule.Types);
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:AdjustVisibility.cs
示例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);
}
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:25,代码来源:SweepStep.cs
示例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;
}
开发者ID:sprosin,项目名称:DrivenMetrics,代码行数:7,代码来源:ILCyclomicComplextityMetirc.cs
示例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);
}
}
}
开发者ID:dbremner,项目名称:smokey,代码行数:25,代码来源:AssemblyAttributeSpellingRule.cs
示例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;
}
开发者ID:pavzaj,项目名称:OpenCover.UI,代码行数:39,代码来源:MSTestDiscoverer.cs
示例11: JSAssembly
public JSAssembly(AssemblyDefinition assembly)
{
if (assembly == null)
throw new ArgumentNullException("assembly");
Assembly = assembly;
}
开发者ID:poizan42,项目名称:JSIL,代码行数:7,代码来源:JSIdentifierTypes.cs
示例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;
}
开发者ID:n017,项目名称:NETDeob,代码行数:30,代码来源:StringDecryptor.cs
示例13: Process
public bool Process(AssemblyDefinition def)
{
foreach (var type in def.MainModule.Types)
ProcessType(def, type);
return true;
}
开发者ID:stschake,项目名称:obfuscatus,代码行数:7,代码来源:DisableReflector.cs
示例14: AssemblyTypeInfoGenerator
public AssemblyTypeInfoGenerator(string assembly, string[] searchDirs)
{
this.assembly_ = AssemblyDefinition.ReadAssembly(assembly, new ReaderParameters
{
AssemblyResolver = AssemblyTypeInfoGenerator.AssemblyResolver.WithSearchDirs(searchDirs)
});
}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:7,代码来源:AssemblyTypeInfoGenerator.cs
示例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;
}
开发者ID:col42dev,项目名称:mono-tools,代码行数:28,代码来源:MainShouldNotBePublicRule.cs
示例16: EmitAssemblyEntryPoint
public void EmitAssemblyEntryPoint (AssemblyDefinition assembly, MethodDefinition entryMethod, MethodSignature signature) {
Formatter.WriteRaw("JSIL.SetEntryPoint");
Formatter.LPar();
Formatter.AssemblyReference(assembly);
Formatter.Comma();
var context = new TypeReferenceContext();
Formatter.TypeReference(entryMethod.DeclaringType, context);
Formatter.Comma();
Formatter.Value(entryMethod.Name);
Formatter.Comma();
Formatter.MethodSignature(
entryMethod, signature, context
);
Formatter.RPar();
Formatter.Semicolon(true);
Formatter.NewLine();
}
开发者ID:sq,项目名称:JSIL,代码行数:26,代码来源:JavascriptAssemblyEmitter.cs
示例17: BaseMergeReflectionVisitor
public BaseMergeReflectionVisitor (MergeContext context, AssemblyDefinition target, AssemblyDefinition source)
{
this.context = context;
this.target = target;
this.source = source;
module = target.MainModule;
}
开发者ID:transformersprimeabcxyz,项目名称:cecil-old,代码行数:7,代码来源:BaseMergeReflectionVisitor.cs
示例18: GetChangesBetween
public IEnumerable<Change<MethodReference>> GetChangesBetween(AssemblyDefinition oldAssembly, AssemblyDefinition newAssembly)
{
var changeDetector = new MethodILChangeDetector();
var oldCache = AssemblyTypeMethodMapBuilder.BuildFor(oldAssembly);
var newCache = AssemblyTypeMethodMapBuilder.BuildFor(newAssembly);
var differences = MapKeyDifferenceFinder.GetChangesBetween(oldCache, newCache);
foreach (var method in newAssembly.AllNonIgnoredMethods())
{
var current = oldAssembly.MainModule.GetType(method.DeclaringType.FullName);
if (current == null) continue;
if (method.ContainsIgnoreAttribute()) continue;
foreach (var oldMethod in current.Methods)
{
if (oldMethod.GetChangeCacheName() == method.GetChangeCacheName())
{
if (changeDetector.AreDifferentIL(oldMethod,
method))
{
differences.Add(
new Change<MethodReference>(
ChangeType.Modify, method.ThreadSafeResolve()));
break;
}
}
}
}
differences = IEnumerableResolver.ResolveCompilerGeneratedCode(differences);
return differences;
}
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:29,代码来源:ChangeDetector.cs
示例19: VisitAssemblyDefinition
public override void VisitAssemblyDefinition (AssemblyDefinition asm)
{
if (asm.Kind != AssemblyKind.Dll && asm.EntryPoint == null)
throw new ReflectionException ("Assembly does not have an entry point defined");
if ((asm.MainModule.Image.CLIHeader.Flags & RuntimeImage.ILOnly) == 0)
throw new NotSupportedException ("Can not write a mixed mode assembly");
foreach (ModuleDefinition module in asm.Modules)
if (module.Image.CLIHeader.Metadata.VirtualAddress != RVA.Zero)
ResetImage (module);
asm.MetadataToken = new MetadataToken (TokenType.Assembly, 1);
ReflectionWriter rw = asm.MainModule.Controller.Writer;
rw.StructureWriter = this;
m_mdWriter = rw.MetadataWriter;
m_tableWriter = rw.MetadataTableWriter;
m_rowWriter = rw.MetadataRowWriter;
if (!rw.SaveSymbols)
return;
FileStream fs = m_binaryWriter.BaseStream as FileStream;
if (fs != null)
rw.OutputFile = fs.Name;
}
开发者ID:nobled,项目名称:mono,代码行数:27,代码来源:StructureWriter.cs
示例20: Emitter
public Emitter(Compiler compiler)
{
Compiler = compiler;
// create assembly object
var name = new AssemblyNameDefinition("MirelleCompiled", new Version(1, 0, 0, 0));
Assembly = AssemblyDefinition.CreateAssembly(name, "MirelleCompiled", ModuleKind.Console);
var attr = typeof(STAThreadAttribute).GetConstructor(new Type[] { } );
// register global method
GlobalBody = new MethodDefinition("main", MethodAttributes.Static | MethodAttributes.Private | MethodAttributes.HideBySig, Assembly.MainModule.TypeSystem.Void);
GlobalBody.CustomAttributes.Add(new CustomAttribute(AssemblyImport(attr)));
RootNode.GlobalMethod = new MethodNode("main", new SignatureNode("void"), true, false, GlobalBody);
RootNode.GlobalMethod.Scope = new Utils.Scope(GlobalBody);
// register global type
GlobalType = new TypeDefinition("MirelleCompiled", ".program", TypeAttributes.AutoClass | TypeAttributes.Public | TypeAttributes.SpecialName | TypeAttributes.BeforeFieldInit, Assembly.MainModule.TypeSystem.Object);
Assembly.MainModule.Types.Add(GlobalType);
GlobalType.Methods.Add(GlobalBody);
Assembly.EntryPoint = GlobalBody;
// register marker interfaces
MirelleTypeInterface = AssemblyImport(typeof(MirelleStdlib.IMirelleType));
MirelleEnumInterface = AssemblyImport(typeof(MirelleStdlib.IMirelleEnum));
}
开发者ID:menozz,项目名称:mirelle,代码行数:26,代码来源:Emitter.cs
注:本文中的Mono.Cecil.AssemblyDefinition类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论