Skip to content
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

C2 Framework Support #8

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b99b1aa
Merge pull request #1 from ropnop/master
Ne0nd0g Feb 26, 2021
86c796b
Update SafeArray functions, fixed example program
Ne0nd0g Mar 18, 2021
46d27d5
Fixed composite literal use of unkeyed fields
Ne0nd0g Mar 18, 2021
d54978b
Fixed misuse of unsafe.Pointer in iclrmetahost
Ne0nd0g Mar 18, 2021
b3af3fa
Fixed misuse of unsafe.Pointer for iclrmetahost
Ne0nd0g Mar 18, 2021
d17a78a
Modified iclrruntimeinfo methods
Ne0nd0g Mar 18, 2021
4715ed5
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
e81f8eb
Update GetDefaultDomain
Ne0nd0g Mar 19, 2021
a46d3ab
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
f0888b8
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
a88b841
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
07d499f
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
ff8ffa7
Updated MethodInfo and PrepareParameters
Ne0nd0g Mar 19, 2021
e8b430e
Updated runtime enumeration
Ne0nd0g Mar 19, 2021
fed3a5e
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
278992d
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
d5949ed
Fixed misuse of unsafe.Pointer
Ne0nd0g Mar 19, 2021
441da9d
Code cleanup
Ne0nd0g Mar 19, 2021
3c6feff
Documentation and cleanup
Ne0nd0g Mar 19, 2021
85f36cd
Added C2 Framework Support
Ne0nd0g Mar 25, 2021
d791ef9
Updated STDOUT/STDERR Read
Ne0nd0g Mar 27, 2021
46c71d5
Added SafeArrayDelete
Ne0nd0g Mar 27, 2021
b7ac0af
Removed unused code
Ne0nd0g Mar 27, 2021
a2bef24
Update go.mod
Ne0nd0g Mar 28, 2021
875ea40
Updated STDOUT/STDERR to use a buffer
Ne0nd0g Apr 8, 2021
37fb9d6
Modules + Tags Hard...
Ne0nd0g Apr 8, 2021
b14c9ea
ignore windows error that doesn't impact execution
audibleblink Feb 10, 2022
474a510
Merge pull request #2 from audibleblink/patch/edgcase_error
Ne0nd0g Apr 2, 2022
b96d0f1
Updated supporting packages
Ne0nd0g Apr 2, 2022
d57278d
Remove must from go-clr.go
mec07 Oct 25, 2022
cb41266
Fixed #4
Ne0nd0g Nov 10, 2022
ce145f5
Merge pull request #3 from mec07/remove-must
Ne0nd0g Nov 10, 2022
7aa95c6
v1.3.0
Ne0nd0g Nov 10, 2022
6176f4a
Fixed CHANGELOG version numbers
Ne0nd0g Nov 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed #4
Ne0nd0g committed Nov 10, 2022
commit cb412660836fe8e684e7352db2e20185ab36be5e
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 1.3.0 2022-XX-XX

### Fixed

- [Issue 4](https://github.com/Ne0nd0g/go-clr/issues/4) - Application's Without A Console Will Not Return Output

## 1.2.0 2022-04-02

### Fixed

- Fixed an error when attempting to load correctly targeted assemblies through https://github.com/Ne0nd0g/go-clr/pull/2

### Changed

- Upgraded supporting Go modules

## 1.1.0 2021-04-08

- Learned how to correctly use tags and updated import

## 1.0.0 2021-04-08

- Initial tagged version from forked

### Added

- Added buffer to collect redirected STDOUT/STDERR
34 changes: 32 additions & 2 deletions io.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package clr
@@ -8,6 +9,7 @@ import (
"fmt"
"os"
"sync"
"syscall"
"time"

"golang.org/x/sys/windows"
@@ -58,13 +60,41 @@ func RedirectStdoutStderr() (err error) {
return
}

// Createa new reader and writer for STDERR
// Create a new reader and writer for STDERR
rSTDERR, wSTDERR, err = os.Pipe()
if err != nil {
err = fmt.Errorf("there was an error calling the os.Pipe() function to create a new STDERR:\n%s", err)
return
}

kernel32 := windows.NewLazySystemDLL("kernel32.dll")
getConsoleWindow := kernel32.NewProc("GetConsoleWindow")

// Ensure the process has a console because if it doesn't there will be no output to capture
hConsole, _, _ := getConsoleWindow.Call()
if hConsole == 0 {
// https://learn.microsoft.com/en-us/windows/console/allocconsole
allocConsole := kernel32.NewProc("AllocConsole")
// BOOL WINAPI AllocConsole(void);
ret, _, err := allocConsole.Call()
// A process can be associated with only one console, so the AllocConsole function fails if the calling process
// already has a console. So long as any console exists we are good to go and therefore don't care about errors
if ret == 0 {
return fmt.Errorf("there was an error calling kernel32!AllocConsole with return code %d: %s", ret, err)
}

// Get a handle to the newly created/allocated console
hConsole, _, _ = getConsoleWindow.Call()

user32 := windows.NewLazySystemDLL("user32.dll")
showWindow := user32.NewProc("ShowWindow")
// Hide the console window
ret, _, err = showWindow.Call(hConsole, windows.SW_HIDE)
if err != syscall.Errno(0) {
return fmt.Errorf("there was an error calling user32!ShowWindow with return %+v: %s", ret, err)
}
}

// Set STDOUT/STDERR to the new files from os.Pipe()
// https://docs.microsoft.com/en-us/windows/console/setstdhandle
if err = windows.SetStdHandle(windows.STD_OUTPUT_HANDLE, windows.Handle(wSTDOUT.Fd())); err != nil {
@@ -132,7 +162,7 @@ func ReadStdoutStderr() (stdout string, stderr string, err error) {
return
}

// CloseSTdoutStderr closes the Reader/Writer for the prviously redirected STDOUT/STDERR
// CloseStdoutStderr closes the Reader/Writer for the previously redirected STDOUT/STDERR
// that was changed to an *os.File
func CloseStdoutStderr() (err error) {
err = rSTDOUT.Close()