コード例 #1
0
        /// <summary>
        /// Find all types with the given names that can currently loaded.
        /// If the module or depending modules was not loaded then a empty list return.
        /// </summary>
        /// <param name="jniClassName">a class name with JNI syntax.</param>
        /// <returns>the list, never null</returns>
        internal IList <TargetType> FindTypes(String jniClassName)
        {
            String             className = DebuggerUtils.ConvertJniClassName(jniClassName);
            IList <TargetType> result;

            try
            {
                result = nameTypeMap[className];
            }
            catch (KeyNotFoundException)
            {
                result = new List <TargetType>();
                nameTypeMap.Add(className, result);
            }
            IList <DebugType> types = FindTypesInModules(className);

            foreach (DebugType type in types)
            {
                bool isFound = false;
                foreach (TargetType tgType in result)
                {
                    if (tgType.Identical(type))
                    {
                        isFound = true;
                        break;
                    }
                }
                if (!isFound)
                {
                    result.Add(new TargetType(type));
                }
            }

            return(result);
        }
コード例 #2
0
        private void testCasesList_SelectedIndexChanged(object sender, EventArgs e)
        {
            var key        = testCasesList.Text;
            var testCase   = _testSuite.cases[key];
            var methodName = testCase.method != null ? testCase.method : _abi.entryPoint.name;

            for (int i = 0; i < paramsList.Items.Count; i++)
            {
                if (paramsList.Items[i].ToString() == methodName)
                {
                    paramsList.SelectedIndex = i;

                    for (int j = 0; j < inputGrid.RowCount; j++)
                    {
                        string val;

                        if (testCase.args != null && j < testCase.args.ChildCount)
                        {
                            var node = testCase.args[j];
                            val = DebuggerUtils.ParseNode(node, j);
                        }
                        else
                        {
                            val = "";
                        }

                        inputGrid.Rows[j].Cells[1].Value           = val;
                        inputGrid.Rows[j].Cells[1].Style.ForeColor = Color.Black;
                    }

                    break;
                }
            }
        }
コード例 #3
0
 private void DeletePrefs()
 {
     foreach (KeyValuePair <IDebuggable, SystemInfo> pair in _gameSystems)
     {
         DebuggerUtils.DeletePrefs(pair.Key, pair.Value, GetSystemPrefix(pair.Key));
     }
 }
コード例 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            KeyPair keyPair;

            if (keyBox.Text.Length == 52)
            {
                keyPair = KeyPair.FromWIF(keyBox.Text);
            }
            else
            if (keyBox.Text.Length == 64)
            {
                var keyBytes = keyBox.Text.HexToBytes();
                keyPair = new KeyPair(keyBytes);
            }
            else
            {
                MessageBox.Show("Invalid key input, must be 52 or 64 hexdecimal characters.");
                return;
            }

            keyDataGrid.Rows.Clear();

            var scriptHash = Emulation.Helper.AddressToScriptHash(keyPair.address);

            keyDataGrid.Rows.Add(new object[] { "Address", keyPair.address });
            keyDataGrid.Rows.Add(new object[] { "Script Hash (RAW, hex) ", scriptHash.ToHexString() });
            keyDataGrid.Rows.Add(new object[] { "Script Hash (RAW, bytes) ", DebuggerUtils.ToReadableByteArrayString(scriptHash) });
            keyDataGrid.Rows.Add(new object[] { "Public Key (RAW, hex)", keyPair.PublicKey.ToHexString() });
            keyDataGrid.Rows.Add(new object[] { "Private Key (RAW, hex)", keyPair.PrivateKey.ToHexString() });
            keyDataGrid.Rows.Add(new object[] { "Private Key (WIF, hex)", keyPair.WIF });
            keyDataGrid.Rows.Add(new object[] { "Private Key (RAW, bytes)", DebuggerUtils.ToReadableByteArrayString(keyPair.PrivateKey) });
        }
