加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

分享如何反编译winform资源文件的详解

(2011-07-03 21:55:04)
标签:

杂谈

本文和大家详细分享一下反编译winform资源文件,希望对你有所帮助。

winform程序,经过.net reflector反编译之后,产生.resources文件不便于VS识别,不能重新编译。在此简单做了一个小工具,就是把.resources文件转化为.resx文件。同时支持批量转换。即一次性浏览选择多个文件,生成之后所有.resx文件放于文件夹resx下面。生成.resx文件之后,一定要拷贝放在相应.cs文件同级目标下,VS就会自动关联起来。然后就可以做相应修改,重编译工作。

在这里我仅是学习性尝试做一个简单的小工具,同时也是拿自己的程序做测试,当然你可尝试反编译别人.net程序,先用reflector反编译之后,再用此工具转化资源文件,但我不支持大家去反编译别人的东西,毕竟要尊重别人的劳动成果和保护知识产权。废话多说了,下面请看界面。

程序界面如下所示:

 

选择多个文件

 

转换成功显示如下图所示:

http://s10/middle/4e2cd3cega72a9ff3e949&690

http://s15/middle/4e2cd3cega72aa06df5ee&690

http://s3/middle/4e2cd3cega72aa08c7f72&690

http://s10/middle/4e2cd3cega72aa0d8aef9&690

程序代码如下:

 Code [http://www.xueit.com]
 private void btnOK_Click(object sender, EventArgs e)
        {
            string basePath = string.Empty;
            string sFile = string.Empty; //不带路径的文件名
            string newFold = "resx";//新文件夹名称
            string savePath = string.Empty;
            int len = 0;
            int index = -1;
            string strResx = string.Empty;
            if (files != null && files.Length > 0)
            {
                sFile = files[0];
                index = sFile.LastIndexOf("\\");
                basePath = sFile.Substring(0, index);//基路径
                savePath = string.Format("{0}\\{1}", basePath, newFold);
                if (!System.IO.Directory.Exists(savePath))
                {
                    Directory.CreateDirectory(savePath);
                }
                ResourceReader reader = null;
                ResXResourceWriter writer = null;
                foreach (string strResources in files)
                {
                    //strResx = sFile.Replace(".resources", ".resx");
                    sFile = strResources;
                    index = sFile.LastIndexOf("\\");
                    len = sFile.Length;
                    if (index > -1 && len > index)
                    {
                        strResx = sFile.Substring(index   1, len - index - 1).Replace(".resources", ".resx");
                    }
                    strResx = string.Format("{0}\\{1}", savePath, strResx);
                    reader = new ResourceReader(strResources);
                    writer = new ResXResourceWriter(strResx);
                    foreach (DictionaryEntry en in reader)
                    {
                        writer.AddMetadata(en.Key.ToString(), en.Value);
                    }
                    if (reader != null)
                    {
                        reader.Close();
                    }
                    if (writer != null)
                    {
                        writer.Close();
                    }
                }
                MessageBox.Show("转换资源文件转换成功", "系统提示");
                txtResources.Text = string.Empty;
            }
            else
            {
                MessageBox.Show("待转换资源文件不能为空", "系统提示");
            }

            // string strResources = this.txtResources.Text;
            // string strResx = this.txtResx.Text;
            //if (string.IsNullOrEmpty(strResources) || string.IsNullOrEmpty(strResx))
            //{
            //    return;
            //}
            //ResourceReader reader = new ResourceReader(strResources);
            //ResXResourceWriter writer = new ResXResourceWriter(strResx);

            //foreach (DictionaryEntry en in reader)
            //{
            //    writer.AddMetadata(en.Key.ToString(), en.Value);
            //}
            //reader.Close();
            //writer.Close();
        }

已做好程序链接ConvertResource.rar

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有