-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
86 lines (85 loc) · 2.71 KB
/
Program.cs
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
using System;
using System.IO;
namespace FileExtractor
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine(
"Drag and drop a file onto this exe to extract embedded SWAR and SBNK files.");
return;
}
foreach (string inputFile in args)
{
if (File.Exists(inputFile))
{
ExtractFiles(inputFile);
}
else
{
Console.WriteLine($"File not found: {inputFile}");
}
}
Console.WriteLine("Extraction completed successfully.");
}
static void ExtractFiles(string inputFile)
{
byte[] data = File.ReadAllBytes(inputFile);
int index = 0;
while (index < data.Length)
{
string fileType = null;
int fileSize = 0;
int headerStartIndex = 0;
if (IsMatch(data, index, "SWAR"))
{
fileType = ".swar";
fileSize = BitConverter.ToInt32(data, index + 8);
headerStartIndex = index;
index += 12;
}
else if (IsMatch(data, index, "SBNK"))
{
fileType = ".sbnk";
fileSize = BitConverter.ToInt32(data, index + 8);
headerStartIndex = index;
index += 12;
}
else
{
index++;
continue;
}
if (!Directory.Exists("extracted"))
{
Directory.CreateDirectory("extracted");
}
string outputFilename = $"extracted/extracted_{index}_{fileType}";
using (var outputFile = new FileStream(outputFilename, FileMode.Create,
FileAccess.Write))
{
outputFile.Write(data, headerStartIndex, fileSize + 8);
}
while (index < data.Length && data[index] != 0xDD)
{
index++;
}
if (index < data.Length)
{
index++;
}
}
}
static bool IsMatch(byte[] data, int index, string marker)
{
for (int i = 0; i < marker.Length; i++)
{
if (data[index + i] != marker[i]) return false;
}
return true;
}
}
}