今天在破解一个棋牌游戏包时发现客户端的文件是明文的,但文件格式是luac的。
因为这个包也是网狐框架cocos lua的 所以我想着能不能拖到win32里面跑一下,但是win32只支持lua后缀,如果一个个文件取改的话效率太慢,也不是我的分割哈哈哈。于是,手写了一个c#批量更换后缀的小工具。如下:
界面设计:
原始格式:修改前的格式
修改格式:修改后的格式
修改文件夹:需要修改的文件夹
选择文件夹按钮:使用FolderBrowserDialog选择文件夹,也可复制,代码如下:
确认修改按钮:
全部代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EditFilesType
{
public partial class Form1 : Form
{
private string editType; // 修改后缀
private string initType; // 初始后缀
private string selectPath; // 选择文件夹路径
int sum; // 修改数量
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void bt_selectPath_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择修改路径";
if (dialog.ShowDialog() == DialogResult.OK) {
if (Directory.Exists(dialog.SelectedPath.ToString()))
{
text_filesPath.Text = dialog.SelectedPath.ToString();
}
else {
MessageBox.Show("文件夹不存在");
}
}
}
private void label4_Click(object sender, EventArgs e)
{
}
private void bt_edit_Click(object sender, EventArgs e)
{
// 将文本框里值赋变量
this.editType = text_editType.Text.ToString();
this.initType = text_initType.Text.ToString();
this.selectPath = text_filesPath.Text.ToString();
if (initType.Length <= 0)
{
MessageBox.Show("请填写初始格式");
return;
}
if ( editType.Length<=0 ) {
MessageBox.Show("请填写修改格式");
return;
}
if (selectPath.Length <= 0)
{
MessageBox.Show("请选择需要修改的文件夹");
return;
}
if ( Directory.Exists(selectPath) == false ) {
MessageBox.Show("文件夹不存在,请重新选择文件夹");
return;
}
sum = 0; // 初始化文件修改数量
this.editFileType(selectPath); // 修改顶级文件夹里面的文件
DirectoryInfo directory = new DirectoryInfo(selectPath);
this.selectDirectoryPath(directory);
}
/// <summary>
/// 递归查文件夹下的子文件夹
/// </summary>
/// <param name="directory">文件夹</param>
public void selectDirectoryPath(DirectoryInfo directory) {
DirectoryInfo[] childDirectorys = directory.GetDirectories();
foreach ( DirectoryInfo dir in childDirectorys ) {
this.editFileType(dir.FullName);
selectDirectoryPath(dir);
}
}
/// <summary>
/// 修改目录下的文件格式
/// </summary>
/// <param name="path">文件夹路径</param>
public void editFileType(string path) {
DirectoryInfo directory = new DirectoryInfo(path);
FileInfo[] allFiles = directory.GetFiles();
foreach ( FileInfo file in allFiles) {
// 判断文件格式是否和需要修改的格式一致
if ( System.IO.Path.GetExtension(file.FullName).ToString() .Equals("."+this.initType) ) {
file.MoveTo(Path.ChangeExtension(path+"\\"+file.Name, this.editType));
text_editSum.Text = (++this.sum).ToString() + "个文件被修改";
}
}
}
}
}