This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
163 lines (145 loc) · 4.43 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python3
# coding: UTF-8
# StudentMain Manager main functions are put here.
import os
import shutil
import psutil
import configparser
import winreg
# Default config file.
defaultConfigFile = '[JiYu]\n'
defaultConfigFile += 'pathToJiYu=C:\\\\Program Files\\\\TopDomain\\\\e-Learning Class\\\\\n'
defaultConfigFile += '\n'
defaultConfigFile += '[utilities]\n'
defaultConfigFile += 'ntsdPath=.\\\\binaries\\\\ntsd.exe\n'
defaultConfigFile += 'suspenderPath=.\\\\binaries\\\\pssuspend.exe\n'
defaultConfigFile += 'jiYuTrainerPath=.\\\\binaries\\\\JiYuTrainer\\\\JiYuTrainer.exe\n'
defaultConfigFile += '\n'
defaultConfigFile += '[Misc]\n'
defaultConfigFile += 'stayOnTop=1'
# Check if config file exists.
if os.path.isfile('config.ini'):
# Open the config file.
configFile = open('config.ini')
else:
# Create the config file.
configFile = open('config.ini', 'w')
configFile.write(defaultConfigFile)
configFile.close()
# Attach the parser to the config file.
parser = configparser.ConfigParser()
parser.read('config.ini')
# Get the information from the parser.
jiYuPath = parser.get('JiYu', 'pathToJiYu')
ntsdPath = parser.get('utilities', 'ntsdPath')
suspenderPath = parser.get('utilities', 'suspenderPath')
trainerPath = parser.get('utilities', 'trainerPath')
patchedSethcPath = parser.get('utilities', 'patchedSethcPath')
if parser.get('Misc', 'stayOnTop') == '0':
winOnTop = False
else:
winOnTop = True
# Get JiYu Status.
def getJiYuStatus():
jiYuExist = os.path.isfile(jiYuPath)
jiYuProc = findJiYuProc()
if jiYuProc != None:
jiYuRunningStatus = jiYuProc.status()
else:
jiYuRunningStatus = 'NotFound'
return jiYuExist, jiYuRunningStatus
def findJiYuProc():
pids = psutil.pids()
for i in pids:
proc = psutil.Process(i)
procName = proc.name()
if procName == 'JiYuTrainer.exe':
return proc
return None
# Kill JiYu with NTSD.
def NTSDKill():
if os.path.isfile(ntsdPath):
os.popen('.\\binaries\\ntsd.exe -c q -pn StudentMain.exe')
return 0
else:
return 1
# Suspend JiYu with PsSuspend.
def suspend():
if os.path.isfile(suspenderPath):
if 'suspended' in os.popen(suspenderPath + ' StudentMain.exe'):
return 0
else:
return 1
else:
return -1
# Trash JiYu by removing the install directory.
def trashJiYu():
if os.path.isdir(jiYuPath):
os.rmdir(jiYuPath)
return 0
else:
return 1
# Launch a fullscreened IE.
def fullscreenIE():
os.popen('cmd /c "start iexplore.exe -k"')
# Get the password from the registry.
def readPassword():
try:
handle = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\\TopDomain\\e-Learning Class Standard\\1.00')
passString, regType = winreg.QueryValueEx(handle, 'UninstallPasswd')
password = passString[7:-1]
return password
except WindowsError:
return None
# Replace C:\Windows\System32\sethc.exe with a patched one.
def replaceSethc():
env = os.environ
windir = env['windir']
try:
os.rename(windir + '\\System32\\sethc.exe', windir + '\\System32\\sethc_bak.exe')
shutil.copy('.\\binaries\\PSethc.exe', windir + '\\System32\\sethc.exe')
return 0
except PermissionError:
return 1
# Restore the patched sethc.
def restoreSethc():
env = os.environ
windir = env['windir']
try:
os.remove(windir + '\\System32\\sethc.exe')
os.rename(windir + '\\System32\\sethc_bak.exe', windir + '\\System32\\sethc.exe')
return 0
except PermissionError:
return 1
# Launch JiYuTrainer.
def launchTrainer():
if os.path.isfile(trainerPath):
os.system(trainerPath)
return 0
else:
return 1
# Launch JiYu.
def launchJiYu():
if os.path.isfile(jiYuPath):
os.system(jiYuPath + 'StudentMain.exe')
return 0
else:
return 1
# Resume JiYu with PsSuspend.
def resume():
if os.path.isfile(suspenderPath):
if 'suspended' in os.popen(suspenderPath + ' -r StudentMain.exe'):
return 0
else:
return 1
else:
return -1
# Write config file.
def writeConfig(newPath, newWindowOnTop):
parser.set('JiYu', 'pathToJiYu', newPath)
if newWindowOnTop:
parser.set('Misc', 'stayOnTop', '1')
else:
parser.set('Misc', 'stayOnTop', '0')
with open('config.ini', 'w+') as file:
parser.write(file)