Allow application to online systems

This commit is contained in:
Fierelier 2022-06-08 15:25:12 +02:00
parent 3273df6e22
commit b3a9598718
2 changed files with 54 additions and 9 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3
dummyMode = False
if __name__ == "__main__":
print("this is supposed to be imported")
exit()
@ -8,7 +8,28 @@ print("opus-nt api says hello world")
import os
import subprocess
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 = {
"type": False, # "wim", "offline" - whether to target a wim file or an offline installed windows
@ -21,8 +42,15 @@ tmpPath = "tmp"
regTmpPath = "HKEY_LOCAL_MACHINE\\opus-nt_"
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
try:
if dummyMode:
print(cmd)
else:
subprocess.run(cmd,stdout=subprocess.DEVNULL,check=True)
except Exception as e:
if check == True: raise e
@ -44,6 +72,7 @@ def getModlist(path):
return modList
def addFiles(path):
if dummyMode: return
if target["type"] == "offline":
for root,dirs,files in os.walk(path):
for file in dirs:
@ -75,7 +104,7 @@ def addFiles(path):
],check=True,stdout=subprocess.DEVNULL)
def readyFile(path):
if target["type"] == "offline": return
if target["type"] in ["offline","online"]: return
if target["type"] == "wim":
subprocess.run([
@ -86,6 +115,7 @@ def readyFile(path):
],check=True,stdout=subprocess.DEVNULL)
def renameFile(path,newpath):
if dummyMode: return
if target["type"] == "offline":
os.rename(filePath(path),filePath(newpath))
@ -97,6 +127,7 @@ def renameFile(path,newpath):
],check=True,stdout=subprocess.DEVNULL)
def removeFile(path):
if dummyMode: return
if target["type"] == "offline":
os.remove(filePath(path))
@ -129,10 +160,17 @@ def fileExists(path):
return True
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)
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])
def unmountReg(path):
@ -140,6 +178,7 @@ def unmountReg(path):
def getVersion(hkey,SOFTWARE):
versionData = {}
if target["type"] == "online": SOFTWARE = "software"
key = winreg.OpenKey(hkey,SOFTWARE + "\\Microsoft\\Windows NT\\CurrentVersion")
isTen = False
@ -168,7 +207,6 @@ def getVersion(hkey,SOFTWARE):
else: # this sucks
versionData["architecture"] = "ia64"
global target
target["version"] = versionData
def getMaxIndex():
@ -190,7 +228,14 @@ def getMaxIndex():
return
def regQueryKeys(rp):
if target["type"] == "online": rp = applyRegmap(rp)
output = subprocess.check_output(["reg","query",rp,"/f","*","/k"]).decode("utf-8","ignore")
output = output.split("\r\n")
output = output[1:-2]
return output
def applyRegmap(rp):
for path in target["regmap"]:
if rp.startswith(path):
return rp.replace(path,target["regmap"][path],1)
return rp

View File

@ -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"])