Please check the Image link, i need to extract the resource content from the MSIL file. I have debugged the file using ILSpy but i need to do it in any other way. with out using any manual intereption.
Asked
Active
Viewed 317 times
0
-
What are you actually trying to accomplish? Are you trying to do this with code? Why isn't ILSpy sufficient? – vcsjones May 21 '15 at 14:06
-
i need to extract more files around 20+. I cannot open every files in ILspy and extract in manually. Any command line type required. Eg. Extracter.exe
– Peter John May 21 '15 at 14:08
1 Answers
1
You can do it with something like:
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;
}
Use it like:
var streams = LoadAssembly("EntityFramework");
streams
is an array of Tuple<string, byte[]>
, where Item1
is the name of the resource and Item2
is the binary content of the resource.
It is quite complex because it does the Assembly.ReflectionOnlyLoad
in another AppDomain
that is then unloaded (AppDomain.CreateDomain
/AppDomain.Unload
).

xanatos
- 109,618
- 12
- 197
- 280