Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
PolicyPuma4 authored Apr 19, 2023
1 parent 1672924 commit 4c866a1
Showing 1 changed file with 52 additions and 41 deletions.
93 changes: 52 additions & 41 deletions PersistentInstant.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
FILE_MAP_READ := 0x4
A_LocalAppData := EnvGet("LOCALAPPDATA")

getPortSecret() {

setInstantReplay(status) {
hMapFile := DllCall("OpenFileMapping", "Ptr", FILE_MAP_READ, "Int", 0, "Str", "{8BA1E16C-FC54-4595-9782-E370A5FBE8DA}")
if not hMapFile {
return
Expand All @@ -29,20 +30,14 @@ getPortSecret() {
DllCall("UnmapViewOfFile", "Ptr", pBuf)
DllCall("CloseHandle", "Ptr", hMapFile)

return {
port: SubStr(string, 9, 5),
secret: SubStr(string, 25, 32),
}
}

enableInstantReplay(portSecret) {
whr := ComObject("WinHttp.WinHttpRequest.5.1")
whr.Open("POST", "http://localhost:" portSecret.port "/ShadowPlay/v.1.0/InstantReplay/Enable", false)
whr.SetRequestHeader("X_LOCAL_SECURITY_COOKIE", portSecret.secret)
whr.Open("POST", "http://localhost:" SubStr(string, 9, 5) "/ShadowPlay/v.1.0/InstantReplay/Enable", false)
whr.SetRequestHeader("X_LOCAL_SECURITY_COOKIE", SubStr(string, 25, 32))
whr.SetRequestHeader("Content-Type", "application/json")
whr.Send("{`"status`":true}")
whr.Send("{`"status`":" (status ? "true" : "false") "}")
}


arg := A_Args.Length ? A_Args[1] : ""
installPath := A_LocalAppData "\Programs\PersistentInstant"
installFullPath := installPath "\PersistentInstant.exe"
Expand Down Expand Up @@ -81,20 +76,51 @@ if (not A_ScriptDir = installPath) {
ExitApp
}

if (not FileExist("denylist.txt")) {
FileAppend("`"C:\Windows\system32\wwahost.exe`" -ServerName:Netflix.App.wwa`r`n`"C:\Program Files\WindowsApps\AmazonVideo.PrimeVideo_1.0.84.0_x64__pwbj9vvecjh7j\PrimeVideo.exe`" -ServerName:App.AppX21qthfa64w8vh9emhw9pfwse20vpg5n9.mca`r`n", "denylist.txt")
}

if (not FileExist("allowlist.txt")) {
FileAppend("`"C:\Windows\system32\wwahost.exe`" -ServerName:Netflix.App.wwa`n`"C:\Program Files\WindowsApps\AmazonVideo.PrimeVideo_1.0.84.0_x64__pwbj9vvecjh7j\PrimeVideo.exe`" -ServerName:App.AppX21qthfa64w8vh9emhw9pfwse20vpg5n9.mca`n", "allowlist.txt")
FileAppend("", "allowlist.txt")
}

A_IconTip := "PersistentInstant"
A_TrayMenu.Add()
A_TrayMenu.Add("Edit allow list", editAllowList)
A_TrayMenu.Add("Edit deny list", menuHandler)
A_TrayMenu.Add("Edit allow list", menuHandler)

editAllowList(*) {
Run("notepad.exe " installPath "\allowlist.txt")

menuHandler(itemName, *) {
if (itemName = "Edit deny list") {
Run("notepad.exe " installPath "\denylist.txt")
}

if (itemName = "Edit allow list") {
Run("notepad.exe " installPath "\allowlist.txt")
}
}

allowedProcesses := StrSplit(FileRead("allowlist.txt"), "`n", "`r")

deny := StrSplit(Trim(FileRead("denylist.txt"), "`r`n"), "`r`n")
allow := StrSplit(Trim(FileRead("allowlist.txt"), "`r`n"), "`r`n")


exists(items) {
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process") {
for item in items {
if (InStr(process.CommandLine, item) = 1) {
return process.ProcessId
}

if (InStr(process.ExecutablePath, item) = 1) {
return process.ProcessId
}
}
}
}


monitoringProcess := false
sleepTime := 1 * 60 * 1000
loop {
if (A_Index > 1) {
Expand All @@ -103,40 +129,25 @@ loop {

isEnabled := RegRead("HKEY_CURRENT_USER\SOFTWARE\NVIDIA Corporation\Global\ShadowPlay\NVSPCAPS", "{1B1D3DAA-601D-49E5-8508-81736CA28C6D}", "")
if (isEnabled) {
if (allow.Length and not ProcessExist(monitoringProcess)) {
setInstantReplay(false)
}

continue
}

isAllowed := false
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process") {
for allowedProcess in allowedProcesses {
if (not allowedProcess) {
continue
}

if (InStr(process.CommandLine, allowedProcess) = 1) {
isAllowed := true
break
}

if (InStr(process.ExecutablePath, allowedProcess) = 1) {
isAllowed := true
break
}
}

if (isAllowed) {
break
if (allow.Length) {
monitoringProcess := exists(allow)
if monitoringProcess {
setInstantReplay(true)
}
}

if (isAllowed) {
continue
}

portSecret := getPortSecret()
if (not portSecret) {
if (exists(deny)) {
continue
}

enableInstantReplay(portSecret)
setInstantReplay(true)
}

0 comments on commit 4c866a1

Please sign in to comment.