fix extract large files

This commit is contained in:
SilicaAndPina 2019-12-15 20:09:10 +13:00
parent 34cc013c5e
commit 5a586d5198
1 changed files with 16 additions and 10 deletions

View File

@ -137,6 +137,8 @@ namespace RMDEC
byte[] output = new byte[size];
uint keyInt = BitConverter.ToUInt32(keydata, 0x00);
byte[] derivedKeyData = new byte[keydata.Length];
Array.Copy(keydata, derivedKeyData, 0x4);
for (int i = 0; i < size; i++)
{
@ -144,16 +146,17 @@ namespace RMDEC
{
// Derive new key
keyInt = ((keyInt * 7) + 3);
byte[] derivedKeyBytes = BitConverter.GetBytes(keyInt);
Array.Copy(derivedKeyBytes, keydata, 0x4); // have to do this in order to make the arguments update..
derivedKeyData = BitConverter.GetBytes(keyInt);
}
output[i] = (byte)(input[i] ^ keydata[i % keydata.Length]);
output[i] = (byte)(input[i] ^ derivedKeyData[i % derivedKeyData.Length]);
}
//Final Derive (incase of >MAX_SIZE)
keyInt = ((keyInt * 7) + 3);
derivedKeyData = BitConverter.GetBytes(keyInt);
Array.Copy(derivedKeyData, keydata, 0x4);
return output;
}
@ -198,20 +201,23 @@ namespace RMDEC
public void DecryptFile(int fileIndex, Stream outStream)
{
int MAX_SIZE = 0x20000000; //512MB (MUST BE DIVISIBLE BY 4)
outStream.SetLength(0);
ArchiveFile fileData = archiveFileList[fileIndex];
byte[] keyData = fileData.Key;
rgss3aStream.Seek(fileData.Offset, SeekOrigin.Begin);
uint size = fileData.Size;
for(int i = 0; i < size; i += 0x20000000)
for (int i = 0; i < size; i += MAX_SIZE)
{
if (size > 0x20000000) //512MB
if (size > MAX_SIZE)
{
byte[] gameData = new byte[0x20000000];
rgss3aStream.Read(gameData, 0x00, 0x20000000);
byte[] gameData = new byte[MAX_SIZE];
rgss3aStream.Read(gameData, 0x00, MAX_SIZE);
gameData = decryptFileData(gameData, keyData);
outStream.Write(gameData, 0x00, gameData.Length);
}