Example #1
0
        public bool Bind()
        {
            if (outputpath == null)
                return false;

            try
            {
                SECURITY_ATTRIBUTES attr = new SECURITY_ATTRIBUTES();
                attr.length = Marshal.SizeOf(attr);
                attr.lpSecurityDescriptor = IntPtr.Zero;
                attr.bInheritHandle = true;

                if( CreatePipe( out readPipe, out writePipeChild, ref attr, 1024 ) == false )
                {
                    MessageBox.Show("CreatePipe Failed", outputpath);
                    return false;
                }

                if( CreatePipe( out readPipeChild, out writePipe, ref attr, 1024 ) == false )
                {
                    Unbind();
                    MessageBox.Show("CreatePipe Failed", outputpath);
                    return false;
                }

                switch( m_Rule.BindType )
                {
                    case BIND_TYPE.Application:
                    {
                        STARTUPINFO si = new STARTUPINFO();
                        si.cb = (uint)Marshal.SizeOf(si);
                        // 				si.wShowWindow = 1;
                        // 				si.dwFlags = 1;
                        PROCESS_INFORMATION pi;

                        if( CreateProcess( outputpath, string.Format( "{0} --vutpp:{1},{2}", outputpath, readPipeChild, writePipeChild ), IntPtr.Zero, IntPtr.Zero, true, 0x08000000, IntPtr.Zero, null, ref si, out pi ) == false )
                        {
                            Unbind();
                            MessageBox.Show("CreateProcess Failed", outputpath);
                            return false;
                        }
                        processChild = pi.hProcess;
                    }
                    break;

                    case BIND_TYPE.DynamicLibrary:
                    {
                        try
                        {
                            m_DllInstance = LoadLibraryExA(outputpath, IntPtr.Zero, 8);
                            if (m_DllInstance != 0)
                            {
                                m_Proc = (BindProc)GetProcAddress( m_DllInstance, "VUTPPBind" );
                                if (m_Proc != null)
                                {
                                    if( DllBindThread == null )
                                    {
                                        DllBindThread = new System.Threading.Thread(new System.Threading.ThreadStart(this.DllBind));
                                        DllBindThread.Start();
                                    }
                                }
                                else
                                {
                                    Unbind();
                                    MessageBox.Show("GetProcAddress(VUTPPBind) Failed", outputpath);
                                }
                            }
                            else
                                MessageBox.Show("LoadLibrary Failed", outputpath);
                        }
                        catch (System.Exception)
                        {

                        }
                    }
                    break;
                }

                string strRead;
                if( ReadString( ConfigManager.Instance.ConnectWait*1000, out strRead ) == false || strRead != "connect" )
                {
                    MessageBox.Show("Bind Failed(Timeout)", outputpath);

                    Unbind();
                    return false;
                }

                return true;
            }
            catch (System.Exception ex)
            {
                Unbind();
                MessageBox.Show(ex.ToString(), outputpath, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            return false;
        }
Example #2
0
 public void Unbind()
 {
     if( processChild != 0 )
     {
         TerminateProcess( processChild, 0 );
         processChild = 0;
     }
     if( m_DllInstance != 0 )
     {
         try
         {
             if( DllBindThread != null )
             {
                 DllBindThread.Abort();
                 DllBindThread = null;
             }
         }
         catch (System.Exception)
         {
         }
         FreeLibrary(m_DllInstance);
         m_DllInstance = 0;
         m_Proc = null;
     }
     CloseHandle( readPipe );
     CloseHandle( writePipe );
     CloseHandle( readPipeChild );
     CloseHandle( writePipeChild );
 }