Advertisement
Guest User

Nightmare of Rebellion License Generator

a guest
Jan 11th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.10 KB | None | 0 0
  1. import ctypes, win32api
  2. import struct, random, time, traceback
  3. import hashlib, zlib, base64, sys
  4.  
  5. def crc32(data):
  6.     return ctypes.c_ulong(zlib.crc32(data)).value
  7.  
  8.  
  9. def sagiri_crypt(data, seed):
  10.     a = 362436069
  11.     b = 521288629
  12.     c = 88675123
  13.     res = ''
  14.     lseed = seed
  15.     for ch in data:
  16.         seed = lseed ^ lseed << 11 & 4294967295L
  17.         lseed = a
  18.         a, b, c = b, c, c ^ seed ^ (seed ^ c >> 11) >> 8
  19.         res += chr((ord(ch) ^ c) & 255)
  20.  
  21.     return res
  22.  
  23.  
  24. def sagiri_hash(s, salt):
  25.     salt1 = ''
  26.     salt2 = ''
  27.     for i in xrange(64):
  28.         if i < len(salt):
  29.             ch = ord(salt[i])
  30.         else:
  31.             ch = 0
  32.         salt1 += chr(ch ^ 54)
  33.         salt2 += chr(ch ^ 92)
  34.  
  35.     return hashlib.sha1(salt2 + hashlib.sha1(salt1 + s).digest()).hexdigest()
  36.  
  37.  
  38. def sagiri_encode(data, key):
  39.     checksum = crc32(data)
  40.     data = sagiri_crypt(data, checksum ^ crc32(key))
  41.     return base64.b64encode(struct.pack('I', checksum) + data)
  42.  
  43.  
  44. def get_volume_serial():
  45.     return ctypes.c_ulong(win32api.GetVolumeInformation('\\')[1]).value
  46.  
  47.  
  48. def generate_sagiri_licence(status, basename, date, gameid):
  49.     fmt = '=4sI41s41sI41s'
  50.     magic = 'HKS'
  51.     key = gameid
  52.     salt = 'hachikuma'
  53.     basehash = sagiri_hash(basename, "Riatre's Alice Magic")
  54.     hash1 = sagiri_hash('%u:%u:%s:%u' % (status, key, basehash, get_volume_serial()), salt)
  55.     hash2 = sagiri_hash('%u:%u:%s:%u' % (status, key, basehash, date), salt)
  56.     licence = struct.pack(fmt, magic, status, basehash, hash1, date, hash2)
  57.     licence = 'LicenceInfo: ' + sagiri_encode(licence, 'hachikuma')
  58.     return licence
  59.  
  60.  
  61. if __name__ == '__main__':
  62.     try:
  63.         gameid = 10040
  64.         if len(sys.argv) > 1:
  65.             gameid = int(sys.argv[1])
  66.         with open('Licence.dat', 'wt') as fp:
  67.             fp.write(generate_sagiri_licence(1, 'Alice Margatroid Saimoe %u' % random.randint(0, 4294967295L), int(time.time()), gameid))
  68.         ctypes.windll.user32.MessageBoxA(None, 'Done/', '', 64)
  69.     except:
  70.         ctypes.windll.user32.MessageBoxA(None, traceback.format_exc(), 'Error', 16)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement