cil

Why is the CLR's jmp instruction unverifiable?

The title says it all. I've known about the jmp instruction for awhile, but it never struck me as being even remotely unsafe. I recently had cause to check the CIL specs and was very surprised to discover jmp is considered unverifiable. Any explanations would be much appreciated. ...

MSIL code problem

Hi all, I am trying to modificate an assembly (mine) just by ildassembling it and by modifying the MSIL code. I just want to pop a MessageBox. Here is my code : .module extern Fusion.dll .module extern kernel32.dll .module extern advapi32.dll .module extern aspnet_state.exe .module extern webengine.dll .module extern aspnet_wp.e...

How to write in an file in MSIL code

Hi all, I have a aspx webpage which uses an assembly mine (which mades a custom authentification). I would like to modify MSIL code (so just with ILDASM/ILASM tools) of my assembly in order to log something in a file. I have tried to add this at the end of the authentification method of my assembly : IL_0034: ldstr "C:\\path_to_...

Where to start with writing MSIL

Where can I look to get started with writing MSIL in c#? ...

Clarification required re: Use of .NET Assemblies in GAC - Set Up to use Globally?

Hi, I've done much reading and experimentation today regarding sigining of assemblies, and their installation into the GAC via various methods (mscorcfg.msc / drag and drop). What I thought, was that once a file was in the GAC, you did not need to make references from projects in Visual studio. I know that you CAN make references via t...

Add File version, Product Version to the Existing Assemblies

I have some set of assemblies. I have disassemble those assemblies using the ISDASM.exe and change the namespace in the IL code and again compile those IL code using the ISASM.exe to get the assemblies without any error. Here my question is after disassemble and assemble those assemblies product version, File version and the copyright i...

How Moles Isolation framework is implemented?

Moles is an isolation framework created by Microsoft. A cool feature of Moles is that it can "mock" static/non-virtual methods and sealed classes (which is not possible with frameworks like Moq). Below is the quick demonstration of what Moles can do: Assert.AreNotEqual(new DateTime(2012, 1, 1), DateTime.Now); // MDateTime is part of ...

Defining custom attributes in CIL

What is the syntax for defining an array literal in CIL for the purposes of decorating a member with a custom attribute? I am writing some .NET code in CIL (using ilasm.exe to compile it) and I need to decorate a method with a custom attribute. The constructor for that attribute takes an array of integers as its only parameter. How can ...

In general, how to convert ilasm syntax into Reflection.Emit calls?

I am writing a special-purpose mini-compiler and I often view disassembled CIL to figure out how to do things. But it's often not obvious how to translate the disassembled code to Reflection.Emit calls. Does a reference manual exist or any other source of information for doing this translation? Edit: yes, mapping the opcodes to ILGenera...

How do I distribute C# apps to computers with an unknown version of .Net?

I wrote a small app that I need to distribute to 700+ computers, the problem being that the computers can be running any version of Windows (though most likely XP or better) with any version of .Net framework installed with internet connections all from OC3 to dialup. I considered bundling .Net with my application but the .net installer...

What is the performance penalty if any for a large .maxstack?

I'm working on writing a compiler and one feature of this compiler is that it automatically generates GetHashCode(), Equals(object), and Equals({this value type}) methods for value types. Right now the Equals({this value type}) implementation basically generates il equivalent to the il generated by this c#: public bool Equals(ThisType o...

How does short circuit evaluation work in MSIL

How does the short circuit evaluation work in the msil interpreter? Does the And instruction contain information about where to jump to if false, and same for the Or with true? ...

Does MSIL have ROL and ROR instructions?

I wrote an Int128 type and it works great. I thought I could improve on its performance with a simple idea: Improve the shift operations which are a bit clumsy. Because they are heavily used in multiplication and division, an improvement would have a ripple effect. So I began creating a dynamic method (to shift low and rotate high), onl...

Is .NET VM a compiler or an interpreter?

Does the .NET's Virtual Machine compiles the CIL bytecode (and then execute the code at the lowest level - CPU assembler), or it is an interpreter (that reads the following instructions and execute them) ? ...

How are explicit interface implementations implemented in IL?

I've been having a look at explicit interface implementations in IL. The method Method in the following class (interface IA has a single Method() on it): public class B : IA object IA.Method() { /* code */ } } is compiled to the following IL method signature: .method private hidebysig newslot virtual final instance ob...

How to insert CIL code to C#

Is it possible to insert IL code to C# method? ...

Changing CIL code into Native code in C#

Possible Duplicate: Is there some way to compile a .NET application to native code? When you compile a C# application, it is compiled to CIL code, to be interpreted by the framework when it is ran, but im wondering if its possible to generate a native x86 EXE file stub for my application(s). This way it is not possible to di...

.Net equivalent of the x86 ASM command XADD

Is there an equivalent of the XADD command in .Net? This is, after all, the most efficient method of locking / checking locks for critical sections or for ensuring accurate increments in a multi-threaded environment. I looked through the IL opcodes, but couldn't find an equivalent. ...

Is there any benefit to making a C# field read-only if its appropriate?

I am working on a project using ReSharper. On occasion it prompts me that a field can be made readonly. Is there any performance or other benefit to this? I am presuming the benefits would be quite low-level, or would any benefits be purely semantic? Thanks With example below the field was initially just private, but resharper prompted...

Instruction-level debugging of .NET files

I am looking for a instruction-level virtual machine debugger for debugging .NET files. The files are release builds and disassembling and then recompiling them is not an option. ...