def ExtDir(idx, key0, key1): idx = bytefile.ByteIO(idx) d = 0x31746285 for i in range(int(len(idx) / 4)): d = ((d << 4) & 0xffffffff) | (d >> 28) shift = d & 0x1f tempkey = [ key1 & 0xff, (key1 & 0xff00) >> 8, (key1 & 0xff0000) >> 16, (key1 & 0xff000000) >> 24 ] for j in range(4): idx[i * 4 + j] ^= tempkey[j] key1 = (key1 >> shift) | ((key1 << (32 - shift)) & 0xffffffff) idx.seek(0) entry_num = idx.readu32() global ci predata_len = idx.readu8() ci[6] = idx.read(predata_len) dirs = [0 for i in range(entry_num)] if ci[1]: mode = idx.readu8() nametree_len = idx.readu32() tree = bytefile.ByteIO(idx.read(nametree_len)) entrylist = bytefile.ByteIO(idx[idx.tell():]) name = b'' if mode: longidxsrch(tree, name, 0, dirs, entrylist) else: shortidxsrch(tree, name, 0, dirs, entrylist) return dirs
def ImpExe(exename,idxname,txtname,newname): fs=open(idxname,'rb') idxstm=bytefile.ByteIO(fs.read()) idx=[] while idxstm.tell()<len(idxstm): idx.append(idxstm.readu32()) fs=open(txtname,'rb') lines=fs.read().decode('U16').split('\r\n') if len(lines)!=len(idx): print('Lines not match') sys.exit() fs=open(exename,'rb') nfs=open(newname,'wb') nfs.write(fs.read()) nfs.close() fs.close() fs=open(newname,'rb+') for i in range(len(idx)): fs.seek(idx[i]) l=lines[i].replace('・','·') fs.write(l.encode('936')+b'\0') fs.close()
def ExpMusic(fname, txtname, idxname=''): fs = open(fname, 'rb') stm = bytefile.ByteIO(fs.read()) fs.close() i = 0 txt = [] idx = [] while i < len(stm) - 2: if stm[i] == 0x4c: if (stm[i+1]>0x60) and (stm[i+1]<0xdf) and\ (stm[i+2]>=0x20) and (stm[i+2]<0xdf): stm.seek(i + 1) idx.append((1, stm.tell())) s = stm.readstr() Decode(s) txt.append(s.decode('932').replace('\n', '\\n')) i = stm.tell() continue i += 1 fs = open(txtname, 'wb') fs.write('\r\n'.join(txt).encode('936', 'replace')) fs.close() if idxname == '': idxname = txtname.replace('.txt', '.idx') if idxname == txtname: idxname += '.idx' WriteIdx(idx, idxname)
def ExpOptions(fname, txtname, idxname=''): fs = open(fname, 'rb') stm = bytefile.ByteIO(fs.read()) fs.close() i = 0 txt = [] idx = [] while i < len(stm) - 3: if stm[i:i + 3] == b'E@s': stm.seek(i + 3) idx.append((0, stm.tell())) txt.append(stm.readstr().decode('932')) i = stm.tell() continue elif stm[i:i + 3] == b'L S': stm.seek(i + 3) idx.append((1, stm.tell())) txt.append(Decode(stm.readstr()).decode('932')) i = stm.tell() continue i += 1 fs = open(txtname, 'wb') fs.write('\r\n'.join(txt).encode('936')) fs.close() if idxname == '': idxname = txtname.replace('.txt', '.idx') if idxname == txtname: idxname += '.idx' WriteIdx(idx, idxname)
def ext(fname, path): if not os.path.exists(path): os.makedirs(path) fs = open(fname, 'rb') hdr = bytefile.ByteIO(fs.read(0x8)) xordec(hdr) count = hdr.readu32p(4) index = bytefile.ByteIO(fs.read(count * 0x88)) xordec(index) for i in range(count): name = index.read(0x80).rstrip(b'\0') size = index.readu32() off = index.readu32() fs.seek(off) content = bytearray(fs.read(size)) xordec(content) newf = open(os.path.join(path, name.decode('sjis')), 'wb') newf.write(content) newf.close()
def __init__(self, mjo): self.text = [] self.code = 0 self.hdr = [mjo[0:0x10]] self.hdr += unpack('III', str(mjo[0x10:0x1c])) mjo.seek(0x1c) self.fidx = [] for i in range(self.hdr[3]): self.fidx.append((mjo.readu32(), mjo.readu32())) size = mjo.readu32() self.vmcode = bytefile.ByteIO(mjo[mjo.tell():mjo.tell() + size]) self.XorDec(self.vmcode)
def ExtDat(fs, ndir): fs.seek(0) hdr = bytefile.ByteIO(fs.read(0x40)) Dec(hdr) magic, val1, val2, f_count, index_len = struct.unpack( '<8sIIII', hdr.read(0x18)) if (magic != b'mgbpack\0') or (val1 != 1) or (val2 != 0x40): print('Format Error!') int3() idx = bytefile.ByteIO(fs.read(index_len)) Dec(idx) for i in range(f_count): slen = idx.readu32() name = idx.read(slen).decode('932') idx.seek(1, 1) off, unk1, fsize, unk2 = struct.unpack('<IIII', idx.read(16)) #if not name.endswith('.dds'): # continue #if (unk1!=0) or (unk2!=0): # int3() print('Extracting ' + name) fs.seek(off + index_len + 0x40) stm = fs.read(fsize) fullname = os.path.join(ndir, name).replace('/', '\\') fullpath = os.path.split(fullname)[0] if not os.path.exists(fullpath): os.makedirs(fullpath) nf = open(os.path.join(ndir, name), 'wb') nf.write(stm) nf.close() ##if name.endswith('ms010.bnt'): ## print('%x'%(off+0x40+index_len)) print("Extract Complete!")
def ImpSingleTxt(name1,name2,name3): fs=open(name1,'rb') parser=BntParser(bytefile.ByteIO(fs.read())) fs.close() if not os.path.exists(name2): return fs=open(name2,'rb') lines=fs.read().decode('U16').split('\r\n') if lines==['']: return nl=parser.ExtTxt()[0:] j=0 for i in range(len(nl)): l=nl[i].strip('\t') half=True for c in l: if ord(c)>0x80: half=False break if not half: nl[i]=lines[j].replace('・','·') j+=1 stm=parser.ImpTxt(nl) rp=os.path.split(name3)[0] if rp!='': if not os.path.exists(rp): os.makedirs(rp) fs=open(name3,'wb') fs.write(stm[0:]) fs.close()
def __init__(self, stm): if stm[0:4] != b'PSB\x00': print("PSB Format Error") self.psb = bytefile.ByteIO(stm)
import bytefile stm = bytefile.ByteIO(open('a.b', 'rb').read()) cnt = int(len(stm) / 4) for i in range(cnt): ii = stm.readu32() if ii >= 0xe0000: print(ii)
#int3() while i<len(stm): if stm[i]!=0: #print('\r%d'%len(txt)) idx.append(i+base) stm.seek(i) txt.append(stm.readstr()) i=stm.tell() continue i+=1 idx=[] txt=[] fs=open('SAKURA_CHS2.EXE','rb') fs.seek(0x34648) stm=bytefile.ByteIO(fs.read(0x3a800)) GetStrs(stm,idx,txt,0x34648) fs.close() fs=open('exe.txt','wb') fs.write(b'\r\n'.join(txt)) fs.close() idxstm=bytearray() for i in idx: idxstm+=struct.pack('I',i) fs=open('exe.idx','wb') fs.write(idxstm) fs.close()
def DecSingle(stm): for i in range(len(stm)): stm[i] ^= dec_key[i & 7] int3() return zlib.decompress(stm[4:]) def ExtSingle(stm): return zlib.decompress(stm[4:]) path = 'E:\\Game\\夏之灯火\\' fs = open(path + 'ARDPics.ARD', 'rb') hdr = bytefile.ByteIO(fs.read(0x100)) hdr.seek(8) count = hdr.readu32() idx = bytefile.ByteIO(fs.read(count * 0x2d)) if 'ARDPics' not in os.listdir(path): os.mkdir(path + 'ARDPics') os.chdir(path + 'ARDPics') for i in range(count): off = idx.readu32() size = idx.readu32() resv = idx.readu32() if size != resv: aaa fs.seek(off)
while i < len(stm): if stm[i] != 0: #print('\r%d'%len(txt)) idx.append(i + base) stm.seek(i) txt.append(stm.readstr().decode('932')) i = stm.tell() continue i += 1 idx = [] txt = [] fs = open('Suika_ASPLUS_CN.exe', 'rb') fs.seek(0x320d8) stm = bytefile.ByteIO(fs.read(0x4141)) GetStrs(stm, idx, txt, 0x320d8) fs.seek(0x365f8) stm = bytefile.ByteIO(fs.read(0x809)) GetStrs(stm, idx, txt, 0x365f8) fs.close() fs = open('exe.txt', 'wb') fs.write('\r\n'.join(txt).encode('U16')) fs.close() idxstm = bytearray() for i in idx: idxstm += struct.pack('I', i)
decode.append(bytes([ybn.readu8() ^ key[n & 3]])) return b''.join(decode) fs = open("ysbin.ypf", 'rb') stm = bytefile.ByteFile(fs.read()) stm.seek(8) count, index_size = struct.unpack("II", stm.read(8)) stm.seek(0x20) for n in range(count): stm.seek(4, 1) len2, = struct.unpack('b', stm.read(1)) name1 = stm.read(str_lens[-len2 - 1]) name = [] for i in range(len(name1)): name.append(chr(name1[i] ^ 0xff ^ 0x36)) name = ''.join(name) type1, is_compressed, uncomplen, complen, offset, datacrc=\ struct.unpack('=BBIIII',stm.read(18)) cur_off = stm.tell() stm.seek(offset) newfile = open(name, 'wb') print(name) if is_compressed: newfile.write( decodeYbn(bytefile.ByteIO(zlib.decompress(stm.read(complen))))) else: newfile.write(decodeYbn(bytefile.ByteIO(stm.read(uncomplen)))) newfile.close() stm.seek(cur_off)
int3() elif t == -2: len1 = GetInt(psb, o - (0x15 - 0xd)) text.append(strings[len1]) elif t == -3: len1 = GetInt(psb, psb.readu8()) type1 = psb.readu8() for i in range(len1): GetInt(psb, type1) elif t == -4: len1 = GetInt(psb, psb.readu8()) type1 = psb.readu8() for i in range(len1): GetInt(psb, type1) len2 = GetInt(psb, psb.readu8()) type2 = psb.readu8() for i in range(len2): GetInt(psb, type2) else: psb.seek(t, 1) return '\r\n'.join(text) fs = open('dec.psb', 'rb') stm = fs.read() bio = bytefile.ByteIO(stm) txt = ParsePsb(bio) fs = open('dec.txt', 'wb') fs.write(txt.encode('utf-8')) fs.close()
if t == 2: news += stm.read(4) elif t == 1: l = stm.readstr() if len(l) != 0 and not l.endswith(b'.bin'): news += lines[j] + b'\0' j += 1 else: news += l + b'\0' else: int3() return news dirs = os.listdir(path2) for f in os.listdir(path1): if not f.endswith('.dat'): continue if f == 'TDM45.dat': continue fs = open(path1 + f, 'rb') stm = bytefile.ByteIO(fs.read()) fname = f.replace('.dat', '.txt') if fname in dirs: fs = open(path2 + f.replace('.dat', '.txt'), 'rb') lines = fs.read().decode('U16').encode('936', 'replace').split(b'\r\n') news = packTxt(stm, lines) else: news = stm[0:] fs = open(path3 + f, 'wb') fs.write(news)
pos += 1 elif entries[pos][4] & 0x10: pos += 1 TraverseDir(cur_root + '\\' + entries[pos - 1][0], entries[pos - 1][3]) else: print("Unknown Type.") sys.exit() def MakeEntries(idx, ents): while idx.tell() < len(idx): off, unclen, complen, flags = struct.unpack('QQQI24x', idx.read(52)) name = idx.readstr().decode('932') entries.append([name, off, complen, unclen, flags]) fs = open(fname, 'rb') magic, hdr1len, hdr2len, dircount, idxuncomprlen, idxcomprlen=struct.unpack(\ "<4sH10xI4xIII4x",fs.read(0x28)) if (magic != b'PAK\0') or (hdr1len != 0x10) or (hdr2len != 0x18): print("Format Error!") sys.exit() idx = fs.read(idxuncomprlen) idx = zlib.decompress(idx, -15) MakeEntries(bytefile.ByteIO(idx), entries) TraverseDir('.', dircount)