2016-10-26 7 views
0

ildasm 출력을 프로그래밍 방식으로 프로그래밍 방식으로 읽을 수 있도록 json 또는 xml과 더 비슷하게 만들려고합니다.ildasm 출력을 프로그래밍 방식으로 읽는 가장 좋은 방법은 무엇입니까

줄마다 출력을 읽은 다음 목록에 클래스 및 메서드 등을 추가 한 다음이를 XML로 수정하고 다시 작성하여 읽는 방식으로 작성했습니다.

질문 : 더 똑똑하고 간단한 방법으로 출력을 읽을 수 있습니까?

+0

* output *의 예와 그 출력으로 수행 할 작업을 지정하십시오. 현재 나는 [this] (http://stackoverflow.com/q/6792828/1997232)와 [this] (http://stackoverflow.com/q/284324/1997232) 사이에서 선택할 수 없습니다 (또는 단지 * broad * vs * 불분명 *). – Sinatr

+2

왜 ildasm을 통해 가나 요? 바이너리를 직접 읽기가 쉬워 보입니다. 세실은 도움이 될만한 도서관입니다. https://github.com/jbevain/cecil/wiki – adrianm

+0

'ildasm' 출력은'ilasm' 이외의 것으로 프로그램 적으로 읽히지 않습니다. 그 방법은 광기를 속인다. –

답변

1

IL 코드를 읽으면 클래스 및 메소드 목록을 얻을 수있는 방법이 있습니다. 내가 말하고있는 해결책은 조금 길지 만 작동 할 것입니다.

IL은 .exe 또는 .dll 이외의 것입니다. 먼저 ILSpy을 사용하여 C# 또는 VB로 변환 해보십시오. 이 도구를 다운로드하고 여기에 DLL을여십시오. 이 도구는 일리노이 코드를 C# 또는 VB로 변환 할 수 있습니다.

변환 후 변환 된 코드를 txt 파일로 저장하십시오.

그런 다음 텍스트 파일을 읽고 그 안에있는 클래스와 메소드를 찾으십시오.

는 방법 이름을 읽으려면 : 라인으로 파일 라인을 통해

반복 처리를하고 라인이 이름 "클래스"이 있는지 여부를 확인합니다

MatchCollection mc = Regex.Matches(str, @"(\s)([A-Z]+[a-z]+[A-Z]*)+\("); 

는 클래스 이름을 읽을 수 있습니다. 이름이 있다면 그 값을 나눠서 "Class" 뒤에 오는 값/텍스트를 저장합니다. ClassName입니다.

전체 코드 : 여기

static void Main(string[] args) 
    { 
     string line; 
     List<string> classLst = new List<string>(); 
     List<string> methodLst = new List<string>(); 
     System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\******\Desktop\TreeView.txt"); 
     string str = File.ReadAllText(@"C:\Users\*******\Desktop\TreeView.txt"); 

     while ((line = file.ReadLine()) != null) 
     {  
       if (line.Contains("class")&&!line.Contains("///")) 
       { 
        // for finding class names 

        int si = line.IndexOf("class"); 
        string followstring = line.Substring(si); 
        if (!string.IsNullOrEmpty(followstring)) 
        { 
         string[] spilts = followstring.Split(' '); 

         if(spilts.Length>1) 
         { 
          classLst.Add(spilts[1].ToString()); 
         } 

        } 
       } 
     } 
     MatchCollection mc = Regex.Matches(str, @"(\s)([A-Z]+[a-z]+[A-Z]*)+\("); 

     foreach (Match m in mc) 
     { 
      methodLst.Add(m.ToString().Substring(1, m.ToString().Length - 2)); 
      //Console.WriteLine(m.ToString().Substring(1, m.ToString().Length - 2)); 
     } 

     file.Close(); 
     Console.WriteLine("******** classes ***********"); 
     foreach (var item in classLst) 
     { 
      Console.WriteLine(item); 
     } 
     Console.WriteLine("******** end of classes ***********"); 

     Console.WriteLine("******** methods ***********"); 
     foreach (var item in methodLst) 
     { 
      Console.WriteLine(item); 
     } 

     Console.WriteLine("******** end of methods ***********"); 
     Console.ReadKey(); 

    } 

내가 목록에서 클래스 이름과 메소드 이름을 저장하고있다. 위에서 설명한대로 나중에 XML 또는 JSON에 저장할 수 있습니다.

문제가 있으면 핑하십시오.