コード例 #5
0
        private void RenderTestCaseParams(DataNode tparams)
        {
            var grid = this.FindControl <Grid>("InputParametersGrid");

            var rowHeader = new RowDefinition {
                Height = new GridLength(20)
            };

            grid.RowDefinitions.Add(rowHeader);

            var paramHeader = new TextBlock {
                Text = "Parameter", FontWeight = FontWeight.Bold, TextAlignment = TextAlignment.Center
            };

            Grid.SetRow(paramHeader, 0);
            Grid.SetColumn(paramHeader, 0);
            grid.Children.Add(paramHeader);

            var valueHeader = new TextBlock {
                Text = "Value", FontWeight = FontWeight.Bold, TextAlignment = TextAlignment.Center
            };

            Grid.SetRow(valueHeader, 0);
            Grid.SetColumn(valueHeader, 1);
            grid.Children.Add(valueHeader);

            var p1 = tparams != null?DebuggerUtils.ParseNode(tparams[0], 0) : "";

            var p2 = tparams != null?DebuggerUtils.ParseNode(tparams[1], 1) : "";

            RenderLine(grid, 1, "operation", p1);
            RenderLine(grid, 2, "args", p2);
        }
コード例 #6
0
 private void RegisterInteraction()
 {
     this.FindControl <Button>("DebugBtn").Click += (_, __) =>
     {
         var op   = ExtractValueFromGrid(1, 1);
         var args = ExtractValueFromGrid(2, 1);
         ViewModel.DebugParams.ArgList = DebuggerUtils.GetArgsListAsNode(string.Concat(op, ",", args));
         ViewModel.Run();
         Close();
     };
 }
コード例 #7
0
        private void button3_Click_1(object sender, EventArgs e)
        {
            var keyPair = DebuggerUtils.GetKeyFromString(privateKeyInput.Text);

            if (keyPair != null)
            {
                Runtime.invokerKeys = keyPair;
                addressLabel.Text   = Runtime.invokerKeys.address;
            }
            else
            {
                MessageBox.Show("Invalid private key, length should be 52 or 64");
            }
        }
コード例 #8
0
        private string ConvertArray(string s)
        {
            if (DebuggerUtils.IsHex(s))
            {
                var bytes = s.HexToBytes();
                s = DebuggerUtils.BytesToString(bytes);
            }
            else if (DebuggerUtils.IsValidWallet(s))
            {
                var scriptHash = s.AddressToScriptHash();
                s = DebuggerUtils.BytesToString(LuxUtils.ReverseHex(scriptHash.ByteToHex()).HexToBytes());
            }
            else
            {
                return(null);
            }

            return(s);
        }
