mono.cecil

How to sort classes/fields/methods/properties in a .NET assembly?

血红的双手。 提交于 2019-12-25 07:35:51
问题 I have an assembly of a program for which I don't have access to the source code and want to sort its classes alphabetically by their fully qualified name inside of the assembly, instead of using the order specified by the compiler used to generate it. I've tried using Mono.Cecil for that, but it seems I can't change the order of classes within ModuleDefinition.Types property because it's a get-only IEnumerable . So how do I change the order of the items of an assembly module? Or is it

Mono.Cecil - How to get custom attributes

蹲街弑〆低调 提交于 2019-12-23 12:42:14
问题 I am trying to use Cecil to inspect the attributes associated with a given method. It seems to find it, but I cannot get its name using the following code: AssemblyDefinition assembly = AssemblyFactory.GetAssembly(pathBin); assembly.MainModule.Types[0].Methods[1].CustomAttributes[0].ToString() I know this must be the attribute I've set my function to, because when I remove it from the dll, the second line of code will turn out to null. What I'd like to do is be able to get the attribute's

Where can I get Mono.Cecil.Pdb.dll?

会有一股神秘感。 提交于 2019-12-23 10:55:12
问题 I'm trying to write a IL Weaver with Mono.Cecil, and for it to remain debugable in VS2010, I need the PdbReaderProvider class, or some similar implementation of ISymbolProvider. I've downloaded the latest Mono dlls from http://mono.ximian.com/daily/, but in the zip there is no Mono.Cecil.Pdb.dll. I've downloaded the source code from https://github.com/jbevain/cecil/tree/master/Mono.Cecil but I can't seem to be able to get that particular project compile under .net 4. Could somebody help me

Mono.Cecil fails to process a Silverlight 5 assembly

北城余情 提交于 2019-12-22 10:29:03
问题 When I am trying to read a Silverlight 5 assembly via Mono.Cecil version 0.9.3.0, I am getting the following exception: System.NotSupportedException: Version not supported: 5.0.5.0 ------ at Mono.Cecil.BaseAssemblyResolver.GetCorlib(AssemblyNameReference reference) in C:\programming\mono.cecil\jbevain-cecil-5df660e\Mono.Cecil\BaseAssemblyResolver.cs:line 200 ------ at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name) in C:\programming\mono.cecil\jbevain-cecil-5df660e\Mono

Adding custom attributes using mono.cecil?

扶醉桌前 提交于 2019-12-21 03:32:50
问题 I can't figure how to add custom attribute to a method using Mono.Cecil The attributes that I would want to add is like this : .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) Does anyone know how to add custom attributes 回答1: It's actually very easy. ModuleDefinition module = ...; MethodDefinition targetMethod = ...; MethodReference attributeConstructor = module.Import( typeof(DebuggerHiddenAttribute).GetConstructor(Type.EmptyTypes));

Mono.Cecil, Missing compiler required member 'System.Runtime.CompilerServices.ExtensionAttribute..ctor'

最后都变了- 提交于 2019-12-20 01:34:33
问题 I downloaded the latest Mono.Cecil and now whenever I start up my project it gives me that error. It goes away if I remove and add mono.cecil. But that is a pain to do every time I open my project. 回答1: This issue is a well know problem for all .NET 2.0 Projects that want to use Extension Methods internally and therefore declare their own internal System.Runtime.CompilerServices.ExtensionAttribute to allow this. There are various ways around this problem, if you're using .NET 3.5 or higher,

Roslyn / Find References - Can't properly load Workspace

守給你的承諾、 提交于 2019-12-19 06:44:22
问题 I'm trying to write some code to find all method invocations of any given method as I am looking to create an open source UML Sequence Diagramming tool. I'm having trouble, however, getting past the first few lines of code :/ The API appears to have changed drastically and I can't seem to infer proper usage by looking at the code. When I do: var workspace = new CustomWorkspace(); string solutionPath = @"C:\Workspace\RoslynTest\RoslynTest.sln"; var solution = workspace.CurrentSolution; I find

Does Mono.Cecil take care of branches etc location?

≡放荡痞女 提交于 2019-12-18 15:24:09
问题 Well this question may seem odd but it's simple - my point is if i have a "goto" (brtrue etc) in the decompiled code like example br IL_0003 call ***** IL_0003: ret and I add a command after that **** call will the br at the top point to ret like it should or to that code. does Cecil do it by itself or I have to take care of all those branches ? :/ it wouldn't be very hard to fix them but if Cecil doesn't then I simply won't start this project, I've no time (or knowledge) for advanced IL

How do I replace embedded resources in a .NET assembly programmatically?

老子叫甜甜 提交于 2019-12-18 12:54:59
问题 I am trying to replace a Resource of an exe(.NET, C#) file using C# code. I have found this article and made this code (using Mono.Cecil 0.6): AssemblyDefinition asdDefinition = AssemblyFactory.GetAssembly("C:\\File.exe"); EmbeddedResource erTemp = new EmbeddedResource("encFile", ManifestResourceAttributes.Public); erTemp.Data = myNewFileBytes; asdDefinition.MainModule.Resources.RemoveAt(0); asdDefinition.MainModule.Resources.Add(erTemp); AssemblyFactory.SaveAssembly(asdDefinition, "C:\

C# Intercept/change/redirect a method

淺唱寂寞╮ 提交于 2019-12-18 04:23:40
问题 Let's say I have a private, "instance," non-static, bool method in a third-party dll. All this method does is return a value. Nothing else. How would I go about intercepting calls to this method, changing it's IL OpCodes/method body, or redirecting it to an extra, overridden or derived method. I do not want to decompile the third-party dll, manually change the source, and recompile it. I also would rather not to save the assembly to disk as this would also involve using a "recompiled"