万能程序补丁工具 C# 源代码详解

万能程序补丁工具 C# 源代码详解

  • 1、概述
  • 2、设计功能
  • [3、VS2017 C# 代码的实现](# 代码的实现)
    • [3.1、VS2017 创建基于.net framework 架构的 C# 解决方案【万能程序补丁工具】](# 解决方案【万能程序补丁工具】)
      • [3.1.1、在默认的 Form1 窗体中设置背景图片等,Form1.Designer.cs 设计代码](#3.1.1、在默认的 Form1 窗体中设置背景图片等,Form1.Designer.cs 设计代码)
      • [3.1.2、Form1 窗体代码 Form1.cs 中,声明引用命名空间](#3.1.2、Form1 窗体代码 Form1.cs 中,声明引用命名空间)
      • [3.1.3、Form1 窗体代码 Form1.cs 中,全部代码如下](#3.1.3、Form1 窗体代码 Form1.cs 中,全部代码如下)
      • [3.1.4、添加 Windows 窗体(新建关于窗体 About)](#3.1.4、添加 Windows 窗体(新建关于窗体 About))
      • [3.1.5、关于窗体 About.Designer.cs 设计代码为](#3.1.5、关于窗体 About.Designer.cs 设计代码为)
      • [3.1.6、关于窗体 About.cs 声明引用命名空间](#3.1.6、关于窗体 About.cs 声明引用命名空间)
      • [3.1.7、关于窗体 About.cs 中全部代码如下](#3.1.7、关于窗体 About.cs 中全部代码如下)
  • 4、程序编译和调试
    • [4.1、Debug 配置下 Any CPU 平台测试运行](#4.1、Debug 配置下 Any CPU 平台测试运行)
    • [4.2、Release 配置下 Any CPU 平台生成解决方案](#4.2、Release 配置下 Any CPU 平台生成解决方案)
  • [5、万能程序补丁工具 程序完整解决方案和编译程序下载](#5、万能程序补丁工具 程序完整解决方案和编译程序下载)

1、概述

万能程序补丁工具程序目的:搜索二进制可执行 EXE 或 DLL 文件分析的特征代码,替换特征代码,达到调试修正目标程序的功能。

2、设计功能

  • 程序启动后,默认加载配置文件为 config.prg
  • 通过鼠标右键,可以选择更改配置文件 config.prg,为各种文件进行补丁。
  • 通过鼠标左键,即可选择目标可执行 EXE 或 DLL 文件,根据配置文件的特征码,达到修改原 EXE 或 DLL 文件的补丁功能!

万用特征码程序补丁器的配置文件 config.prg,可以设置任何可执行目标文件,

  • 第一行为目标文件文件名,
  • 第二行为目标文件版本,
  • 以下其它行,每二行十六进制码为对应的原始码与补丁码。

必须保证特征码的唯一性!!才能保证程序修改正确!!特征码十六进制码空格必须有且只能一个!!

例如 config.prg文件内容如下:

某程序名称

R1 V11.2.160.168

8B D8 48 85 C0 75 08 8D 43 FF

31 C0 90 90 90 90 90 90 90 90

80 7F 60 00 74 10 45 33 C0 48 8B 57 58 48 8B 4D 98 E8 4F 1C 4F

80 7F 60 00 EB 10 45 33 C0 48 8B 57 58 48 8B 4D 98 E8 4F 1C 4F

04 00 00 85 C0 74 07 BB 01 00 00 00

04 00 00 85 C0 74 00 BB 01 00 00 00

0F B6 C0 85 C0 74 56

0F B6 C0 85 C0 74 00

F3 FF FF 83 F8 FF 75

F3 FF FF 83 F8 FF EB

48 01 00 00 C1 92 35 7C

00 00 10 00 C1 92 35 7C

3、VS2017 C# 代码的实现

3.1、VS2017 创建基于.net framework 架构的 C# 解决方案【万能程序补丁工具】

3.1.1、在默认的 Form1 窗体中设置背景图片等,Form1.Designer.cs 设计代码

csharp 复制代码
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.SuspendLayout();
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackgroundImage = global::万能程序补丁工具.Properties.Resources.老虎;//背景图片
            this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.ClientSize = new System.Drawing.Size(370, 347);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
            this.MaximizeBox = false;//禁止最大化窗体
            this.MinimizeBox = false;//禁止最小化窗体
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "万能程序补丁工具";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseClick);
            this.ResumeLayout(false);
        }

3.1.2、Form1 窗体代码 Form1.cs 中,声明引用命名空间

csharp 复制代码
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;

3.1.3、Form1 窗体代码 Form1.cs 中,全部代码如下

csharp 复制代码
namespace 万能程序补丁工具
{
    public partial class Form1 : Form
    {
        string TargetFileName = null;//目标文件名
        string TargetFilePathName = null;//目标完整文件名
        OpenFileDialog OpenFileDialog1 = new OpenFileDialog();//声明打开对话框
        string[] SourceHex = null;//原始特征码
        string[] PatchHex = null; //补丁特征码
        bool ConfBool = false; //是否载入有效配置文件

        public Form1()
        {
            InitializeComponent();
        }
  
        /// <summary>窗体载入事件调用配置文件</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            string ConfigFile = Application.StartupPath + "\\config.prg";//目标特征码配置文件
            OpenConfigFile(ConfigFile);//调用打开配置文件
        }

        /// <summary>鼠标单击事件</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)//按鼠标左键对目标文件进行补丁
            {
                if (!ConfBool)
                {
                    MessageBox.Show("没有默认配置文件 config.prg\r\n鼠标右键加载 *.prg 配置文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                OpenFileDialog1.Filter = "可执行文件(*.exe)|*.exe|库文件(*.dll)|*.dll|所有文件(*.*)|*.*";//打开文件对话框筛选器
                OpenFileDialog1.FilterIndex = 1;//默认选择筛选器第 1 项
                OpenFileDialog1.Title = "打开目标文件";//打开文件对话框标题
                OpenFileDialog1.FileName = TargetFileName;//目标文件名
                OpenFileDialog1.InitialDirectory = System.IO.Directory.GetCurrentDirectory(); //首选当前目录

                if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        TargetFilePathName = OpenFileDialog1.FileName; //完整目标文件名
                        int Pos = TargetFilePathName.LastIndexOf(".");
                        string CrackFilePathName = TargetFilePathName.Substring(0, Pos) + "-PJ" + TargetFilePathName.Substring(Pos); //完整补丁文件名

                        byte[] FSData = File.ReadAllBytes(TargetFilePathName); //目标文件读入字节数组

                        //Rename(TargetFilePathName, BakFilePathName) '舍弃备份文件方式
                        bool BytesChange = false;
                        int PatchNum = SourceHex.Length - 1; //补丁个数
                        byte[] SourceByte = null; //原始特征码字节数组
                        byte[] PatchByte = null; //补丁特征码字节数组

                        for (int i = 1; i <= PatchNum; i++)
                        {
                            string[] HexStr = SourceHex[i].Split(' '); //将十六进制特征码按空格拆分为字符串数组
                            int HexNum = HexStr.Length - 1; //字符串数组个数

                            Array.Resize(ref SourceByte, HexNum + 1);
                            Array.Resize(ref PatchByte, HexNum + 1);

                            for (int j = 0; j <= HexNum; j++)
                            {
                                SourceByte[j] = Convert.ToByte(HexStr[j], 16);//原始特征码转换为字节数组
                            }

                            HexStr = PatchHex[i].Split(' '); //将补丁的十六进制特征码按空格拆分为字符串数组
                            for (int k = 0; k <= HexNum; k++)
                            {
                                PatchByte[k] = Convert.ToByte(HexStr[k], 16);//补丁特征码转换为字节数组
                            }

                            int Index = IndexOf(FSData, SourceByte); //检索原始特征码在程序中的索引位置

                            if (Index != -1) //特征码匹配
                            {
                                int P = 0;
                                int Indexs = Index + PatchByte.Length - 1;
                                for (int m = Index; m <= Indexs; m++)
                                {
                                    FSData[m] = PatchByte[P]; //替换特征码
                                    P += 1;
                                }
                                BytesChange = true;//字节已更改
                            }
                          }
                        if (BytesChange)
                        {
                            File.WriteAllBytes(CrackFilePathName, FSData);
                            MessageBox.Show("程序保存在相同目录下,文件为:\r\n" + Path.GetFileName(CrackFilePathName), "完成程序补丁", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("prg文件特征码补丁,不符合本程序!", "程序补丁失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("配置文件中错误:\r\n1、原始特征码和补丁特征码不匹配,不符合设定!\r\n2、特征码十六进制空格或位数不符合设定!\r\n\r\n" + ex.Source, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                }
            }

            if (e.Button == MouseButtons.Middle)//按鼠标中键打开关于对话框
            {
                Form About = new About();
                About.Show();
            }
            if (e.Button == MouseButtons.Right)//按鼠标右键选择打开或更改配置文件
            {
                //定义打开对话框属性
                OpenFileDialog1.Filter = "目标配置文件(*.prg)|*.prg";
                OpenFileDialog1.FilterIndex = 1;
                OpenFileDialog1.Title = "更改目标配置文件";
                OpenFileDialog1.InitialDirectory = Environment.CurrentDirectory; //首选当前目录
                if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    TargetFilePathName = OpenFileDialog1.FileName;
                    OpenConfigFile(TargetFilePathName);
                }
            }
        }

        /// <summary>打开或更改配置文件</summary>
        /// <param name="ConfigFilePathName">配置文件含完整目录全称</param>
        private void OpenConfigFile(string ConfigFilePathName)
        {
            if (File.Exists(ConfigFilePathName))
            {
                try
                {
                    StreamReader TargetFile = new StreamReader(ConfigFilePathName, Encoding.UTF8);
                    int i = 0;
                    SourceHex = null;
                    PatchHex = null;
                    while (TargetFile.Peek() > 0)
                    {
                        Array.Resize(ref SourceHex, i + 1);
                        Array.Resize(ref PatchHex, i + 1);
                        SourceHex[i] = TargetFile.ReadLine().Trim();//读原特征码行
                        PatchHex[i] = TargetFile.ReadLine().Trim();//读补丁特征码行
                        i += 1;
                    }
                    TargetFile.Dispose();      //注销文件流
                    TargetFileName = SourceHex[0];  //目标文件名
                    string TargetFileVer = PatchHex[0];//目标版本
                    this.Text = "万能特征码补丁器 [" + TargetFileName + " " + TargetFileVer + "]";
                    ConfBool = true;
                }
                catch (Exception ex)
                {
                    ConfBool = false;
                    MessageBox.Show("配置文件错误:\r\n配置文件非法或不符合设定!\r\n\r\n" + ex.StackTrace, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                this.Text = "万能特征码补丁器 [无配置文件 Config.prg]";
                ConfBool = false;
            }
        }

        /// <summary>报告指定的 System.Byte() 在此实例中的第一个匹配项的索引。</summary>
        /// <param name="srcBytes">被执行查找的 System.Byte()。</param>
        /// <param name="searchBytes">要查找的 System.Byte()。</param>
        /// <returns>如果找到该字节数组,则为 searchBytes 的索引位置;如果未找到该字节数组,则为 -1。如果 searchBytes 为 null 或者长度为0,则返回值为 -1。</returns>
        private int IndexOf(byte[] SrcBytes, byte[] SearchBytes)
        {
            if (SrcBytes == null || SearchBytes == null || SrcBytes.Length == 0 || SearchBytes.Length == 0 || SrcBytes.Length < SearchBytes.Length) return -1;

            for (int i = 0; i <= SrcBytes.Length - SearchBytes.Length - 1; i++)
            {
                Console.WriteLine(SearchBytes[0]);

                if (SrcBytes[i] == SearchBytes[0])//先比较首字节
                {

                    if (SearchBytes.Length == 1) return i;  //搜索字节只一位

                    bool flag = true;

                    //比较首字节后面的其它字节
                    for (int j = 1; j <= SearchBytes.Length - 1; j++)
                    {

                        if (SrcBytes[i + j] != SearchBytes[j])
                        {
                            flag = false;
                            break; //只要其中有一个字节不匹配则退出循环
                        }
                    }

                    if (flag) return i;  //搜索到匹配的字节,返回字节位置索引
                }
            }
            return -1;
        }
    }

}

3.1.4、添加 Windows 窗体(新建关于窗体 About)

3.1.5、关于窗体 About.Designer.cs 设计代码为

csharp 复制代码
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(About));
            this.TableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
            this.LogoPictureBox = new System.Windows.Forms.PictureBox();
            this.LabelProductName = new System.Windows.Forms.Label();
            this.LabelVersion = new System.Windows.Forms.Label();
            this.LabelCopyright = new System.Windows.Forms.Label();
            this.TextBoxDescription = new System.Windows.Forms.TextBox();
            this.OKButton = new System.Windows.Forms.Button();
            this.TableLayoutPanel.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.LogoPictureBox)).BeginInit();
            this.SuspendLayout();
            // 
            // TableLayoutPanel
            // 
            this.TableLayoutPanel.ColumnCount = 2;
            this.TableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33F));
            this.TableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 67F));
            this.TableLayoutPanel.Controls.Add(this.LogoPictureBox, 0, 0);
            this.TableLayoutPanel.Controls.Add(this.LabelProductName, 1, 0);
            this.TableLayoutPanel.Controls.Add(this.LabelVersion, 1, 1);
            this.TableLayoutPanel.Controls.Add(this.LabelCopyright, 1, 2);
            this.TableLayoutPanel.Controls.Add(this.TextBoxDescription, 1, 4);
            this.TableLayoutPanel.Controls.Add(this.OKButton, 1, 5);
            this.TableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
            this.TableLayoutPanel.Location = new System.Drawing.Point(0, 0);
            this.TableLayoutPanel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.TableLayoutPanel.Name = "TableLayoutPanel";
            this.TableLayoutPanel.RowCount = 6;
            this.TableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 24.7191F));
            this.TableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 29.21348F));
            this.TableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 29.21348F));
            this.TableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16.85393F));
            this.TableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 168F));
            this.TableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 37F));
            this.TableLayoutPanel.Size = new System.Drawing.Size(510, 324);
            this.TableLayoutPanel.TabIndex = 1;
            // 
            // LogoPictureBox
            // 
            this.LogoPictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
            this.LogoPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("LogoPictureBox.Image")));
            this.LogoPictureBox.Location = new System.Drawing.Point(4, 5);
            this.LogoPictureBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.LogoPictureBox.Name = "LogoPictureBox";
            this.TableLayoutPanel.SetRowSpan(this.LogoPictureBox, 6);
            this.LogoPictureBox.Size = new System.Drawing.Size(160, 314);
            this.LogoPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.LogoPictureBox.TabIndex = 0;
            this.LogoPictureBox.TabStop = false;
            // 
            // LabelProductName
            // 
            this.LabelProductName.Dock = System.Windows.Forms.DockStyle.Fill;
            this.LabelProductName.Location = new System.Drawing.Point(177, 0);
            this.LabelProductName.Margin = new System.Windows.Forms.Padding(9, 0, 4, 0);
            this.LabelProductName.MaximumSize = new System.Drawing.Size(0, 24);
            this.LabelProductName.Name = "LabelProductName";
            this.LabelProductName.Size = new System.Drawing.Size(329, 24);
            this.LabelProductName.TabIndex = 0;
            this.LabelProductName.Text = "产品名称";
            this.LabelProductName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // LabelVersion
            // 
            this.LabelVersion.Dock = System.Windows.Forms.DockStyle.Fill;
            this.LabelVersion.Location = new System.Drawing.Point(177, 29);
            this.LabelVersion.Margin = new System.Windows.Forms.Padding(9, 0, 4, 0);
            this.LabelVersion.MaximumSize = new System.Drawing.Size(0, 24);
            this.LabelVersion.Name = "LabelVersion";
            this.LabelVersion.Size = new System.Drawing.Size(329, 24);
            this.LabelVersion.TabIndex = 0;
            this.LabelVersion.Text = "版本";
            this.LabelVersion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // LabelCopyright
            // 
            this.LabelCopyright.Dock = System.Windows.Forms.DockStyle.Fill;
            this.LabelCopyright.Location = new System.Drawing.Point(177, 63);
            this.LabelCopyright.Margin = new System.Windows.Forms.Padding(9, 0, 4, 0);
            this.LabelCopyright.MaximumSize = new System.Drawing.Size(0, 24);
            this.LabelCopyright.Name = "LabelCopyright";
            this.LabelCopyright.Size = new System.Drawing.Size(329, 24);
            this.LabelCopyright.TabIndex = 0;
            this.LabelCopyright.Text = "版权";
            this.LabelCopyright.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // TextBoxDescription
            // 
            this.TextBoxDescription.Dock = System.Windows.Forms.DockStyle.Fill;
            this.TextBoxDescription.Location = new System.Drawing.Point(177, 122);
            this.TextBoxDescription.Margin = new System.Windows.Forms.Padding(9, 5, 4, 5);
            this.TextBoxDescription.Multiline = true;
            this.TextBoxDescription.Name = "TextBoxDescription";
            this.TextBoxDescription.ReadOnly = true;
            this.TextBoxDescription.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.TextBoxDescription.Size = new System.Drawing.Size(329, 158);
            this.TextBoxDescription.TabIndex = 0;
            this.TextBoxDescription.TabStop = false;
            this.TextBoxDescription.Text = "说明 :\r\n\r\n(在运行时,将用应用程序的程序集信息替换这些标签的文本。\r\n在";
            // 
            // OKButton
            // 
            this.OKButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.OKButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.OKButton.Location = new System.Drawing.Point(394, 290);
            this.OKButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.OKButton.Name = "OKButton";
            this.OKButton.Size = new System.Drawing.Size(112, 29);
            this.OKButton.TabIndex = 0;
            this.OKButton.Text = "确定(&O)";
            this.OKButton.Click += new System.EventHandler(this.OKButton_Click);
            // 
            // About
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(510, 324);
            this.Controls.Add(this.TableLayoutPanel);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "About";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "关于";
            this.Load += new System.EventHandler(this.About_Load);
            this.TableLayoutPanel.ResumeLayout(false);
            this.TableLayoutPanel.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.LogoPictureBox)).EndInit();
            this.ResumeLayout(false);

        }

        internal System.Windows.Forms.TableLayoutPanel TableLayoutPanel;
        internal System.Windows.Forms.PictureBox LogoPictureBox;
        internal System.Windows.Forms.Label LabelProductName;
        internal System.Windows.Forms.Label LabelVersion;
        internal System.Windows.Forms.Label LabelCopyright;
        internal System.Windows.Forms.TextBox TextBoxDescription;
        internal System.Windows.Forms.Button OKButton;

