-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharc_extract.py
More file actions
72 lines (53 loc) · 2.15 KB
/
arc_extract.py
File metadata and controls
72 lines (53 loc) · 2.15 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
import struct
import sys
import os
"""
ARC File Extractor for BGI/Ethornell
Extracts all files from BURIKO ARC20 (.arc) archives
"""
def extract_arc(arc_path, output_dir=None):
"""Extract all files from an ARC archive"""
if output_dir is None:
output_dir = os.path.splitext(arc_path)[0] + "_extracted"
os.makedirs(output_dir, exist_ok=True)
with open(arc_path, 'rb') as f:
# Read header
signature = f.read(16)
if not signature.startswith(b'BURIKO ARC20'):
print("Error: Not a valid BURIKO ARC20 file")
return
file_count = struct.unpack('<I', f.read(4))[0]
print(f"Archive: {arc_path}")
print(f"Files: {file_count}")
print(f"Output: {output_dir}")
print()
# Read file index
entries = []
for i in range(file_count):
name_bytes = f.read(64)
name = name_bytes.split(b'\x00', 1)[0].decode('shift-jis', errors='replace')
offset = struct.unpack('<I', f.read(4))[0]
size = struct.unpack('<I', f.read(4))[0]
entries.append((name, offset, size))
# Extract files
for i, (name, offset, size) in enumerate(entries, 1):
f.seek(offset)
data = f.read(size)
output_path = os.path.join(output_dir, name)
# Create subdirectories if needed
os.makedirs(os.path.dirname(output_path), exist_ok=True)
with open(output_path, 'wb') as out:
out.write(data)
print(f"[{i}/{file_count}] {name} ({size:,} bytes)")
print(f"\nExtracted {file_count} files to {output_dir}")
def main():
if len(sys.argv) < 2:
print("Usage: python arc_extract.py <arc_file> [output_dir]")
print("Example: python arc_extract.py data01500.arc")
print(" python arc_extract.py data01500.arc extracted_files")
sys.exit(1)
arc_file = sys.argv[1]
output_dir = sys.argv[2] if len(sys.argv) > 2 else None
extract_arc(arc_file, output_dir)
if __name__ == "__main__":
main()