![]() |
|
[.NET] Read .NET assembly classes - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Read .NET assembly classes (/showthread.php?tid=6020927) |
Read .NET assembly classes - fisica638 - Oct 31, 2019 Hi, I need help with the use of: github.com/0xd4d/dnlib Basically I want to list all the classes of a .Net assembly. I want to get all the names of the classes and their methods and list them in a listbox. But for some reason I can't do it. This is what I want to get: (Only the names of the classes.) ![]() Thank you RE: Read .NET assembly classes - MavenGradle - Nov 2, 2019 If I understand your inquiry correctly, something like this is what you'd be looking for: Code Private Function GetMethods() as List(Of String)If all you want is just the classes, just use GetTypes on an Assembly object: Code Assembly.GetTypes()RE: Read .NET assembly classes - 0xDEAD10CC - Nov 2, 2019 (Nov 2, 2019 11:44 AM)MavenGradle Wrote: If I understand your inquiry correctly, something like this is what you'd be looking for: That's not an implementation of dnlib usage: Quote:Hi, I need help with the use of: @OP: What's wrong with the examples in the repo? https://github.com/0xd4d/dnlib/blob/master/Examples/Example1.cs RE: Read .NET assembly classes - MavenGradle - Nov 2, 2019 (Nov 2, 2019 02:06 PM)0xDEAD10CC Wrote: That's not an implementation of dnlib usage: This should suffice for dnlib Code Private Function GetTypes() as List(Of String)& If you want method names: Code Dim modDef As ModuleDefMD = ModuleDefMD.Load(Assembly.GetExecutingAssembly)RE: Read .NET assembly classes - 0xDEAD10CC - Nov 2, 2019 (Nov 2, 2019 02:17 PM)MavenGradle Wrote: This should suffice for dnlib Ugh, VB.net looks so ugly. Why are you using Ctype though in the first? RE: Read .NET assembly classes - MavenGradle - Nov 2, 2019 (Nov 2, 2019 04:57 PM)0xDEAD10CC Wrote: Ugh, VB.net looks so ugly. Why are you using Ctype though in the first? I absolutely 100% agree with you. This is the first time I've written VB.NET in approximately 12 years. Unfortunately the Name property is an UTF-8 string and has to be converted to UTF-16 in this particular case because I'm returning a list of type String which by default is UTF-16 encoded. You could use the ToString method as well if that is preferred if it wasn't for the fact that a range variable name cannot match the name of a member of the 'Object' class. You'd have to use something like: Code (From t In modDef.GetTypes() Select t.Name).Select(Function(dummy) CType(dummy, String))RE: Read .NET assembly classes - 0xDEAD10CC - Nov 2, 2019 (Nov 2, 2019 04:59 PM)MavenGradle Wrote: I absolutely 100% agree with you. This is the first time I've written VB.NET in approximately 12 years. Yeah but the UTF8String type has a String property which is what gets returned via ToString() since it's overriden. The implementation already takes care of this. Code public string StringI don't see why you're using CType at all. There's even an implicit conversion in there which eventually leads to a System.String but adds an additional check in there to return null before returning that String property; it calls ToSystemString() -- a static function of that UTF8String class. RE: Read .NET assembly classes - MavenGradle - Nov 2, 2019 (Nov 2, 2019 05:25 PM)0xDEAD10CC Wrote: Yeah but the UTF8String type has a String property which is what gets returned via ToString() since it's overriden. Aha, good catch. You're right! This would be the correct way to do it: Code Private Function GetTypes() as List(Of String)Code has been updated. dnlib thought of everything! RE: Read .NET assembly classes - fisica638 - Nov 4, 2019 Thanks for the answers. I could use System.Reflection but it fails with executables protected with, for example LizGuard. That's why I tried to use dnlib but I got a little confused and could not use it correctly. The end I found a library called Mono.Cecil and it works perfectly. Anyway thanks for answering. I already tried the code with dnlib and it works thanks. Code you use with Mono.cecil : PHP Code |