3.1.6、关于窗体 About.cs 声明引用命名空间

csharp 复制代码
using System;
using System.Windows.Forms;
using System.Reflection;

3.1.7、关于窗体 About.cs 中全部代码如下

csharp 复制代码
namespace 万能程序补丁工具
{
    public partial class About : Form
    {
        public About()
        {
            InitializeComponent();
        }

        private void About_Load(object sender, EventArgs e)
        {
            // 设置此窗体的标题。
            this.Text = string.Format("关于 {0}", AssemblyTitle);

            this.LabelProductName.Text = AssemblyProduct;
            this.LabelVersion.Text = string.Format("版本 {0}", AssemblyVersion);
            this.LabelCopyright.Text = AssemblyCopyright;
            //Me.LabelCompanyName.Text = My.Application.Info.CompanyName &
            this.TextBoxDescription.Text = AssemblyDescription + "十六进制搜索替换" + "\r\n" + "\r\n" + "鼠标右键打开配置文件" + "\r\n" + "鼠标左键打开补丁文件" + "\r\n" + "鼠标中键打开关于窗口" + "\r\n" + "\r\n" + "中游鱼 2024.08";

        }

        /// <summary>获取程序集标题</summary>
        public string AssemblyTitle
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        /// <summary>获取程序集版本</summary>
        public string AssemblyVersion
        {
            get
            {
                return Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

        /// <summary>获取程序集说明</summary>
        public string AssemblyDescription
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        /// <summary>获取程序集产品</summary>
        public string AssemblyProduct
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        /// <summary>获取程序集版权</summary>
        public string AssemblyCopyright
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        /// <summary>获取程序集公司</summary>
        public string AssemblyCompany
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }

        /// <summary>获取程序集配置</summary>
        public string AssemblyConfiguration
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyConfigurationAttribute)attributes[0]).Configuration;
            }
        }

        /// <summary>获取程序集商标</summary>
        public string AssemblyTrademark
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTrademarkAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyTrademarkAttribute)attributes[0]).Trademark;
            }
        }

        /// <summary>获取程序集文化</summary>
        public string AssemblyCulture
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCultureAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCultureAttribute)attributes[0]).Culture;
            }
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

