-
Notifications
You must be signed in to change notification settings - Fork 3
/
AssemblyResolver.cs
52 lines (44 loc) · 1.42 KB
/
AssemblyResolver.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Basic.Reference.Assemblies;
using ICSharpCode.Decompiler.Metadata;
namespace DecompilationDiffer;
internal class AssemblyResolver : IAssemblyResolver
{
private readonly List<PEFile> _peFiles;
private readonly List<Stream> _streams;
public AssemblyResolver()
{
_peFiles = [];
_streams = [];
foreach (var reference in Net80.ReferenceInfos.All)
{
var stream = new MemoryStream(reference.ImageBytes);
_peFiles.Add(new PEFile(reference.FileName, stream));
stream.Seek(0, SeekOrigin.Begin);
_streams.Add(stream);
}
}
public MetadataFile? Resolve(IAssemblyReference reference)
{
return _peFiles.FirstOrDefault(r => r.FullName == reference.FullName);
}
public Task<MetadataFile?> ResolveAsync(IAssemblyReference reference)
{
return Task.FromResult(_peFiles.FirstOrDefault(r => r.FullName == reference.FullName) as MetadataFile);
}
public MetadataFile? ResolveModule(MetadataFile mainModule, string moduleName)
{
return null;
}
public Task<MetadataFile?> ResolveModuleAsync(MetadataFile mainModule, string moduleName)
{
return Task.FromResult<MetadataFile?>(null);
}
internal IEnumerable<Stream> GetAllStreams()
{
return _streams;
}
}