Esempio n. 1
0
        public static void CsrClientCallServer(IntPtr Process, IntPtr Thread, uint PID, uint TID)
        {
            CSRMsg CSRMessage = new CSRMsg();

            CSRMessage.ProcessInfo = new PROCESS_INFORMATION(Process, Thread, PID, TID);
            NTdll.CsrClientCallServer(&CSRMessage);
        }
Esempio n. 2
0
        public static int ExecThread(IntPtr Proc, IntPtr Func, IntPtr Param, bool Wait = false)
        {
            IntPtr Thread;

            NTdll.RtlCreateUserThread(Proc, Func, Param, out Thread);
            int Ret = 0;

            if (Wait)
            {
                Ret = Kernel32.WaitForSingleObject(Thread, Kernel32.INFINITE);
            }
            if (!Kernel32.CloseHandle(Thread))
            {
                throw new Win32Exception();
            }
            return(Ret);
        }
Esempio n. 3
0
        public unsafe static int Fork()
        {
            ProcessInfo PInfo = new ProcessInfo();

            //Kernel32.FreeConsole();
            CloneStatus S = NTdll.RtlCloneUserProcess(CloneProcessFlags.CreateSuspended | CloneProcessFlags.InheritHandles, &PInfo);

            /*Kernel32.AllocConsole();
             * Console.OpenStandardError();
             * Console.OpenStandardInput();
             * Console.OpenStandardOutput();*/

            if (S == CloneStatus.Parent)
            {
                int ChildPID = Kernel32.GetProcessId(PInfo.Process);
                if (ChildPID == 0)
                {
                    return(-2);
                }

                NTdll.CsrClientCallServer(PInfo.Process, PInfo.Thread, PInfo.CID.ProcessID,
                                          PInfo.CID.ThreadID);
                Kernel32.ResumeThread(PInfo.Thread);
                Kernel32.CloseHandle(PInfo.Process);
                Kernel32.CloseHandle(PInfo.Thread);
                return(ChildPID);
            }
            else if (S == CloneStatus.Child)
            {
                Kernel32.FreeConsole();
                Kernel32.AllocConsole();

                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                StreamWriter OutWriter = new StreamWriter(Console.OpenStandardOutput());
                OutWriter.AutoFlush = true;
                Console.SetOut(OutWriter);
                StreamWriter ErrWriter = new StreamWriter(Console.OpenStandardError());
                ErrWriter.AutoFlush = true;
                Console.SetError(ErrWriter);
                return(0);
            }
            return(-1);
        }