-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
232 lines (199 loc) · 8.79 KB
/
Form1.cs
File metadata and controls
232 lines (199 loc) · 8.79 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Bittersweet
{
public partial class Form1 : Form
{
private CancellationTokenSource cts;
public const int SALT_LENGTH = 0x35;
private static readonly byte[] saltHash = new byte[]
{
0x73, 0x5D, 0x9A, 0xB9, 0x4E, 0xCA, 0x74, 0xD8, 0xE2, 0x50, 0x67, 0xF5, 0x8C, 0x4C, 0xCA, 0x6B,
0x8E, 0x92, 0x6F, 0x39, 0xC8, 0x8E, 0x36, 0xB9, 0x33, 0xF9, 0xF0, 0x9D, 0x6D, 0x95, 0x32, 0x60
};
private static readonly long[] offsets = new long[]
{
0x00000000, // salt.txt
0x0AC24A6C, // ssa pc usa
0x0BEBA11C, // ssa pc usa
0x0D9590C8, // ssa jp wii
0x0B407354, // ssa brazil wii
0x00D396D4, // sg build 6
0x0000000101C5DB04, // ssf wii
0x0AACC6B8, // stt wii
0x0BBED868, // sscr wii
0x62CBA430, // sscr wii
0x00013E48 // spyrolibrary
};
public Form1()
{
InitializeComponent();
}
private void PCUSAToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFile(offsets[1], offsets[2]);
}
private void spyroNoDaiboukenToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFile(offsets[3]);
}
private void wiiBrazilRVZToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFile(offsets[4]);
}
private void july102012AlphaRVTHToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFile(offsets[5]);
}
private void SFWiiToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFile(offsets[6]);
}
private void TTWiiRVZToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFile(offsets[7]);
}
private void SSCRWiiToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFile(offsets[8], offsets[9]);
}
private void spyroLibrarydllToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFile(offsets[10]);
}
private async void otherAutoToolStripMenuItem_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "All Files|*.*";
if (openFileDialog.ShowDialog() != DialogResult.OK) return;
cts?.Cancel();
cts = new CancellationTokenSource();
FileInfo info = new FileInfo(openFileDialog.FileName);
if (info.Length < SALT_LENGTH)
{
consoleLabel.Text = "File size is too small for salt";
consoleLabel.ForeColor = Color.Red;
return;
}
using (FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
{
byte[] buffer = new byte[SALT_LENGTH];
foreach (long offset in offsets)
{
fs.Seek(offset, SeekOrigin.Begin);
fs.Read(buffer, 0, SALT_LENGTH);
if (SHA256.Create().ComputeHash(buffer).SequenceEqual(saltHash))
{
consoleLabel.Invoke((MethodInvoker)(() =>
{
consoleLabel.Text = $"Salt found successfully";
consoleLabel.ForeColor = Color.Green;
SaveFile(buffer);
}));
return;
}
}
}
DialogResult dialogResult = MessageBox.Show("Salt could not be found at a known offset. Would you like to do a progressive scan of the file?\n(Note: this can take a couple of minutes, depending on file size)", "Bittersweet", MessageBoxButtons.YesNo);
if (dialogResult != DialogResult.Yes) return;
long max = info.Length - SALT_LENGTH;
progressBar1.Value = 0;
progressBar1.Maximum = 100;
consoleLabel.Text = "Searching...";
consoleLabel.ForeColor = Color.Blue;
IProgress<int> progress = new Progress<int>(x => progressBar1.Value = x);
await Task.Run(() =>
{
using (FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
{
byte[] buffer = new byte[SALT_LENGTH];
for (long i = 0; i <= max; i++)
{
if (cts.Token.IsCancellationRequested) return;
fs.Seek(i, SeekOrigin.Begin);
fs.Read(buffer, 0, SALT_LENGTH);
if (SHA256.Create().ComputeHash(buffer).SequenceEqual(saltHash))
{
consoleLabel.Invoke((MethodInvoker)(() =>
{
progress.Report(100);
consoleLabel.Text = $"Salt found successfully";
consoleLabel.ForeColor = Color.Green;
SaveFile(buffer);
}));
return;
}
if (i % 10000 == 0)
{
int percentage = (int)(i * 100 / (max - SALT_LENGTH));
progress.Report(percentage);
}
}
progress.Report(100);
consoleLabel.Invoke((MethodInvoker)(() =>
{
consoleLabel.Text = "Salt could not be found";
consoleLabel.ForeColor = Color.Red;
}));
}
}, cts.Token);
}
}
private void OpenFile(params long[] offsets)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "All Files|*.*";
if (openFileDialog.ShowDialog() != DialogResult.OK) return;
cts?.Cancel();
cts = new CancellationTokenSource();
long maxOffset = offsets.Max();
FileInfo info = new FileInfo(openFileDialog.FileName);
if (info.Length < maxOffset + SALT_LENGTH)
{
consoleLabel.Text = "File size is too small for salt";
consoleLabel.ForeColor = Color.Red;
return;
}
foreach (long offset in offsets)
{
byte[] buffer = new byte[SALT_LENGTH];
using (FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
{
{
fs.Seek(offset, SeekOrigin.Begin);
fs.Read(buffer, 0, SALT_LENGTH);
}
Console.WriteLine(Encoding.UTF8.GetString(buffer));
if (SHA256.Create().ComputeHash(buffer).SequenceEqual(saltHash))
{
consoleLabel.Text = "Salt found successfully";
consoleLabel.ForeColor = Color.Green;
SaveFile(buffer);
return;
}
}
}
consoleLabel.Text = "Could not retrieve salt from file\nWas the correct file given?";
consoleLabel.ForeColor = Color.Red;
}
}
private void SaveFile(byte[] salt)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
saveFileDialog.FileName = "salt.txt";
saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
File.WriteAllBytes(saveFileDialog.FileName, salt);
}
}
}