Beispiel #1
0
        public static int ClrExcute(string paramstr)
        {
            try
            {
                //加载DLL
                LoadDlls();
                if (ProcessAPI.GetProcessModule(Process.GetCurrentProcess().Id).Any(m => m.ModuleName == "ClrLoader.dll"))
                {
                    CMethod2();
                }
                else
                {
                    //c# 调用c++函数
                    CMethod();

                    //c++调用c#函数
                    SetCallback(_cCallback);
                }
                JsonConvert.DeserializeObject("{}");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(1);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var strPid = args.Length > 0 ? args[0] : null;

            if (int.TryParse(strPid, out int pid))
            {
                RemoteExcuteAPI.InjectDLL(pid, InjectNativeDll);
                ProcessAPI.LoadLibrary(InjectNativeDll);
                var module      = ProcessAPI.GetProcessModule(Process.GetCurrentProcess().Id).First(m => m.ModuleName == InjectNativeDll);
                var startProc   = ProcessAPI.GetProcAddress(module.BaseAddress, "Start") - (int)module.BaseAddress;
                var remotModule = ProcessAPI.GetProcessModule(pid).First(m => m.ModuleName == InjectNativeDll);
                RemoteExcuteAPI.ExcuteRemoteFunction(pid, remotModule.BaseAddress + (int)startProc, Encoding.Unicode.GetBytes(Directory.GetCurrentDirectory() + "\\" + InjectSharpDll));
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var pid = Process.GetProcessesByName("DemoWinFormApp").First().Id;

            if (!File.Exists(InjectNativeDll))
            {
                Console.WriteLine($"{InjectNativeDll} not exists!");
                return;
            }
            ProcessAPI.LoadLibrary(InjectNativeDll);
            var module = ProcessAPI.GetProcessModule(Process.GetCurrentProcess().Id).FirstOrDefault(m => m.ModuleName == InjectNativeDll);

            if (module == null)
            {
                Console.WriteLine("locale native dll load failed!");
                return;
            }
            var startProc = ProcessAPI.GetProcAddress(module.BaseAddress, "LoadClrLibrary") - (int)module.BaseAddress;

            RemoteExcuteAPI.InjectDLL(pid, Directory.GetCurrentDirectory() + "\\" + InjectNativeDll);
            WindowsApi.ProcessModule remotModule = null;
            for (int i = 0; i < 10 && remotModule == null; i++)
            {
                remotModule = ProcessAPI.GetProcessModule(pid).FirstOrDefault(m => m.ModuleName == InjectNativeDll);
                if (remotModule == null)
                {
                    Thread.Sleep(100);
                }
            }
            if (remotModule == null)
            {
                Console.WriteLine("remote native dll load failed!");
                return;
            }
            if (!RemoteExcuteAPI.ExcuteRemoteFunction(pid, remotModule.BaseAddress + (int)startProc, GetParamAddress))
            {
                Console.WriteLine("excute remote function failed!");
            }
        }