il

Why is the 'br.s' IL opcode used in this case?

不羁的心 提交于 2019-12-23 06:53:02
问题 For educational purposes I'm learning a bit of IL (mainly because I was curious what happens to '%' under the hood (which turns out to be rem) and started digressing...). I wrote a method, just returning true to break things down a bit and was wondering about the 'br.s' opcode: .method public hidebysig static bool ReturnTrue() cil managed { // Code size 7 (0x7) .maxstack 1 .locals init ([0] bool CS$1$0000) IL_0000: nop IL_0001: ldc.i4.1 IL_0002: stloc.0 IL_0003: br.s IL_0005 IL_0005: ldloc.0

Why is the 'br.s' IL opcode used in this case?

人走茶凉 提交于 2019-12-23 06:51:49
问题 For educational purposes I'm learning a bit of IL (mainly because I was curious what happens to '%' under the hood (which turns out to be rem) and started digressing...). I wrote a method, just returning true to break things down a bit and was wondering about the 'br.s' opcode: .method public hidebysig static bool ReturnTrue() cil managed { // Code size 7 (0x7) .maxstack 1 .locals init ([0] bool CS$1$0000) IL_0000: nop IL_0001: ldc.i4.1 IL_0002: stloc.0 IL_0003: br.s IL_0005 IL_0005: ldloc.0

Signing pre-build assemblies

ぐ巨炮叔叔 提交于 2019-12-23 03:21:16
问题 Before I go digging through the IL, hopefully someone has run into this issue before: Trying to sign a third-party assembly (in this case, the latest HtmlAgilityPack). I've done this before with no issues. Doing the usual ildasm => ilasm, but when I go to use my newly-signed assembly, Visual Studio complains it "cannot enumerate resources in the executable". What might cause this? 回答1: I've done it before too. If it's managed only, one pass through Mono.Cecil and Mono.Security can do it. If

Signing pre-build assemblies

南楼画角 提交于 2019-12-23 03:21:01
问题 Before I go digging through the IL, hopefully someone has run into this issue before: Trying to sign a third-party assembly (in this case, the latest HtmlAgilityPack). I've done this before with no issues. Doing the usual ildasm => ilasm, but when I go to use my newly-signed assembly, Visual Studio complains it "cannot enumerate resources in the executable". What might cause this? 回答1: I've done it before too. If it's managed only, one pass through Mono.Cecil and Mono.Security can do it. If

call instead of callvirt in case of the new c# 6 “?” null check

微笑、不失礼 提交于 2019-12-22 03:16:07
问题 Given the two methods: static void M1(Person p) { if (p != null) { var p1 = p.Name; } } static void M2(Person p) { var p1 = p?.Name; } Why the M1 IL code use callvirt : IL_0007: brfalse.s IL_0012 IL_0009: nop IL_000a: ldarg.0 IL_000b: callvirt instance string ConsoleApplication4.Person::get_Name() and the M2 IL use call : brtrue.s IL_0007 IL_0004: ldnull IL_0005: br.s IL_000d IL_0007: ldarg.0 IL_0008: call instance string ConsoleApplication4.Person::get_Name() I just can guess that it because

call instead of callvirt in case of the new c# 6 “?” null check

孤人 提交于 2019-12-22 03:16:01
问题 Given the two methods: static void M1(Person p) { if (p != null) { var p1 = p.Name; } } static void M2(Person p) { var p1 = p?.Name; } Why the M1 IL code use callvirt : IL_0007: brfalse.s IL_0012 IL_0009: nop IL_000a: ldarg.0 IL_000b: callvirt instance string ConsoleApplication4.Person::get_Name() and the M2 IL use call : brtrue.s IL_0007 IL_0004: ldnull IL_0005: br.s IL_000d IL_0007: ldarg.0 IL_0008: call instance string ConsoleApplication4.Person::get_Name() I just can guess that it because

Mechanism to extract specific IL (.NET Intermediate Language) signatures from an assembly

大城市里の小女人 提交于 2019-12-21 23:16:03
问题 I have a list of about 25 types found in the Microsoft .NET assembly mscorlib.dll where I need to extract the IL signatures of the class and its members. I want one file per type, with each signature on one line. So, for example, take the type System.Collections.Generic.Comparer<T> I want to extract the following from the assembly for that type (there are some private members I won't need, but I can handle that manually if needed). .class public abstract auto ansi serializable beforefieldinit

generics with IL?

淺唱寂寞╮ 提交于 2019-12-21 05:01:26
问题 Is it possible to use generics with the IL Generator? DynamicMethod method = new DynamicMethod( "GetStuff", typeof(int), new Type[] { typeof(object) }); ILGenerator il = method.GetILGenerator(); ... etc 回答1: Yes, it is possible, but not with the DynamicMethod class. If you are restricted to using this class, you're out of luck. If you can instead use a MethodBuilder object, read on. Emitting the body of a generic method is, for most intents and purposes, no different from emitting the body of

Value Type Conversion in Dynamically Generated IL

点点圈 提交于 2019-12-20 18:35:31
问题 Update Over a year later, and I finally realized the cause of this behavior. Essentially, an object can't be unboxed to a different type than it was boxed as (even if that type casts or converts to the destination type), and if you don't know the correct type you have to discover it somehow. The assignment may be perfectly valid, but it is not feasible for this to happen automatically. For example, even though a byte fits into an Int64, you can't unbox a byte as a long. You must unbox a byte

Traverse a c# method and anazlye the method body

北战南征 提交于 2019-12-19 16:36:49
问题 Whats the easiest way to traverse a methodinfo in c#? I want to traverse the method body and find field-references and such and retrieves the types. In System.Reflection there is: mi.GetMethodBody().GetILAsByteArray() which is kinda low-level and would require "some" work before I would be able to traverse the body. I know Cecil exists, but there's a problem in loading an in memory assembly with cecil. The assembly i'm working with is't always "on disk" it can be an in memory assembly