4、程序编译和调试

4.1、Debug 配置下 Any CPU 平台测试运行

VS2017 下按 F5 启动运行调试,经过测试,程序对目标文件进行补丁成功

4.2、Release 配置下 Any CPU 平台生成解决方案

在 万能程序补丁工具\bin\Release 目录下生成编译程序,Release 配置下生成 EXE 文件比 Debug 配置下生成文件小。

5、万能程序补丁工具 程序完整解决方案和编译程序下载

C# 解决方案源代码本地下载: https://download.csdn.net/download/zyyujq/90017250

编译程序本地下载: https://download.csdn.net/download/zyyujq/90017265

相关推荐
hccee2 分钟前
C# IO文件操作
开发语言·c#
广煜永不挂科2 小时前
Devexpress.Dashboard的调用二义性
c#·express
初九之潜龙勿用4 小时前
C#校验画布签名图片是否为空白
开发语言·ui·c#·.net
吾与谁归in5 小时前
【C#设计模式(13)——代理模式(Proxy Pattern)】
设计模式·c#·代理模式
吾与谁归in5 小时前
【C#设计模式(14)——责任链模式( Chain-of-responsibility Pattern)】
设计模式·c#·责任链模式
神仙别闹6 小时前
基于C#和Sql Server 2008实现的(WinForm)订单生成系统
开发语言·c#
向宇it16 小时前
【unity小技巧】unity 什么是反射?反射的作用?反射的使用场景?反射的缺点?常用的反射操作?反射常见示例
开发语言·游戏·unity·c#·游戏引擎
九鼎科技-Leo16 小时前
什么是 WPF 中的依赖属性?有什么作用?
windows·c#·.net·wpf
Heaphaestus,RC17 小时前
【Unity3D】获取 GameObject 的完整层级结构
unity·c#
baivfhpwxf202317 小时前
C# 5000 转16进制 字节(激光器串口通讯生成指定格式命令)
开发语言·c#