Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ctypes, win32api
- import struct, random, time, traceback
- import hashlib, zlib, base64, sys
- def crc32(data):
- return ctypes.c_ulong(zlib.crc32(data)).value
- def sagiri_crypt(data, seed):
- a = 362436069
- b = 521288629
- c = 88675123
- res = ''
- lseed = seed
- for ch in data:
- seed = lseed ^ lseed << 11 & 4294967295L
- lseed = a
- a, b, c = b, c, c ^ seed ^ (seed ^ c >> 11) >> 8
- res += chr((ord(ch) ^ c) & 255)
- return res
- def sagiri_hash(s, salt):
- salt1 = ''
- salt2 = ''
- for i in xrange(64):
- if i < len(salt):
- ch = ord(salt[i])
- else:
- ch = 0
- salt1 += chr(ch ^ 54)
- salt2 += chr(ch ^ 92)
- return hashlib.sha1(salt2 + hashlib.sha1(salt1 + s).digest()).hexdigest()
- def sagiri_encode(data, key):
- checksum = crc32(data)
- data = sagiri_crypt(data, checksum ^ crc32(key))
- return base64.b64encode(struct.pack('I', checksum) + data)
- def get_volume_serial():
- return ctypes.c_ulong(win32api.GetVolumeInformation('\\')[1]).value
- def generate_sagiri_licence(status, basename, date, gameid):
- fmt = '=4sI41s41sI41s'
- magic = 'HKS'
- key = gameid
- salt = 'hachikuma'
- basehash = sagiri_hash(basename, "Riatre's Alice Magic")
- hash1 = sagiri_hash('%u:%u:%s:%u' % (status, key, basehash, get_volume_serial()), salt)
- hash2 = sagiri_hash('%u:%u:%s:%u' % (status, key, basehash, date), salt)
- licence = struct.pack(fmt, magic, status, basehash, hash1, date, hash2)
- licence = 'LicenceInfo: ' + sagiri_encode(licence, 'hachikuma')
- return licence
- if __name__ == '__main__':
- try:
- gameid = 10040
- if len(sys.argv) > 1:
- gameid = int(sys.argv[1])
- with open('Licence.dat', 'wt') as fp:
- fp.write(generate_sagiri_licence(1, 'Alice Margatroid Saimoe %u' % random.randint(0, 4294967295L), int(time.time()), gameid))
- ctypes.windll.user32.MessageBoxA(None, 'Done/', '', 64)
- except:
- ctypes.windll.user32.MessageBoxA(None, traceback.format_exc(), 'Error', 16)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement