Example #1
0
        public void Start()
        {
            IntPtr handle = IntPtr.Zero;
            int    threadId;

            try
            {
                while (procMem.DataAddress["__delegatorParams"] != null)
                {
                    Thread.Sleep(0);
                }
                procMem.AddData("__delegatorFunction", delegatorFunction);
                BinaryWriter wtr = new BinaryWriter(new MemoryStream());
                foreach (int element in delegatorParams)
                {
                    wtr.Write(element);
                }
                procMem.AddData("__delegatorParams", ((MemoryStream)wtr.BaseStream).ToArray());

                handle = ProcessMemoryApi.CreateRemoteThread(procMem.Handle, IntPtr.Zero, 0, (IntPtr)procMem.DataAddress["__delegatorFunction"], (IntPtr)procMem.DataAddress["__delegatorParams"], 0, out threadId);
                while (true)
                {
                    ProcessMemoryApi.GetExitCodeThread(handle, out result);
                    if (result != STILL_ACTIVE)
                    {
                        break;
                    }
                    Thread.Sleep(100);
                }
            }
            catch (ThreadAbortException)
            {
                ProcessMemoryApi.TerminateThread(handle, out result);
            }
            finally
            {
                procMem.RemoveData("__delegatorFunction");
                procMem.RemoveData("__delegatorParams");
            }
        }