Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- #
- # Fate Mobile DAT File Repacker v1.2
- # 2015/06/11
- #
- # Copyright (c) 2015 Hintay <hintay(at)me.com>
- # Copyright (c) 2015 dorobo-hamster
- import os, codecs, hashlib, sys
- # Change dat filename in here
- container_name = 'test.dat'
- #This has only been tested on fate_000.dat.
- #Other files may be different so check the output for other files.
- ENCRYPTION_KEY = [0x5d, 0x55, 0x82, 0xf2, 0xbe, 0x45, 0x31, 0xeb,
- 0x29, 0xbc, 0xf7, 0x2c, 0xe2, 0xb5, 0xc0, 0x5b]
- def main(startdir, encrypt):
- with open(container_name , 'wb') as datwr:
- fileinfo = codecs.open('fileinfo.txt' , 'w', 'utf-8')
- os.chdir(startdir)
- offset = 0
- bytesoffset = 0
- n = 1024*4
- line_end = {0:'\n', 1:'::\n'}
- for obj in os.listdir(os.curdir):
- print(obj)
- m = hashlib.md5()
- dat = open(obj, 'rb')
- while True:
- buf = dat.read(n)
- if buf:
- m.update(buf)
- if encrypt:
- data = bytearray(buf)
- for i in range(len(data)):
- data[i] = data[i]^ENCRYPTION_KEY[bytesoffset%16]^(bytesoffset%256)
- bytesoffset += 1
- buf = data
- datwr.write(buf)
- else:
- break
- dat.close()
- file_hash = m.hexdigest()
- print(file_hash)
- size = bytesoffset - offset
- name, extension = obj.split('.')[:2]
- # Maybe you should decode filename.
- name = name.decode("GBK")
- 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]))
- offset = bytesoffset
- datwr.close()
- fileinfo.close()
- if __name__ == '__main__':
- while True:
- startdir = raw_input(u'Please input startdir: ')
- if(os.path.exists(startdir)):
- break
- else:
- print(u'%s not exits, please input again.'%startdir)
- yesorno = {'y':True, 'n':False}
- while True:
- encrypt = raw_input(u'Encrypt? (y/n): ')
- if(encrypt == 'y' or encrypt == 'n'):
- encrypt = yesorno[encrypt]
- break
- else:
- print(u'Your input is incorrect, please input again.')
- main(startdir, encrypt)
Advertisement
Add Comment
Please, Sign In to add comment