diff --git a/.gitignore b/.gitignore index ac0c55e..901de3a 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,5 @@ MapEditorHtml/tools/Data MapEditorHtml/tools/allents.js ZXCheckGenerator/.vs/* ZXCheckGenerator/bin/* -ZXCheckGenerator/obj/* \ No newline at end of file +ZXCheckGenerator/obj/* +ZXCheckGenerator/packages/* \ No newline at end of file diff --git a/ZXCheckGenerator/FodyWeavers.xml b/ZXCheckGenerator/FodyWeavers.xml new file mode 100644 index 0000000..c6e1b7c --- /dev/null +++ b/ZXCheckGenerator/FodyWeavers.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ZXCheckGenerator/Program.cs b/ZXCheckGenerator/Program.cs index 02fe64e..1793844 100644 --- a/ZXCheckGenerator/Program.cs +++ b/ZXCheckGenerator/Program.cs @@ -1,4 +1,5 @@ -using System; +using Ionic.Zip; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -156,13 +157,13 @@ public static void extractPassword(string pathToSaveFile) foreach (MethodInfo possibleHelper in possibleType.GetMethods(BindingFlags.NonPublic | BindingFlags.Static)) { ParameterInfo[] helperParams = possibleHelper.GetParameters(); - + if (helperParams.Length != 3) continue; if (helperParams[0].ParameterType.FullName != "System.String") continue; if (helperParams[1].ParameterType.FullName != "System.Int32") continue; if (helperParams[2].ParameterType.FullName != "System.Boolean") continue; - if(possibleHelper.ReturnType.FullName != "System.Void") continue; + if (possibleHelper.ReturnType.FullName != "System.Void") continue; possibleHelper.Invoke(null, new object[] { pathToSaveFile, flag, true }); @@ -174,6 +175,53 @@ public static void extractPassword(string pathToSaveFile) Console.WriteLine("Found password = " + thePassword); System.IO.File.AppendAllText("_passwords.txt", "Password = " + thePassword + Environment.NewLine); + + // Get a working directory + string myDir = GetTemporaryDirectory(); + + using (ZipFile zip = ZipFile.Read(pathToSaveFile)) + { + // Add the password + zip.Password = thePassword; + + // Extract all + try + { + zip.ExtractAll(myDir); + + using (ZipFile newZip = new ZipFile()) + { + // Add the contents of the directory to my file + newZip.AddDirectory(myDir); + + // Write it to disk + string saveFolder = Path.GetDirectoryName(pathToSaveFile); + string saveBaseName = Path.GetFileNameWithoutExtension(pathToSaveFile); + + // Set the filename + string newRawFileName = saveBaseName + "_decrpyted.zxsav"; + string newFileName = Path.Combine(saveFolder, newRawFileName); ; + newZip.Name = saveFolder + @"\" + saveBaseName + "_decrpyted.zxsav"; + + // Save it + newZip.Save(); + + // Sign it + generateZXCheck(newFileName); + + // Cleanup the temp directory + DeleteDirectory(myDir); + + // Tell the user that we decrypted it + Console.WriteLine("Successfully decrypted save file! New file called '" + newRawFileName + "'"); + } + } + catch(Exception e) + { + Console.WriteLine("Failed to extract zxsav :/"); + Console.WriteLine(e.Message); + } + } } } @@ -192,7 +240,35 @@ public static void extractPassword(string pathToSaveFile) } } } - + + // Deletes a directory + public static void DeleteDirectory(string target_dir) + { + string[] files = Directory.GetFiles(target_dir); + string[] dirs = Directory.GetDirectories(target_dir); + + foreach (string file in files) + { + File.SetAttributes(file, FileAttributes.Normal); + File.Delete(file); + } + + foreach (string dir in dirs) + { + DeleteDirectory(dir); + } + + Directory.Delete(target_dir, false); + } + + // Returns a random temp directory to work with + public static string GetTemporaryDirectory() + { + string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + Directory.CreateDirectory(tempDirectory); + return tempDirectory; + } + // Called when the program is launched static void Main(string[] args) { diff --git a/ZXCheckGenerator/ZXCheckGenerator.csproj b/ZXCheckGenerator/ZXCheckGenerator.csproj index 43c8b8d..4eebe5f 100644 --- a/ZXCheckGenerator/ZXCheckGenerator.csproj +++ b/ZXCheckGenerator/ZXCheckGenerator.csproj @@ -13,6 +13,8 @@ 512 true + + AnyCPU @@ -59,6 +61,14 @@ true + + packages\Costura.Fody.1.6.2\lib\dotnet\Costura.dll + True + + + packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll + True + @@ -74,8 +84,21 @@ + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + +