-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
74 lines (63 loc) · 2.44 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
using System;
using System.IO;
using System.Linq;
namespace BFSAR_Split
{
internal class Program
{
private static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("\a\nUsage: BFSAR_Split.exe <Input.bfsar>");
}
else
{
var Strm = File.OpenRead(args[0]);
var Reader = new BinaryReader(Strm);
Directory.CreateDirectory($@"{args[0]}_Extracted");
try
{
while (true)
{
int TryRdMagic = Reader.ReadInt32();
void Extract(string Extension)
{
long PosOffs = Reader.ReadInt64();
int SizeOf = Reader.ReadInt32();
byte[] Data = Reader.ReadBytes(SizeOf - 0x10);
int RelPos = (int)Strm.Position - SizeOf;
string Range = $"0x{RelPos:x}-0x{RelPos + SizeOf:x}";
Console.WriteLine($"Extracting {Extension} at {Range}...");
var WrtStrm = File.OpenWrite($@"{args[0]}_Extracted/{Range}.{Extension}");
var Writer = new BinaryWriter(WrtStrm);
Writer.Write(TryRdMagic);
Writer.Write(PosOffs);
Writer.Write(SizeOf);
Writer.Write(Data);
Writer.Dispose();
WrtStrm.Dispose();
Strm.Position -= Strm.Position % 4;
}
if (TryRdMagic == 0x56415746)
{
Extract("bfwav");
}
else if (TryRdMagic == 0x50545346)
{
Extract("bfstp");
}
else if (TryRdMagic == 0x51455346)
{
Extract("bfseq");
}
}
}
catch (EndOfStreamException)
{
Console.WriteLine("\nDone!");
}
}
}
}
}