Example #1
0
        private static void Main()
        {
            try
            {
                PyEngine     = Python.CreateEngine();
                NtrClient    = new NtrClient();
                ScriptHelper = new ScriptHelper();

                GlobalScope = PyEngine.CreateScope();
                GlobalScope.SetVariable("nc", ScriptHelper);

                LoadConfig();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                GCmdWindow = new CmdWindow();
                Dc         = new DebugConsole();
                Application.Run(GCmdWindow);
            }
            catch (Exception e)
            {
                BugReporter br = new BugReporter(e, "Program exception");
                MessageBox.Show(
                    @"WARNING - NTRDebugger has encountered an error" + Environment.NewLine +
                    @"This error is about to crash the program, please send the generated" + Environment.NewLine +
                    @"Error log to imthe666st!" + Environment.NewLine + Environment.NewLine +
                    @"Sorry for the inconvinience -imthe666st"
                    );
            }
        }
        public MainViewModel()
        {
            IPControlManager = new CIPManager();
            ClearStaticIP();

            LogList = new ObservableCollection <string>();
            isAdmin = IsAdministrator();
            if (!isAdmin)
            {
                InsertLog("[Error] Please execute as Admin");
            }

            WindowHeight    = 400;
            WindowWidth     = 260;
            IsStaticVisible = Visibility.Collapsed;

            cmdWindow                = new CmdWindow();
            TargetIP                 = "192.168.0.101";
            NetworkInterfaces        = IPControlManager.m_ArrayNetworkInterface;
            SelectedNetworkInterface = NetworkInterfaces[0];
        }
