From 661b686ae81c5b3cea168e666187582216d73df0 Mon Sep 17 00:00:00 2001 From: Zusier Date: Sat, 4 Dec 2021 09:54:57 -0600 Subject: [PATCH] Rename folder --- {gamemode => gameutil}/.gitignore | 30 ++-- {gamemode => gameutil}/WindowsProcess.go | 162 +++++++++++----------- {gamemode => gameutil}/build.bat | 0 {gamemode => gameutil}/config.go | 60 ++++---- {gamemode => gameutil}/config.json | 0 {gamemode => gameutil}/go.mod | 0 {gamemode => gameutil}/go.sum | 0 {gamemode => gameutil}/launch-example.bat | 2 +- {gamemode => gameutil}/main.go | 0 {gamemode => gameutil}/win32api.go | 124 ++++++++--------- 10 files changed, 189 insertions(+), 189 deletions(-) rename {gamemode => gameutil}/.gitignore (94%) rename {gamemode => gameutil}/WindowsProcess.go (95%) rename {gamemode => gameutil}/build.bat (100%) rename {gamemode => gameutil}/config.go (93%) rename {gamemode => gameutil}/config.json (100%) rename {gamemode => gameutil}/go.mod (100%) rename {gamemode => gameutil}/go.sum (100%) rename {gamemode => gameutil}/launch-example.bat (98%) rename {gamemode => gameutil}/main.go (100%) rename {gamemode => gameutil}/win32api.go (96%) diff --git a/gamemode/.gitignore b/gameutil/.gitignore similarity index 94% rename from gamemode/.gitignore rename to gameutil/.gitignore index 9b0d83c..66fd13c 100644 --- a/gamemode/.gitignore +++ b/gameutil/.gitignore @@ -1,15 +1,15 @@ -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -# vendor/ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ diff --git a/gamemode/WindowsProcess.go b/gameutil/WindowsProcess.go similarity index 95% rename from gamemode/WindowsProcess.go rename to gameutil/WindowsProcess.go index 7798683..22d7846 100644 --- a/gamemode/WindowsProcess.go +++ b/gameutil/WindowsProcess.go @@ -1,81 +1,81 @@ -// authored by @spddl, thank you! -package main - -import ( - "strconv" - "strings" - "syscall" - "unsafe" - - "golang.org/x/sys/windows" -) - -const TH32CS_SNAPPROCESS = 0x00000002 - -type Processes struct { - Processes []Process -} - -type Process struct { - ProcessID int - ParentProcessID int - Exe string -} - -func (wp *Processes) getProcesses() error { - handle, err := windows.CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) - if err != nil { - return err - } - defer windows.CloseHandle(handle) - - var entry windows.ProcessEntry32 - entry.Size = uint32(unsafe.Sizeof(entry)) - - // get the first process - err = windows.Process32First(handle, &entry) - if err != nil { - return err - } - - for { - wp.Processes = append(wp.Processes, newWindowsProcess(&entry)) - - err = windows.Process32Next(handle, &entry) - if err != nil { - // windows sends ERROR_NO_MORE_FILES on last process - if err == syscall.ERROR_NO_MORE_FILES { - return nil - } - return err - } - } -} - -func (wp Processes) findProcessIDByNames(names []string) []string { - var result []string - for _, p := range wp.Processes { - for _, name := range names { - if strings.EqualFold(p.Exe, name) { - result = append(result, strconv.Itoa(p.ProcessID)) - } - } - - } - return result -} -func newWindowsProcess(e *windows.ProcessEntry32) Process { - // Find when the string ends for decoding - end := 0 - for { - if e.ExeFile[end] == 0 { - break - } - end++ - } - return Process{ - ProcessID: int(e.ProcessID), - ParentProcessID: int(e.ParentProcessID), - Exe: syscall.UTF16ToString(e.ExeFile[:end]), - } -} +// authored by @spddl, thank you! +package main + +import ( + "strconv" + "strings" + "syscall" + "unsafe" + + "golang.org/x/sys/windows" +) + +const TH32CS_SNAPPROCESS = 0x00000002 + +type Processes struct { + Processes []Process +} + +type Process struct { + ProcessID int + ParentProcessID int + Exe string +} + +func (wp *Processes) getProcesses() error { + handle, err := windows.CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) + if err != nil { + return err + } + defer windows.CloseHandle(handle) + + var entry windows.ProcessEntry32 + entry.Size = uint32(unsafe.Sizeof(entry)) + + // get the first process + err = windows.Process32First(handle, &entry) + if err != nil { + return err + } + + for { + wp.Processes = append(wp.Processes, newWindowsProcess(&entry)) + + err = windows.Process32Next(handle, &entry) + if err != nil { + // windows sends ERROR_NO_MORE_FILES on last process + if err == syscall.ERROR_NO_MORE_FILES { + return nil + } + return err + } + } +} + +func (wp Processes) findProcessIDByNames(names []string) []string { + var result []string + for _, p := range wp.Processes { + for _, name := range names { + if strings.EqualFold(p.Exe, name) { + result = append(result, strconv.Itoa(p.ProcessID)) + } + } + + } + return result +} +func newWindowsProcess(e *windows.ProcessEntry32) Process { + // Find when the string ends for decoding + end := 0 + for { + if e.ExeFile[end] == 0 { + break + } + end++ + } + return Process{ + ProcessID: int(e.ProcessID), + ParentProcessID: int(e.ParentProcessID), + Exe: syscall.UTF16ToString(e.ExeFile[:end]), + } +} diff --git a/gamemode/build.bat b/gameutil/build.bat similarity index 100% rename from gamemode/build.bat rename to gameutil/build.bat diff --git a/gamemode/config.go b/gameutil/config.go similarity index 93% rename from gamemode/config.go rename to gameutil/config.go index 9d92a65..b7db843 100644 --- a/gamemode/config.go +++ b/gameutil/config.go @@ -1,30 +1,30 @@ -package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" -) - -// config -type config struct { - TIMERRES int16 - KILL_DWM bool - KILL_EXPLORER bool - DISABLE_IDLE bool -} - -func GetConfig(params ...string) config { - file, err := ioutil.ReadFile("config.json") - if err != nil { - fmt.Println("Error ReadFile:", err) - } - - var data = config{} - err = json.Unmarshal(file, &data) - if err != nil { - fmt.Println("Error Unmarshal:", err) - } - - return data -} +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" +) + +// config +type config struct { + TIMERRES int16 + KILL_DWM bool + KILL_EXPLORER bool + DISABLE_IDLE bool +} + +func GetConfig(params ...string) config { + file, err := ioutil.ReadFile("config.json") + if err != nil { + fmt.Println("Error ReadFile:", err) + } + + var data = config{} + err = json.Unmarshal(file, &data) + if err != nil { + fmt.Println("Error Unmarshal:", err) + } + + return data +} diff --git a/gamemode/config.json b/gameutil/config.json similarity index 100% rename from gamemode/config.json rename to gameutil/config.json diff --git a/gamemode/go.mod b/gameutil/go.mod similarity index 100% rename from gamemode/go.mod rename to gameutil/go.mod diff --git a/gamemode/go.sum b/gameutil/go.sum similarity index 100% rename from gamemode/go.sum rename to gameutil/go.sum diff --git a/gamemode/launch-example.bat b/gameutil/launch-example.bat similarity index 98% rename from gamemode/launch-example.bat rename to gameutil/launch-example.bat index 3820080..353ef5e 100644 --- a/gamemode/launch-example.bat +++ b/gameutil/launch-example.bat @@ -1,2 +1,2 @@ -nsudo -U:T -P:E -CurrentDirectory:%~dp0 gameutil.exe +nsudo -U:T -P:E -CurrentDirectory:%~dp0 gameutil.exe pause \ No newline at end of file diff --git a/gamemode/main.go b/gameutil/main.go similarity index 100% rename from gamemode/main.go rename to gameutil/main.go diff --git a/gamemode/win32api.go b/gameutil/win32api.go similarity index 96% rename from gamemode/win32api.go rename to gameutil/win32api.go index f2b5fb8..80149cd 100644 --- a/gamemode/win32api.go +++ b/gameutil/win32api.go @@ -1,62 +1,62 @@ -// coauthored by @spddl, thank you! -package main - -import ( - "syscall" - - "golang.org/x/sys/windows" -) - -// Breaks when calling from main.go, just replaced with 0x1F0FFF -// const PROCESS_ALL_ACCESS = 0x1F0FF - -var ( - // Library - ntdllDLL = windows.NewLazySystemDLL("ntdll.dll") - - // Functions - procNtSuspendProcess = ntdllDLL.NewProc("NtSuspendProcess") - procNtResumeProcess = ntdllDLL.NewProc("NtResumeProcess") - // procNtQueryTimerResolution = ntdllDLL.NewProc("NtQueryTimerResolution") - procNtSetTimerResolution = ntdllDLL.NewProc("NtSetTimerResolution") -) - -func SuspendProc(pid uint32) { - handle, err := windows.OpenProcess(0x1F0FFF, false, pid) - if err != nil { - panic(err) - } - procNtSuspendProcess.Call(uintptr(handle)) -} - -func NtResumeProcess(pid uint32) { - handle, err := windows.OpenProcess(0x1F0FFF, false, pid) - if err != nil { - panic(err) - } - procNtResumeProcess.Call(uintptr(handle)) -} - -/* -// https://www.pinvoke.net/default.aspx/ntdll.NtQueryTimerResolution -// http://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FTime%2FNtQueryTimerResolution.html -func NtQueryTimerResolution(maximumResolution, minimumResolution, currentResolution *uint64) bool { - ret, _, _ := syscall.Syscall(procNtQueryTimerResolution.Addr(), 3, - uintptr(unsafe.Pointer(maximumResolution)), - uintptr(unsafe.Pointer(minimumResolution)), - uintptr(unsafe.Pointer(¤tResolution)), - ) - return ret != 0 -} -*/ - -func NtSetTimerRes(res int16) (currentResolution uint64) { - syscall.Syscall(procNtSetTimerResolution.Addr(), 3, - uintptr(res), - uintptr(1), - // Believe this isn't required, and adds extra module. - // uintptr(unsafe.Pointer(¤tResolution)), - 0, - ) - return -} +// coauthored by @spddl, thank you! +package main + +import ( + "syscall" + + "golang.org/x/sys/windows" +) + +// Breaks when calling from main.go, just replaced with 0x1F0FFF +// const PROCESS_ALL_ACCESS = 0x1F0FF + +var ( + // Library + ntdllDLL = windows.NewLazySystemDLL("ntdll.dll") + + // Functions + procNtSuspendProcess = ntdllDLL.NewProc("NtSuspendProcess") + procNtResumeProcess = ntdllDLL.NewProc("NtResumeProcess") + // procNtQueryTimerResolution = ntdllDLL.NewProc("NtQueryTimerResolution") + procNtSetTimerResolution = ntdllDLL.NewProc("NtSetTimerResolution") +) + +func SuspendProc(pid uint32) { + handle, err := windows.OpenProcess(0x1F0FFF, false, pid) + if err != nil { + panic(err) + } + procNtSuspendProcess.Call(uintptr(handle)) +} + +func NtResumeProcess(pid uint32) { + handle, err := windows.OpenProcess(0x1F0FFF, false, pid) + if err != nil { + panic(err) + } + procNtResumeProcess.Call(uintptr(handle)) +} + +/* +// https://www.pinvoke.net/default.aspx/ntdll.NtQueryTimerResolution +// http://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FTime%2FNtQueryTimerResolution.html +func NtQueryTimerResolution(maximumResolution, minimumResolution, currentResolution *uint64) bool { + ret, _, _ := syscall.Syscall(procNtQueryTimerResolution.Addr(), 3, + uintptr(unsafe.Pointer(maximumResolution)), + uintptr(unsafe.Pointer(minimumResolution)), + uintptr(unsafe.Pointer(¤tResolution)), + ) + return ret != 0 +} +*/ + +func NtSetTimerRes(res int16) (currentResolution uint64) { + syscall.Syscall(procNtSetTimerResolution.Addr(), 3, + uintptr(res), + uintptr(1), + // Believe this isn't required, and adds extra module. + // uintptr(unsafe.Pointer(¤tResolution)), + 0, + ) + return +}