-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDecompiler.cs
34 lines (28 loc) · 918 Bytes
/
Decompiler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
namespace Cilurbo;
static class Decompiler {
static readonly Dictionary<string, CSharpDecompiler> decompilers = new ();
static CSharpDecompiler GetDecompiler (PEFile file)
{
if (!decompilers.TryGetValue (file.FileName, out var decompiler)) {
decompiler = new CSharpDecompiler (file.FileName, new DecompilerSettings {
ThrowOnAssemblyResolveErrors = false,
});
decompilers.Add (file.FileName, decompiler);
}
return decompiler;
}
static public string Decompile (this PEFile pe)
{
var d = GetDecompiler (pe);
return d.DecompileModuleAndAssemblyAttributesToString ();
}
static public string Decompile (this IEntity entity)
{
var d = GetDecompiler (entity.ParentModule.PEFile!);
return d.DecompileAsString (entity.MetadataToken);
}
}