Example #3
0
        public void Execute()
        {
            int  index      = 0;
            int  dummyCount = 0;
            bool gsIf       = true;
            bool valid      = true;
            int  gsIfLayer  = 0;
            int  gsIfSLayer = 0;

            do
            {
                GatesharkAr gsAr = _lines[index];
                uint        cmd  = gsAr.GetCmd();

                if (cmd != 0xff)
                {
                    Addlog(string.Format("GS | {0:X} {1:X} {2:X} -> [{3}, {4}, {5}, {6:X}]", cmd, gsAr.getBlock_A(), gsAr.getBlock_B(), valid, gsIfLayer, gsIfSLayer, _offset));
                }

                if (gsIfLayer == 0 && valid)
                {
                    if ((cmd == 0) || (cmd == 1) || (cmd == 2))
                    {
                        Program.Sm.GsUsed += 1;
                        valid              = gsAr.Execute(_offset);
                    }
                    // Conditional codes
                    else if (cmd == 0x3)
                    {
                        uint read = Convert.ToUInt32(CmdWindow.FromLe(Program.GCmdWindow.readValue(gsAr.getBlock_A() + _offset, 4), 0));
                        gsIf = read < gsAr.getBlock_B();
                    }
                    else if (cmd == 0x4)
                    {
                        uint r1 = Program.GCmdWindow.readValue(gsAr.getBlock_A() + _offset, 4);
                        uint r2 = CmdWindow.FromLe(r1, 0);

                        uint read = Convert.ToUInt32(r2);
                        gsIf = read > gsAr.getBlock_B();
                    }
                    else if (cmd == 0x5)
                    {
                        uint read = Convert.ToUInt32(CmdWindow.FromLe(Program.GCmdWindow.readValue(gsAr.getBlock_A() + _offset, 4), 0));
                        gsIf = read == gsAr.getBlock_B();
                    }
                    else if (cmd == 0x6)
                    {
                        uint read = Convert.ToUInt32(CmdWindow.FromLe(Program.GCmdWindow.readValue(gsAr.getBlock_A() + _offset, 4), 0));
                        gsIf = read != gsAr.getBlock_B();
                    }
                    else if (cmd == 0x7)
                    {
                        uint read = Convert.ToUInt32(CmdWindow.FromLe(Program.GCmdWindow.readValue(gsAr.getBlock_A() + _offset, 2), 2));
                        gsIf = read < gsAr.getBlock_B();
                    }
                    else if (cmd == 0x8)
                    {
                        uint read = Convert.ToUInt32(CmdWindow.FromLe(Program.GCmdWindow.readValue(gsAr.getBlock_A() + _offset, 2), 2));
                        gsIf = read > gsAr.getBlock_B();
                    }
                    else if (cmd == 0x9)
                    {
                        uint read = Convert.ToUInt32(CmdWindow.FromLe(Program.GCmdWindow.readValue(gsAr.getBlock_A() + _offset, 2), 2));
                        gsIf = read == gsAr.getBlock_B();
                    }
                    else if (cmd == 0xA)
                    {
                        uint read = Convert.ToUInt32(CmdWindow.FromLe(Program.GCmdWindow.readValue(gsAr.getBlock_A() + _offset, 2), 2));
                        gsIf = read != gsAr.getBlock_B();
                    }
                    else if (cmd == 0xB)
                    {
                        _offset = CmdWindow.FromLe(Program.GCmdWindow.readValue(gsAr.getBlock_A() + _offset, 4), 4);
                    }
                    else if (cmd == 0xC)
                    {
                        _loop      = true;
                        _loopIndex = index;
                        _loopCount = gsAr.getBlock_B() + 1;
                    }
                    else if (cmd == 0xD1)
                    {
                        if (_loop)
                        {
                            _loopCount--;
                            if (_loopCount == 0)
                            {
                                _loop = false;
                            }
                            else
                            {
                                index    = _loopIndex;
                                _offset += Convert.ToUInt32(gsAr.getBlock_B());
                            }
                        }
                    }
                    else if (cmd == 0xD2) // RESET
                    {
                        _loop      = false;
                        _loopCount = 0;
                        _loopIndex = 0;

                        _offset    = 0;
                        gsIfLayer  = 0;
                        gsIfSLayer = 0;
                    }
                    else if (cmd == 0xD3) // Read offset
                    {
                        // Fix for Issue #8
                        _offset = gsAr.getBlock_B();
                    }
                    else if (cmd == 0xD4)
                    {
                        // Fix for Issue #8
                        uint b = gsAr.getBlock_B();

                        _dxData += b;
                    }
                    else if (cmd == 0xD5) // DxData WRITE
                    {
                        _dxData = gsAr.getBlock_B();
                    }
                    else if (cmd == 0xD6) // DxData WORD
                    {
                        uint   len       = 4;
                        string cmdString = Program.GCmdWindow.GenerateWriteString(gsAr.getBlock_B() + _offset, _dxData, len);
                        Program.GCmdWindow.RunCmd(cmdString);
                        _offset += len;
                    }
                    else if (cmd == 0xD7) // DxData SHORT
                    {
                        uint   len       = 2;
                        string cmdString = Program.GCmdWindow.GenerateWriteString(gsAr.getBlock_B() + _offset, _dxData, len);
                        Program.GCmdWindow.RunCmd(cmdString);
                        _offset += len;
                    }
                    else if (cmd == 0xD8) // DxData Byte
                    {
                        uint   len       = 1;
                        string cmdString = Program.GCmdWindow.GenerateWriteString(gsAr.getBlock_B() + _offset, _dxData, len);
                        Program.GCmdWindow.RunCmd(cmdString);
                        _offset += len;
                    }
                    else if (cmd == 0xD9) // DxData read WORD
                    {
                        uint addr = gsAr.getBlock_B() + _offset;
                        _dxData = CmdWindow.FromLe(Program.GCmdWindow.readValue(addr, 4), 4);
                    }
                    else if (cmd == 0xDA) // DxData read SHORT
                    {
                        uint addr = gsAr.getBlock_B() + _offset;
                        _dxData = CmdWindow.FromLe(Program.GCmdWindow.readValue(addr, 2), 2);
                    }
                    else if (cmd == 0xDB) // DxData read BYTE
                    {
                        uint addr = gsAr.getBlock_B() + _offset;
                        _dxData = Program.GCmdWindow.readValue(addr, 1);
                    }
                    else if (cmd == 0xDC)
                    {
                        // Fix for Issue #8
                        uint b = gsAr.getBlock_B();

                        _offset += b;
                    }
                    else if (cmd == 0xDF)
                    {
                        // This doesn't actually exist! It's for testing only!
                        dummyCount++;
                        MessageBox.Show(string.Format(
                                            "I: {0} \r\n" +
                                            "O: {1:X} \r\n" +
                                            "LOOP: {2} {3} {4} \r\n" +
                                            "DX: {5:X} \r\n" +
                                            "DUMMY: {6}\r\n" +
                                            "LAYERS: {7} {8}"
                                            , index, _offset, _loop, _loopIndex, _loopCount, _dxData, dummyCount, gsIfSLayer, gsIfLayer));
                    }

                    if (!gsIf)
                    {
                        gsIf       = true;
                        gsIfLayer += 1;
                    }
                }
                else if (cmd >= 0x3 && cmd <= 0xA)
                {
                    gsIfSLayer += 1;
                }
                else if (cmd == 0xD0)
                {
                    if (gsIfSLayer > 0)
                    {
                        gsIfSLayer -= 1;
                    }
                    else if (gsIfLayer > 0)
                    {
                        gsIfLayer -= 1;
                    }
                }
                else if (cmd == 0xD2)
                {
                    _loop      = false;
                    _loopCount = 0;
                    _loopIndex = 0;

                    _offset    = 0;
                    gsIfLayer  = 0;
                    gsIfSLayer = 0;
                }
                index++;
            } while (index < _lines.Count);
        }