RikuNoctis

Realta Nua Mobile - Repack

Jun 15th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Fate Mobile DAT File Repacker v1.2
  4. # 2015/06/11
  5. #
  6. # Copyright (c) 2015 Hintay <hintay(at)me.com>
  7. # Copyright (c) 2015 dorobo-hamster
  8.  
  9. import os, codecs, hashlib, sys
  10.  
  11. # Change dat filename in here
  12. container_name = 'test.dat'
  13. #This has only been tested on fate_000.dat.
  14. #Other files may be different so check the output for other files.
  15. ENCRYPTION_KEY = [0x5d, 0x55, 0x82, 0xf2, 0xbe, 0x45, 0x31, 0xeb,
  16.                   0x29, 0xbc, 0xf7, 0x2c, 0xe2, 0xb5, 0xc0, 0x5b]
  17.  
  18. def main(startdir, encrypt):
  19.     with open(container_name , 'wb') as datwr:
  20.         fileinfo = codecs.open('fileinfo.txt' , 'w', 'utf-8')
  21.         os.chdir(startdir)
  22.         offset = 0
  23.         bytesoffset = 0
  24.         n = 1024*4
  25.         line_end = {0:'\n', 1:'::\n'}
  26.  
  27.         for obj in os.listdir(os.curdir):
  28.             print(obj)
  29.             m = hashlib.md5()
  30.  
  31.             dat = open(obj, 'rb')
  32.             while True:
  33.                 buf = dat.read(n)
  34.                 if buf:
  35.                     m.update(buf)
  36.                     if encrypt:
  37.                         data = bytearray(buf)
  38.                         for i in range(len(data)):
  39.                             data[i] = data[i]^ENCRYPTION_KEY[bytesoffset%16]^(bytesoffset%256)
  40.                             bytesoffset += 1
  41.                         buf = data
  42.                     datwr.write(buf)
  43.                 else:
  44.                     break
  45.             dat.close()
  46.  
  47.             file_hash = m.hexdigest()
  48.             print(file_hash)
  49.  
  50.             size = bytesoffset - offset
  51.             name, extension = obj.split('.')[:2]
  52.             # Maybe you should decode filename.
  53.             name = name.decode("GBK")
  54.             fileinfo.write(u'%s::%s::sys/%s::%s::%s::%s::%s%s'%(name, extension, container_name, offset, size, file_hash, int(encrypt), line_end[encrypt]))
  55.  
  56.             offset = bytesoffset
  57.         datwr.close()
  58.         fileinfo.close()
  59.  
  60. if __name__ == '__main__':
  61.     while True:
  62.         startdir = raw_input(u'Please input startdir: ')
  63.         if(os.path.exists(startdir)):
  64.             break
  65.         else:
  66.             print(u'%s not exits, please input again.'%startdir)
  67.  
  68.     yesorno = {'y':True, 'n':False}
  69.     while True:
  70.         encrypt = raw_input(u'Encrypt? (y/n): ')
  71.         if(encrypt == 'y' or encrypt == 'n'):
  72.             encrypt = yesorno[encrypt]
  73.             break
  74.         else:
  75.             print(u'Your input is incorrect, please input again.')
  76.  
  77.     main(startdir, encrypt)
Advertisement
Add Comment
Please, Sign In to add comment