diff --git a/pkg/memory/process.go b/pkg/memory/process.go index caecd0a..44c54e4 100644 --- a/pkg/memory/process.go +++ b/pkg/memory/process.go @@ -3,6 +3,7 @@ package memory import ( "bytes" "encoding/binary" + "errors" "golang.org/x/sys/windows" "strings" "syscall" @@ -37,6 +38,25 @@ func NewProcess() (Process, error) { }, nil } +func NewProcessForPID(pid uint32) (Process, error) { + module, found := getMainModule(pid) + if found { + return Process{}, errors.New("no module found for the specified PID") + } + + h, err := windows.OpenProcess(0x0010, false, module.ProcessID) + if err != nil { + return Process{}, err + } + + return Process{ + handler: h, + pid: module.ProcessID, + moduleBaseAddressPtr: module.ModuleBaseAddress, + moduleBaseSize: module.ModuleBaseSize, + }, nil +} + func getGameModule() (ModuleInfo, error) { processes := make([]uint32, 2048) length := uint32(0)