Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dbg_flag := false
- dbg_trace := ""
- pid_table := []
- base_pid := GetCurrentProcess()
- ffxiv_ppid := GetFFXIVParentPID(base_pid)
- if (ffxiv_ppid) {
- FileAppend %ffxiv_ppid%, *
- ExitApp 0
- }
- if (dbg_flag) {
- FileAppend %dbg_trace%, *
- FileAppend %dbg_trace%, **
- }
- ExitApp 404
- GetParentProcess(PID)
- {
- static function := DllCall("GetProcAddress", "ptr", DllCall("GetModuleHandle", "str", "kernel32.dll", "ptr"), "astr", "Process32Next" (A_IsUnicode ? "W" : ""), "ptr")
- if !(h := DllCall("CreateToolhelp32Snapshot", "uint", 2, "uint", 0))
- return
- VarSetCapacity(pEntry, sz := (A_PtrSize = 8 ? 48 : 36)+(A_IsUnicode ? 520 : 260))
- Numput(sz, pEntry, 0, "uint")
- DllCall("Process32First" (A_IsUnicode ? "W" : ""), "ptr", h, "ptr", &pEntry)
- loop
- {
- if (pid = NumGet(pEntry, 8, "uint") || !DllCall(function, "ptr", h, "ptr", &pEntry))
- break
- }
- DllCall("CloseHandle", "ptr", h)
- return Numget(pEntry, 16+2*A_PtrSize, "uint")
- }
- GetProcessName(PID)
- {
- static function := DllCall("GetProcAddress", "ptr", DllCall("GetModuleHandle", "str", "kernel32.dll", "ptr"), "astr", "Process32Next" (A_IsUnicode ? "W" : ""), "ptr")
- if !(h := DllCall("CreateToolhelp32Snapshot", "uint", 2, "uint", 0))
- return
- VarSetCapacity(pEntry, sz := (A_PtrSize = 8 ? 48 : 36)+260*(A_IsUnicode ? 2 : 1))
- Numput(sz, pEntry, 0, "uint")
- DllCall("Process32First" (A_IsUnicode ? "W" : ""), "ptr", h, "ptr", &pEntry)
- loop
- {
- if (pid = NumGet(pEntry, 8, "uint") || !DllCall(function, "ptr", h, "ptr", &pEntry))
- break
- }
- DllCall("CloseHandle", "ptr", h)
- return StrGet(&pEntry+28+2*A_PtrSize, A_IsUnicode ? "utf-16" : "utf-8")
- }
- GetCurrentProcess()
- {
- return DllCall("GetCurrentProcessId")
- }
- HasVal(haystack, needle) {
- if !(IsObject(haystack)) || (haystack.Length() = 0)
- return 0
- for index, value in haystack
- if (value = needle)
- return index
- return 0
- }
- d(output)
- {
- global dbg_trace
- global dbg_flag
- if (dbg_flag)
- dbg_trace .= "[ffxiv_parent_pid]: " . output . "`n"
- }
- GetFFXIVParentPID(currentPID)
- {
- global pid_table
- d("Examining " . currentPID)
- parentID := GetParentProcess(currentPID)
- d(" Parent ID is " . parentID)
- if not HasVal(pid_table, parentID) {
- d(" We have not seen this PID before, adding [" . parentId . "] to pid_table")
- pid_table.push(parentID)
- parentName := GetProcessName(parentID)
- d(" Process Name is [" . parentName . "]")
- if (parentName = "ffxiv_dx11.exe") {
- d(" Nailed it! Returning " . parentID)
- return parentID
- }
- d(" These are not the droid we are looking for. Moving along...")
- return GetFFXIVParentPID(parentID)
- }
- d(" We've already seen " . parentID . " before, returning 0 to prevent loop")
- return 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement