home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 16694 / magicami.7z / magicami.py
Encoding:
Python Source  |  2019-09-07  |  2.5 KB  |  83 lines

  1. from urllib.request import ProxyHandler, build_opener, install_opener, urlopen
  2. import lz4
  3. import lz4.block
  4. from itertools import islice
  5. from multiprocessing.dummy import Pool as ThreadPool
  6. import os
  7. import io
  8. import struct
  9. pool = ThreadPool(10)
  10.  
  11. if not os.path.exists("magicami"):
  12.     os.makedirs("magicami")
  13. #proxy = urllib.request.ProxyHandler({'http': 'http://192.168.1.91:8888'})
  14. proxy = ProxyHandler({})
  15. opener = build_opener(proxy)
  16. opener.addheaders = [('Refere','https://api.magicami.jp/Top/Main?magicami-sessid=thus9ievqvgslol0abcd2abcdefg5abc'),('Origin','https://api.magicami.jp'),('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763')]
  17. install_opener(opener)
  18.  
  19.  
  20.  
  21. def geturl(name):
  22.     try:
  23.         if os.path.exists('magicami\\' + name[1]):
  24.             pass
  25.         else:
  26.             print('Downlaoding',name)
  27.             myFile = urlopen(name[0]).read()
  28.             with open('magicami\\' + name[1], 'wb') as f:
  29.                 f.write(myFile)
  30.         
  31.     except:
  32.         pass
  33.  
  34.  
  35. with open('magicami.bundle', "rb" ) as f:
  36.     names = []
  37.     bs = io.BytesIO(f.read())
  38.     b1,b2,b3 = struct.unpack('BBB', bs.read(3))
  39.     #print(b1,b2,b3)
  40.     typeDict = {18: 'assetbundle', 26: 'assetbundle', 34: 'resources'}
  41.  
  42.     for i in range(0,14000):
  43.         unk00,unk01,unk02,unk03  = struct.unpack('4B', bs.read(4))
  44.         if unk00 == 0x2A:
  45.             bs.seek(bs.tell() - 3,0)
  46.             url = bs.read(struct.unpack('B', bs.read(1))[0]).decode("utf-8")
  47.             print(url)
  48.             break
  49.         else:
  50.             unk04 = struct.unpack('B', bs.read(1))[0]
  51.             while unk04 != 0x1A:
  52.                 unk04 = struct.unpack('B', bs.read(1))[0]
  53.             unk05 = struct.unpack('B', bs.read(1))[0]
  54.             #print(unk00,unk01,unk02,unk03,unk04,unk05)
  55.             #print(bs.tell())
  56.             tmp = bs.tell()
  57.             try:
  58.                 fileName = bs.read(unk05).decode("utf-8")
  59.             except:
  60.                 bs.seek(tmp,0)
  61.                 fileName = bs.read(struct.unpack('B', bs.read(1))[0]).decode("utf-8")
  62.             #print(fileName,typeDict[unk00])
  63.             unk06 = bs.read(0x8)
  64.             #print(unk06)
  65.             tb = struct.unpack('B', bs.read(1))[0]
  66.             while tb != 0x52:
  67.                 tb = struct.unpack('B', bs.read(1))[0]
  68.             md5Size = struct.unpack('B', bs.read(1))[0]
  69.             md5 = bs.read(md5Size).decode("ASCII")
  70.             #print(md5)
  71.             hVal,hSize = struct.unpack('BB', bs.read(2))
  72.             hName = bs.read(hSize).decode("ASCII")
  73.             #print(hVal,hSize,hName)
  74.             unk07 = bs.read(0xB)
  75.             #print(unk07)
  76.             #print(hex(bs.tell()))
  77.             if len(hName) == 6:
  78.                 url = 'https://d66zh4czgmp8a.cloudfront.net/magicami-prod-1-' + typeDict[unk00] + '/' + hName
  79.                 names.append([url,fileName])
  80.  
  81.     pool.map(geturl, names )
  82.  
  83.