Ejemplo n.º 1
0
    public static IntPtr DestroyScope()
    {
        if (runspace != null)
        {
            // FreeLibrary直前の関数の呼び出し。
            try
            {
                //if (runspace.SessionStateProxy.GetVariable("DestroyScope") != null)
                //{
                DoString("DestroyScope", "DestroyScope");
                //}
            }
            catch (Exception)
            {
            }
            runspace.Dispose();
            runspace = null;
        }

        SetCodePage((IntPtr)default_codepage);
        iDllBindHandle = 0;
        tmpVar         = null;

        dpr = null;

        return((IntPtr)0);
    }
    public static IntPtr DestroyScope()
    {
        if (engine != null)
        {
            // FreeLibrary直前の関数の呼び出し。
            try
            {
                if (engine.Script["DestroyScope"] != null)
                {
                    DoString("DestroyScope()", "DestroyScope");
                }
            }
            catch (Exception)
            {
            }
            engine = null;
        }

        SetCodePage((IntPtr)default_codepage);
        iDllBindHandle = 0;
        tmpVar         = null;

        dpr = null;

        return((IntPtr)0);
    }
Ejemplo n.º 3
0
    public static IntPtr CreateScope()
    {
        // まだエンジンが作られていなければ
        if (l == null || g == null)
        {
            try
            {
                //エンジン作成
                l = new Lua();
                g = l.CreateEnvironment();

                hm = new Hidemaru();
                g.RegisterPackage("hm", typeof(Hidemaru));
                dpr = new DllPathResolver();
                // アセンブリのローダのショートカット
                g["load_assembly"] = new Func <String, Assembly>(asmname => System.Reflection.Assembly.Load(asmname));

                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message);
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
Ejemplo n.º 4
0
    //----------------------------------------------------------------------------------------------
    public static IntPtr CreateScope()
    {
        // まだエンジンが作られていなければ
        if (runspace == null)
        {
            try
            {
                // create Powershell runspace
                runspace = RunspaceFactory.CreateRunspace();

                // open it
                runspace.Open();


                hm = new Hidemaru();
                runspace.SessionStateProxy.SetVariable("hm", hm);
                runspace.SessionStateProxy.SetVariable("AssemblyPath", new List <String>());
                dpr = new DllPathResolver();

                // ダミー関数の定義
                DoString("function DestroyScope() {}");

                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message + "生成時エラー");
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
Ejemplo n.º 5
0
    public static IntPtr DestroyScope()
    {
        if (engine != null)
        {
            // FreeLibrary直前の関数の呼び出し。
            try
            {
                DoString("DestroyScope()", "DestroyScope");
            }
            catch (Exception)
            {
            }
            engine = null;
        }

        SetCodePage((IntPtr)default_codepage);
        iDllBindHandle = 0;
        tmpVar         = null;
        iDebuggingPort = 0;

        dpr = null;

        core.Dispose();
        core = null;

        return((IntPtr)0);
    }
Ejemplo n.º 6
0
    static int Run()
    {
        // Locate path to certificates folder in distribution.
        string rootDir  = DllPathResolver.FindDistributionRootDir();
        string certsDir = Path.Combine(rootDir, "certs");

        // Initialize RCF.
        RCFProto.Init();

        // Create server.
        RcfProtoServer server = new RcfProtoServer();

        // Bind Protobuf service.
        SearchServiceImpl myService = new SearchServiceImpl();

        server.BindService(myService);

        // Add the endpoints that this server will support.
        List <Endpoint> endpoints = new List <Endpoint>();

        endpoints.Add(new TcpEndpoint(50001));
        endpoints.Add(new HttpEndpoint(50002));
        endpoints.Add(new HttpsEndpoint(50003));
        endpoints.Add(new Win32NamedPipeEndpoint("DemoServerPipe"));

        foreach (Endpoint endpoint in endpoints)
        {
            server.AddEndpoint(endpoint);
        }

        // By default, the server serves clients on a single thread. Here, we are
        // configuring the server to use a thread pool with up to 10 threads.
        ThreadPool threadPool = new ThreadPool(1, 10);

        threadPool.SetThreadName("RCFProto Server");
        server.SetThreadPool(threadPool);

        // Configure SSL certificate.

        // Load certificate from PFX format.
        string      certPath = Path.Combine(certsDir, "certA.p12");
        Certificate cert     = new PfxCertificate(certPath, "", "localhost");

        server.SetCertificate(cert);
        server.SetSslImplementation(SslImplementation.Schannel);

        // Start the server.
        server.Start();

        // Wait for shutdown.
        SearchServiceImpl.ShutdownEvent.WaitOne();
        System.Console.WriteLine("Shutting down server.");

        // Stop server.
        server.Stop();

        return(0);
    }
Ejemplo n.º 7
0
    static int Main(string[] args)
    {
        try
        {
            // Configure DLL loading paths for RCFProto_NET.dll and RCFProto_NET_impl.dll.
            DllPathResolver.Resolve(args);

            return(Run(args));
        }
        catch (Exception e)
        {
            System.Console.WriteLine(e.Message);
        }
        return(1);
    }
Ejemplo n.º 8
0
    public static IntPtr DetachScope()
    {
        if (engine != null)
        {
            // FreeLibrary直前の関数の呼び出し。
            try
            {
                CallMethod("DestroyScope()", "DestroyScope");
            }
            catch (Exception)
            {
            }
            engine = null;
        }

        iDllBindHandle = 0;
        tmpVar         = null;

        dpr = null;

        return((IntPtr)1);
    }
Ejemplo n.º 9
0
    //----------------------------------------------------------------------------------------------
    public static IntPtr CreateScope()
    {
        // まだエンジンが作られていなければ
        if (engine == null)
        {
            try
            {
                // Standardモードのコンプライアンスまで引き上げる
                engine = new Microsoft.ClearScript.Windows.JScriptEngine(Microsoft.ClearScript.Windows.WindowsScriptEngineFlags.EnableStandardsMode | Microsoft.ClearScript.Windows.WindowsScriptEngineFlags.EnableDebugging);
                engine.AddHostObject("clr", new HostTypeCollection("mscorlib", "System", "System.Core"));
                engine.AddHostObject("host", new ExtendedHostFunctions());
                engine.AddHostObject("AssemblyPath", new List <String>());

                hm = new Hidemaru();
                engine.AddHostType("hm", typeof(Hidemaru));
                console = new hmJSConsole();
                engine.AddHostType("console", typeof(hmJSConsole));

                // ヒアドキュメント用の関数 R(text)
                String expression = @"
                function R(text){
                    return text.toString().match(/\/\*([\s\S]*)\*\//)[1].toString();
                }
                ";
                engine.Execute(expression);

                dpr = new DllPathResolver();

                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message);
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
Ejemplo n.º 10
0
    //----------------------------------------------------------------------------------------------
    public static IntPtr AttachScope()
    {
        // まだエンジンが作られていなければ
        if (engine == null)
        {
            try
            {
                // Standardモードのコンプライアンスまで引き上げる
                engine = new Object();

                hm = new Hidemaru();

                dpr = new DllPathResolver();

                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message);
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
Ejemplo n.º 11
0
    public static IntPtr DestroyScope()
    {
        if (l != null)
        {
            // FreeLibrary直前の関数の呼び出し。
            try
            {
                DoString("if DestroyScope then DestroyScope() end", "DestroyScope");
            }
            catch (Exception)
            {
            }
            g.Clear();
            l.Dispose();
            l   = null;
            dpr = null;
        }

        SetCodePage((IntPtr)default_codepage);
        iDllBindHandle = 0;
        tmpVar         = null;

        return((IntPtr)0);
    }
Ejemplo n.º 12
0
    //----------------------------------------------------------------------------------------------
    public static IntPtr CreateScope()
    {
        // まだエンジンが作られていなければ
        if (engine == null)
        {
            try
            {
                core   = CreateCore();
                engine = core.Engine;
                core.ExposeGlobalRequire(); // requireが使えるように

                // 秀丸クラスの登録
                hm = new Hidemaru();
                engine.AddHostType("hm", typeof(Hidemaru));

                // consoleの簡易版
                console = new hmV8Console();
                engine.AddHostType("console", typeof(hmV8Console));

                // ①ヒアドキュメント用の関数
                // ②:空のDestory関数
                String expression = @"
                function R(text){
                    return text.toString().match(/\/\*([\s\S]*)\*\//)[1].toString();
                }

                hm.Macro.Var = new Proxy(()=>{}, {
                    apply: function(target, that, args) {
                        if (args.length > 1 ) {
                            return hm.Macro.__Var(args[0], args[1]);
                        }
                        else if (args.length == 1 ) {
                            return hm.Macro.__Var(args[0]);
                        }
                    },
                    get(target, prop, receiver) {
                        return hm.Macro.__Var(prop);
                    },
                    set(target, prop, val, receiver) {
                        return hm.Macro.__Var(prop, val);
                    }
                }
                )
                ";

                engine.Execute(expression);

                engine.Script.DestroyScope = new Action(() => { });

                dpr = new DllPathResolver();
                engine.AddHostObject("AssemblyPath", new List <String>());

                // ヒアドキュメント用の関数 R(text)
                return((IntPtr)1);
            }
            catch (Exception e)
            {
                OutputDebugStream(e.Message);
                return((IntPtr)0);
            }
        }
        return((IntPtr)1);
    }
Ejemplo n.º 13
0
    static int Run(string[] args)
    {
        ParseCommandLine(args);

        // Locate path to certificates folder in distribution.
        string rootDir  = DllPathResolver.FindDistributionRootDir();
        string certsDir = Path.Combine(rootDir, "certs");

        // Initialize RCFProto.
        RCFProto.Init();

        // Build a search request.
        SearchRequest request = SearchRequest.CreateBuilder()
                                .SetQuery("something to search for")
                                .SetResultPerPage(10)
                                .SetPageNumber(0)
                                .Build();

        // Call the server on each of its supported endpoints.
        List <Endpoint> endpoints = new List <Endpoint>();

        endpoints.Add(new TcpEndpoint(50001));
        endpoints.Add(new HttpEndpoint(50002));
        endpoints.Add(new HttpsEndpoint(50003));
        endpoints.Add(new Win32NamedPipeEndpoint("DemoServerPipe"));

        foreach (Endpoint endpoint in endpoints)
        {
            // Create channel.
            RcfProtoChannel    channel       = new RcfProtoChannel(endpoint);
            RcfProtoController rcfController = new RcfProtoController();
            SearchService.Stub searchService = new SearchService.Stub(channel);

            // Set certificate validation callback, for SSL.
            channel.SetCertificateValidationCallback(OnValidateCertificate);

            {
                // Synchronous remote call.
                searchService.Search(null, request, null);
                SearchResponse response = (SearchResponse)channel.GetResponse();
            }

            {
                // Asynchronous remote call.
                channel.SetAsynchronousRpcMode(true);

                Action <SearchResponse> done = delegate(SearchResponse response)
                {
                    OnRpcDone(searchService, rcfController, request, response);
                };
                searchService.Search(rcfController, request, done);

                while (gCallCompleted == false)
                {
                    System.Threading.Thread.Sleep(500);
                }
            }
        }

        {
            // Create TCP channel.
            RcfProtoChannel    channel       = new RcfProtoChannel(endpoints[0]);
            RcfProtoController rcfController = new RcfProtoController();
            SearchService.Stub searchService = new SearchService.Stub(channel);

            // Enable compression (requires zlib to be installed).
            //channel.SetEnableCompression(true);

            // Custom connection timeout (10s).
            channel.SetConnectTimeoutMs(10 * 1000);

            // Custom remote call timeout (60s).
            channel.SetRemoteCallTimeoutMs(60 * 1000);

            // Enable NTLM authentication and encryption.
            channel.SetTransportProtocol(TransportProtocol.Ntlm);

            // The channel will pick up the credentials of the user running the
            // program. Alternatively, we can set the credentials explicitly:

            //channel.setUsername("MyDomain\\MyUsername");
            //channel.setPassword("MyPassword");

            searchService.Search(null, request, null);
            SearchResponse response = (SearchResponse)channel.GetResponse();

            // Enable SSL, with custom certificate validation callback.
            channel.SetTransportProtocol(TransportProtocol.Ssl);
            channel.SetCertificateValidationCallback(OnValidateCertificate);

            searchService.Search(null, request, null);
            response = (SearchResponse)channel.GetResponse();

            // Enable SSL, with validation against Windows certificate root store. Requires Schannel.
            string certPath = Path.Combine(certsDir, "caCertA.p12");

            // Open CA certificate.
            PfxCertificate caCert = new PfxCertificate(certPath, "", "RCF CA A");

            // Add it to the root store of the local machine.
            caCert.AddToStore(Win32CertificateLocation.LocalMachine, Win32CertificateStore.Root);

            channel.SetEnableSchannelCertificateValidation("localhost");
            channel.SetSslImplementation(SslImplementation.Schannel);

            // Disconnect so SSL handshake takes place again.
            channel.Disconnect();

            searchService.Search(null, request, null);
            response = (SearchResponse)channel.GetResponse();
        }

        return(0);
    }