Allow application to online systems
This commit is contained in:
parent
3273df6e22
commit
b3a9598718
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
dummyMode = False
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("this is supposed to be imported")
|
print("this is supposed to be imported")
|
||||||
exit()
|
exit()
|
||||||
@ -8,7 +8,28 @@ print("opus-nt api says hello world")
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import winreg
|
import winreg
|
||||||
p = os.path.join
|
def p(*args):
|
||||||
|
args = list(args)
|
||||||
|
index = 0
|
||||||
|
length = len(args)
|
||||||
|
while index < length:
|
||||||
|
arg = args[index]
|
||||||
|
arg = arg.replace("/",os.path.sep)
|
||||||
|
arg = arg.replace("\\",os.path.sep)
|
||||||
|
if index != 0: arg = arg.lstrip(os.path.sep)
|
||||||
|
arg = arg.rstrip(os.path.sep)
|
||||||
|
while os.path.sep + os.path.sep in arg:
|
||||||
|
arg = arg.replace(os.path.sep + os.path.sep,os.path.sep)
|
||||||
|
|
||||||
|
if arg == "":
|
||||||
|
del args[index]
|
||||||
|
length -= 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
args[index] = arg
|
||||||
|
index += 1
|
||||||
|
|
||||||
|
return os.path.sep.join(args)
|
||||||
|
|
||||||
target = {
|
target = {
|
||||||
"type": False, # "wim", "offline" - whether to target a wim file or an offline installed windows
|
"type": False, # "wim", "offline" - whether to target a wim file or an offline installed windows
|
||||||
@ -21,9 +42,16 @@ tmpPath = "tmp"
|
|||||||
regTmpPath = "HKEY_LOCAL_MACHINE\\opus-nt_"
|
regTmpPath = "HKEY_LOCAL_MACHINE\\opus-nt_"
|
||||||
|
|
||||||
def runReg(cmd,check = True):
|
def runReg(cmd,check = True):
|
||||||
|
if target["type"] == "online":
|
||||||
|
cmd[1] = applyRegmap(cmd[1])
|
||||||
|
if cmd[0] == "unload":
|
||||||
|
if not cmd[1].startswith(regTmpPath): return
|
||||||
cmd = ["reg"] + cmd
|
cmd = ["reg"] + cmd
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd,stdout=subprocess.DEVNULL,check=True)
|
if dummyMode:
|
||||||
|
print(cmd)
|
||||||
|
else:
|
||||||
|
subprocess.run(cmd,stdout=subprocess.DEVNULL,check=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if check == True: raise e
|
if check == True: raise e
|
||||||
|
|
||||||
@ -44,6 +72,7 @@ def getModlist(path):
|
|||||||
return modList
|
return modList
|
||||||
|
|
||||||
def addFiles(path):
|
def addFiles(path):
|
||||||
|
if dummyMode: return
|
||||||
if target["type"] == "offline":
|
if target["type"] == "offline":
|
||||||
for root,dirs,files in os.walk(path):
|
for root,dirs,files in os.walk(path):
|
||||||
for file in dirs:
|
for file in dirs:
|
||||||
@ -75,7 +104,7 @@ def addFiles(path):
|
|||||||
],check=True,stdout=subprocess.DEVNULL)
|
],check=True,stdout=subprocess.DEVNULL)
|
||||||
|
|
||||||
def readyFile(path):
|
def readyFile(path):
|
||||||
if target["type"] == "offline": return
|
if target["type"] in ["offline","online"]: return
|
||||||
|
|
||||||
if target["type"] == "wim":
|
if target["type"] == "wim":
|
||||||
subprocess.run([
|
subprocess.run([
|
||||||
@ -86,6 +115,7 @@ def readyFile(path):
|
|||||||
],check=True,stdout=subprocess.DEVNULL)
|
],check=True,stdout=subprocess.DEVNULL)
|
||||||
|
|
||||||
def renameFile(path,newpath):
|
def renameFile(path,newpath):
|
||||||
|
if dummyMode: return
|
||||||
if target["type"] == "offline":
|
if target["type"] == "offline":
|
||||||
os.rename(filePath(path),filePath(newpath))
|
os.rename(filePath(path),filePath(newpath))
|
||||||
|
|
||||||
@ -97,6 +127,7 @@ def renameFile(path,newpath):
|
|||||||
],check=True,stdout=subprocess.DEVNULL)
|
],check=True,stdout=subprocess.DEVNULL)
|
||||||
|
|
||||||
def removeFile(path):
|
def removeFile(path):
|
||||||
|
if dummyMode: return
|
||||||
if target["type"] == "offline":
|
if target["type"] == "offline":
|
||||||
os.remove(filePath(path))
|
os.remove(filePath(path))
|
||||||
|
|
||||||
@ -129,10 +160,17 @@ def fileExists(path):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def filePath(path):
|
def filePath(path):
|
||||||
if target["type"] == "offline": return p(target["path"],path)
|
if target["type"] in ["offline","online"]: return p(target["path"],path)
|
||||||
if target["type"] == "wim": return p(tmpPath,path)
|
if target["type"] == "wim": return p(tmpPath,path)
|
||||||
|
|
||||||
def mountReg(path,regFile):
|
def mountReg(path,regFile,regList,reg):
|
||||||
|
if target["type"] == "online":
|
||||||
|
try:
|
||||||
|
runReg(["load",path,regFile])
|
||||||
|
except Exception:
|
||||||
|
if reg.startswith("user-"):
|
||||||
|
del regList[reg]
|
||||||
|
return
|
||||||
runReg(["load",path,regFile])
|
runReg(["load",path,regFile])
|
||||||
|
|
||||||
def unmountReg(path):
|
def unmountReg(path):
|
||||||
@ -140,6 +178,7 @@ def unmountReg(path):
|
|||||||
|
|
||||||
def getVersion(hkey,SOFTWARE):
|
def getVersion(hkey,SOFTWARE):
|
||||||
versionData = {}
|
versionData = {}
|
||||||
|
if target["type"] == "online": SOFTWARE = "software"
|
||||||
key = winreg.OpenKey(hkey,SOFTWARE + "\\Microsoft\\Windows NT\\CurrentVersion")
|
key = winreg.OpenKey(hkey,SOFTWARE + "\\Microsoft\\Windows NT\\CurrentVersion")
|
||||||
|
|
||||||
isTen = False
|
isTen = False
|
||||||
@ -168,7 +207,6 @@ def getVersion(hkey,SOFTWARE):
|
|||||||
else: # this sucks
|
else: # this sucks
|
||||||
versionData["architecture"] = "ia64"
|
versionData["architecture"] = "ia64"
|
||||||
|
|
||||||
global target
|
|
||||||
target["version"] = versionData
|
target["version"] = versionData
|
||||||
|
|
||||||
def getMaxIndex():
|
def getMaxIndex():
|
||||||
@ -190,7 +228,14 @@ def getMaxIndex():
|
|||||||
return
|
return
|
||||||
|
|
||||||
def regQueryKeys(rp):
|
def regQueryKeys(rp):
|
||||||
|
if target["type"] == "online": rp = applyRegmap(rp)
|
||||||
output = subprocess.check_output(["reg","query",rp,"/f","*","/k"]).decode("utf-8","ignore")
|
output = subprocess.check_output(["reg","query",rp,"/f","*","/k"]).decode("utf-8","ignore")
|
||||||
output = output.split("\r\n")
|
output = output.split("\r\n")
|
||||||
output = output[1:-2]
|
output = output[1:-2]
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def applyRegmap(rp):
|
||||||
|
for path in target["regmap"]:
|
||||||
|
if rp.startswith(path):
|
||||||
|
return rp.replace(path,target["regmap"][path],1)
|
||||||
|
return rp
|
@ -1 +1 @@
|
|||||||
opusnt.runReg(["add",opusnt.regTmpPath + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Attachments","/v","SaveZoneInformation","/t","REG_DWORD","/d","1","/f"])
|
opusnt.runReg(["add",opusnt.regTmpPath + "software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Attachments","/v","SaveZoneInformation","/t","REG_DWORD","/d","1","/f"])
|
||||||
|
Loading…
Reference in New Issue
Block a user