tools(assets): audit original AVA2 FoxFS archives for missing hydra motions
This commit is contained in:
@@ -25,7 +25,7 @@ motlist 现在参与资源依赖检查,maps.json 的 missing_motions 明确列
|
||||
- defensewave_hydra_boss/drop.msa(以及原始 drop.gr2);
|
||||
- defensewave_minihydra/special_attack1.msa(以及对应原始动作模型)。
|
||||
|
||||
完整扫描还报告 blue_dragon_red/water_dragon_2.gr2、reddragon_room_boss2/normal_attack.msa、zone/eastplain/gaint_build a_01_d.gr2,以及两个 hydra 地形纹理。未通过复制其他动作冒充原始文件。需完整 AVA2 素材或 FoxFS 解包工具。
|
||||
完整扫描还报告 blue_dragon_red/water_dragon_2.gr2、reddragon_room_boss2/normal_attack.msa、zone/eastplain/gaint_build a_01_d.gr2,以及两个 hydra 地形纹理。未通过复制其他动作冒充原始文件。2026-10-16 已继续核查整个客户端包集合:完成 FoxFS 只读解析,46 个包、94,220 个条目均无这四个动作文件;XML 清单、展开源目录和 FILES+SRC.tgz 服务端备份也无对应文件。八个已有资源通过 XXH32 校验并与源文件逐字节一致,原包 motlist 仍包含缺失引用。详见 `docs/AVA2-RESOURCE-AUDIT-20261016.json` 和 `tools/foxfs/README.md`;不能将该分发包自身的缺失引用归为移植漏拷。VDI 未挂载,不声称已清点其文件系统。
|
||||
|
||||
## NPC / sash / 任务函数
|
||||
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
{
|
||||
"targets": {
|
||||
"d:/ymir work/monster2/defensewave_hydra_boss/drop.msa": {
|
||||
"crc32": "69a15bfa",
|
||||
"source": [],
|
||||
"source_files": [],
|
||||
"archives": [],
|
||||
"server_backup": []
|
||||
},
|
||||
"d:/ymir work/monster2/defensewave_hydra_boss/drop.gr2": {
|
||||
"crc32": "8f4fef23",
|
||||
"source": [],
|
||||
"source_files": [],
|
||||
"archives": [],
|
||||
"server_backup": []
|
||||
},
|
||||
"d:/ymir work/monster2/defensewave_minihydra/special_attack1.msa": {
|
||||
"crc32": "53221dab",
|
||||
"source": [],
|
||||
"source_files": [],
|
||||
"archives": [],
|
||||
"server_backup": []
|
||||
},
|
||||
"d:/ymir work/monster2/defensewave_minihydra/special_attack1.gr2": {
|
||||
"crc32": "b5cca972",
|
||||
"source": [],
|
||||
"source_files": [],
|
||||
"archives": [],
|
||||
"server_backup": []
|
||||
}
|
||||
},
|
||||
"archives": [
|
||||
{
|
||||
"name": "BGM",
|
||||
"entries": 35
|
||||
},
|
||||
{
|
||||
"name": "Costumes",
|
||||
"entries": 340
|
||||
},
|
||||
{
|
||||
"name": "ETC",
|
||||
"entries": 4588
|
||||
},
|
||||
{
|
||||
"name": "Effect",
|
||||
"entries": 2051
|
||||
},
|
||||
{
|
||||
"name": "Map_Sands",
|
||||
"entries": 1289
|
||||
},
|
||||
{
|
||||
"name": "Maps",
|
||||
"entries": 11780
|
||||
},
|
||||
{
|
||||
"name": "Monster",
|
||||
"entries": 3952
|
||||
},
|
||||
{
|
||||
"name": "Monster2",
|
||||
"entries": 9066
|
||||
},
|
||||
{
|
||||
"name": "NPC",
|
||||
"entries": 2147
|
||||
},
|
||||
{
|
||||
"name": "NPC2",
|
||||
"entries": 1111
|
||||
},
|
||||
{
|
||||
"name": "NPC_MOUNT",
|
||||
"entries": 680
|
||||
},
|
||||
{
|
||||
"name": "NPC_PET",
|
||||
"entries": 71
|
||||
},
|
||||
{
|
||||
"name": "PC",
|
||||
"entries": 4428
|
||||
},
|
||||
{
|
||||
"name": "PC2",
|
||||
"entries": 3125
|
||||
},
|
||||
{
|
||||
"name": "Patch_dungeon_meley",
|
||||
"entries": 466
|
||||
},
|
||||
{
|
||||
"name": "Patch_wiki",
|
||||
"entries": 43
|
||||
},
|
||||
{
|
||||
"name": "Sound",
|
||||
"entries": 5277
|
||||
},
|
||||
{
|
||||
"name": "Terrain",
|
||||
"entries": 891
|
||||
},
|
||||
{
|
||||
"name": "Tree",
|
||||
"entries": 393
|
||||
},
|
||||
{
|
||||
"name": "Wheel",
|
||||
"entries": 13
|
||||
},
|
||||
{
|
||||
"name": "Zone",
|
||||
"entries": 5902
|
||||
},
|
||||
{
|
||||
"name": "icon",
|
||||
"entries": 4363
|
||||
},
|
||||
{
|
||||
"name": "item",
|
||||
"entries": 3268
|
||||
},
|
||||
{
|
||||
"name": "locale",
|
||||
"entries": 999
|
||||
},
|
||||
{
|
||||
"name": "metin2_patch_citys",
|
||||
"entries": 463
|
||||
},
|
||||
{
|
||||
"name": "metin2_patch_m_summer",
|
||||
"entries": 985
|
||||
},
|
||||
{
|
||||
"name": "metin2_patch_zodiac",
|
||||
"entries": 2945
|
||||
},
|
||||
{
|
||||
"name": "pack_2019",
|
||||
"entries": 1075
|
||||
},
|
||||
{
|
||||
"name": "pack_2020",
|
||||
"entries": 904
|
||||
},
|
||||
{
|
||||
"name": "patch_battlefied",
|
||||
"entries": 277
|
||||
},
|
||||
{
|
||||
"name": "patch_conqueror_of_yohara",
|
||||
"entries": 5603
|
||||
},
|
||||
{
|
||||
"name": "patch_design_wa",
|
||||
"entries": 95
|
||||
},
|
||||
{
|
||||
"name": "patch_drop_item",
|
||||
"entries": 35
|
||||
},
|
||||
{
|
||||
"name": "patch_dungeon_info",
|
||||
"entries": 78
|
||||
},
|
||||
{
|
||||
"name": "patch_dungeon_new",
|
||||
"entries": 2607
|
||||
},
|
||||
{
|
||||
"name": "patch_new_petsystem",
|
||||
"entries": 846
|
||||
},
|
||||
{
|
||||
"name": "patch_new_select_ui",
|
||||
"entries": 10
|
||||
},
|
||||
{
|
||||
"name": "patch_offline_shop",
|
||||
"entries": 348
|
||||
},
|
||||
{
|
||||
"name": "patch_ranking_guild",
|
||||
"entries": 44
|
||||
},
|
||||
{
|
||||
"name": "patch_search",
|
||||
"entries": 38
|
||||
},
|
||||
{
|
||||
"name": "patch_tournament",
|
||||
"entries": 361
|
||||
},
|
||||
{
|
||||
"name": "patch_yohara",
|
||||
"entries": 441
|
||||
},
|
||||
{
|
||||
"name": "property",
|
||||
"entries": 9988
|
||||
},
|
||||
{
|
||||
"name": "root",
|
||||
"entries": 399
|
||||
},
|
||||
{
|
||||
"name": "textureset",
|
||||
"entries": 234
|
||||
},
|
||||
{
|
||||
"name": "uiscript",
|
||||
"entries": 166
|
||||
}
|
||||
],
|
||||
"verified_controls": [
|
||||
{
|
||||
"path": "d:/ymir work/monster2/defensewave_hydra_boss/wait.msa",
|
||||
"bytes": 199,
|
||||
"sha256": "7f38863ceb4364c465d7715a60b8eab92389a3cc084f451d64938f9145364ab7"
|
||||
},
|
||||
{
|
||||
"path": "d:/ymir work/monster2/defensewave_hydra_boss/wait.gr2",
|
||||
"bytes": 63698,
|
||||
"sha256": "877706e00ce21a74a34a334fc2e626b4cc4e4a1e21800b3fddd30bdef61552c0"
|
||||
},
|
||||
{
|
||||
"path": "d:/ymir work/monster2/defensewave_hydra_boss/motlist.txt",
|
||||
"bytes": 235,
|
||||
"sha256": "69152cdb0d882ebdc9933d08372bcfadf5aed9cddb7478269ce127793d041bf7"
|
||||
},
|
||||
{
|
||||
"path": "d:/ymir work/monster2/defensewave_hydra_boss/special_attack1.msa",
|
||||
"bytes": 15851,
|
||||
"sha256": "045180235a1687aeed6e2b81fd350ffe34b55905dffa1f1768c984ae2e7c8b09"
|
||||
},
|
||||
{
|
||||
"path": "d:/ymir work/monster2/defensewave_hydra_boss/special_attack1.gr2",
|
||||
"bytes": 39715,
|
||||
"sha256": "c1829082ba48782cd6e77d5333fada943c0f727a79d87b5fb56e5dc8bc0f15cd"
|
||||
},
|
||||
{
|
||||
"path": "d:/ymir work/monster2/defensewave_minihydra/wait.msa",
|
||||
"bytes": 198,
|
||||
"sha256": "cbd3315932e53b9088fb0b4adc18b6be4cf5357cd458d4e21974c967412f83e9"
|
||||
},
|
||||
{
|
||||
"path": "d:/ymir work/monster2/defensewave_minihydra/normal_attack1.msa",
|
||||
"bytes": 1248,
|
||||
"sha256": "6ef976e034f385273c6340fdaaa8d6d1d611234e9da9e20f89453a67a64b50f3"
|
||||
},
|
||||
{
|
||||
"path": "d:/ymir work/monster2/defensewave_minihydra/motlist.txt",
|
||||
"bytes": 344,
|
||||
"sha256": "89b447100e5e3dca68f4afb6efd09a59267f4ef309b5f5e4d91e089b41a13942"
|
||||
}
|
||||
],
|
||||
"server_backup_candidates": [
|
||||
"home/srv1/share/data/monster/defensewave_minihydra/defensewave_minihydra.msm",
|
||||
"home/srv1/share/data/monster/defensewave_minihydra/front_damage.msa",
|
||||
"home/srv1/share/data/monster/defensewave_minihydra/front_dead.msa",
|
||||
"home/srv1/share/data/monster/defensewave_minihydra/motlist.txt",
|
||||
"home/srv1/share/data/monster/defensewave_minihydra/normal_attack1.msa",
|
||||
"home/srv1/share/data/monster/defensewave_minihydra/wait.msa",
|
||||
"home/srv1/share/data/monster/defensewave_minihydra/wait1.msa",
|
||||
"home/srv1/share/data/monster/defensewave_hydra_boss/defensewave_hydra_boss.msm",
|
||||
"home/srv1/share/data/monster/defensewave_hydra_boss/front_dead.msa",
|
||||
"home/srv1/share/data/monster/defensewave_hydra_boss/motlist.txt",
|
||||
"home/srv1/share/data/monster/defensewave_hydra_boss/special_attack1.msa",
|
||||
"home/srv1/share/data/monster/defensewave_hydra_boss/special_attack2.msa",
|
||||
"home/srv1/share/data/monster/defensewave_hydra_boss/special_attack3.msa",
|
||||
"home/srv1/share/data/monster/defensewave_hydra_boss/wait.msa"
|
||||
],
|
||||
"archive_count": 46,
|
||||
"entry_count": 94220,
|
||||
"note": "VDI guest filesystem not mounted; packed client, XML manifests and source controls audited."
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
# AVA2 FoxFS 资源核查(只读)
|
||||
|
||||
`foxfs.py` 在 macOS/Python 3 直接读取 AVA2 的 FoxFS 包,无需运行 FileArchiver.exe、Wine 或 Windows。依据本地 `AVA2/3. Source BIN/Extern/lib/FoxFS.lib` 的 Archive.obj 中 load、generateFilenameIndex、get 函数确认格式:
|
||||
|
||||
- 68 字节头,magic=0x000fed0c;32 字节 AES key、32 字节 IV 字段(CFB 使用前 16 字节)。
|
||||
- 每个文件的 20 字节记录:原始大小、XXH32、数据偏移、存储大小、规范化路径的 CRC32;记录与数据交错存储。
|
||||
- 路径转小写,反斜杠转正斜杠后计算 CRC32。重复 CRC 保留第一个条目,与原库一致。
|
||||
- AES-256-CFB 解码后按需解压原始 LZ4 block;检查输出长度与种子 0x000fed0c 的 XXH32。
|
||||
|
||||
只支持已经核实的 AVA2 包格式;其他格式或使用额外 key-server XOR 的包会报错。解码依赖 Python `cryptography`,LZ4/XXH32 使用本目录实现。只查询索引不需要 cryptography。
|
||||
|
||||
```sh
|
||||
python3 tools/foxfs/test_foxfs.py
|
||||
python3 tools/foxfs/audit_ava2.py --ava ../AVA2 --output build/foxfs-audit/verified-audit.json
|
||||
```
|
||||
|
||||
核查包括所有包(含 Index 未启用的包)、XML 清单、展开的源文件和 FILES+SRC.tgz 服务端动作备份。检查原包内八个已有动作/MSA/GR2/列表,要求通过内容校验并与展开源文件逐字节相同。VDI 虚拟磁盘未挂载,不将其宣称为完整文件系统清点。
|
||||
|
||||
2026-10-16 结果:46 个包、94,220 个条目;九头蛇 `drop.msa/drop.gr2` 和小九头蛇 `special_attack1.msa/special_attack1.gr2` 没有对应索引记录,XML/源目录/服务端备份也没有这四个文件。原包内 motlist.txt 仍引用两个不存在的 MSA,与展开源目录一致。这是该 AVA2 分发包自身的缺失引用。
|
||||
|
||||
额外的本机内容扫描(`build/foxfs-audit/content-report.json`)解码检查了 84,697 个 30–100,000 字节条目,找到 43 个含 hydra 目录引用的文件;动作引用仍为现有 wait、normal_attack1、special_attack1/2 等,未找到缺失的出生和小九头蛇额外攻击动作。该范围不代表全部大文件内容扫描。
|
||||
|
||||
可复核的完整结构化结果:`docs/AVA2-RESOURCE-AUDIT-20261016.json`。
|
||||
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check AVA2 source files and every FoxFS archive for the missing hydra motions."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import tarfile
|
||||
from pathlib import Path
|
||||
from foxfs import Archive,MAGIC,filename_crc
|
||||
|
||||
TARGETS=['d:/ymir work/monster2/'+name for name in (
|
||||
'defensewave_hydra_boss/drop.msa','defensewave_hydra_boss/drop.gr2',
|
||||
'defensewave_minihydra/special_attack1.msa','defensewave_minihydra/special_attack1.gr2')]
|
||||
|
||||
def audit(ava):
|
||||
client=ava/'1. Client DEV';maker=client/'pack_maker'
|
||||
report={'targets':{name:{'crc32':'%08x'%filename_crc(name),'source':[],'source_files':[],
|
||||
'archives':[],'server_backup':[]} for name in TARGETS},
|
||||
'archives':[],'verified_controls':[],'server_backup_candidates':[]}
|
||||
# Include all pack files, even those not currently registered by pack/Index.
|
||||
for path in sorted((client/'pack').iterdir()):
|
||||
if not path.is_file():continue
|
||||
with path.open('rb') as source:magic=source.read(4)
|
||||
if magic!=MAGIC.to_bytes(4,'little'):continue
|
||||
pack=Archive(path)
|
||||
report['archives'].append({'name':path.name,'entries':len(pack.rows)})
|
||||
for name in TARGETS:
|
||||
data=pack.get(name)
|
||||
if data is not None:
|
||||
report['targets'][name]['archives'].append({'pack':path.name,'bytes':len(data),
|
||||
'sha256':hashlib.sha256(data).hexdigest()})
|
||||
if path.name=='Monster2':
|
||||
for folder,files in [('defensewave_hydra_boss',['wait.msa','wait.gr2','motlist.txt','special_attack1.msa','special_attack1.gr2']),
|
||||
('defensewave_minihydra',['wait.msa','normal_attack1.msa','motlist.txt'])]:
|
||||
for filename in files:
|
||||
name='d:/ymir work/monster2/'+folder+'/'+filename
|
||||
data=pack.get(name)
|
||||
source=maker/'Monster2/ymir work/monster2'/folder/filename
|
||||
if data is None or data!=source.read_bytes():raise ValueError('control differs: '+name)
|
||||
report['verified_controls'].append({'path':name,'bytes':len(data),
|
||||
'sha256':hashlib.sha256(data).hexdigest()})
|
||||
for xml in sorted(maker.glob('*_create.xml')):
|
||||
for name,source in re.findall(r'ArchivedPath="([^"]+)"><!\[CDATA\[([^\]]+)\]\]>',xml.read_text(encoding='latin1')):
|
||||
normalized=name.lower().replace('\\','/')
|
||||
if normalized in report['targets']:
|
||||
report['targets'][normalized]['source'].append({'manifest':xml.name,'path':source,
|
||||
'exists':(client/source).is_file()})
|
||||
for name in TARGETS:
|
||||
relative=name.split('d:/',1)[1]
|
||||
for folder in maker.iterdir():
|
||||
if folder.is_dir() and (folder/relative).is_file():
|
||||
report['targets'][name]['source_files'].append(str((folder/relative).relative_to(ava)))
|
||||
backup=ava/'2. Backup SF+SRC and SQL/FILES+SRC.tgz'
|
||||
with tarfile.open(backup,'r:gz') as archive:
|
||||
for member in archive:
|
||||
if not member.isfile():continue
|
||||
path=member.name.lower()
|
||||
if 'defensewave_hydra_boss/' in path or 'defensewave_minihydra/' in path:
|
||||
report['server_backup_candidates'].append(member.name)
|
||||
for name in TARGETS:
|
||||
suffix=name.split('/monster2/',1)[1]
|
||||
if path.endswith('/'+suffix):report['targets'][name]['server_backup'].append(member.name)
|
||||
report['archive_count']=len(report['archives'])
|
||||
report['entry_count']=sum(p['entries'] for p in report['archives'])
|
||||
report['note']='VDI guest filesystem not mounted; packed client, XML manifests and source controls audited.'
|
||||
return report
|
||||
|
||||
if __name__=='__main__':
|
||||
parser=argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--ava',required=True,type=Path)
|
||||
parser.add_argument('--output',required=True,type=Path)
|
||||
args=parser.parse_args();report=audit(args.ava)
|
||||
args.output.parent.mkdir(parents=True,exist_ok=True)
|
||||
args.output.write_text(json.dumps(report,indent=2,ensure_ascii=False)+'\n')
|
||||
print('Checked %d archives, %d entries; %d controls match source and content checksum'%(
|
||||
report['archive_count'],report['entry_count'],len(report['verified_controls'])))
|
||||
for name,result in report['targets'].items():print(name, result)
|
||||
@@ -0,0 +1,89 @@
|
||||
"""Read-only AVA2 FoxFS reader. Layout verified against bundled FoxFS.lib Archive.obj:
|
||||
load, generateFilenameIndex and get. No Windows program is executed.
|
||||
"""
|
||||
import struct
|
||||
import zlib
|
||||
from pathlib import Path
|
||||
|
||||
MAGIC=0x000FED0C
|
||||
MASK=0xFFFFFFFF
|
||||
|
||||
def xxh32(data,seed=MAGIC):
|
||||
p1,p2,p3,p4,p5=2654435761,2246822519,3266489917,668265263,374761393
|
||||
def rol(n,bits):
|
||||
n &= MASK
|
||||
return ((n<<bits)|(n>>(32-bits))) & MASK
|
||||
def step(acc,word):return rol(acc+word*p2,13)*p1 & MASK
|
||||
at,length=0,len(data)
|
||||
if length>=16:
|
||||
v=[(seed+p1+p2)&MASK,(seed+p2)&MASK,seed&MASK,(seed-p1)&MASK]
|
||||
while at<=length-16:
|
||||
v=[step(a,w) for a,w in zip(v,struct.unpack_from('<4I',data,at))];at+=16
|
||||
result=sum(rol(a,b) for a,b in zip(v,(1,7,12,18))) & MASK
|
||||
else:result=(seed+p5)&MASK
|
||||
result=(result+length)&MASK
|
||||
while at+4<=length:
|
||||
result=rol(result+struct.unpack_from('<I',data,at)[0]*p3,17)*p4 & MASK;at+=4
|
||||
for byte in data[at:]:result=rol(result+byte*p5,11)*p1 & MASK
|
||||
result ^= result>>15;result=result*p2 & MASK
|
||||
result ^= result>>13;result=result*p3 & MASK
|
||||
return (result^(result>>16)) & MASK
|
||||
|
||||
def decompress_lz4(data,expected):
|
||||
"""Bounded raw block decoder; overlapping matches retain LZ4 semantics."""
|
||||
output=bytearray();at=0
|
||||
def length(value):
|
||||
nonlocal at
|
||||
if value==15:
|
||||
while True:
|
||||
if at>=len(data):raise ValueError('truncated LZ4 length')
|
||||
byte=data[at];at+=1;value+=byte
|
||||
if byte!=255:break
|
||||
return value
|
||||
while at<len(data):
|
||||
token=data[at];at+=1;literals=length(token>>4)
|
||||
if at+literals>len(data) or len(output)+literals>expected:raise ValueError('invalid LZ4 literals')
|
||||
output+=data[at:at+literals];at+=literals
|
||||
if at==len(data):break
|
||||
if at+2>len(data):raise ValueError('truncated LZ4 match')
|
||||
distance=data[at]|data[at+1]<<8;at+=2;match=length(token&15)+4
|
||||
if not 0<distance<=len(output) or len(output)+match>expected:raise ValueError('invalid LZ4 match')
|
||||
for _ in range(match):output.append(output[-distance])
|
||||
if len(output)!=expected:raise ValueError('LZ4 decoded size mismatch')
|
||||
return bytes(output)
|
||||
|
||||
def filename_crc(name):return zlib.crc32(name.lower().replace('\\','/').encode('latin1'))
|
||||
|
||||
class Archive:
|
||||
def __init__(self,path):
|
||||
self.path=Path(path);self.rows={}
|
||||
with self.path.open('rb') as source:
|
||||
header=source.read(68)
|
||||
if len(header)!=68 or struct.unpack_from('<I',header)[0]!=MAGIC:
|
||||
raise ValueError('not an AVA2 FoxFS archive: '+str(path))
|
||||
self.key,self.iv=header[4:36],header[36:52]
|
||||
at,size=68,self.path.stat().st_size
|
||||
while at<size:
|
||||
source.seek(at);raw=source.read(20)
|
||||
if len(raw)!=20:raise ValueError('truncated FoxFS entry')
|
||||
row=struct.unpack('<5I',raw);original,checksum,offset,stored,crc=row
|
||||
if offset!=at+20 or offset+stored>size:raise ValueError('invalid FoxFS entry extent')
|
||||
# Original load() retains the earliest entry on a CRC collision.
|
||||
self.rows.setdefault(crc,row);at=offset+stored
|
||||
|
||||
def get(self,name,max_bytes=64*1024*1024):return self.get_crc(filename_crc(name),max_bytes)
|
||||
|
||||
def get_crc(self,crc,max_bytes=64*1024*1024):
|
||||
row=self.rows.get(crc)
|
||||
if row is None:return None
|
||||
original,checksum,offset,stored,_=row
|
||||
if max(original,stored)>max_bytes:raise ValueError('FoxFS resource exceeds requested size limit')
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher,algorithms,modes
|
||||
with self.path.open('rb') as source:
|
||||
source.seek(offset);encrypted=source.read(stored)
|
||||
if len(encrypted)!=stored:raise ValueError('FoxFS archive changed during read')
|
||||
decoder=Cipher(algorithms.AES(self.key),modes.CFB(self.iv)).decryptor()
|
||||
raw=decoder.update(encrypted)+decoder.finalize()
|
||||
if original!=stored:raw=decompress_lz4(raw,original)
|
||||
if xxh32(raw)!=checksum:raise ValueError('FoxFS content checksum mismatch: '+str(self.path))
|
||||
return raw
|
||||
@@ -0,0 +1,44 @@
|
||||
import struct
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher,algorithms,modes
|
||||
from foxfs import Archive,MAGIC,filename_crc,xxh32,decompress_lz4
|
||||
|
||||
class ReaderTests(unittest.TestCase):
|
||||
def fixture(self,path,compressed=False):
|
||||
self.name='d:/ymir work/monster2/test/wait.msa'
|
||||
data=b'ScriptType MotionData\r\nMotionDuration 1.0\r\n'
|
||||
stored=data
|
||||
if compressed:stored=b'\xf0'+bytes([len(data)-15])+data
|
||||
key=bytes(range(32));iv=bytes(range(32,64))
|
||||
encoder=Cipher(algorithms.AES(key),modes.CFB(iv[:16])).encryptor()
|
||||
encrypted=encoder.update(stored)+encoder.finalize()
|
||||
path.write_bytes(struct.pack('<I',MAGIC)+key+iv+struct.pack('<5I',len(data),xxh32(data),88,len(encrypted),filename_crc(self.name))+encrypted)
|
||||
return data
|
||||
|
||||
def test_read_and_corruption(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
path=Path(folder)/'pack'
|
||||
for compressed in (False,True):
|
||||
data=self.fixture(path,compressed)
|
||||
pack=Archive(path)
|
||||
self.assertEqual(pack.get(self.name.upper().replace('/','\\')),data)
|
||||
self.assertIsNone(pack.get('missing.msa'))
|
||||
with self.assertRaises(ValueError):pack.get(self.name,max_bytes=5)
|
||||
raw=bytearray(path.read_bytes());raw[-1]^=1;path.write_bytes(raw)
|
||||
with self.assertRaises(ValueError):Archive(path).get(self.name)
|
||||
|
||||
def test_invalid_index_and_blocks(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
path=Path(folder)/'pack';self.fixture(path)
|
||||
good=path.read_bytes()
|
||||
for raw in (good[:3],good[:70],good[:68]+struct.pack('<5I',1,0,5,100,0)):
|
||||
path.write_bytes(raw)
|
||||
with self.assertRaises(ValueError):Archive(path)
|
||||
self.assertEqual(xxh32(b'',0),0x02cc5d05)
|
||||
self.assertEqual(decompress_lz4(b'\x10a\x01\x00\x50bcdef',10),b'aaaaabcdef')
|
||||
for data,size in [(b'\xf0',20),(b'\x00\x00\x00',4),(b'\x10a',0),(b'\x10a\x01',5)]:
|
||||
with self.assertRaises(ValueError):decompress_lz4(data,size)
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in New Issue
Block a user