Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dbg_flag := false
  2. dbg_trace := ""
  3. pid_table := []
  4. base_pid := GetCurrentProcess()
  5. ffxiv_ppid := GetFFXIVParentPID(base_pid)
  6.  
  7. if (ffxiv_ppid) {
  8.     FileAppend %ffxiv_ppid%, *
  9.     ExitApp 0
  10. }
  11. if (dbg_flag) {
  12.     FileAppend %dbg_trace%, *
  13.     FileAppend %dbg_trace%, **
  14. }
  15. ExitApp 404
  16.  
  17. GetParentProcess(PID)
  18. {
  19.   static function := DllCall("GetProcAddress", "ptr", DllCall("GetModuleHandle", "str", "kernel32.dll", "ptr"), "astr", "Process32Next" (A_IsUnicode ? "W" : ""), "ptr")
  20.   if !(h := DllCall("CreateToolhelp32Snapshot", "uint", 2, "uint", 0))
  21.     return
  22.   VarSetCapacity(pEntry, sz := (A_PtrSize = 8 ? 48 : 36)+(A_IsUnicode ? 520 : 260))
  23.   Numput(sz, pEntry, 0, "uint")
  24.   DllCall("Process32First" (A_IsUnicode ? "W" : ""), "ptr", h, "ptr", &pEntry)
  25.   loop
  26.   {
  27.     if (pid = NumGet(pEntry, 8, "uint") || !DllCall(function, "ptr", h, "ptr", &pEntry))
  28.       break
  29.   }
  30.   DllCall("CloseHandle", "ptr", h)
  31.   return Numget(pEntry, 16+2*A_PtrSize, "uint")
  32. }
  33.  
  34. GetProcessName(PID)
  35. {
  36.   static function := DllCall("GetProcAddress", "ptr", DllCall("GetModuleHandle", "str", "kernel32.dll", "ptr"), "astr", "Process32Next" (A_IsUnicode ? "W" : ""), "ptr")
  37.   if !(h := DllCall("CreateToolhelp32Snapshot", "uint", 2, "uint", 0))
  38.     return
  39.   VarSetCapacity(pEntry, sz := (A_PtrSize = 8 ? 48 : 36)+260*(A_IsUnicode ? 2 : 1))
  40.   Numput(sz, pEntry, 0, "uint")
  41.   DllCall("Process32First" (A_IsUnicode ? "W" : ""), "ptr", h, "ptr", &pEntry)
  42.   loop
  43.   {
  44.     if (pid = NumGet(pEntry, 8, "uint") || !DllCall(function, "ptr", h, "ptr", &pEntry))
  45.       break
  46.   }
  47.   DllCall("CloseHandle", "ptr", h)
  48.   return StrGet(&pEntry+28+2*A_PtrSize, A_IsUnicode ? "utf-16" : "utf-8")
  49. }
  50.  
  51. GetCurrentProcess()
  52. {
  53.   return DllCall("GetCurrentProcessId")
  54. }
  55.  
  56. HasVal(haystack, needle) {
  57.     if !(IsObject(haystack)) || (haystack.Length() = 0)
  58.         return 0
  59.     for index, value in haystack
  60.         if (value = needle)
  61.             return index
  62.     return 0
  63. }
  64.  
  65. d(output)
  66. {
  67.     global dbg_trace
  68.     global dbg_flag
  69.    
  70.     if (dbg_flag)
  71.         dbg_trace .= "[ffxiv_parent_pid]: " . output . "`n"
  72.    
  73. }
  74.  
  75. GetFFXIVParentPID(currentPID)
  76. {
  77.     global pid_table
  78.    
  79.     d("Examining " . currentPID)
  80.    
  81.     parentID := GetParentProcess(currentPID)
  82.     d("  Parent ID is " . parentID)
  83.    
  84.     if not HasVal(pid_table, parentID) {
  85.        
  86.         d("  We have not seen this PID before, adding [" . parentId . "] to pid_table")
  87.         pid_table.push(parentID)
  88.        
  89.         parentName := GetProcessName(parentID)
  90.         d("  Process Name is [" . parentName . "]")
  91.        
  92.         if (parentName = "ffxiv_dx11.exe") {
  93.             d("  Nailed it! Returning " . parentID)
  94.             return parentID
  95.         }
  96.        
  97.         d("  These are not the droid we are looking for. Moving along...")
  98.         return GetFFXIVParentPID(parentID)
  99.     }
  100.         d("  We've already seen " . parentID . " before, returning 0 to prevent loop")
  101.         return 0
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement