Advertisement
Lavos

Yuuki Yuuna wa Yuusha de Aru -- not good!

Nov 15th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.41 KB | None | 0 0
  1. import os,sys,struct,zlib
  2.  
  3. def get_data(filename):
  4.     totalbytes = os.path.getsize(filename)
  5.     infile = open(filename, 'rb')
  6.     totalfiledata = infile.read(totalbytes)
  7.     return totalfiledata
  8.  
  9. if __name__ == '__main__':
  10.     filedata = get_data(sys.argv[1])
  11.     xor = 0xAFDD92A7
  12.     filecnt = 0
  13.    
  14.     #some unknown dword at 0x0
  15.     #2 more umknown dwords at 0xd6 and 0xda
  16.     #in between is table of contents I assume, 0x15 bytes for each, all crypted,
  17.     #except first dword used as a key
  18.    
  19.     for i in range(0x4,0xd6,0x15):
  20.         newfiledata = ''
  21.         key = struct.unpack('<I',filedata[i:i+0x4])[0]
  22.         key ^= xor
  23.        
  24.         if filecnt == 0: #done
  25.             for a in xrange(0xde,0xde+0x6048,0x4):
  26.                 newfiledata += struct.pack('<I',struct.unpack('<I',filedata[a:a+0x4])[0] ^ key)
  27.             newfiledata += filedata[0xde+0x6048:0xde+0x604b]
  28.                    
  29.         elif filecnt == 1: #done
  30.             for a in xrange(0x6129,0x6129+0x4c8,0x4):
  31.                 newfiledata += struct.pack('<I',struct.unpack('<I',filedata[a:a+0x4])[0] ^ key)
  32.  
  33.         elif filecnt == 2: #done
  34.             for a in xrange(0x65f1,0x65f1+0xc,0x4):
  35.                 newfiledata += struct.pack('<I',struct.unpack('<I',filedata[a:a+0x4])[0] ^ key)
  36.                  
  37.         elif filecnt == 3: #done
  38.             for a in xrange(0x65fd,0x65fd+0x1324,0x4):
  39.                 newfiledata += struct.pack('<I',struct.unpack('<I',filedata[a:a+0x4])[0] ^ key)
  40.             newfiledata += filedata[0x65fd+0x1324:0x65fd+0x1326]
  41.  
  42.         elif filecnt == 4: #done
  43.             for a in xrange(0x7923,0x7923+0x2008,0x4):
  44.                 newfiledata += struct.pack('<I',struct.unpack('<I',filedata[a:a+0x4])[0] ^ key)
  45.             newfiledata += filedata[0x7923+0x2008:0x7923+0x2009]
  46.  
  47.         elif filecnt == 5: #done
  48.             for a in xrange(0x992c,0x992c+0x170,0x4):
  49.                 newfiledata += struct.pack('<I',struct.unpack('<I',filedata[a:a+0x4])[0] ^ key)
  50.             newfiledata += filedata[0x992c+0x170:0x992c+0x171]
  51.  
  52.         elif filecnt == 6: #done
  53.             for a in xrange(0x9a9d,0x9a9d+0x2618,0x4):
  54.                 newfiledata += struct.pack('<I',struct.unpack('<I',filedata[a:a+0x4])[0] ^ key)
  55.             newfiledata += filedata[0x992c+0x170:0x992c+0x171]
  56.  
  57.         elif filecnt == 7: #done
  58.             for a in xrange(0xc0b5,0xc0b5+0x276C,0x4):
  59.                 newfiledata += struct.pack('<I',struct.unpack('<I',filedata[a:a+0x4])[0] ^ key)
  60.             newfiledata += filedata[0xc0b5+0x276C:0xc0b5+0x276D]
  61.  
  62.         elif filecnt == 8: #done
  63.             for a in xrange(0xe822,0xe822+0x228C,0x4):
  64.                 newfiledata += struct.pack('<I',struct.unpack('<I',filedata[a:a+0x4])[0] ^ key)
  65.             newfiledata += filedata[0xe822+0x228C:0xe822+0x228f]
  66.        
  67.         elif filecnt == 9: #done
  68.             for a in xrange(0x10ab1,0x10ab1+0x184,0x4):
  69.                 newfiledata += struct.pack('<I',struct.unpack('<I',filedata[a:a+0x4])[0] ^ key)
  70.                    
  71.         else:
  72.             print 'unknown file key: %x' % struct.unpack('<I',filedata[i:i+0x4])[0]
  73.             sys.exit()
  74.  
  75.         print 'File %d key %x' % (filecnt,struct.unpack('<I',filedata[i:i+0x4])[0])
  76.         newfiledata = zlib.decompress(newfiledata)
  77.    
  78.         outfile = open('File_%d.txt' % filecnt,'wb')
  79.         outfile.write(newfiledata)
  80.         outfile.close()
  81.  
  82.         filecnt += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement