-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
137 lines (102 loc) · 3.93 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Xayrga.SARC;
namespace sArcExtract
{
class Program
/* sArcExtract
* Created by XayrGA
* Made for extracting the sound archive from a 3DS game
* Only tested on mario and luigi dream team!
*
*
*
*
*
*/
/*
The structure of an SARC file
-- SMALL E
int32 Section Type Archive Type (confirmed)
00 = WAVE
01 = SOUNDEFFECT
04 = CUTSCENE
int32 Record Count (Confirmed)
int32 Jumpsize to next section from section base (confirmed)
int32 Jumpsize to data start from section base (confirmed)
int32 ??? -- Looks like a pointer back to this section? (probably)
int32 ??? Maybe a pointer to a section divider? like... idk (dunno)
int32 ??? Always 0 ?
int32 ??? Always 0 ?
0x20 First record
< Record Format > * Record Count
int32 index_number
int32 length
int32 offset from header end
int32 padding ??? (always 0 ?) alignment
0x20 + ( Records * 16) Name Index Table
<Name Record> * Record Count
// Each Record in the name table is analog with the index in the order they were defined .
byte 0x0A
Cstring name (Null Terminated)
*/
{
static BinaryReader SARC;
static SARCSection[] SArr = new SARCSection[64];
static void Main(string[] args)
{
try
{
string filename = args[0];
SARC = new BinaryReader(File.Open(filename, FileMode.Open, FileAccess.Read));
} catch
{
Console.WriteLine("sArcExtract: Error, supply a file as the first parameter!");
Console.WriteLine("Example: sArcExtract ./rawr.arc");
Environment.Exit(-1);
}
var go = true;
uint idx = 0;
while (go)
{
var stype = SARC.ReadUInt32();
var records = SARC.ReadUInt32();
var next_sec = SARC.ReadUInt32();
var next_data = SARC.ReadUInt32();
var sbase = SARC.ReadUInt32();
SARC.ReadUInt32(); // Don't know what this is, just have to allign.
SARC.ReadUInt32(); // Don't know what this is, just have to allign.
SARC.ReadUInt32(); // Don't know what this is, just have to allign.
Console.WriteLine("{4:X} Section type 0x{0:X} with 0x{1:X} records , data at 0x{2:X}. Next section at {3:X} ",stype,records,next_data,next_sec,sbase);
SARCSection rawr = new SARCSection(SARC, idx, records, sbase, next_data);
rawr.nibbleEntries();
SArr[idx] = rawr;
SARC.BaseStream.Seek(next_sec + sbase,0);
if (SARC.BaseStream.Length == SARC.BaseStream.Position)
{
Console.WriteLine("Next section points to EOF -- end sections");
go = false;
break;
}
idx++;
}
Directory.CreateDirectory("out");
for (int i = 0; i < idx; i++) {
Directory.CreateDirectory("out/" + i);
var sect = SArr[i];
for (int sidx = 0; sidx < sect.recordcount; sidx++)
{
var ent = sect.Entries[sidx];
SARC.BaseStream.Seek(ent.offset_absolute, 0);
var data = SARC.ReadBytes((int)ent.size);
File.WriteAllBytes("out/" + i + "/" + ent.name + ".rsd", data);
}
}
Console.WriteLine("Done extracting!");
}
}
}