84 lines
3.0 KiB
C#
84 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace xaskel_decoder
|
|
{
|
|
internal class Program
|
|
{
|
|
private const int blockSize = 12; // encoded block length
|
|
private const int encodeSize = 3000; // encoded byte count
|
|
private const int decodeSize = blockSize * encodeSize;
|
|
private static readonly string[] extensions = { ".colrw", ".colc", ".txdrw", ".txdc", ".dffrw", ".dffc" };
|
|
|
|
static void Main()
|
|
{
|
|
Console.Write("Enter password: ");
|
|
string password = Console.ReadLine().Trim();
|
|
if (string.IsNullOrWhiteSpace(password))
|
|
return;
|
|
|
|
Console.Write("Enter directory path: ");
|
|
List<string> files = GetFiles(Console.ReadLine().Trim());
|
|
if (files.Count == 0)
|
|
return;
|
|
Console.WriteLine("Done.");
|
|
|
|
Console.Write("Decoding files... ");
|
|
foreach (string file in files)
|
|
{
|
|
DecryptFile(file, password);
|
|
}
|
|
Console.WriteLine("Done.");
|
|
|
|
Console.ReadLine();
|
|
}
|
|
|
|
static List<string> GetFiles(string directoryPath)
|
|
{
|
|
List<string> files = Directory.GetFiles(directoryPath, "*.*", SearchOption.TopDirectoryOnly)
|
|
.Where(file => extensions.Contains(Path.GetExtension(file).ToLower()))
|
|
.ToList();
|
|
return files;
|
|
}
|
|
|
|
static void DecryptFile(string filePath, string password)
|
|
{
|
|
string newFilePath = filePath + ".decoded";
|
|
|
|
using (MD5 md5 = MD5.Create())
|
|
{
|
|
byte[] inputBytes = Encoding.UTF8.GetBytes(password),
|
|
hashBytes = md5.ComputeHash(inputBytes);
|
|
string key = BitConverter.ToString(hashBytes).Replace("-", "").Substring(0, 16);
|
|
|
|
byte[] data = File.ReadAllBytes(filePath);
|
|
string fileContent = Encoding.UTF8.GetString(data);
|
|
int bytesToDecode = Math.Min(decodeSize, fileContent.Length);
|
|
|
|
List<byte> decodedBytes = new List<byte>();
|
|
for (int i = 0; i < bytesToDecode; i += blockSize)
|
|
{
|
|
int length = Math.Min(blockSize, bytesToDecode - i);
|
|
string block = fileContent.Substring(i, length),
|
|
decrypted = Tea.Decode(block, key);
|
|
decodedBytes.AddRange(Encoding.UTF8.GetBytes(decrypted));
|
|
}
|
|
|
|
if (File.Exists(newFilePath))
|
|
{
|
|
File.Delete(newFilePath);
|
|
}
|
|
|
|
using (FileStream fs = new FileStream(newFilePath, FileMode.CreateNew))
|
|
{
|
|
fs.Write(decodedBytes.ToArray(), 0, decodedBytes.Count);
|
|
fs.Write(data, decodeSize, data.Length - decodeSize);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |