Skip to content

Commit 6f52cbd

Browse files
author
RemoteNet
committed
[RemoteNET] Read Loader errors from type listing calls
1 parent 08dec3a commit 6f52cbd

2 files changed

Lines changed: 44 additions & 10 deletions

File tree

src/RemoteNET/ManagedRemoteApp.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Reflection;
66
using RemoteNET.Internal;
77
using RemoteNET.Internal.Reflection.DotNet;
8+
using RemoteNET.Utils;
89
using ScubaDiver.API;
910
using ScubaDiver.API.Interactions.Dumps;
1011
using ScubaDiver.API.Utils;
@@ -127,23 +128,16 @@ public ManagedRemoteApp(Process procWithDiver, DiverCommunicator managedCommunic
127128

128129
public override IEnumerable<CandidateType> QueryTypes(string typeFullNameFilter)
129130
{
130-
List<TypesDump.TypeIdentifiers> typeIdentifiers;
131131
try
132132
{
133-
typeIdentifiers = _managedCommunicator.DumpTypes(typeFullNameFilter).Types;
133+
List<TypesDump.TypeIdentifiers> typeIdentifiers = _managedCommunicator.DumpTypes(typeFullNameFilter, out _).Types;
134+
return TypesDumpHelpers.ToCandidateTypes(typeIdentifiers);
134135
}
135136
catch
136137
{
137138
// TODO:
138139
Debug.WriteLine($"[{nameof(ManagedRemoteApp)}][{nameof(QueryTypes)}] Exception thrown when Querying for Type filter: {typeFullNameFilter}");
139-
yield break;
140-
}
141-
foreach (TypesDump.TypeIdentifiers type in typeIdentifiers)
142-
{
143-
ulong? xoredMethodTable = null;
144-
if (type.XoredMethodTable.HasValue)
145-
xoredMethodTable = type.XoredMethodTable ^ TypesDump.TypeIdentifiers.XorMask;
146-
yield return new CandidateType(RuntimeType.Managed, type.FullTypeName, type.Assembly, xoredMethodTable);
140+
return new List<CandidateType>();
147141
}
148142
}
149143

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using ScubaDiver.API.Interactions.Dumps;
4+
5+
namespace RemoteNET.Utils
6+
{
7+
public static class TypesDumpHelpers
8+
{
9+
public static List<CandidateType> QueryTypes(RemoteApp app, string typeFullNameFilter, out List<TypesDump.AssemblyLoadError> loadErrors)
10+
{
11+
if (app is ManagedRemoteApp managedApp)
12+
{
13+
TypesDump dump = managedApp.Communicator.DumpTypes(typeFullNameFilter, out loadErrors);
14+
List<TypesDump.TypeIdentifiers> typeIdentifiers = dump?.Types ?? new List<TypesDump.TypeIdentifiers>();
15+
return ToCandidateTypes(typeIdentifiers);
16+
}
17+
18+
loadErrors = new List<TypesDump.AssemblyLoadError>();
19+
return app.QueryTypes(typeFullNameFilter).ToList();
20+
}
21+
22+
public static ulong? UnmaskMethodTable(ulong? xoredMethodTable)
23+
{
24+
if (!xoredMethodTable.HasValue)
25+
return null;
26+
return xoredMethodTable ^ TypesDump.TypeIdentifiers.XorMask;
27+
}
28+
29+
public static List<CandidateType> ToCandidateTypes(IEnumerable<TypesDump.TypeIdentifiers> typeIdentifiers)
30+
{
31+
List<CandidateType> results = new();
32+
foreach (TypesDump.TypeIdentifiers type in typeIdentifiers)
33+
{
34+
ulong? methodTable = UnmaskMethodTable(type.XoredMethodTable);
35+
results.Add(new CandidateType(RuntimeType.Managed, type.FullTypeName, type.Assembly, methodTable));
36+
}
37+
return results;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)