Hack Forums
[C#] Is there any way to execute dll file ? - 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: [C#] Is there any way to execute dll file ? (/showthread.php?tid=6241636)

Pages: Pages 1 2


Is there any way to execute dll file ? - Transporter007 - May 14, 2023

Hey guys,

Is there any way to execute dll file ? I want to execute dll file even if its reference in console executable cmd app.

How to fix this error: [Image: 0237757a19.png]

Regards.


RE: Is there any way to execute dll file ? - HFDone - May 14, 2023

DLL is a library https://en.wikipedia.org/wiki/Dynamic-link_library


RE: Is there any way to execute dll file ? - Transporter007 - May 14, 2023

(May 14, 2023 11:53 AM)HFDone Wrote:  DLL is a library https://en.wikipedia.org/wiki/Dynamic-link_library

Yes I know. I want to open and execute that dll through executable file whether its cmd console, or form app, or bat file.


RE: Is there any way to execute dll file ? - webdev77 - May 14, 2023

(May 14, 2023 12:40 PM)Transporter007 Wrote:  Yes I know. I want to open and execute that dll through executable file whether its cmd console, or form app, or bat file.

You can execute a function contained with the library by importing the dll. You can't "execute" a dll directly.

https://www.c-sharpcorner.com/UploadFile/1e050f/creating-and-using-dll-class-library-in-C-Sharp/


RE: Is there any way to execute dll file ? - HFDone - May 14, 2023

(May 14, 2023 01:10 PM)webdev77 Wrote:  You can execute a function contained with the library by importing the dll. You can't "execute" a dll directly.

https://www.c-sharpcorner.com/UploadFile/1e050f/creating-and-using-dll-class-library-in-C-Sharp/

just for you https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain


RE: Is there any way to execute dll file ? - webdev77 - May 14, 2023

(May 14, 2023 01:53 PM)HFDone Wrote:  just for you https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain

Not sure why you are quoting me. Calling a DLL from an existing process isn't direct execution.


RE: Is there any way to execute dll file ? - Cl0ser - May 15, 2023

As people before me told you, DLL is a library. If you want to call these, you need to know their signatures.

If you just want to call the entry point (DllMain), just importing it should work (depending on the implementation)

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportattribute


RE: Is there any way to execute dll file ? - Transporter007 - May 15, 2023

(May 14, 2023 01:10 PM)webdev77 Wrote:  You can execute a function contained with the library by importing the dll. You can't "execute" a dll directly.

https://www.c-sharpcorner.com/UploadFile/1e050f/creating-and-using-dll-class-library-in-C-Sharp/

Can this method execute the dll aswell ?

Can you tell me how to call that dll file and execute it through windows console or windows form on load.

(May 14, 2023 11:21 PM)phantomman55 Wrote:  What's a form app?

Windows Form Application

(May 15, 2023 12:51 AM)Cl0ser Wrote:  As people before me told you, DLL is a library. If you want to call these, you need to know their signatures.

If you just want to call the entry point (DllMain), just importing it should work (depending on the implementation)

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportattribute

Can this method execute the dll aswell ?


RE: Is there any way to execute dll file ? - webdev77 - May 15, 2023

(May 15, 2023 06:36 AM)Transporter007 Wrote:  Can this method execute the dll aswell ?

Can you tell me how to call that dll file and execute it through windows console or windows form on load.

DLLs are not executables. You have to call their functions to execute their contents.

It would look something like this. See the link above that I linked you to.

Code
[DllImport("MyDLL.dll")]
public static extern int MyFunction(int param1, int param2);



RE: Is there any way to execute dll file ? - webdev77 - May 15, 2023

(May 15, 2023 08:11 AM)shatter Wrote:  disagree

that, by definition, is an executable

that's how malware is executed directly in memory

Nope. Executables are standalone files that can be run. A DLL is not that.


RE: Is there any way to execute dll file ? - webdev77 - May 15, 2023

(May 15, 2023 09:04 AM)shatter Wrote:  im not going to sit here and argue that dll doesnt have executable logic

DLLs do have logic that is executable. That's an objective fact. That does not make them an executable. They are very specifically called Dynamic Link Libraries for a reason and not executables.


RE: Is there any way to execute dll file ? - HFDone - May 15, 2023

(May 15, 2023 09:23 AM)webdev77 Wrote:  DLLs do have logic that is executable. That's an objective fact. That does not make them an executable. They are very specifically called Dynamic Link Libraries for a reason and not executables.

we talking about using it in code so both need to be load first by their pe format and thats make dll much simple to do by api call.


RE: Is there any way to execute dll file ? - webdev77 - May 15, 2023

(May 15, 2023 11:45 AM)shatter Wrote:  what is the title of this thread?

Refer to steps 4 to 6 of the link of my first post in the thread.


RE: Is there any way to execute dll file ? - Transporter007 - May 15, 2023

(May 15, 2023 08:02 AM)webdev77 Wrote:  DLLs are not executables. You have to call their functions to execute their contents.

It would look something like this. See the link above that I linked you to.

Code
[DllImport("MyDLL.dll")]
public static extern int MyFunction(int param1, int param2);

Error:

[Image: dd44087663.png]


Code:

[Image: 643eb2943b.png]


RE: Is there any way to execute dll file ? - Cl0ser - May 15, 2023

Code
using System;
using System.Runtime.InteropServices;
using System.Threading;

public class Program
{
    [DllImport("kernel32.dll", SetLastError = true)]
    private static extern IntPtr LoadLibrary(string dllToLoad);

    public static void Main()
    {
        var dllPath = @"C:\path\to\your\dll.dll";
        var handle = LoadLibrary(dllPath);
        if (handle == IntPtr.Zero)
        {
            int errorCode = Marshal.GetLastWin32Error();
            throw new Exception($"Failed to load DLL. Error code: {errorCode}");
        }

        Console.ReadLine();
    }
}

Since you have no clue about the DLL content, this will just load the DLL which will in turn execute the DllMain with attach params.
note that DLL you are trying to load might not even do anything at attach event or the context might be wrong and you will get an error(or not ¯\_(ツ)_/¯ ).