写了个Total Uninstall注册表代码转Inno注册表代码的工具
此工具还不太完善,望大家多多支持!
运行截图:
下载链接在最下面,压缩包中\标准注册表文件格式转Inno代码\bin\Debug\标准注册表文件格式转Inno代码.exe为可执行文件
以下是源码:
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 标准注册表文件格式转Inno代码
{
class Program
{
enum WordType
{
str = 0,
assign = 1,
num = 2,
typesplit = 3,
type = 4,
}
struct Word
{
public WordType Type;
public string Text;
}
private static Word[] AnalysisLine(string line)
{
List<Word> Words = new List<Word>();
var str = new StringBuilder();
for(var i = 0;i < line.Length;i++)
{
switch(line[i])
{
case '\"':
str = new StringBuilder();
while(line[++i] != '\"')
{
if(line[i] == '\\')
{
str.Append(line[++i]);
}
else
{
str.Append(line[i]);
}
}
Words.Add(new Word{Type = WordType.str,Text = str.ToString()});
break;
case '=':
Words.Add(new Word{Type = WordType.assign,Text = line[i] + ""});
break;
case ':':
Words.Add(new Word{Type = WordType.typesplit,Text = line[i] + ""});
break;
default:
str = new StringBuilder();
while(i < line.Length && line[i] != ':')
{
str.Append(line[i++]);
}
if(i < line.Length && line[i] == ':')
{
Words.Add(new Word{Type = WordType.type,Text = str.ToString()});
i--;
}
else
{
Words.Add(new Word{Type = WordType.num,Text = str.ToString()});
}
break;
}
}
return Words.ToArray();
}
private static string GenerateResultLine(string curpath,Word[] words)
{
string root;
string subkey;
var pos = curpath.IndexOf('\\');
if(pos < 0)
{
pos = curpath.Length;
}
var str = curpath.Substring(0,pos).ToUpper();
switch(str)
{
case "HKEY_LOCAL_MACHINE":
root = "HKLM";
break;
case "HKEY_CLASSES_ROOT":
root = "HKCR";
break;
case "HKEY_CURRENT_USER":
root = "HKCU";
break;
default:
throw new Exception("不支持的Root:" + str);
}
subkey = curpath.Substring(pos,curpath.Length - pos);
if(words == null)
{
return "Root: " + root + "; SubKey: " + subkey + "; Flags: uninsdeletekeyifempty";
}
else
{
var name = "";
var value = "";
var type = "";
var cur = 0;
if(words[cur].Type != WordType.str)
{
throw new Exception("属性名不为字符串!");
}
name = words[cur++].Text;
if(words[cur++].Type != WordType.assign)
{
throw new Exception("属性名后不为赋值符号!");
}
if(words[cur].Type == WordType.type)
{
switch(words[cur++].Text)
{
case "dword":
type = "dword";
break;
case "qword":
type = "qword";
break;
default:
throw new Exception("不支持的类型:" + type);
}
if(words[cur++].Type != WordType.typesplit)
{
throw new Exception("类型后不为类型分隔符!");
}
}
else
{
type = "string";
}
value = words[cur++].Text;
if(cur < words.Length)
{
throw new Exception("值后有多余字符!");
}
return "Root: " + root + "; SubKey: " + subkey + "; ValueType: " + type + "; ValueName: " + name + "; ValueData: " + value + "; Flags: uninsdeletevalue uninsdeletekeyifempty";
}
}
static void Main(string[] args)
{
try
{
//var srcpath = @"D:\程序\项目\标准注册表文件格式转Inno代码\Total Uninstall代码以及Inno代码\Total Uninstall 注册表.txt";
//var dstpath = @"D:\程序\项目\标准注册表文件格式转Inno代码\Total Uninstall代码以及Inno代码\output.txt";
Console.WriteLine("吾爱破解论坛 [url]www.52pojie.cn[/url] lizhirui制作");
Console.Write("请输入源文件路径:");
var srcpath = Console.ReadLine();
Console.Write("请输入目标文件路径:");
var dstpath = Console.ReadLine();
var curpath = "";
//Read Source File
var lines = File.ReadAllLines(srcpath);
var result = new StringBuilder();
foreach(var line in lines)
{
var pline = line.Trim();
//Skip Comment
if(pline == "" || pline[0] == ';')
{
continue;
}
if(pline[0] == '[' && pline[pline.Length - 1] == ']')
{
curpath = pline.Substring(1,pline.Length - 2);
GenerateResultLine(curpath,null);
}
else if(curpath != "")
{
var words = AnalysisLine(pline);
result.Append(GenerateResultLine(curpath,words));
result.Append("\r\n");
}
}
File.WriteAllText(dstpath,result.ToString());
Console.WriteLine("转换成功!");
}
catch(Exception ex)
{
Console.WriteLine("错误:" + ex.Message);
throw ex;
}
Console.ReadKey();
}
}
}
源码使用VS2017编写
标准注册表文件格式转Inno代码.rar
(183.8 KB, 下载次数: 116)
|