cil

What is the difference between normal and shortform opcodes in CIL?

≡放荡痞女 提交于 2019-12-01 15:50:19
问题 I am going through various opcodes in CIL and I find a lot of similar looking codes like Beq,Beq_S Bge,Bge_S Bgt,Bgt_S Br,Br_S Where S is supposedly "short form". What does that mean?? 回答1: The short forms of the instructions take up less space (that is, the binary encoding of the CIL instructions are themselves shorter, so your assembly will take up less space on disk or in memory). Therefore, they would typically be preferred when applicable. However, the tradeoff is that they have limited

Reference 'this' in dynamic event handler

北慕城南 提交于 2019-12-01 14:36:37
In my 'myClass' class, I am using Reflection.Emit to dynamically write an event handler for one of the myClass class' members. I have done this successfully. Now, I want to modify the event handler to call one of the instance methods in the myClass class. However, I cannot figure out how to push a reference to 'this' onto the MSIL stack using Reflection.Emit. Within the event handler, Ldarg_0 is not a reference to 'this', but rather the first parameter of the event handler. Does anyone know how to push a reference to 'this' on the stack so that I can call an instance method. For example, this

How to prevent MSIL runtime injection? [closed]

风格不统一 提交于 2019-12-01 14:20:38
As seen here Programmatic MSIL injection or here http://www.codeproject.com/Articles/463508/NET-CLR-Injection-Modify-IL-Code-during-Run-time you can modify IL code at runtime using some tricky injections. My question is : how to prevent that? For instance, if someone use that to bypass a security feature, how can i avoid that security hole? how to prevent that? You can't, as far as I understand . But you can do make it not easy. In the simple case, you don't even need to inject IL. You can do IL weaving to modify the assembly. For example, you can find the login method ant delete the original

How to prevent MSIL runtime injection? [closed]

两盒软妹~` 提交于 2019-12-01 12:34:54
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . As seen here Programmatic MSIL injection or here http://www.codeproject.com/Articles/463508/NET-CLR-Injection-Modify-IL-Code-during-Run-time you can modify IL code at runtime using some tricky injections. My question is : how to prevent that? For instance, if someone use that to

Reference 'this' in dynamic event handler

天涯浪子 提交于 2019-12-01 12:28:19
问题 In my 'myClass' class, I am using Reflection.Emit to dynamically write an event handler for one of the myClass class' members. I have done this successfully. Now, I want to modify the event handler to call one of the instance methods in the myClass class. However, I cannot figure out how to push a reference to 'this' onto the MSIL stack using Reflection.Emit. Within the event handler, Ldarg_0 is not a reference to 'this', but rather the first parameter of the event handler. Does anyone know

How to compile CIL code?

倾然丶 夕夏残阳落幕 提交于 2019-12-01 08:04:29
I have a code written in CIL . Let's say, a file called some_il_code.il holds it. I want to compile it to create a managed exe assembly. How do I achieve that? Alex You can use the ilasm tool. ilasm /exe Your.il /deb=opt peverify /md /il Your.exe ilasm compiles it, peverify verifies it. 来源: https://stackoverflow.com/questions/12741607/how-to-compile-cil-code

How to compile CIL code?

我怕爱的太早我们不能终老 提交于 2019-12-01 06:26:50
问题 I have a code written in CIL . Let's say, a file called some_il_code.il holds it. I want to compile it to create a managed exe assembly. How do I achieve that? 回答1: You can use the ilasm tool. ilasm /exe Your.il /deb=opt peverify /md /il Your.exe ilasm compiles it, peverify verifies it. 来源: https://stackoverflow.com/questions/12741607/how-to-compile-cil-code

Feeding an object literal to ILGenerator

≡放荡痞女 提交于 2019-12-01 05:40:31
Food obj = ...; ILGenerator gen = (...).GetILGenerator(); gen.Emit( ?? obj ?? ); // replace this gen.Emit(OpCodes.Call, typeof(Person).GetMethod("Eat")); It's apparently not possible to cleanly push obj onto the evaluation stack, but I am open to ugly hacks which might compromise e.g. portability. ModuleBuilder.DefineInitializedData allows one to store a System.Byte[] in the .sdata. Any ideas? Edit: the generated method is being emitted as part of a new assembly. object o = ...; Func<object> sneaky = () => o; gen.Emit(OpCodes.Call, sneaky.Method); On a side note, make sure you can't use System

When I declare a class as internal, why does the IL show it as private?

落花浮王杯 提交于 2019-12-01 04:36:55
问题 If I declare a class as internal, why does the IL show it as private? internal class Thing .class private auto ansi beforefieldinit Thing.Thing extends [mscorlib]System.Object 回答1: From IL's point of view, private means private to the assembly , i.e. internal in C#. In C#, it is not possible to mark types as private if they are not nested. IL's equivalent accessibility for such types is nested private . So we have: C#'s internal -> IL's private (to the assembly) C#'s private -> IL's nested

Indexing arrays with enums in C#

試著忘記壹切 提交于 2019-12-01 02:26:28
I have a lot of fixed-size collections of numbers where each entry can be accessed with a constant. Naturally this seems to point to arrays and enums: enum StatType { Foo = 0, Bar // ... } float[] stats = new float[...]; stats[StatType.Foo] = 1.23f; The problem with this is of course that you cannot use an enum to index an array without a cast (though the compiled IL is using plain ints). So you have to write this all over the place: stats[(int)StatType.foo] = 1.23f; I have tried to find ways to use the same easy syntax without casting but haven't found a perfect solution yet. Using a