Created
March 17, 2013 16:55
-
-
Save averrin/5182430 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from __future__ import print_function | |
| import os | |
| import logging | |
| logging.basicConfig(format='[%(asctime)s] %(levelname)s:\t\t%(message)s', filename='check_morrowind.log', level=logging.DEBUG, | |
| datefmt='%d.%m %H:%M:%S') | |
| __author__ = 'Alexey "Averrin" Nabrodov' | |
| __version__ = '0.1' | |
| try: | |
| import winreg | |
| except ImportError: | |
| import _winreg as winreg | |
| import platform | |
| import hashlib | |
| from win32com.client import Dispatch | |
| arch = platform.machine() | |
| REG_KEYS = {'HKEY_LOCAL_MACHINE': winreg.HKEY_LOCAL_MACHINE, 'HKEY_CURRENT_USER': winreg.HKEY_CURRENT_USER, | |
| 'HKLM': winreg.HKEY_LOCAL_MACHINE, 'HKCU': winreg.HKEY_CURRENT_USER,} | |
| STEAM_ID = 22320 | |
| if arch == 'AMD64': | |
| wow = 'Wow6432Node\\' | |
| else: | |
| wow = '' | |
| app_path = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\morrowind.exe' | |
| path = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\%sBethesda Softworks\\Morrowind' #Steam version has no "Installed Path" here | |
| uninstall_steam = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\%%sMicrosoft\\Windows\\CurrentVersion\\Uninstall\\Steam App %s' % STEAM_ID | |
| steam_path = 'HKEY_CURRENT_USER\\Software\\Valve\\Steam' | |
| steam_morrowind_postfix = '\\Apps\\%s' % STEAM_ID | |
| versions = { | |
| '38268efe176de02193ed8b5babb20d6231f1324113c65b7fc5308e51d4fde5d3': { | |
| 'version': '1.2.0.722', | |
| 'desc': 'Russian 1C. No addons' | |
| }, | |
| '26cc5aa36ebf07e38cea398c21759e3100f57f6336738dd00387ab220fad7663': { | |
| 'version': '1.3.0.1029', | |
| 'desc': 'Russian 1C. With Tribunal' | |
| }, | |
| '14e5eb34b249358a48eb0d8c8be8504e66e32bed945fd0298bf9128757e9932c': { | |
| 'version': '1.4.0.1313', | |
| 'desc': 'Russian 1C. With Tribunal. Patched' | |
| }, | |
| '496faca0b8e683431cbe0f0b5462cfc32c45e8af24c0ba5fff3d392cbc869cae': { | |
| 'version': '1.6.0.1820', | |
| 'desc': 'Steam GOTY. MGSO installed' | |
| }, | |
| 'eac72e1b3524ee0012d080d3c2e2e00e401464e41ee54f9afd6aaaadf2c221f5': { | |
| 'version': '1.6.0.1820', | |
| 'desc': 'Russian 1C. Steam GOTY' | |
| }, | |
| 'ecb347304134f63cabf1ab38f0728dcff5fbfb11e7ac2b87a03c8639936ab094': { | |
| 'version': '1.6.0.1820', | |
| 'desc': 'Russian 1C. With Bloodmoon (+Tribunal)' | |
| }, | |
| } | |
| cracked = {'a0dfd7343dc40d8c61da6178912ff1988086f9d32695fe44dc3522662d90e2ce': {'version': '1.6.0.1820', 'desc': 'http://xtes.ru/index.php?name=downloads&op=full&file=7'}, | |
| '2899d97d6430d68d08bb28cde663c82962c273e0991541f067074b8d399945f7': {'version': '1.6.0.1820', 'desc': 'http://nodvd.net/912-the-elder-scrolls-iii-morrowind-v16-ru-nodvd.html'}} | |
| path = path % wow | |
| uninstall = uninstall_steam % wow | |
| def check_steam(): | |
| try: | |
| installed = int(get_reg_value(get_reg_key(steam_path + steam_morrowind_postfix), 'Installed')) | |
| if installed: | |
| return True | |
| else: | |
| return False | |
| except: | |
| return False | |
| def get_reg_key(key): | |
| if key.split('\\')[0] in REG_KEYS: | |
| parent = REG_KEYS[key.split('\\')[0]] | |
| key = '\\'.join(key.split('\\')[1:]) | |
| else: | |
| raise Exception('Wrong key format') | |
| return winreg.OpenKey(parent, key) | |
| def enum_reg_values(key): | |
| print(key) | |
| key = get_reg_key(key) | |
| try: | |
| i = 0 | |
| while 1: | |
| name, value, reg_type = winreg.EnumValue(key, i) | |
| print('\t', repr(name), get_reg_value(key, name)) | |
| i += 1 | |
| except WindowsError: | |
| pass | |
| def get_reg_value(key, subkey): | |
| result = winreg.QueryValueEx(key, subkey)[0] | |
| return result | |
| def exe_info(path): | |
| m = hashlib.sha256(open(path, 'rb').read()) | |
| ver_parser = Dispatch('Scripting.FileSystemObject') | |
| version = ver_parser.GetFileVersion(path) | |
| hash = m.hexdigest() | |
| if hash not in versions: | |
| if hash in cracked: | |
| logging.info('Morrowind.exe was cracked') | |
| print('Morrowind.exe was cracked') | |
| else: | |
| logging.info(hash, version) | |
| print(hash, version) | |
| logging.info('Unknown hash') | |
| print('Unknown hash') | |
| return False | |
| else: | |
| if version != versions[hash]['version']: | |
| logging.info(hash, version) | |
| print(hash, version) | |
| logging.info('Version and hash not math') | |
| print('Version and hash not math') | |
| return False | |
| return hash, version, versions[hash]['desc'] | |
| def get_path(version): | |
| if version == 'Steam': | |
| steam_dir = get_reg_value(get_reg_key(steam_path), 'SteamPath') | |
| logging.info('Steam folder: "%s"' % steam_dir) | |
| print('Steam folder: "%s"' % steam_dir) | |
| return os.path.normpath(os.path.join(steam_dir, 'SteamApps\\common\\Morrowind')) | |
| else: | |
| return os.path.normpath(get_reg_value(get_reg_key(path), 'Installed Path')) | |
| def check_valid_exe(morrowind_dir): | |
| logging.info('Morrowind folder: "%s"' % morrowind_dir) | |
| print('Morrowind folder: "%s"' % morrowind_dir) | |
| if os.path.isdir(morrowind_dir): | |
| morrowind_exe = os.path.join(morrowind_dir, 'Morrowind.exe') | |
| # morrowind_launcher = os.path.join(morrowind_dir, 'Morrowind Launcher.exe') | |
| if os.path.isfile(morrowind_exe): | |
| return exe_info(morrowind_exe) | |
| else: | |
| logging.info('No Morrowind.exe founded') | |
| print('No Morrowind.exe founded') | |
| return False | |
| else: | |
| logging.info('Folder not exists') | |
| print('Folder not exists') | |
| return False | |
| def main(): | |
| logging.info('Start') | |
| is_steam = check_steam() | |
| if is_steam: | |
| logging.info('Steam version detected') | |
| print('Steam version detected') | |
| morrowind_version = 'Steam' | |
| else: | |
| morrowind_version = 'Retail' | |
| try: | |
| morrowind_dir = get_path(morrowind_version) | |
| is_valid = check_valid_exe(morrowind_dir) | |
| if is_valid: | |
| logging.info('Morrowind version: %s [%s]' % is_valid[1:]) | |
| print('Morrowind version: %s [%s]' % is_valid[1:]) | |
| else: | |
| logging.info('Unknown Morrowind.exe file') | |
| print('Unknown Morrowind.exe file') | |
| except: | |
| logging.info('No Morrowind detected') | |
| print('No Morrowind detected') | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment