C
C#2y ago
__cdeclan

❔ Help with Assemblies and the TypeRef table

I am trying to load a .NET DLL as an assembly and read the TypeRef table. End goal is to get all the TypeNames and their corresponding NameSpaces. The image shows all the results I should get, but I am only getting one result "Program". Code provided
public List<TypesClass> parseBinary()
{
Console.WriteLine("Calculating TypeRef hash for: " + binaryName);

Assembly asm = Assembly.LoadFile(binaryName);
List<Type> typesList = asm.GetExportedTypes().ToList();
List<TypesClass> allTypes = new List<TypesClass>();

foreach (Type t in typesList)
{
TypesClass newType = new TypesClass();
newType.TypeName = t.Name;

if (t.Namespace == null)
{
newType.TypeNameSpace = "";
}
else
{
newType.TypeNameSpace = t.Namespace;
}
allTypes.Add(newType);
}

return allTypes;
}
public List<TypesClass> parseBinary()
{
Console.WriteLine("Calculating TypeRef hash for: " + binaryName);

Assembly asm = Assembly.LoadFile(binaryName);
List<Type> typesList = asm.GetExportedTypes().ToList();
List<TypesClass> allTypes = new List<TypesClass>();

foreach (Type t in typesList)
{
TypesClass newType = new TypesClass();
newType.TypeName = t.Name;

if (t.Namespace == null)
{
newType.TypeNameSpace = "";
}
else
{
newType.TypeNameSpace = t.Namespace;
}
allTypes.Add(newType);
}

return allTypes;
}
6 Replies
phaseshift
phaseshift2y ago
not sure if it''s all of your problem, but 'get exported types' are only public types. Try GetTypes() instad
reflectronic
reflectronic2y ago
you cannot get this information using System.Reflection reflection lets you look at type and member definitions. there is no API that gets you all of the types referenced in the DLL you need to use a raw metadata reader like System.Reflection.Metadata (completely different API from System.Reflection) for that
__cdeclan
__cdeclanOP2y ago
Ok so I should look into System.Reflection.Metadata? I can probably learn that and implement it into my code. Thank you I tried this as well, per @reflectronic 's answer I think I need a new API
__cdeclan
__cdeclanOP2y ago
Awesome, thank you
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server