コード例 #9
0
    public static void LoadSettings(IDebuggable system, DebugSystemComponent.SystemInfo info, string prefix)
    {
        LoadVariable(prefix + "_isEnabled", ref info.isDebuggingEnabled);
        LoadVariable(prefix + "_showLog", ref info.showLog);

        foreach (FieldInfo field in system.GetType().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
        {
            if (CanDisplayField(field) && field.GetCustomAttributes(typeof(DontRememberFieldValue), false).Length == 0)
            {
                if (field.FieldType == typeof(bool))
                {
                    bool value = (bool)field.GetValue(system);
                    DebuggerUtils.LoadVariable(prefix + "_" + field.Name, ref value);
                    field.SetValue(system, value);
                }
                else if (field.FieldType == typeof(int))
                {
                    int value = (int)field.GetValue(system);
                    DebuggerUtils.LoadVariable(prefix + "_" + field.Name, ref value);
                    field.SetValue(system, value);
                }
                else if (field.FieldType == typeof(float))
                {
                    float value = (float)field.GetValue(system);
                    DebuggerUtils.LoadVariable(prefix + "_" + field.Name, ref value);
                    field.SetValue(system, value);
                }
                else if (field.FieldType == typeof(string))
                {
                    string value = (string)field.GetValue(system);
                    DebuggerUtils.LoadVariable(prefix + "_" + field.Name, ref value);
                    field.SetValue(system, value);
                }
            }
        }

        if (system is IDebuggableEx)
        {
            ((IDebuggableEx)system).OnPreviousValuesLoaded();
        }
    }
コード例 #10
0
    private void RenderSystemRecursive(IDebuggable system)
    {
        SystemInfo info    = _gameSystems[system];
        bool       isDirty = false;

        GUILayout.BeginVertical();

        if (GUILayout.Button(new GUIContent(info.systemName, info.IsShowing ? toggleOn : toggleOff), "Toggle"))
        {
            info.ToggleIsShowing();
        }

        if (info.IsShowing)
        {
            GUI.skin.toggle.fontSize = (int)(fontSize * 0.9f);
            GUI.skin.label.fontSize  = (int)(fontSize * 0.9f);
            GUI.skin.button.fontSize = (int)(fontSize * 0.9f);

            // Show all SystemInfo bools
            foreach (FieldInfo field in typeof(SystemInfo).GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (!DebuggerUtils.CanDisplayField(field))
                {
                    continue;
                }

                // Only way to make a tab...
                GUILayout.BeginHorizontal();
                GUILayout.Space(tabSize);
                if (!System.Object.ReferenceEquals(system, this) && !(system == _log && (field.Name == "showLog")) && field.Name != "systemName")
                {
                    bool oldValue = (bool)field.GetValue(info);
                    bool newValue = Toggle(oldValue, DebuggerUtils.FormatFieldName(field.Name));

                    // Save if is changed
                    if (oldValue != newValue)
                    {
                        DebuggerUtils.SaveVariable(GetSystemPrefix(system) + "_" + field.Name, newValue);
                        isDirty = true;
                    }

                    field.SetValue(info, newValue);
                }

                GUILayout.EndHorizontal();
            }

            GUILayout.BeginVertical();

            // Draw public bools of the class
            foreach (FieldInfo field in system.GetType().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                GUILayout.BeginHorizontal();

                GUILayout.Space(tabSize);

                if (DebuggerUtils.CanDisplayField(field))
                {
                    object oldValue = field.GetValue(system);
                    object newValue;

                    if (field.FieldType == typeof(bool))
                    {
                        newValue = Toggle((bool)oldValue, DebuggerUtils.FormatFieldName(field.Name));
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(DebuggerUtils.FormatFieldName(field.Name));
                        newValue = GUILayout.TextField(oldValue.ToString());
                        GUILayout.EndHorizontal();

                        try
                        {
                            if (field.FieldType == typeof(float))
                            {
                                newValue = float.Parse(newValue.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture);
                            }
                            else if (field.FieldType == typeof(int))
                            {
                                newValue = int.Parse(newValue.ToString());
                            }
                        } catch
                        {
                            newValue = oldValue;
                        }
                    }

                    // If value changed
                    if (!newValue.Equals(oldValue))
                    {
                        field.SetValue(system, newValue);
                        DebuggerUtils.SaveVariable(GetSystemPrefix(system) + "_" + field.Name, newValue);
                        isDirty = true;

                        if (system is IDebuggableEx)
                        {
                            ((IDebuggableEx)system).OnValueChanged(field, oldValue, newValue);
                        }
                    }
                }

                GUILayout.EndHorizontal();
            }

            // If the system's designer wants to add anything
            GUILayout.BeginHorizontal();
            GUILayout.Space(tabSize);
            system.OnDebugPanelGUI();
            GUILayout.EndHorizontal();

            GUI.skin.toggle.fontSize = fontSize;
            GUI.skin.label.fontSize  = fontSize;
            GUI.skin.button.fontSize = fontSize;

            if (!info.IsUnique && GUILayout.Button("Save Instance's Settings As Default"))
            {
                DebuggerUtils.SaveDefaultSettings(system, GetSystemPrefix(system));
            }

            // Draw sub-systems
            if (info.subSystems != null && info.subSystems.Count > 0)
            {
                GUILayout.BeginHorizontal();

                GUILayout.Space(tabSize);

                GUILayout.BeginVertical();

                foreach (IDebuggable subSystem in info.subSystems)
                {
                    if (_gameSystems[subSystem].ShowInDebugger)
                    {
                        RenderSystemRecursive(subSystem);
                    }
                }

                GUILayout.EndVertical();

                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
        }

        GUILayout.EndVertical();

        if (isDirty)
        {
            PlayerPrefs.Save();
        }
    }
コード例 #11
0
    public void RegisterSystem(IDebuggable system, string name = null, IDebuggable parent = null, bool isUnique = false, bool showInDebugger = true)
    {
        if (_gameSystems.ContainsKey(system))
        {
            return;
        }

        if (isUnique && GetSystemFromName(name) != null)
        {
            Log(this, "The system name " + name + " already exists. Please find another name or use RegisterInstance.", LogType.Error);
            return;
        }
        if (!isUnique)
        {
            IDebuggable otherSys = GetSystemFromName(name);
            if (otherSys != null && _gameSystems[otherSys].IsUnique)
            {
                Log(this, "The instance name " + name + " is already used by a system. Please find another name.", LogType.Error);
                return;
            }
        }

        SystemInfo info = new SystemInfo(isUnique, showInDebugger);

        // If name is null, default to type name
        if (name == null)
        {
            name = system.GetType().Name;
        }
        info.systemName = name;

        // If parent is not null, check if it exists;
        // if it doesn't, default to null
        if (parent != null)
        {
            if (!_gameSystems.ContainsKey(parent))
            {
                parent = null;
                Log(this, "Specified parent of type " + parent.GetType().Name + " is not a registered system; defaulted to null", LogType.Warning);
            }
            else
            {
                if (_gameSystems[parent].subSystems == null)
                {
                    _gameSystems[parent].subSystems = new List <IDebuggable>();
                }
                _gameSystems[parent].subSystems.Add(system);
            }
        }
        info.parent = parent;

        // If non-sub system, create list of subsystems
        if (parent == null)
        {
            info.subSystems = new List <IDebuggable>();
        }

        _gameSystems.Add(system, info);

        // Load default settings from PlayerPrefs
        DebuggerUtils.LoadSettings(system, info, GetSystemPrefix(system));
    }
コード例 #12
0
        private bool InitInvoke()
        {
            var key = paramsList.Text;
            var f   = _abi.functions[key];

            _debugParameters = new DebugParameters();

            //Get the private key used
            _debugParameters.PrivateKey = privateKeyInput.Text;

            //Get the witness mode
            CheckWitnessMode witnessMode;
            var ws = witnessComboBox.SelectedItem.ToString().Replace(" ", "");

            if (!Enum.TryParse <CheckWitnessMode>(ws, out witnessMode))
            {
                return(false);
            }
            _debugParameters.WitnessMode = witnessMode;

            //Get the trigger type
            TriggerType type;
            var         ts = triggerComboBox.SelectedItem.ToString().Replace(" ", "");

            if (!Enum.TryParse <TriggerType>(ts, out type))
            {
                return(false);
            }
            _debugParameters.TriggerType = type;

            //Get the arguments list
            var argList = "";

            if (f.inputs != null)
            {
                int index = 0;
                foreach (var p in f.inputs)
                {
                    var temp = ($"{key}_{f.name}").ToLower();
                    var name = inputGrid.Rows[index].Cells[0].Value;

                    object val;

                    // detect placeholder
                    if (inputGrid.Rows[index].Cells[1].Style.ForeColor == Color.Gray)
                    {
                        val = "";
                    }
                    else
                    {
                        val = ReadCellVal(index, 1);
                    }

                    if (val == null)
                    {
                        val = ""; // temporary hack, necessary to avoid VM crash
                    }

                    if (val != null && !val.Equals(""))
                    {
                        var param_key = (currentContractName + "_" + f.name + "_" + p.name).ToLower();
                        //Add our default running parameters for next time
                        _debugParameters.DefaultParams[param_key] = val.ToString();
                    }

                    if (index > 0)
                    {
                        argList += ",";
                    }

                    if (p.type == Emulator.Type.Array || p.type == Emulator.Type.ByteArray)
                    {
                        var s = val.ToString();

                        if (s.StartsWith("[") && s.EndsWith("]"))
                        {
                            val = s;
                        }
                        else
                        if (s.StartsWith("\"") && s.EndsWith("\""))
                        {
                            s = s.Substring(1, s.Length - 2);
                            if (DebuggerUtils.IsHex(s))
                            {
                                var bytes = s.HexToBytes();
                                s = DebuggerUtils.BytesToString(bytes);
                            }
                            else if (DebuggerUtils.IsValidWallet(s))
                            {
                                var scriptHash = Emulation.Helper.AddressToScriptHash(s);
                                s = DebuggerUtils.BytesToString(scriptHash);
                            }
                            else
                            {
                                ShowArgumentError(f, index, val);
                                return(false);
                            }

                            val = $"[{s}]";
                        }
                        else
                        {
                            ShowArgumentError(f, index, val);
                            return(false);
                        }
                    }
                    else
                    {
                        switch (p.type)
                        {
                        case Emulator.Type.String:
                        {
                            var s = val.ToString();
                            if (!s.StartsWith("\"") || !s.EndsWith("\""))
                            {
                                ShowArgumentError(f, index, val);
                                return(false);
                            }

                            break;
                        }

                        case Emulator.Type.Integer:
                        {
                            BigInteger n;
                            var        s = val.ToString();
                            if (string.IsNullOrEmpty(s) || !BigInteger.TryParse(s, out n))
                            {
                                ShowArgumentError(f, index, val);
                                ResetTabs();
                                return(false);
                            }
                            break;
                        }

                        case Emulator.Type.Boolean:
                        {
                            switch (val.ToString().ToLower())
                            {
                            case "true": val = true; break;

                            case "false": val = false; break;

                            default:
                            {
                                ShowArgumentError(f, index, val);
                                ResetTabs();
                                return(false);
                            }
                            }
                            break;
                        }
                        }
                    }

                    argList += val;
                    index++;
                }
            }
            if (key != _abi.entryPoint.name)
            {
                if (f.inputs == null || f.inputs.Count == 0)
                {
                    argList = "[null]";
                }
                var operation = Char.ToLowerInvariant(key[0]) + key.Substring(1);
                argList = $"\"{operation}\", {argList}";
            }

            //Set the arguments list
            try
            {
                _debugParameters.ArgList = DebuggerUtils.GetArgsListAsNode(argList);
            }
            catch
            {
                MessageBox.Show("Error parsing input!");
                ResetTabs();
                return(false);
            }

            if (assetComboBox.SelectedIndex > 0)
            {
                foreach (var entry in Asset.Entries)
                {
                    if (entry.name == assetComboBox.SelectedItem.ToString())
                    {
                        BigInteger amount;
                        BigInteger.TryParse(assetAmount.Text, out amount);
                        if (amount > 0)
                        {
                            amount *= Asset.Decimals; // fix decimals

                            //Add the transaction info
                            _debugParameters.Transaction.Add(entry.id, amount);
                        }
                        else
                        {
                            MessageBox.Show(entry.name + " amount must be greater than zero");
                            return(false);
                        }

                        break;
                    }
                }
            }

            uint timestamp;

            if (!uint.TryParse(timestampBox.Text, out timestamp))
            {
                MessageBox.Show("Invalid timestamp");
                return(false);
            }
            else
            {
                _debugParameters.Timestamp = timestamp;
            }

            return(true);
        }