예제 #1
0
        private async void HookScript(int id, ScriptInfo info)
        {
            StopProcessing();
            Pause();

            for (int i = 1; i <= info.Lines.Length; i++)
            {
                await PlaceBreakpoint(new {
                    location = new {
                        scriptId   = info.IDString,
                        lineNumber = i
                    }
                });

                // Disable for logging
                Progress(i, info.Lines.Length);
            }
            info.IsTracked = true;
            info.IsHooked  = true;

            StartProcessing();
            Resume();
        }
예제 #2
0
        private void Debug()
        {
            dbg = MainWindow.webContents.debugger;
            if (!dbg.isAttached())
            {
                dbg.attach();
            }

            dbg.on(lit.message, (ev, message, para) => {
                //Console.WriteLine(message);

                if (!ProcessingEnabled)
                {
                    return;
                }

                switch (message)
                {
                case "Debugger.breakpointResolved":
                    break;

                case "Debugger.scriptParsed":
                    dynamic data = para.ToDynamic();
                    OnScriptParsed(data);
                    break;

                case "Debugger.paused":
                    //Console.Write("enter:");
                    object[] frames = para.ToDynamic().callFrames;
                    dynamic frame   = frames[0];

                    int scriptId = int.Parse(frame.location.scriptId);
                    if (scripts.ContainsKey(scriptId))
                    {
                        // print line of script
                        int lineNo = int.Parse(frame.location.lineNumber);

                        ScriptInfo info = scripts[scriptId];
                        if (info.IsTracked)
                        {
                            Console.WriteLine($"[{info.Location}:{lineNo}] => {info.Lines[lineNo]}");
                            //dbg.sendCommand("Debugger.stepInto");
                        }
                        dbg.sendCommand("Debugger.resume");
                    }
                    //Progress();
                    break;

                case "Debugger.resumed":
                    //Console.Write("leave:");
                    break;

                default:
                    Console.WriteLine($"Unhandled message '{message}'");
                    break;
                }
            });

            dbg.sendCommand("Debugger.enable");

            dbg.sendCommand("Debugger.setSkipAllPauses", new {
                skip = false
            }, (err, result) => {
                //node.console2.log(err);
            });

            dbg.sendCommand("Debugger.setBreakpointByUrl", new {
                lineNumber = 1,
                urlRegex   = BP_REGEX
            }, (err, result) => {
                node.console2.log(result);
            });

            dbg.sendCommand("Debugger.setBreakpointsActive", new {
                active = true
            }, (err, result) => {
                //node.console2.log(err);
            });

            bool stop = false;

            MainWindow.webContents.on(lit.did_finish_load, () => {
                stop = true;
                AfterInit();
            });
        }