Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninohana committed Sep 14, 2024
0 parents commit 2827e1d
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <ProcessName>
```

then will show the command line arguments and output a file named `command_line_<ProcessName>.txt`.
There into `<ProcessName>` 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)
10 changes: 10 additions & 0 deletions app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Binary file added argsfet.dll
Binary file not shown.
27 changes: 27 additions & 0 deletions argsfet.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module argsfet

go 1.23.1
Empty file added go.sum
Empty file.
20 changes: 20 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit 2827e1d

Please sign in to comment.