Skip to content

Instantly share code, notes, and snippets.

@Prince-of-sea
Created September 18, 2022 17:08
Show Gist options
  • Select an option

  • Save Prince-of-sea/7085d075b14caf6997b18723fc81e242 to your computer and use it in GitHub Desktop.

Select an option

Save Prince-of-sea/7085d075b14caf6997b18723fc81e242 to your computer and use it in GitHub Desktop.
sincerip_rio_cui
#!/usr/bin/env python3
import os
################################################################################
# sincerip_rio_cui.py
#
# Imaha486氏の解析結果を参考に作った、Will系.arc展開ツールです。
# ヘッダ個数のチェック処理を端折っているため、
# 複数のファイル種類が格納されているアーカイブ(Chip.arcとか)には使えません
#
# GARBroで展開したRio.arcが、ひとつもり氏制作かにしのコンバータで利用できず、
# 別途CUIで動くRio展開ツールが必要になったのがそもそもの製作動機です。
# 基本的に一般用途ではGARBro使ったほうがいいと思います。
#
# 参考: http://hp.vector.co.jp/authors/VA018359/download.html
################################################################################
def rio_extract(data, out):
with open(data, 'rb') as d:
b = d.read()
if not (b[:4] == b'\x01\x00\x00\x00'):#エラー回避用
print('extract error!')
return
# ファイル形式(拡張子)
ext = (b[4:8].replace(b'\x00', b'')).decode()
#格納ファイル個数
l = b''
for i in reversed(range(8, 12)):
l += (b[i:i+1])
cnt = int(l.hex(), 16)
#フォルダ作成
os.makedirs(dir, exist_ok=True)
for j in range(cnt):
dataset = b[16+(j*17):16+((j+1)*17)]
# 8文字以内のファイル名とNULL(00)
name = (dataset[0:9].replace(b'\x00', b'')).decode()
# ファイルサイズ
l2 = b''
for i in reversed(range(9, 13)):
l2 += (dataset[i:i+1])
size = int(l2.hex(), 16)
# アーカイブ内での開始オフセット
l3 = b''
for i in reversed(range(13, 17)):
l3 += (dataset[i:i+1])
offset = int(l3.hex(), 16)
#保存
path = os.path.join(out, name + '.' + ext)
with open(path, mode='wb') as result:
result.write(b[offset:offset+size])
rio = r'C:/Users/User/Desktop/Rio.arc'
dir = r'C:/Users/User/Desktop/Rio/'
rio_extract(rio, dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment