WinForm反编译的resources文件转换成resx
利用.Net Reflector或者dnSpy高版本 进行winform 反编译的时候,无法将resx还原,可以利用下面的代码将resources文件转换成resx,函数ConvertResourcesToResx。
(dnSpy v3.0.2可以反编译出resx文件)
public static FileInfo[] GetAllFiles(string path, string seachPattern) { var files = new List<FileInfo>(); files.AddRange(new DirectoryInfo(path).GetFiles(seachPattern)); var tmpdics = new DirectoryInfo(path).GetDirectories(); foreach (var dic in tmpdics) { files.AddRange(GetAllFiles(dic.FullName, seachPattern)); } return files.ToArray(); } private void ConvertResourcesToResx(FileInfo fileName) { var strResources = fileName; var strResx = string.Format("{0}\\{1}", strResources.DirectoryName, strResources.Name.Replace(".resources", ".resx")); var reader = new ResourceReader(strResources.FullName); var writer = new ResXResourceWriter(strResx); foreach (DictionaryEntry en in reader) { writer.AddMetadata(en.Key.ToString(), en.Value); } reader.Close(); reader.Dispose(); writer.Close(); writer.Dispose(); }