-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
124 lines (111 loc) · 5.01 KB
/
Copy pathProgram.cs
File metadata and controls
124 lines (111 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.IO;
using System.Text;
namespace NMSResign
{
class Program
{
static string BanksPath = ".";
static string GetFilePath(string fileName)
{
return Path.Combine(BanksPath, fileName);
}
static void Main(string[] args)
{
bool decrypt = args.Length > 0 && args[0].ToLower() == "-decrypt";
bool encrypt = args.Length > 0 && args[0].ToLower() == "-encrypt";
bool createbin = args.Length > 0 && args[0].ToLower() == "-createbin";
bool createdec = args.Length > 0 && args[0].ToLower() == "-createdec";
bool help = args.Length == 0 || args[0].ToLower() == "-help";
string fileName = "BankSignatures.bin";
if (args.Length > 1)
{
fileName = args[1];
}
var bankSigsPath = GetFilePath(fileName);
var bankSigsKey = Encoding.ASCII.GetBytes("ds8r5fV80hbtbDCXXHXPT0dAKMgndVl1");
Array.Resize(ref bankSigsKey, 0x10); // some reason they use a key larger than 0x10 bytes, even though only first 0x10 is used...
if (help || (!decrypt && !encrypt && !createbin && !createdec))
{
if (args.Length > 0 && !help)
{
Console.WriteLine("Invalid argument");
}
Console.WriteLine("Usage:");
Console.WriteLine("\t-decrypt");
Console.WriteLine("\t\tDecrypts a .bin file to a .dec file.");
Console.WriteLine("\t-encrypt");
Console.WriteLine("\t\tEncrypts a .dec file to a .bin file.");
Console.WriteLine("\t-createbin");
Console.WriteLine("\t\tCreates a new encrypted bin file from the folder of pak files.");
Console.WriteLine("\t-createdec");
Console.WriteLine("\t\tCreates a new decrypted bin.dec file from the folder of pak files.");
Console.WriteLine("\t-help");
Console.WriteLine("\t\tDisplays this help message");
Console.WriteLine("\n\tAll commands also accept a filename as an additional argument, although this is mostly for testing purposes.");
return;
}
if (decrypt)
{
if (!File.Exists(bankSigsPath))
{
Console.WriteLine($"Failed to find {bankSigsPath} file...");
return;
}
var data = File.ReadAllBytes(bankSigsPath);
data = Xxtea.XXTEA.Decrypt(data, bankSigsKey);
File.WriteAllBytes(bankSigsPath + ".dec", data);
Console.WriteLine($"Wrote decrypted {fileName} to {bankSigsPath}.dec");
return;
}
if (encrypt)
{
var decFilePath = bankSigsPath + ".dec";
if (!File.Exists(decFilePath))
{
Console.WriteLine($"Failed to find {decFilePath} file...");
return;
}
var data = File.ReadAllBytes(decFilePath);
data = Xxtea.XXTEA.Encrypt(data, bankSigsKey);
File.WriteAllBytes(bankSigsPath, data);
Console.WriteLine($"Wrote encrypted {fileName}.dec to {bankSigsPath}");
return;
}
if (createbin || createdec)
{
// Create Bank"Signature" file
var bankSigs = "";
foreach (var pak in Directory.GetFiles(BanksPath, "*.pak"))
{
var info = new FileInfo(pak);
var normalizedFileName = Path.GetFileName(pak).Normalize(NormalizationForm.FormC).ToUpperInvariant();
bankSigs += normalizedFileName + "," + info.Length.ToString() + "\r\n";
}
var bankSigsData = Encoding.ASCII.GetBytes(bankSigs);
var stream = new MemoryStream();
using (var writer = new BinaryWriter(stream))
{
writer.Write(bankSigsData);
while (stream.Length % 4 != 0) // If the stream length is not a multiple of 4
{
writer.Write((byte)0); // Add a zero byte for 4-byte alignment
}
writer.Write(bankSigsData.Length);
bankSigsData = stream.ToArray();
}
if (createbin)
{
bankSigsData = Xxtea.XXTEA.Encrypt(bankSigsData, bankSigsKey);
File.WriteAllBytes(bankSigsPath, bankSigsData);
Console.WriteLine($"Wrote updated {fileName} to {bankSigsPath}");
}
if (createdec)
{
File.WriteAllBytes(bankSigsPath + ".dec", bankSigsData);
Console.WriteLine($"Wrote updated {fileName} to {bankSigsPath}.dec");
}
}
}
}
}