Results 1 to 9 of 9

Thread: Is there a way to know what functions exist in a DLL or EXE?

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    Is there a way to know what functions exist in a DLL or EXE?

    is that possible? and if yes, is it possible to know their parameters?

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    yes..and yes

    this should get you stated

    Code:
    Imports System
    Imports System.Reflection
    
    Public Module DLLReport
    	Public Sub Main(ByVal args() As String)
    		LoadDLL(args(0))
    	
    	End Sub
    	
    	Public Sub LoadDLL(ByVal filename As String)
    		Dim asm As [Assembly]     ' Assembly is reserved vb word so use the brackets to override
    		Dim myClasses() As Type
    		Dim myMethods() As MethodInfo
    		Dim myEvents() As EventInfo
    		Dim myProperties() As PropertyInfo
    		Dim myParameters() As ParameterInfo
    		
    		Dim myTypes As Type
    		Dim myMethodInfo As MethodInfo
    		Dim myEventInfo As EventInfo
    		Dim myPropertyInfo As PropertyInfo
    		Dim myParameterInfo As ParameterInfo
    		
    		asm = [Assembly].LoadFrom(filename)
    		If Not(asm Is Nothing) Then
    			myClasses = asm.GetTypes()
    		End If
    		
    		For Each myTypes In myClasses
    			' Output Classname
    			Console.Writeline(myTypes.ToString())
    			
    			' Lets get all methods(sub and function) from this class
    			myMethods = myTypes.GetMethods()
    			For Each myMethodInfo In myMethods
    				Console.Writeline("---Method---" & myMethodInfo.Name & " Returns " & myMethodInfo.ReturnType.ToString())
    				
    				' Now lets get the Parameters for this method
    				myParameters = myMethodInfo.GetParameters()
    				For Each myParameterInfo In myParameters
    					Console.WriteLine("    ---Parameter---" & myParameterInfo.Name & " As " & myParameterInfo.ParameterType.ToString())	
    				Next myParameterInfo
    			Next myMethodInfo
    			
    			' Lets get all events
    			myEvents = myTypes.GetEvents()
    			For Each myEventInfo In myEvents
    				Console.Writeline("---Event---" & myEventInfo.Name)
    			Next myEventInfo
    			
    			' Lets get all properties
    			myProperties = myTypes.GetProperties()			
    			For Each myPropertyInfo In myProperties
    				Console.Writeline("---Properties---" & myPropertyInfo.Name & " As " & myPropertyInfo.PropertyType.ToString())
    			Next myPropertyInfo
    		Next myTypes
    	End Sub
    End Module
    you can compile that to an exe and pass in a dll filename and path as a command line parameter to see it work
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmmm i antecipated and got a example of a friend...and then i tryed to make that by myself but i am getting an error...i have the following code:

    Plugin Code
    VB Code:
    1. Imports System
    2. Imports System.ComponentModel
    3.  
    4. Public Class MathSystem
    5.  
    6.     Public Function Somar(ByVal numero1 As Integer, ByVal numero2 As Integer) As Integer
    7.         Return numero1 + numero2
    8.     End Function
    9.  
    10.     Public Function Subtrair(ByVal numero1 As Integer, ByVal numero2 As Integer) As Integer
    11.         Return numero1 - numero2
    12.     End Function
    13.  
    14.     Public Function Multiplicar(ByVal numero1 As Integer, ByVal numero2 As Integer) As Integer
    15.         Return numero1 * numero2
    16.     End Function
    17.  
    18.     Public Function Dividir(ByVal numero1 As Integer, ByVal numero2 As Integer) As Integer
    19.         Return numero1 \ numero2
    20.     End Function
    21.  
    22. End Class

    Program code:
    VB Code:
    1. Dim MeuAssembly As [Assembly]
    2.     Dim obj As Object
    3.     Dim Estructura As Type
    4.     Dim MeuMetodo As MethodInfo
    5.     Dim args(1) As Object
    6.     Dim ValorRetorno As Object
    7.  
    8.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    9.         MeuAssembly = [Assembly].Load("plugintest123")
    10.         Estructura = MeuAssembly.GetType("plugintest123.MathSystem")
    11.         MeuMetodo = Estructura.GetMethod("Somar")
    12.         obj = Activator.CreateInstance(Estructura)
    13.         args(0) = TextBox1.Text 'this is 10
    14.         args(1) = TextBox2.Text 'this is 10
    15.         [b]ValorRetorno = MeuMetodo.Invoke(obj, BindingFlags.Public Or BindingFlags.InvokeMethod, Nothing, args, Nothing)[/b]
    16.         MsgBox(ValorRetorno)
    17.     End Sub

    i am getting error in the bold line

  4. #4

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    ah the error says:
    An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

    Additional information: Cannot widen from target type to primitive type.

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    what error do you get
    ?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    try declaring ValorRetorno As integer
    then

    ValorRetorno = CType(MeuMetodo.Invoke(obj, BindingFlags.Public Or BindingFlags.InvokeMethod, Nothing, args, Nothing), Integer)
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm ill try

  8. #8

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    same error..any ideas..? lol

  9. #9

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    here is the code if u want to see it
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width