cil

Parse CIL code with Regex

匆匆过客 提交于 2019-12-19 10:58:09
问题 I have a *.il file. I want to find all non-empty methods in it (.method). For example: .class private auto ansi beforefieldinit MyApp.Program extends [mscorlib]System.Object { //catch its body .method private hidebysig static void Main(string[] args) cil managed { .entrypoint // .maxstack 8 IL_0000: nop IL_0001: ret } //catch its body .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { // .maxstack 8 IL_0000: ldarg.0 IL_0001: call instance void [mscorlib

Can't catch exception inside AIF service

我与影子孤独终老i 提交于 2019-12-19 04:17:10
问题 I have created an AIF service in dynamics AX 2012, when I tested it by calling the entrypoint method from a job, it worked fine, but when it is deployed en the calls are comming from the soap UI, it crashes inside with an error: "Unhandled esception". While debugging I found out the unhandled exception is thrown inside my catch clause of my try catch statement. It gets inside the catch because the method I am calling inside the try clause thows an error. So does anyone know why I can catch

Is there a way to count the number of IL instructions executed?

梦想的初衷 提交于 2019-12-19 03:37:07
问题 I want to do some benchmarking of a C# process, but I don't want to use time as my vector - I want to count the number of IL instructions that get executed in a particular method call. Is this possible? Edit I don't mean static analysis of a method body - I'm referring to the actual number of instructions that are executed - so if, for example, the method body includes a loop, the count would be increased by however many instructions make up the loop * the number of times the loop is iterated

MSIL - how do you invoke a private method from MSIL?

て烟熏妆下的殇ゞ 提交于 2019-12-18 16:51:32
问题 I'm writing a "weak event factory" - code which converts any Delegate into a new delegate with an identical signature, but with implementing a WeakReference on the target. I'm using MSIL to avoid calls to Delegate.CreateDelegate (which performance have shown to be slow). The weak reference delegates work perfectly as long as the underlying method (the Method of the original delegate), was declared public. As soon as a private or anonymous method is used, the MSIL bombs at run time with a

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

Why Is the .MaxStack Directive Optional in MSIL Code?

六月ゝ 毕业季﹏ 提交于 2019-12-18 14:52:13
问题 I am learning assembly language in my spare time. Can anyone explain why .maxstack appears to be optional in this program. I have tried to find the answer online and in my book with no such luck i.e. the program will compile and run with .Maxstack commented out: //Add.il //Add Two Numbers .assembly extern mscorlib {} .assembly Add { .ver 1:0:1:0 } .module add.exe .method static void main() cil managed { //.maxstack 2 .entrypoint ldstr "The sum of 50 and 30 is = " call void [mscorlib]System

Why Is the .MaxStack Directive Optional in MSIL Code?

廉价感情. 提交于 2019-12-18 14:52:04
问题 I am learning assembly language in my spare time. Can anyone explain why .maxstack appears to be optional in this program. I have tried to find the answer online and in my book with no such luck i.e. the program will compile and run with .Maxstack commented out: //Add.il //Add Two Numbers .assembly extern mscorlib {} .assembly Add { .ver 1:0:1:0 } .module add.exe .method static void main() cil managed { //.maxstack 2 .entrypoint ldstr "The sum of 50 and 30 is = " call void [mscorlib]System

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"

What's the point of MethodImplOptions.InternalCall?

ε祈祈猫儿з 提交于 2019-12-17 23:16:43
问题 Many methods in the BCL are marked with the [MethodImpl(MethodImplOptions.InternalCall)] attribute. This indicates that the "method is implemented within the common language runtime itself". What was the point of designing the framework in this way over having specified explicit CIL instructions that the runtime would be forced to implement? Ultimately, the attribute is creating contractual obligations for the runtime, but in a way that appears to me to be confusing and not immediately

What's the purpose of the nop opcode?

不打扰是莪最后的温柔 提交于 2019-12-17 17:24:34
问题 I'm going through MSIL and noticing there are a lot of nop instructions. The MSDN article says they take no action and are used to fill space if the opcode is patched. They're used a lot more in debug builds than release builds. I know that these kinds of statements are used in assembly languages to make sure an opcode fits on a word boundary, but why is it needed in MSIL? 回答1: NOPs serve several purposes: They allow the debugger to place a breakpoint on a line even if it is combined with