cil

Linking a .NET Expression Tree into a new assembly

允我心安 提交于 2019-12-05 01:28:09
问题 I'm trying to write my own toy My Toy Language -> MSIL compiler in order to get a better understanding of how compilers work. I got the parsing and lexing working, I have built the expression trees and using the System.Linq.Expressions expression tree API, I have a working interpreter. Now I would like to emit some real MSIL assemblies. The problem is, I can't figure out how to actually build these assemblies. The MethodBuilder class only accepts raw MSIL method bodies, so I have to get the

How to convert CIL to a LINQ Expression Tree [closed]

南楼画角 提交于 2019-12-05 01:19:36
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Has any work been done on the direct conversion of CIL to LINQ expression trees? This would include class libraries, blogs, books, academic papers, etc. What are the known mismatches between CIL and LINQ

The curiosity of the let_ property method

梦想与她 提交于 2019-12-04 22:54:26
Every .net developer knows about the concept of properties. A rough 99.99%, it's just a piece of metadata gluing together two methods, a getter, and a setter. Same thing usually goes for events, with their add, remove, and invoke method. The ECMA-335 describes a «Other» kind of method semantic, that would apply to either a property or an event. Conceptually, a property or an event could have a multiple number of «other» methods. Today's the first day I stumbled upon a property with an «other» method. And of course it had to be related to COM. The interface EnvDTE.Property, in the EnvDTE

Manually edit MSIL in compiled DLL

99封情书 提交于 2019-12-04 18:52:45
If you want to make a small change to a .net application, is it possible to edit the MSIL directly? Use ildasm.exe to decompile and recompile with ilasm.exe . For strong-named assemblies you will need the key file if you want that the recompiled assembly has the same identity as the original assembly. 来源: https://stackoverflow.com/questions/6746387/manually-edit-msil-in-compiled-dll

MSIL inspection

非 Y 不嫁゛ 提交于 2019-12-04 15:25:57
I have some MSIL in byte format (result of reflection's GetMethodBody()) that I'd like to analyze a bit. I'd like to find all classes created with the new operator in the MSIL. Any ideas on how to do that programmatically? I ended up using the MSIL parser here: http://blogs.msdn.com/zelmalki/archive/2008/12/11/msil-parser.aspx , with the source slightly modified to work on ConstructorInfo as well as MethodInfo (results returned from reflector). It will give a list of operations, with the opcode and parameters. The opcode is an enum, based on that value the parameters can be interpreted. The

Programmatic MSIL injection

时光总嘲笑我的痴心妄想 提交于 2019-12-04 11:44:33
问题 Let's say I have a buggy application like this: using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine("2 + 1 = {0}", Add(2, 1)); } static int Add(int x, int y) { return x + x; // <-- oops! } } } The application is already compiled and deployed into the wild. Someone has found the bug, and now they are requesting a fix for it. While I could re-deploy this application with the fix, its an extreme hassle for reasons outside of my

Is there a good wrapper around ILGenerator? [closed]

本秂侑毒 提交于 2019-12-04 11:31:58
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I'm using System.Reflection.Emit for a while now, and find it (who don't?) as painful as bug prone. Do you know if there is a good

.NET 4.5 MethodBuilder.SetMethodBody

﹥>﹥吖頭↗ 提交于 2019-12-04 10:02:12
In the newest version of the .NET framework, version 4.5, the MethodBuilder class has a method called SetMethodBody that I believe is exactly what I'm looking at as an alternative to using ILGenerator (which is annoying and limited in odd ways). The documentation can be found here , although since .NET 4.5 is not out yet, it is not fully documented. I can supply all but two of the arguments, but the rest I will need help with. The first that I don't understand is byte[] localSignature , the third argument. MSDN states that it is "An array of bytes that contain the serialized local variable

Why does 'unbox.any' not provide a helpful exception text the way 'castclass' does?

眉间皱痕 提交于 2019-12-04 09:59:30
问题 To illustrate my question, consider these trivial examples (C#): object reference = new StringBuilder(); object box = 42; object unset = null; // CASE ONE: bad reference conversions (CIL instrcution 0x74 'castclass') try { string s = (string)reference; } catch (InvalidCastException ice) { Console.WriteLine(ice.Message); // Unable to cast object of type 'System.Text.StringBuilder' to type 'System.String'. } try { string s = (string)box; } catch (InvalidCastException ice) { Console.WriteLine

Learning CIL [closed]

感情迁移 提交于 2019-12-04 09:29:00
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Does anybody know any good resources for learning how to program CIL with in-depth descriptions of commands, etc.? I have looked