2015-05-21 57 views
0

請檢查圖像鏈接,我需要從MSIL文件中提取資源內容。我已經使用ILSpy調試了該文件,但我需要以任何其他方式執行此操作。沒有使用任何人工干預。如何從MSIL或.NET PE文件中提取資源內容

http://i.stack.imgur.com/ZQdRc.png

+0

你究竟在做什麼?你是否試圖用代碼來做到這一點?爲什麼ILSpy不夠? – vcsjones

+0

我需要提取20個左右的文件。我無法打開ILspy中的每個文件並手動提取。任何需要的命令行類型。例如。 Extracter.exe

回答

0

你可以像做:

public class LoadAssemblyInfo : MarshalByRefObject 
{ 
    public string AssemblyName { get; set; } 

    public Tuple<string, byte[]>[] Streams; 

    public void Load() 
    { 
     Assembly assembly = Assembly.ReflectionOnlyLoad(AssemblyName); 

     string[] resources = assembly.GetManifestResourceNames(); 

     var streams = new List<Tuple<string, byte[]>>(); 

     foreach (string resource in resources) 
     { 
      ManifestResourceInfo info = assembly.GetManifestResourceInfo(resource); 

      using (var stream = assembly.GetManifestResourceStream(resource)) 
      { 
       byte[] bytes = new byte[stream.Length]; 
       stream.Read(bytes, 0, bytes.Length); 

       streams.Add(Tuple.Create(resource, bytes)); 
      } 
     } 

     Streams = streams.ToArray(); 
    } 
} 

// Adapted from from http://stackoverflow.com/a/225355/613130 
public static Tuple<string, byte[]>[] LoadAssembly(string assemblyName) 
{ 
    LoadAssemblyInfo lai = new LoadAssemblyInfo 
    { 
     AssemblyName = assemblyName, 
    }; 

    AppDomain tempDomain = null; 

    try 
    { 
     tempDomain = AppDomain.CreateDomain("TemporaryAppDomain"); 
     tempDomain.DoCallBack(lai.Load); 
    } 
    finally 
    { 
     if (tempDomain != null) 
     { 
      AppDomain.Unload(tempDomain); 
     } 
    } 

    return lai.Streams; 
} 

這樣使用它:

var streams = LoadAssembly("EntityFramework"); 

streamsTuple<string, byte[]>一個數組,其中Item1是資源的名稱而Item2是資源的二進制內容。

,因爲它的Assembly.ReflectionOnlyLoad在另一個AppDomain,然後將其卸載(AppDomain.CreateDomain/AppDomain.Unload)這是很複雜的。