mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
* feat: Add experimental proxy based npm interceptor * refactor: Analysis cache * ci: Add E2E for npm proxy * fix: Handle dry-run in proxy flow * fix: Handle special case for scope package name * fix: Misc fixes * fix: Code review fixes * fix: Code review fixes * refactor: Reusable code into base registry interceptor * Pause npm process during user confirmation (#90) * pause npm process when prompting user for confirmation * disable progress bar * fix logging and close chan on return * update use of deprecated field * refactor: Separation of concerns for handling process state * fix: Safe permission for cert file * fix: Handle nil check for interaction hook * fix: Add test for base registry * Fix goreleaser for windows build (#93) * introduce platform specific process control * rename common.go to common_flow.go * feat: Add support for pause resume on windows * fix: Code review fixes * test: Add confirmation handler tests --------- Co-authored-by: Sahil Bansal <bansalsahil315@gmail.com>
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package flows
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
var (
|
|
modntdll = windows.NewLazySystemDLL("ntdll.dll")
|
|
procNtSuspendProcess = modntdll.NewProc("NtSuspendProcess")
|
|
procNtResumeProcess = modntdll.NewProc("NtResumeProcess")
|
|
)
|
|
|
|
// platformPauseProcess suspends the process using Windows NT API.
|
|
//
|
|
// Known limitations:
|
|
// - Race condition: threads created during suspension are not suspended
|
|
// - Remote thread injection still possible (very rare)
|
|
//
|
|
// For PMG's use case (brief suspension during user prompts), these limitations
|
|
// are acceptable.
|
|
//
|
|
// References:
|
|
// - gopsutil: https://github.com/shirou/gopsutil/blob/master/process/process_windows.go
|
|
// - Analysis: https://github.com/diversenok/Suspending-Techniques
|
|
func platformPauseProcess(cmd *exec.Cmd) error {
|
|
if cmd == nil || cmd.Process == nil {
|
|
return nil
|
|
}
|
|
|
|
handle, err := windows.OpenProcess(
|
|
windows.PROCESS_SUSPEND_RESUME,
|
|
false,
|
|
uint32(cmd.Process.Pid),
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to open process for suspension: %w", err)
|
|
}
|
|
|
|
defer windows.CloseHandle(handle)
|
|
|
|
r1, _, _ := procNtSuspendProcess.Call(uintptr(handle))
|
|
if r1 != 0 {
|
|
return fmt.Errorf("NtSuspendProcess failed with NTSTATUS=0x%.8X", r1)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// platformResumeProcess resumes a suspended process using Windows NT API.
|
|
func platformResumeProcess(cmd *exec.Cmd) error {
|
|
if cmd == nil || cmd.Process == nil {
|
|
return nil
|
|
}
|
|
|
|
handle, err := windows.OpenProcess(
|
|
windows.PROCESS_SUSPEND_RESUME,
|
|
false,
|
|
uint32(cmd.Process.Pid),
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to open process for resumption: %w", err)
|
|
}
|
|
|
|
defer windows.CloseHandle(handle)
|
|
|
|
r1, _, _ := procNtResumeProcess.Call(uintptr(handle))
|
|
if r1 != 0 {
|
|
return fmt.Errorf("NtResumeProcess failed with NTSTATUS=0x%.8X", r1)
|
|
}
|
|
|
|
return nil
|
|
}
|