NativeAOT assisted native .NET DLL injection

syedatharhussain

Заглянувший
Заглянувший
S

syedatharhussain

Заглянувший
Заглянувший
Сообщения
11
Реакции
3
csharp]EntryPoint.cs
---------------------
C++:
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace SharpNativeDLL
{
    public class EntryPoint
    {
        private const uint DLL_PROCESS_DETACH = 0,
                           DLL_PROCESS_ATTACH = 1,
                           DLL_THREAD_ATTACH = 2,
                           DLL_THREAD_DETACH = 3;

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type);

        [UnmanagedCallersOnly(EntryPoint = "DllMain", CallConvs = new[] { typeof(CallConvStdcall) })]
        public static bool DllMain(IntPtr hModule, uint ul_reason_for_call, IntPtr lpReserved)
        {
            switch (ul_reason_for_call)
            {
                case DLL_PROCESS_ATTACH:
                    MessageBox(0, "DLL_PROCESS_ATTACH", "Your kind @", 0);
                    break;
                default:
                    break;
            }
            return true;
        }
    }
}
 

Сверху Снизу