Directory eines D88-Image inkl. Sektoren in Cluster-Tabelle einlesen
import sys from struct import unpack RECORDSIZE=128 CLUSTERSIZE=RECORDSIZE*16 CLUSTERCOUNT=140 DIRSIZE=32 d=open(sys.argv[1],"rb") #struct d88hdr_t { char title[17]; BYTE rsrv[9]; BYTE protect; BYTE type; DWORD size; DWORD trkptr[164]; }; title,protect,type,size=unpack("<17s9xBBL",d.read(32)) trackpnt=[] dat=unpack("<L",d.read(4))[0] while dat!=0: trackpnt.append(dat) dat=unpack("<L",d.read(4))[0] trackpnt=sorted(trackpnt) cluster = [bytes(CLUSTERSIZE)]*CLUSTERCOUNT #struct d88sct_t { BYTE c, h, r, n; WORD nsec; BYTE dens, del, stat; BYTE rsrv[5]; WORD size; }; for t in range(len(trackpnt)-1): fr,to=trackpnt[t],trackpnt[t+1] d.seek(fr) while fr<to: c,h,r,n,nsec,dens,dl,stat,size=unpack("<BBBBHBBB5xH",d.read(16)) n=RECORDSIZE<<n pos,start=((c-4)<<2)|(h<<1)|(0 if r<9 else 1),((r-1) & 7)*n if pos>=0 and pos<CLUSTERCOUNT: cluster[pos]=cluster[pos][:start]+d.read(n)+cluster[pos][start+n:] fr+=n+16 dir={} for t in range(0,CLUSTERSIZE,DIRSIZE): st,nam,ext,xt,records,bmap=unpack("<B8s3sB2xB16s",cluster[0][t:t+DIRSIZE]) if st != 0xe5: ro,sy=(ext[0] >> 7)==1,(ext[1] >> 7)==1 nam,ext=bytes([n & 0x7f for n in nam]).decode().rstrip(),bytes([n & 0x7f for n in ext]).decode().rstrip() if (nam,ext) in dir: dir[nam,ext]['ext'][(xt >> 1)&0xf]={'bmp':[i for i in bmap if i!=0],'records':records+((xt & 1)<<7)} else: dir[nam,ext]={"USER":st & 0xf,"RO":ro,"SYS":sy,'ext':{(xt >> 1)&0xf:{'bmp':[i for i in bmap if i!=0],'records':records+((xt & 1)<<7)}}} for k,v in dir.items(): print(f'"{k[0]}.{k[1]}" USER {v["USER"]}','RO' if v['RO'] else 'RW', 'SYS' if v['SYS'] else '') print('Extends',end='') for k2,v2 in v['ext'].items(): print('\t',k2,v2) print()