Add Encryption Option
This commit is contained in:
parent
ae0bd69649
commit
d3164bac33
|
@ -159,8 +159,32 @@ namespace RMDEC
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void EncryptFile(Stream inStream, Stream outStream)
|
||||||
|
{
|
||||||
|
outStream.Seek(0x00, SeekOrigin.Begin);
|
||||||
|
outStream.SetLength(0x00);
|
||||||
|
|
||||||
|
BinaryWriter boutStream = new BinaryWriter(outStream);
|
||||||
|
string magic = "RPGMV";
|
||||||
|
byte[] magicBytes = Encoding.UTF8.GetBytes(magic);
|
||||||
|
|
||||||
|
outStream.Write(magicBytes, 0x00, magicBytes.Length);
|
||||||
|
boutStream.Write(0x00);
|
||||||
|
boutStream.Write(0x103);
|
||||||
|
outStream.Write(new byte[0x3], 0x00, 0x3);
|
||||||
|
|
||||||
|
inStream.Seek(0x00, SeekOrigin.Begin);
|
||||||
|
byte[] plaintextHeader = new byte[0x10];
|
||||||
|
inStream.Read(plaintextHeader, 0x00, 0x10);
|
||||||
|
|
||||||
|
byte[] encryptedHeader = xor(plaintextHeader, encryptionKey);
|
||||||
|
outStream.Write(encryptedHeader, 0x00, encryptedHeader.Length);
|
||||||
|
inStream.CopyTo(outStream);
|
||||||
|
}
|
||||||
public void DecryptFile(Stream inStream, Stream outStream)
|
public void DecryptFile(Stream inStream, Stream outStream)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
inStream.Seek(0x00, SeekOrigin.Begin);
|
inStream.Seek(0x00, SeekOrigin.Begin);
|
||||||
|
|
||||||
byte[] magic = new byte[0x05];
|
byte[] magic = new byte[0x05];
|
||||||
|
@ -177,6 +201,10 @@ namespace RMDEC
|
||||||
inStream.Read(encryptedHeader, 0x00, 0x10);
|
inStream.Read(encryptedHeader, 0x00, 0x10);
|
||||||
|
|
||||||
byte[] plaintextHeader = xor(encryptedHeader, encryptionKey);
|
byte[] plaintextHeader = xor(encryptedHeader, encryptionKey);
|
||||||
|
|
||||||
|
outStream.Seek(0x00, SeekOrigin.Begin);
|
||||||
|
outStream.SetLength(0);
|
||||||
|
|
||||||
outStream.Write(plaintextHeader, 0x00, plaintextHeader.Length);
|
outStream.Write(plaintextHeader, 0x00, plaintextHeader.Length);
|
||||||
inStream.CopyTo(outStream);
|
inStream.CopyTo(outStream);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace RMDEC
|
||||||
private List<string> encFileList = new List<string>();
|
private List<string> encFileList = new List<string>();
|
||||||
private List<string> decFileList = new List<string>();
|
private List<string> decFileList = new List<string>();
|
||||||
|
|
||||||
|
private string[] blacklistedFiles = { Path.Combine("icon","icon.png"), Path.Combine("img","system","Window.png"), Path.Combine("img","system","Loading.png") };
|
||||||
|
|
||||||
private bool encryptedIndexingComplete = false;
|
private bool encryptedIndexingComplete = false;
|
||||||
private bool unencryptedIndexingComplete = false;
|
private bool unencryptedIndexingComplete = false;
|
||||||
private void onIndexThreadComplete()
|
private void onIndexThreadComplete()
|
||||||
|
@ -59,13 +61,13 @@ namespace RMDEC
|
||||||
|
|
||||||
List<string> pngList = new List<string>();
|
List<string> pngList = new List<string>();
|
||||||
List<string> oggList = new List<string>();
|
List<string> oggList = new List<string>();
|
||||||
List<string> M4AList = new List<string>();
|
List<string> m4aList = new List<string>();
|
||||||
|
|
||||||
foreach (string file in Directory.EnumerateFiles(mvProject.FilePath, "*", SearchOption.AllDirectories))
|
foreach (string file in Directory.EnumerateFiles(mvProject.FilePath, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
string fileExtension = Path.GetExtension(file);
|
string fileExtension = Path.GetExtension(file).ToLower();
|
||||||
|
|
||||||
switch (fileExtension)
|
switch (fileExtension)
|
||||||
{
|
{
|
||||||
|
@ -76,7 +78,7 @@ namespace RMDEC
|
||||||
oggList.Add(file);
|
oggList.Add(file);
|
||||||
break;
|
break;
|
||||||
case ".rpgmvm":
|
case ".rpgmvm":
|
||||||
M4AList.Add(file);
|
m4aList.Add(file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,14 +108,14 @@ namespace RMDEC
|
||||||
}
|
}
|
||||||
|
|
||||||
//add M4A
|
//add M4A
|
||||||
foreach (string M4A in M4AList)
|
foreach (string m4a in m4aList)
|
||||||
{
|
{
|
||||||
string relativeName = M4A.Remove(0, mvProject.FilePath.Length+1);
|
string relativeName = m4a.Remove(0, mvProject.FilePath.Length+1);
|
||||||
Invoke((Action)delegate
|
Invoke((Action)delegate
|
||||||
{
|
{
|
||||||
encryptedFileList.Items.Add("[M4A] " + relativeName);
|
encryptedFileList.Items.Add("[M4A] " + relativeName);
|
||||||
});
|
});
|
||||||
encFileList.Add(M4A);
|
encFileList.Add(m4a);
|
||||||
}
|
}
|
||||||
|
|
||||||
Invoke((Action)delegate
|
Invoke((Action)delegate
|
||||||
|
@ -131,12 +133,18 @@ namespace RMDEC
|
||||||
|
|
||||||
List<string> pngList = new List<string>();
|
List<string> pngList = new List<string>();
|
||||||
List<string> oggList = new List<string>();
|
List<string> oggList = new List<string>();
|
||||||
List<string> M4AList = new List<string>();
|
List<string> m4aList = new List<string>();
|
||||||
|
|
||||||
foreach (string file in Directory.EnumerateFiles(mvProject.FilePath, "*", SearchOption.AllDirectories))
|
foreach (string file in Directory.EnumerateFiles(mvProject.FilePath, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
|
|
||||||
string fileExtension = Path.GetExtension(file);
|
string relativeName = file.Remove(0, mvProject.FilePath.Length + 1);
|
||||||
|
string fileExtension = Path.GetExtension(file).ToLower();
|
||||||
|
|
||||||
|
if(blacklistedFiles.Contains(relativeName))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch (fileExtension)
|
switch (fileExtension)
|
||||||
{
|
{
|
||||||
|
@ -146,8 +154,8 @@ namespace RMDEC
|
||||||
case ".ogg":
|
case ".ogg":
|
||||||
oggList.Add(file);
|
oggList.Add(file);
|
||||||
break;
|
break;
|
||||||
case ".M4A":
|
case ".m4a":
|
||||||
M4AList.Add(file);
|
m4aList.Add(file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +166,7 @@ namespace RMDEC
|
||||||
foreach (string png in pngList)
|
foreach (string png in pngList)
|
||||||
{
|
{
|
||||||
string relativeName = png.Remove(0, mvProject.FilePath.Length+1);
|
string relativeName = png.Remove(0, mvProject.FilePath.Length+1);
|
||||||
|
|
||||||
Invoke((Action)delegate
|
Invoke((Action)delegate
|
||||||
{
|
{
|
||||||
decryptedFileList.Items.Add("[PNG] " + relativeName);
|
decryptedFileList.Items.Add("[PNG] " + relativeName);
|
||||||
|
@ -169,6 +178,7 @@ namespace RMDEC
|
||||||
foreach (string ogg in oggList)
|
foreach (string ogg in oggList)
|
||||||
{
|
{
|
||||||
string relativeName = ogg.Remove(0, mvProject.FilePath.Length+1);
|
string relativeName = ogg.Remove(0, mvProject.FilePath.Length+1);
|
||||||
|
|
||||||
Invoke((Action)delegate
|
Invoke((Action)delegate
|
||||||
{
|
{
|
||||||
decryptedFileList.Items.Add("[OGG] " + relativeName);
|
decryptedFileList.Items.Add("[OGG] " + relativeName);
|
||||||
|
@ -177,14 +187,15 @@ namespace RMDEC
|
||||||
}
|
}
|
||||||
|
|
||||||
//add M4A
|
//add M4A
|
||||||
foreach (string M4A in M4AList)
|
foreach (string m4a in m4aList)
|
||||||
{
|
{
|
||||||
string relativeName = M4A.Remove(0, mvProject.FilePath.Length+1);
|
string relativeName = m4a.Remove(0, mvProject.FilePath.Length+1);
|
||||||
|
|
||||||
Invoke((Action)delegate
|
Invoke((Action)delegate
|
||||||
{
|
{
|
||||||
decryptedFileList.Items.Add("[M4A] " + relativeName);
|
decryptedFileList.Items.Add("[M4A] " + relativeName);
|
||||||
});
|
});
|
||||||
decFileList.Add(M4A);
|
decFileList.Add(m4a);
|
||||||
}
|
}
|
||||||
|
|
||||||
Invoke((Action)delegate
|
Invoke((Action)delegate
|
||||||
|
@ -205,7 +216,99 @@ namespace RMDEC
|
||||||
|
|
||||||
private void encryptSelected_Click(object sender, EventArgs e)
|
private void encryptSelected_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
SelectedIndexCollection itemList = decryptedFileList.SelectedIndices;
|
||||||
|
int itemCount = itemList.Count;
|
||||||
|
|
||||||
|
if (itemCount < 1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int item = 0;
|
||||||
|
|
||||||
|
processingBar.Style = ProgressBarStyle.Continuous;
|
||||||
|
processingBar.Maximum = itemCount;
|
||||||
|
|
||||||
|
processingText.BackColor = Color.Yellow;
|
||||||
|
|
||||||
|
encryptSelected.Enabled = false;
|
||||||
|
decryptSelected.Enabled = false;
|
||||||
|
|
||||||
|
|
||||||
|
Thread decryptFilesThread = new Thread(() =>
|
||||||
|
{
|
||||||
|
int i = 1;
|
||||||
|
int total = itemCount;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
|
||||||
|
Invoke((Action)delegate
|
||||||
|
{
|
||||||
|
|
||||||
|
itemCount = itemList.Count;
|
||||||
|
item = itemList[0];
|
||||||
|
|
||||||
|
processingText.Text = "Encrypting " + i.ToString() + "/" + total.ToString();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
string decryptedFile = decFileList[item];
|
||||||
|
string extension = Path.GetExtension(decryptedFile).ToLower();
|
||||||
|
string newExtension = "";
|
||||||
|
|
||||||
|
switch (extension)
|
||||||
|
{
|
||||||
|
case ".png":
|
||||||
|
newExtension = ".rpgmvp";
|
||||||
|
break;
|
||||||
|
case ".ogg":
|
||||||
|
newExtension = ".rpgmvo";
|
||||||
|
break;
|
||||||
|
case ".m4a":
|
||||||
|
newExtension = ".rpgmvm";
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
string encryptedFile = Path.ChangeExtension(decryptedFile, newExtension);
|
||||||
|
|
||||||
|
FileStream Decrypted = File.OpenRead(decryptedFile);
|
||||||
|
FileStream Encrypted = File.OpenWrite(encryptedFile);
|
||||||
|
|
||||||
|
mvProject.EncryptFile(Decrypted, Encrypted);
|
||||||
|
|
||||||
|
Encrypted.Close();
|
||||||
|
Decrypted.Close();
|
||||||
|
|
||||||
|
File.Delete(decryptedFile);
|
||||||
|
|
||||||
|
Invoke((Action)delegate
|
||||||
|
{
|
||||||
|
string entry = decryptedFileList.Items[item].ToString();
|
||||||
|
string encryptedEntry = Path.ChangeExtension(entry, newExtension);
|
||||||
|
encryptedFileList.Items.Add(encryptedEntry);
|
||||||
|
encFileList.Add(encryptedFile);
|
||||||
|
|
||||||
|
decryptedFileList.Items.RemoveAt(item);
|
||||||
|
decFileList.RemoveAt(item);
|
||||||
|
|
||||||
|
processingBar.Value = i;
|
||||||
|
});
|
||||||
|
|
||||||
|
i++;
|
||||||
|
} while (itemCount > 1);
|
||||||
|
|
||||||
|
Invoke((Action)delegate
|
||||||
|
{
|
||||||
|
encryptSelected.Enabled = true;
|
||||||
|
decryptSelected.Enabled = true;
|
||||||
|
processingText.BackColor = Color.Green;
|
||||||
|
processingText.Text = "Encrypted " + total.ToString() + " files!";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
decryptFilesThread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void decryptSelected_Click(object sender, EventArgs e)
|
private void decryptSelected_Click(object sender, EventArgs e)
|
||||||
|
@ -218,11 +321,8 @@ namespace RMDEC
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] selectedIndexes = new int[itemCount];
|
|
||||||
int item = 0;
|
int item = 0;
|
||||||
|
|
||||||
itemList.CopyTo(selectedIndexes, 0);
|
|
||||||
|
|
||||||
processingBar.Style = ProgressBarStyle.Continuous;
|
processingBar.Style = ProgressBarStyle.Continuous;
|
||||||
processingBar.Maximum = itemCount;
|
processingBar.Maximum = itemCount;
|
||||||
|
|
||||||
|
@ -250,7 +350,7 @@ namespace RMDEC
|
||||||
|
|
||||||
|
|
||||||
string encryptedFile = encFileList[item];
|
string encryptedFile = encFileList[item];
|
||||||
string extension = Path.GetExtension(encryptedFile);
|
string extension = Path.GetExtension(encryptedFile).ToLower();
|
||||||
string newExtension = "";
|
string newExtension = "";
|
||||||
|
|
||||||
switch (extension)
|
switch (extension)
|
||||||
|
@ -286,7 +386,7 @@ namespace RMDEC
|
||||||
decryptedFileList.Items.Add(decryptedEntry);
|
decryptedFileList.Items.Add(decryptedEntry);
|
||||||
decFileList.Add(decryptedFile);
|
decFileList.Add(decryptedFile);
|
||||||
|
|
||||||
encryptedFileList.Items.Remove(entry);
|
encryptedFileList.Items.RemoveAt(item);
|
||||||
encFileList.RemoveAt(item);
|
encFileList.RemoveAt(item);
|
||||||
|
|
||||||
processingBar.Value = i;
|
processingBar.Value = i;
|
||||||
|
@ -304,13 +404,7 @@ namespace RMDEC
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
decryptFilesThread.Start();
|
||||||
|
|
||||||
decryptFilesThread.Start();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue