Пример #1
0
        private void SetReflector(IHost host, string path)
        {
            //already set in SimpleReflector.OpenReflector
            //host.SetPropertyValue(Plugin.PropertyReflector, path);

            if (!String.IsNullOrEmpty(path) && File.Exists(path))
            {
                host.AddAssemblyResolveDir(Path.GetDirectoryName(path));
            }
        }
Пример #2
0
        private void SetReflector(IHost host, string path)
        {
            //already set in SimpleReflector.OpenReflector
            //host.SetPropertyValue(Plugin.PropertyReflector, path);

            if (!String.IsNullOrEmpty(path) && File.Exists(path))
            {
                host.AddAssemblyResolveDir(Path.GetDirectoryName(path));
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            MethodDefinition md = _frmClassView.SelectedMethod;

            if (md == null)
            {
                SimpleMessage.ShowInfo("Please choose a method");
                return;
            }

            bool resolveDirAdded = false;

            try
            {
                Utils.EnableUI(this.Controls, false);
                resolveDirAdded = _host.AddAssemblyResolveDir(_sourceDir);

                //string path = _rows[0];
                MethodBase mb = AssemblyUtils.ResolveMethod(md);

                object[] p = new object[_parameters.Rows.Count];

                for (int i = 0; i < _parameters.Rows.Count; i++)
                {
                    string s;
                    s = _parameters.Rows[i]["value"] == null ? String.Empty : _parameters.Rows[i]["value"].ToString();
                    if (!String.IsNullOrEmpty(s) && s.IndexOf("\\u") >= 0)
                    {
                        try
                        {
                            s = SimpleParse.ParseUnicodeString(s);
                        }
                        catch
                        {
                        }
                    }

                    string paramType = _parameters.Rows[i]["type"].ToString();
                    switch (paramType)
                    {
                    case "System.String":
                        p[i] = s;
                        break;

                    case "System.Int32":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = Int32.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = Int32.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.Int16":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = Int16.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = Int16.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.Int64":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = Int64.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = Int64.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.UInt32":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = UInt32.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = UInt32.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.UInt16":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = UInt16.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = UInt16.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.UInt64":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = UInt64.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = UInt64.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.Decimal":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = Decimal.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = Decimal.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.Double":
                        if (s.StartsWith("0x"))
                        {
                            p[i] = Double.Parse(s.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            p[i] = Double.Parse(s, NumberStyles.Any);
                        }
                        break;

                    case "System.Byte":
                        p[i] = Convert.ToByte(s);
                        break;

                    case "System.SByte":
                        p[i] = Convert.ToSByte(s);
                        break;

                    case "System.Boolean":
                        p[i] = Convert.ToBoolean(s);
                        break;

                    case "System.Char":
                        p[i] = Convert.ToChar(s);
                        break;

                    case "System.DateTime":
                        p[i] = DateTime.Parse(s);
                        break;

                    case "System.Byte[]":
                        string[] byteStrs = s.Replace(" ", "").Replace("\r", "").Replace("\n", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        byte[]   bytes    = new byte[byteStrs.Length];
                        for (int j = 0; j < bytes.Length; j++)
                        {
                            string tmpStr = byteStrs[j];
                            if (tmpStr.StartsWith("0x"))
                            {
                                bytes[j] = Byte.Parse(tmpStr.Substring(2), NumberStyles.HexNumber);
                            }
                            else
                            {
                                bytes[j] = Byte.Parse(tmpStr, NumberStyles.Any);
                            }
                        }
                        p[i] = bytes;
                        break;

                    default:
                        p[i] = s;
                        break;
                    }
                }


                SimpleTextbox.AppendText(txtInfo, String.Format("=== Started at {0} ===\r\n", DateTime.Now));

                object o = mb.Invoke(null, p);
                if (o != null)
                {
                    SimpleTextbox.AppendText(txtInfo, String.Format("Return Value: {0}\r\n", o));
                    ParameterInfo[] pi = mb.GetParameters();
                    for (int i = 0; i < pi.Length; i++)
                    {
                        if (pi[i].IsOut || pi[i].ParameterType.IsByRef)
                        {
                            SimpleTextbox.AppendText(txtInfo, String.Format("{0}: {1}\r\n", pi[i].Name, p[i]));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SimpleMessage.ShowException(ex);
            }
            finally
            {
                Utils.EnableUI(this.Controls, true);
                if (resolveDirAdded)
                {
                    _host.RemoveAssemblyResolveDir(_sourceDir);
                }
                SimpleTextbox.AppendText(txtInfo, String.Format("=== Completed at {0} ===\r\n\r\n", DateTime.Now));
            }

            //this.Close();
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            //if (SimpleMessage.ShowInfo("Are you sure to remove Strong Name of selected assemblies?",
            //    "Confirm",
            //    MessageBoxButtons.YesNo, MessageBoxIcon.Question,
            //    MessageBoxDefaultButton.Button2) == DialogResult.No)
            //{
            //    return;
            //}

            if (_sourceDir != null && _sourceDir.Equals(txtOutputDir.Text))
            {
                Config.SNOutputDir = String.Empty;
            }
            else
            {
                Config.SNOutputDir = txtOutputDir.Text;
            }


            if (rbSign.Checked)
            {
                string keyFile = txtKeyFile.Text;
                if (String.IsNullOrEmpty(keyFile))
                {
                    SimpleMessage.ShowInfo("Please choose key file.");
                    return;
                }

                if (!String.IsNullOrEmpty(keyFile) && !File.Exists(keyFile))
                {
                    SimpleMessage.ShowInfo("Invalid key file");
                    return;
                }

                if (!String.IsNullOrEmpty(keyFile))
                {
                    Config.StrongKeyFile = keyFile;
                }
            }

            Config.SNAdditionalOptions = txtAdditionalOptions.Text;

            bool resolveDirAdded1 = false;
            bool resolveDirAdded2 = false;

            try
            {
                resolveDirAdded1 = _host.AddAssemblyResolveDir(this._sourceDir);
                resolveDirAdded2 = _host.AddAssemblyResolveDir(txtOutputDir.Text);

                Utils.EnableUI(this.Controls, false);

                StrongNameOptions options = new StrongNameOptions();

                options.Host              = _host;
                options.Rows              = _rows;
                options.SourceDir         = _sourceDir;
                options.OutputDir         = txtOutputDir.Text;
                options.TextInfoBox       = txtInfo;
                options.AdditionalOptions = txtAdditionalOptions.Text;

                options.chkQuietChecked = chkQuiet.Checked;
                options.chkOverwriteOriginalFileChecked = chkOverwrite.Checked;
                options.rbRemoveChecked     = rbRemoveSN.Checked;
                options.rbSignChecked       = rbSign.Checked;
                options.rbVrChecked         = rbVr.Checked;
                options.rbVlChecked         = rbVl.Checked;
                options.rbvfChecked         = rbvf.Checked;
                options.rbVxChecked         = rbVx.Checked;
                options.rbVuChecked         = rbVu.Checked;
                options.rbRaChecked         = false;
                options.rbCustomChecked     = rbCustom.Checked;
                options.rbGacInstallChecked = rbGacInstall.Checked;
                options.rbGacRemoveChecked  = rbGacRemove.Checked;
                options.KeyFile             = txtKeyFile.Text;

                new StrongNamer(options).Go();
            }
            catch (Exception ex)
            {
                SimpleMessage.ShowException(ex);
            }
            finally
            {
                if (resolveDirAdded1)
                {
                    _host.RemoveAssemblyResolveDir(this._sourceDir);
                }
                if (resolveDirAdded2)
                {
                    _host.RemoveAssemblyResolveDir(txtOutputDir.Text);
                }
                Utils.EnableUI(this.Controls, true);
            }
        }