Skip to content

Commit

Permalink
Updated zxcheck generator to add passwords to save files
Browse files Browse the repository at this point in the history
  • Loading branch information
ash47 committed Apr 4, 2018
1 parent 0ef1148 commit 2fa5c29
Showing 1 changed file with 87 additions and 24 deletions.
111 changes: 87 additions & 24 deletions ZXCheckGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static void generateZXCheck(string pathToSaveFile)
Console.WriteLine("Failed to generate .zxcheck :(");
}

public static void extractPassword(string pathToSaveFile)
public static void extractPassword(string pathToSaveFile, bool addPassword=false)
{
System.IO.File.AppendAllText("_passwords.txt", pathToSaveFile + Environment.NewLine);

Expand Down Expand Up @@ -188,40 +188,103 @@ public static void extractPassword(string pathToSaveFile)
try
{
zip.ExtractAll(myDir);
}
catch(Exception e)
{
Console.WriteLine("Failed to extract zxsav :/");
Console.WriteLine(e.Message);
return;
}
}

// Craete a decrypted one
using (ZipFile newZip = new ZipFile())
{
//newZip.Password = thePassword;

using (ZipFile newZip = new ZipFile())
{
// Add the contents of the directory to my file
newZip.AddDirectory(myDir);
// 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);
// 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";
// Set the filename
string newRawFileName = saveBaseName + "_decrpyted.zxsav";
string newFileNameBackup = Path.Combine(saveFolder, newRawFileName); ;
newZip.Name = saveFolder + @"\" + saveBaseName + "_decrpyted.zxsav";

// Save it
newZip.Save();
// Save it
newZip.Save();

// Sign it
generateZXCheck(newFileName);
// Sign it
generateZXCheck(newFileNameBackup);

// Tell the user that we decrypted it
Console.WriteLine("Successfully decrypted save file! New file called '" + newRawFileName + "'");
}

// Cleanup the temp directory
DeleteDirectory(myDir);
// Figure out a filename that isn't taken
int i = 1;
string newFileName = null;
while(true)
{
newFileName = pathToSaveFile + ".bak" + i;

// Tell the user that we decrypted it
Console.WriteLine("Successfully decrypted save file! New file called '" + newRawFileName + "'");
}
if(File.Exists(newFileName))
{
++i;
}
catch(Exception e)
else
{
Console.WriteLine("Failed to extract zxsav :/");
Console.WriteLine(e.Message);
break;
}
}

// Move the old zip
try
{
File.Move(pathToSaveFile, newFileName);
}
catch
{
// Cleanup the temp directory
DeleteDirectory(myDir);

Console.WriteLine("Unable to backup zxsav -- Is it open? " + pathToSaveFile);
return;
}

// Add a password to teh original
using (ZipFile newZip = new ZipFile())
{
// Add a password
newZip.Password = thePassword;

// 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 + ".zxsav";
string newFileNameBackup = Path.Combine(saveFolder, newRawFileName); ;
newZip.Name = saveFolder + @"\" + saveBaseName + ".zxsav";

// Save it
newZip.Save();

// Sign it
generateZXCheck(newFileNameBackup);

// Cleanup the temp directory
DeleteDirectory(myDir);

// Tell the user that we decrypted it
Console.WriteLine("Added a password successfully to '" + newRawFileName + "'");
}
}

}
Expand Down

0 comments on commit 2fa5c29

Please sign in to comment.