Fix xor-ing the last 100 bytes and update README
Using Array.Reverse to automatically reverse KEY and store to REVERSE_KEY leading to unexpected result to entire decryption process. When using manually reversed KEY constant (REVERSE_KEY), the problem is fixed. Signed-off-by: Bayu Satiyo <itsyuukunz@gmail.com>
This commit is contained in:
parent
2718391ff5
commit
33848ae084
70
Program.cs
70
Program.cs
@ -1,10 +1,11 @@
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace LightvnTools
|
namespace LightvnTools
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
static readonly string VERSION = "0.0.1";
|
static readonly string VERSION = "1.0.0";
|
||||||
|
|
||||||
// PKZip signature
|
// PKZip signature
|
||||||
static readonly byte[] PKZIP = { 0x50, 0x4B, 0x03, 0x04 };
|
static readonly byte[] PKZIP = { 0x50, 0x4B, 0x03, 0x04 };
|
||||||
@ -12,34 +13,8 @@ namespace LightvnTools
|
|||||||
// Key used to decrypt the file header and footer (reverse)
|
// Key used to decrypt the file header and footer (reverse)
|
||||||
// Text: `d6c5fKI3GgBWpZF3Tz6ia3kF0`
|
// Text: `d6c5fKI3GgBWpZF3Tz6ia3kF0`
|
||||||
// Source: https://github.com/morkt/GARbro/issues/440
|
// Source: https://github.com/morkt/GARbro/issues/440
|
||||||
static readonly byte[] KEY =
|
static readonly byte[] KEY = { 0x64, 0x36, 0x63, 0x35, 0x66, 0x4B, 0x49, 0x33, 0x47, 0x67, 0x42, 0x57, 0x70, 0x5A, 0x46, 0x33, 0x54, 0x7A, 0x36, 0x69, 0x61, 0x33, 0x6B, 0x46, 0x30 };
|
||||||
{
|
static readonly byte[] REVERSED_KEY = { 0x30, 0x46, 0x6B, 0x33, 0x61, 0x69, 0x36, 0x7A, 0x54, 0x33, 0x46, 0x5A, 0x70, 0x57, 0x42, 0x67, 0x47, 0x33, 0x49, 0x4B, 0x66, 0x35, 0x63, 0x36, 0x64 };
|
||||||
0x64,
|
|
||||||
0x36,
|
|
||||||
0x63,
|
|
||||||
0x35,
|
|
||||||
0x66,
|
|
||||||
0x4B,
|
|
||||||
0x49,
|
|
||||||
0x33,
|
|
||||||
0x47,
|
|
||||||
0x67,
|
|
||||||
0x42,
|
|
||||||
0x57,
|
|
||||||
0x70,
|
|
||||||
0x5A,
|
|
||||||
0x46,
|
|
||||||
0x33,
|
|
||||||
0x54,
|
|
||||||
0x7A,
|
|
||||||
0x36,
|
|
||||||
0x69,
|
|
||||||
0x61,
|
|
||||||
0x33,
|
|
||||||
0x6B,
|
|
||||||
0x46,
|
|
||||||
0x30
|
|
||||||
};
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@ -155,21 +130,17 @@ namespace LightvnTools
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
byte[] REVERSED_KEY = KEY;
|
int bufferLength;
|
||||||
Array.Reverse(REVERSED_KEY);
|
|
||||||
|
|
||||||
using (FileStream inputStream = File.OpenRead(filePath))
|
using (FileStream inputStream = File.OpenRead(filePath))
|
||||||
{
|
{
|
||||||
using MemoryStream outputStream = new();
|
buffer = new byte[bufferLength = (int)inputStream.Length];
|
||||||
inputStream.CopyTo(outputStream);
|
inputStream.Read(buffer, 0, bufferLength);
|
||||||
buffer = outputStream.ToArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int length = buffer.Length;
|
if (bufferLength < 100)
|
||||||
|
|
||||||
if (length < 100)
|
|
||||||
{
|
{
|
||||||
if (length == 0)
|
if (bufferLength == 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Skipping {filePath}. File is empty.");
|
Console.WriteLine($"Skipping {filePath}. File is empty.");
|
||||||
return;
|
return;
|
||||||
@ -177,24 +148,23 @@ namespace LightvnTools
|
|||||||
|
|
||||||
Console.WriteLine($"File size is smaller than 100 bytes: {filePath}");
|
Console.WriteLine($"File size is smaller than 100 bytes: {filePath}");
|
||||||
|
|
||||||
// XOR the first 100 bytes
|
// XOR entire bytes
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < bufferLength; i++)
|
||||||
buffer[i] ^= REVERSED_KEY[i % 25];
|
buffer[i] ^= REVERSED_KEY[i % KEY.Length];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// XOR the last 100 bytes
|
|
||||||
for (int i = 0; i < 99; i++)
|
|
||||||
buffer[length - 99 + i] ^= REVERSED_KEY[i % 25];
|
|
||||||
|
|
||||||
// XOR the first 100 bytes
|
// XOR the first 100 bytes
|
||||||
for (int i = 0; i < 100; i++)
|
for (int i = 0; i < 100; i++)
|
||||||
buffer[i] ^= KEY[i % 25];
|
buffer[i] ^= KEY[i % KEY.Length];
|
||||||
}
|
|
||||||
using (FileStream outputStream = File.OpenWrite(filePath))
|
// XOR the last 100 bytes
|
||||||
{
|
for (int i = 0; i < 99; i++)
|
||||||
outputStream.Write(buffer, 0, length);
|
buffer[bufferLength - 99 + i] ^= REVERSED_KEY[i % KEY.Length];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using FileStream outputStream = File.OpenWrite(filePath);
|
||||||
|
outputStream.Write(buffer, 0, bufferLength);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
**<p align="center">This tool is very unstable and not work on the newer version of Light.vn</p>**
|
Light.vnTools is an unpack and repacking tool for game created with [Light.vn](https://lightvn.net "Light.vn") game engine.
|
||||||
|
|
||||||
Light.vnTools is a simple unpack and repacking tool for game created using [Light.vn](https://lightvn.net "Light.vn") game engine.
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
@ -30,4 +28,4 @@ For more information about the GNU General Public License version 3.0 (GNU GPL 3
|
|||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
|
|
||||||
This tool is intentionally created as a modding tool to translate the visual novel game created with Light.vn game engine. I didn't condone any piracy in any forms such as taking the game visual and sell it illegally which harm the developer. Use the tool at your own risk (DWYOR - Do What You Own Risk).
|
This tool is intentionally created as a modding tool to translate the visual novel game created with Light.vn game engine. I didn't condone any piracy in any forms such as taking the game visual and sell it illegally which harm the game developer. Use the tool at your own risk (DWYOR - Do What You Own Risk).
|
||||||
|
Loading…
Reference in New Issue
Block a user