解析与正则表达式CIL代码 [英] Parse CIL code with Regex

查看:131
本文介绍了解析与正则表达式CIL代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个* .il内的文件。我想找到它(。方法)所有非空的方法。例如:

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]System.Object::.ctor()
    IL_0006:  ret
  }  

   //don't touch, it's empty
   .method public hidebysig newslot virtual 
          instance string  Invoke(string a) runtime managed
  {
  }  
 //......................................
}

现在我这样做,使用类字符串。这是相当非理性的。我试着用正则表达式,但我无法弄清楚如何创建一个reg表达式只捕获

Now I'm doing that using class string. It's quite nonrational. I tried using Regex but I could not figure out how to create a reg expression to catch only


  • 方法(而不是类)

  • 只有非空体

是否有人能帮助我吗?

推荐答案

尝试使用正则表达式

(\.method\s[^{]+?)(?=\s*{)(?!\s*{\s*})

测试它的 这里

要也搭上身体 {...} 每种方法,使用正则表达式

To catch also the body {...} of each method, use regex pattern

(\.method\s[^{]+{(?!\s*}).*?})

测试它的这里

Test it here.

要了解更多关于正则表达式参观的 regular-expressions.info

To learn more about regular expressions visit regular-expressions.info

这篇关于解析与正则表达式CIL代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