-
-
Notifications
You must be signed in to change notification settings - Fork 392
fix: run multiple apps #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AdianKozlica
wants to merge
12
commits into
TibixDev:main
Choose a base branch
from
AdianKozlica:fix/run_multiple_apps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1cf2d9e
fix: run multiple apps
AdianKozlica b840d7b
add build-rdp-exec to build:gs
AdianKozlica f517c17
refactor and set default working directory
AdianKozlica d3a58ad
fix: path with spaces wouldn't run so we set the app name to null and…
AdianKozlica f903641
Merge remote-tracking branch 'upstream/main' into fix/run_multiple_apps
AdianKozlica 7843fda
Merge remote-tracking branch 'upstream/main' into fix/run_multiple_apps
AdianKozlica 3b72bc2
fix: expand environment paths
AdianKozlica 1b7f722
prettier run
AdianKozlica 136a054
feat: launch multiple apps with shift
AdianKozlica 27a5f95
Merge remote-tracking branch 'upstream/main' into fix/run_multiple_apps
AdianKozlica 5fadaab
feat: use base64 for cmd and args
AdianKozlica 4ff229f
fix: run files with different extensions
AdianKozlica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| cd rdp_exec | ||
| GOOS=windows GOARCH=amd64 go build -o rdp_exec.exe -ldflags="-H windowsgui" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module rdp-exec | ||
|
|
||
| go 1.24.8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "syscall" | ||
| "unsafe" | ||
| ) | ||
|
|
||
| var ( | ||
| cmd = flag.String("cmd", "", "Command to run") | ||
| cmd_args = flag.String("cmd_args", "", "Command args") | ||
| dummy = flag.String("dummy", "", "Dummy info") | ||
| ) | ||
|
|
||
| var ( | ||
| kernel32 = syscall.NewLazyDLL("kernel32.dll") | ||
| shlwapi = syscall.NewLazyDLL("Shlwapi.dll") | ||
| procAssocQueryStringW = shlwapi.NewProc("AssocQueryStringW") | ||
| procExpandEnvString = kernel32.NewProc("ExpandEnvironmentStringsW") | ||
| ) | ||
|
|
||
| const ( | ||
| ASSOCF_NONE = 0 | ||
| ASSOCSTR_EXECUTABLE = 2 | ||
| ) | ||
|
|
||
| func getDefaultApp(extension string) (string, error) { | ||
| if !strings.HasPrefix(extension, ".") { | ||
| extension = "." + extension | ||
| } | ||
|
|
||
| extUTF16, err := syscall.UTF16PtrFromString(extension) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| var size uint32 = 260 | ||
| buf := make([]uint16, size) | ||
|
|
||
| ret, _, _ := procAssocQueryStringW.Call( | ||
| uintptr(ASSOCF_NONE), | ||
| uintptr(ASSOCSTR_EXECUTABLE), | ||
| uintptr(unsafe.Pointer(extUTF16)), | ||
| 0, | ||
| uintptr(unsafe.Pointer(&buf[0])), | ||
| uintptr(unsafe.Pointer(&size)), | ||
| ) | ||
|
|
||
| if ret != 0 { | ||
| return "", fmt.Errorf("failed to get default app") | ||
| } | ||
|
|
||
| return syscall.UTF16ToString(buf), nil | ||
| } | ||
|
|
||
| func expandWindowsEnv(s string) string { | ||
| utf16Str, _ := syscall.UTF16FromString(s) | ||
|
|
||
| n, _, _ := procExpandEnvString.Call( | ||
| uintptr(unsafe.Pointer(&utf16Str[0])), | ||
| 0, | ||
| 0, | ||
| ) | ||
|
|
||
| if n == 0 { | ||
| return s | ||
| } | ||
|
|
||
| buf := make([]uint16, n) | ||
| procExpandEnvString.Call( | ||
| uintptr(unsafe.Pointer(&utf16Str[0])), | ||
| uintptr(unsafe.Pointer(&buf[0])), | ||
| uintptr(n), | ||
| ) | ||
|
|
||
| return syscall.UTF16ToString(buf) | ||
| } | ||
|
|
||
| func decodeb64(b64 string) string { | ||
| res, _ := base64.StdEncoding.DecodeString(b64) | ||
| return string(res) | ||
| } | ||
|
|
||
| func main() { | ||
| flag.Parse() | ||
|
|
||
| if *cmd == "" || *dummy == "" { | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| cmd_decoded := decodeb64(*cmd) | ||
| args := strings.Fields(cmd_decoded) | ||
|
|
||
| if len(args) == 0 { | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| cmd_full := cmd_decoded | ||
|
|
||
| ext := strings.ToLower(filepath.Ext(cmd_decoded)) | ||
|
|
||
| if ext != "" && ext != ".exe" && ext != ".bat" && ext != ".cmd" { | ||
| defaultApp, err := getDefaultApp(ext) | ||
| if err == nil { | ||
| cmd_decoded = `"` + defaultApp + `" "` + cmd_decoded + `"` | ||
| } | ||
| } | ||
|
|
||
| cmd_full = cmd_decoded | ||
|
|
||
| if *cmd_args != "" { | ||
| cmd_full += " " + decodeb64(*cmd_args) | ||
| } | ||
|
|
||
| expandedCmd := expandWindowsEnv(cmd_full) | ||
| commandLine := syscall.StringToUTF16Ptr(expandedCmd) | ||
| workingDir := syscall.StringToUTF16Ptr(`C:\Windows\System32`) | ||
|
|
||
| var startupInfo syscall.StartupInfo | ||
| var processInfo syscall.ProcessInformation | ||
|
|
||
| startupInfo.Cb = uint32(unsafe.Sizeof(startupInfo)) | ||
|
|
||
| syscall.CreateProcess( | ||
| nil, | ||
| commandLine, | ||
| nil, // Default process security attributes | ||
| nil, // Default thread security attributes | ||
| false, // Inherit handles | ||
| 0, // Creation flags | ||
| nil, // Use parent's environment | ||
| workingDir, | ||
| &startupInfo, | ||
| &processInfo, | ||
| ) | ||
|
|
||
| syscall.WaitForSingleObject(processInfo.Process, syscall.INFINITE) | ||
| syscall.CloseHandle(processInfo.Process) | ||
| syscall.CloseHandle(processInfo.Thread) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.