diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf9d2dc --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# .gitignore for Go projects + +# Build artifacts +_dist/ +_build/ +_out/ +bin/ +pkg/ +target/ + +# Go specific build artifacts +.obj/ +.go-work/ +.gopath/ +.gotmp/ +# go mod and go sum files are usually not ignored +# but you might want to if you're not using them +#go.mod +#go.sum + +# IDEs and editors +.idea/ +*.swo +*.swp +*.swx +*.log +*.tmp +*.bak +*.rej +*.orig +*.synctex.gz +*~ # Emacs and others temp files + +# OS generated +.DS_Store +Thumbs.db +desktop.ini + +# Coverage profiles +.coverprofile \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d483add --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Arguments Fetcher: argsfet + +A simple tool to fetch command line arguments. + +# Build + +```shell +rsrc -manifest app.manifest -o app.syso +go build -ldflags="-w -s" -o argsfet.exe +``` + +# Usage + +Execute + +```shell +argsfet.exe +``` + +then will show the command line arguments and output a file named `command_line_.txt`. +There into `` is the process name which you want to fetch. + +# Reference + +[build - https://github.com/akavel/rsrc](https://github.com/akavel/rsrc) + +[argsfet.dll - https://github.com/Ninohana/argsfet](https://github.com/Ninohana/argsfet) \ No newline at end of file diff --git a/app.manifest b/app.manifest new file mode 100644 index 0000000..e81e3bb --- /dev/null +++ b/app.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/argsfet.dll b/argsfet.dll new file mode 100644 index 0000000..b85f783 Binary files /dev/null and b/argsfet.dll differ diff --git a/argsfet.go b/argsfet.go new file mode 100644 index 0000000..5301a09 --- /dev/null +++ b/argsfet.go @@ -0,0 +1,27 @@ +package main + +import ( + "syscall" + "unsafe" +) + +func ObtainProcessCommandArgs(processName string) string { + // 将进程名转换为UTF-16指针 + processNameUTF16, _ := syscall.UTF16PtrFromString(processName) + + // 加载DLL以及函数 + dll := syscall.MustLoadDLL("argsfet.dll") + GetProcessIdByName := dll.MustFindProc("GetProcessIdByName") + GetCommandLineByProcessId := dll.MustFindProc("GetCommandLineByProcessId") + + // 获取PID + ret, _, _ := GetProcessIdByName.Call(uintptr(unsafe.Pointer(processNameUTF16))) + + // 获取命令行参数 + ret, _, _ = GetCommandLineByProcessId.Call(ret) + commandLine := syscall.UTF16ToString((*[1 << 16]uint16)(unsafe.Pointer(ret))[:]) + + // 释放DLL + _ = dll.Release() + return commandLine +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..bcf9837 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module argsfet + +go 1.23.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/main.go b/main.go new file mode 100644 index 0000000..376b70d --- /dev/null +++ b/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +func main() { + if len(os.Args) > 1 { + processName := os.Args[1] + commandLine := ObtainProcessCommandArgs(processName) + fmt.Print(commandLine) + file, _ := os.Create(fmt.Sprintf("command_line_%s.txt", processName)) + defer file.Close() + writer := bufio.NewWriter(file) + writer.WriteString(commandLine) + writer.Flush() + } +}