Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os,sys,struct
- def get_data(filename):
- totalbytes = os.path.getsize(filename)
- infile = open(filename, 'rb')
- totalfiledata = infile.read(totalbytes)
- infile.close()
- return totalfiledata
- charname = {
- 0x0:"",0x1:"Yuuji",0x2:"Saki",0x3:"Misaki",0x4:"Kozue",
- 0x5:"Rei",0x6:"Misato",0x7:"Sumiyoshi",0x8:"Takeaki",0x9:"Kataoka",
- 0xa:"Keijiro",0xb:"Vice Principal",0xc:"Sumiyoshi's Mother",0xd:"Kuraki",
- 0xe:"Saki & Sumiyoshi",0xf:"Kozue & Saki",0x10:"Misaki & Misato",0x11:"Rei's Father",
- 0x12:"Rei's Mother",0x13:"Student",0x14:"Man",0x15:"Man A",0x16:"Man B",0x17:"Boy A",
- 0x18:"Boy B",0x19:"Woman",0x1a:"Woman A",0x1b:"Woman B",0x1c:"Girl",0x1d:"Girl A",
- 0x1e:"Girl B",0x1f:"Girl C",0x20:"Customer",0x21:"Customer A",0x22:"Customer B",
- 0x23:"Customer C",0x24:"Toshizou",0x25:"Oyuki",0x26:"Man in Black",0x27:"Master",
- 0x28:"Butler",0x29:"Passenger",0x2a:"Optometrist",0x2b:"Sakura",0x2c:"Snow Sakura",
- 0x2d:"Dog",0x2e:"Voice",0x2f:"TV",0x30:"Movie",0x31:"Broadcast",0x32:"Everyone",
- 0x33:"???",0x34:"Crab",0x35:"Yuuji & Sumiyoshi",0x36:"Yuuji & Saki",
- }
- if __name__ == '__main__':
- filedata = get_data(sys.argv[1])
- filecnt = struct.unpack('<I',filedata[0x8:0xc])[0]
- datastart = struct.unpack('<I',filedata[0xc:0x10])[0]
- for i in range(0x20,0x20+(filecnt*0x14),0x14):
- filename = ''
- a = i
- while (ord(filedata[a]) != 0x0) and (len(filename) <= 12):
- filename += filedata[a:a+1]
- a += 1
- filepos = struct.unpack('<I',filedata[i+0xc:i+0x10])[0]
- filelen = struct.unpack('<I',filedata[i+0x10:i+0x14])[0]
- print 'Extracting %s - pos %x len %x' % (filename,filepos,filelen)
- filed = bytearray(filedata[filepos:filepos+filelen])
- if struct.unpack('>H',filed[0x4:0x6])[0] == 0x9597:
- #xor
- for a in range(0x8,len(filed)):
- filed[a] = ((filed[a] << 0x6) | (filed[a] >> 0x2)) & 0xFF
- #try read the strings...
- newfiledata = ''
- strpos = struct.unpack('<I',filed[:4])[0]
- stringcount = 0
- for a in range(0x8,strpos,0x4):
- currstrpos = struct.unpack('<I',filed[a:a+4])[0] + strpos
- if a+0x4 == strpos:
- nextstrpos = len(filed)
- else:
- nextstrpos = struct.unpack('<I',filed[a+4:a+8])[0] + strpos
- #print 'start of string: %x end of string %x' % (currstrpos,nextstrpos)
- if filed.find('\x2b',currstrpos,nextstrpos) != -1:
- stringpos = filed.find('\xff\x7f',currstrpos,nextstrpos)
- if stringpos != -1:
- #assume we have a string
- #get the char name
- charnamepos = filed.find('\x03\x11',currstrpos,nextstrpos)
- #print 'name: %x' % filed[charnamepos+2]
- if not charname.has_key(filed[charnamepos+2]):
- print 'Character %x not found at pos %x' % (filed[charnamepos+2],charnamepos+2)
- sys.exit()
- #get the string
- stringpos += 2
- string = ''
- while filed[stringpos] != 0x0 and stringpos <= nextstrpos:
- if filed[stringpos] != 0x7f:
- string += chr(filed[stringpos])
- stringpos += 1
- if filed[charnamepos+2] > 0:
- newfiledata += charname[filed[charnamepos+2]] + ': ' + string + '\n'
- else:
- newfiledata += string + '\n'
- stringcount += 1
- #print 'string was: %s' % string
- outfile = open('Out\\' + filename,'wb')
- outfile.write(filed)
- outfile.close()
- outfile = open('Out\\' + filename.rsplit('.',1)[0] + '_strings.txt','wb')
- outfile.write(newfiledata)
- outfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement