├── .github └── workflows │ └── go.yml ├── .gitignore ├── .goreleaser.yml ├── LICENSE ├── README.md ├── beaconscan └── beaconscan.go ├── go.mod ├── go.sum ├── lib ├── http │ ├── alpn_test.go │ ├── cgi │ │ ├── child.go │ │ ├── child_test.go │ │ ├── host.go │ │ ├── host_test.go │ │ ├── integration_test.go │ │ ├── plan9_test.go │ │ ├── posix_test.go │ │ └── testdata │ │ │ └── test.cgi │ ├── client.go │ ├── client_test.go │ ├── clientserver_test.go │ ├── clone.go │ ├── cookie.go │ ├── cookie_test.go │ ├── cookiejar │ │ ├── dummy_publicsuffix_test.go │ │ ├── example_test.go │ │ ├── jar.go │ │ ├── jar_test.go │ │ ├── punycode.go │ │ └── punycode_test.go │ ├── doc.go │ ├── example_filesystem_test.go │ ├── example_handle_test.go │ ├── example_test.go │ ├── export_test.go │ ├── fcgi │ │ ├── child.go │ │ ├── fcgi.go │ │ └── fcgi_test.go │ ├── filetransport.go │ ├── filetransport_test.go │ ├── fs.go │ ├── fs_test.go │ ├── h2_bundle.go │ ├── header.go │ ├── header_test.go │ ├── http.go │ ├── http_test.go │ ├── httpproxy │ │ ├── export_test.go │ │ ├── go19_test.go │ │ ├── proxy.go │ │ └── proxy_test.go │ ├── httptest │ │ ├── example_test.go │ │ ├── httptest.go │ │ ├── httptest_test.go │ │ ├── recorder.go │ │ ├── recorder_test.go │ │ ├── server.go │ │ └── server_test.go │ ├── httptrace │ │ ├── example_test.go │ │ ├── trace.go │ │ └── trace_test.go │ ├── httputil │ │ ├── dump.go │ │ ├── dump_test.go │ │ ├── example_test.go │ │ ├── httputil.go │ │ ├── persist.go │ │ ├── reverseproxy.go │ │ └── reverseproxy_test.go │ ├── internal │ │ ├── ascii │ │ │ ├── print.go │ │ │ └── print_test.go │ │ ├── chunked.go │ │ ├── chunked_test.go │ │ └── testcert │ │ │ └── testcert.go │ ├── jar.go │ ├── main_test.go │ ├── method.go │ ├── omithttp2.go │ ├── pprof │ │ ├── pprof.go │ │ └── pprof_test.go │ ├── proxy_test.go │ ├── range_test.go │ ├── readrequest_test.go │ ├── request.go │ ├── request_test.go │ ├── requestwrite_test.go │ ├── response.go │ ├── response_test.go │ ├── responsewrite_test.go │ ├── roundtrip.go │ ├── roundtrip_js.go │ ├── serve_test.go │ ├── server.go │ ├── server_test.go │ ├── sniff.go │ ├── sniff_test.go │ ├── socks_bundle.go │ ├── status.go │ ├── testdata │ │ ├── file │ │ ├── index.html │ │ └── style.css │ ├── transfer.go │ ├── transfer_test.go │ ├── transport.go │ ├── transport_internal_test.go │ ├── transport_test.go │ └── triv.go ├── internal │ ├── abi │ │ ├── abi.go │ │ ├── abi_amd64.go │ │ ├── abi_generic.go │ │ ├── abi_test.go │ │ ├── abi_test.s │ │ ├── export_test.go │ │ └── testdata │ │ │ ├── x.go │ │ │ └── x.s │ ├── buildcfg │ │ ├── cfg.go │ │ ├── exp.go │ │ └── zbootstrap.go │ ├── bytealg │ │ ├── bytealg.go │ │ ├── compare_386.s │ │ ├── compare_amd64.s │ │ ├── compare_arm.s │ │ ├── compare_arm64.s │ │ ├── compare_generic.go │ │ ├── compare_mips64x.s │ │ ├── compare_mipsx.s │ │ ├── compare_native.go │ │ ├── compare_ppc64x.s │ │ ├── compare_s390x.s │ │ ├── compare_wasm.s │ │ ├── count_amd64.s │ │ ├── count_arm.s │ │ ├── count_arm64.s │ │ ├── count_generic.go │ │ ├── count_native.go │ │ ├── count_ppc64x.s │ │ ├── count_riscv64.s │ │ ├── count_s390x.s │ │ ├── equal_386.s │ │ ├── equal_amd64.s │ │ ├── equal_arm.s │ │ ├── equal_arm64.s │ │ ├── equal_generic.go │ │ ├── equal_mips64x.s │ │ ├── equal_mipsx.s │ │ ├── equal_native.go │ │ ├── equal_ppc64x.s │ │ ├── equal_riscv64.s │ │ ├── equal_s390x.s │ │ ├── equal_wasm.s │ │ ├── index_amd64.go │ │ ├── index_amd64.s │ │ ├── index_arm64.go │ │ ├── index_arm64.s │ │ ├── index_generic.go │ │ ├── index_native.go │ │ ├── index_ppc64x.go │ │ ├── index_ppc64x.s │ │ ├── index_s390x.go │ │ ├── index_s390x.s │ │ ├── indexbyte_386.s │ │ ├── indexbyte_amd64.s │ │ ├── indexbyte_arm.s │ │ ├── indexbyte_arm64.s │ │ ├── indexbyte_generic.go │ │ ├── indexbyte_mips64x.s │ │ ├── indexbyte_mipsx.s │ │ ├── indexbyte_native.go │ │ ├── indexbyte_ppc64x.s │ │ ├── indexbyte_riscv64.s │ │ ├── indexbyte_s390x.s │ │ └── indexbyte_wasm.s │ ├── cfg │ │ └── cfg.go │ ├── cpu │ │ ├── cpu.go │ │ ├── cpu.s │ │ ├── cpu_386.go │ │ ├── cpu_amd64.go │ │ ├── cpu_arm.go │ │ ├── cpu_arm64.go │ │ ├── cpu_arm64.s │ │ ├── cpu_arm64_android.go │ │ ├── cpu_arm64_darwin.go │ │ ├── cpu_arm64_freebsd.go │ │ ├── cpu_arm64_hwcap.go │ │ ├── cpu_arm64_linux.go │ │ ├── cpu_arm64_other.go │ │ ├── cpu_mips.go │ │ ├── cpu_mips64x.go │ │ ├── cpu_mipsle.go │ │ ├── cpu_no_name.go │ │ ├── cpu_ppc64x.go │ │ ├── cpu_ppc64x_aix.go │ │ ├── cpu_ppc64x_linux.go │ │ ├── cpu_riscv64.go │ │ ├── cpu_s390x.go │ │ ├── cpu_s390x.s │ │ ├── cpu_s390x_test.go │ │ ├── cpu_test.go │ │ ├── cpu_wasm.go │ │ ├── cpu_x86.go │ │ ├── cpu_x86.s │ │ ├── cpu_x86_test.go │ │ └── export_test.go │ ├── execabs │ │ ├── execabs.go │ │ └── execabs_test.go │ ├── fmtsort │ │ ├── export_test.go │ │ ├── sort.go │ │ └── sort_test.go │ ├── goexperiment │ │ ├── exp_fieldtrack_off.go │ │ ├── exp_fieldtrack_on.go │ │ ├── exp_preemptibleloops_off.go │ │ ├── exp_preemptibleloops_on.go │ │ ├── exp_regabi_off.go │ │ ├── exp_regabi_on.go │ │ ├── exp_regabiargs_off.go │ │ ├── exp_regabiargs_on.go │ │ ├── exp_regabidefer_off.go │ │ ├── exp_regabidefer_on.go │ │ ├── exp_regabig_off.go │ │ ├── exp_regabig_on.go │ │ ├── exp_regabireflect_off.go │ │ ├── exp_regabireflect_on.go │ │ ├── exp_regabiwrappers_off.go │ │ ├── exp_regabiwrappers_on.go │ │ ├── exp_staticlockranking_off.go │ │ ├── exp_staticlockranking_on.go │ │ ├── flags.go │ │ └── mkconsts.go │ ├── goroot │ │ ├── gc.go │ │ └── gccgo.go │ ├── goversion │ │ └── goversion.go │ ├── itoa │ │ ├── itoa.go │ │ └── itoa_test.go │ ├── lazyregexp │ │ └── lazyre.go │ ├── lazytemplate │ │ └── lazytemplate.go │ ├── nettrace │ │ └── nettrace.go │ ├── obscuretestdata │ │ └── obscuretestdata.go │ ├── oserror │ │ └── errors.go │ ├── poll │ │ ├── copy_file_range_linux.go │ │ ├── errno_unix.go │ │ ├── errno_windows.go │ │ ├── error_linux_test.go │ │ ├── error_stub_test.go │ │ ├── error_test.go │ │ ├── export_linux_test.go │ │ ├── export_posix_test.go │ │ ├── export_test.go │ │ ├── export_windows_test.go │ │ ├── fcntl_js.go │ │ ├── fcntl_libc.go │ │ ├── fcntl_syscall.go │ │ ├── fd.go │ │ ├── fd_fsync_darwin.go │ │ ├── fd_fsync_posix.go │ │ ├── fd_fsync_windows.go │ │ ├── fd_io_plan9.go │ │ ├── fd_mutex.go │ │ ├── fd_mutex_test.go │ │ ├── fd_opendir_darwin.go │ │ ├── fd_plan9.go │ │ ├── fd_poll_js.go │ │ ├── fd_poll_runtime.go │ │ ├── fd_posix.go │ │ ├── fd_posix_test.go │ │ ├── fd_unix.go │ │ ├── fd_windows.go │ │ ├── fd_windows_test.go │ │ ├── fd_writev_darwin.go │ │ ├── fd_writev_illumos.go │ │ ├── fd_writev_unix.go │ │ ├── hook_cloexec.go │ │ ├── hook_unix.go │ │ ├── hook_windows.go │ │ ├── iovec_illumos.go │ │ ├── iovec_unix.go │ │ ├── read_test.go │ │ ├── sendfile_bsd.go │ │ ├── sendfile_linux.go │ │ ├── sendfile_solaris.go │ │ ├── sendfile_windows.go │ │ ├── sock_cloexec.go │ │ ├── sockopt.go │ │ ├── sockopt_linux.go │ │ ├── sockopt_unix.go │ │ ├── sockopt_windows.go │ │ ├── sockoptip.go │ │ ├── splice_linux.go │ │ ├── splice_linux_test.go │ │ ├── strconv.go │ │ ├── sys_cloexec.go │ │ ├── writev.go │ │ └── writev_test.go │ ├── profile │ │ ├── encode.go │ │ ├── filter.go │ │ ├── legacy_profile.go │ │ ├── merge.go │ │ ├── profile.go │ │ ├── profile_test.go │ │ ├── proto.go │ │ ├── proto_test.go │ │ └── prune.go │ ├── race │ │ ├── doc.go │ │ ├── norace.go │ │ └── race.go │ ├── reflectlite │ │ ├── all_test.go │ │ ├── asm.s │ │ ├── export_test.go │ │ ├── reflect_mirror_test.go │ │ ├── set_test.go │ │ ├── swapper.go │ │ ├── tostring_test.go │ │ ├── type.go │ │ └── value.go │ ├── singleflight │ │ ├── singleflight.go │ │ └── singleflight_test.go │ ├── syscall │ │ ├── execenv │ │ │ ├── execenv_default.go │ │ │ └── execenv_windows.go │ │ ├── unix │ │ │ ├── asm_aix_ppc64.s │ │ │ ├── asm_darwin.s │ │ │ ├── asm_solaris.s │ │ │ ├── at.go │ │ │ ├── at_aix.go │ │ │ ├── at_darwin.go │ │ │ ├── at_freebsd.go │ │ │ ├── at_libc.go │ │ │ ├── at_solaris.go │ │ │ ├── at_sysnum_darwin.go │ │ │ ├── at_sysnum_dragonfly.go │ │ │ ├── at_sysnum_fstatat64_linux.go │ │ │ ├── at_sysnum_fstatat_linux.go │ │ │ ├── at_sysnum_linux.go │ │ │ ├── at_sysnum_netbsd.go │ │ │ ├── at_sysnum_newfstatat_linux.go │ │ │ ├── at_sysnum_openbsd.go │ │ │ ├── copy_file_range_linux.go │ │ │ ├── fcntl_linux_32bit.go │ │ │ ├── getentropy_darwin.go │ │ │ ├── getentropy_openbsd.go │ │ │ ├── getrandom.go │ │ │ ├── getrandom_dragonfly.go │ │ │ ├── getrandom_freebsd.go │ │ │ ├── getrandom_linux.go │ │ │ ├── getrandom_solaris.go │ │ │ ├── ioctl_aix.go │ │ │ ├── nonblocking.go │ │ │ ├── nonblocking_js.go │ │ │ ├── nonblocking_libc.go │ │ │ ├── pipe2_illumos.go │ │ │ ├── sysnum_linux_386.go │ │ │ ├── sysnum_linux_amd64.go │ │ │ ├── sysnum_linux_arm.go │ │ │ ├── sysnum_linux_generic.go │ │ │ ├── sysnum_linux_mips64x.go │ │ │ ├── sysnum_linux_mipsx.go │ │ │ ├── sysnum_linux_ppc64x.go │ │ │ ├── sysnum_linux_s390x.go │ │ │ └── writev_illumos.go │ │ └── windows │ │ │ ├── exec_windows_test.go │ │ │ ├── mksyscall.go │ │ │ ├── psapi_windows.go │ │ │ ├── registry │ │ │ ├── export_test.go │ │ │ ├── key.go │ │ │ ├── mksyscall.go │ │ │ ├── registry_test.go │ │ │ ├── syscall.go │ │ │ ├── value.go │ │ │ └── zsyscall_windows.go │ │ │ ├── reparse_windows.go │ │ │ ├── security_windows.go │ │ │ ├── symlink_windows.go │ │ │ ├── syscall_windows.go │ │ │ ├── sysdll │ │ │ └── sysdll.go │ │ │ └── zsyscall_windows.go │ ├── sysinfo │ │ └── sysinfo.go │ ├── testenv │ │ ├── testenv.go │ │ ├── testenv_cgo.go │ │ ├── testenv_notwin.go │ │ └── testenv_windows.go │ ├── testlog │ │ ├── exit.go │ │ └── log.go │ ├── trace │ │ ├── gc.go │ │ ├── gc_test.go │ │ ├── goroutines.go │ │ ├── mkcanned.bash │ │ ├── mud.go │ │ ├── mud_test.go │ │ ├── order.go │ │ ├── parser.go │ │ ├── parser_test.go │ │ ├── testdata │ │ │ ├── http_1_10_good │ │ │ ├── http_1_11_good │ │ │ ├── http_1_5_good │ │ │ ├── http_1_7_good │ │ │ ├── http_1_9_good │ │ │ ├── stress_1_10_good │ │ │ ├── stress_1_11_good │ │ │ ├── stress_1_5_good │ │ │ ├── stress_1_5_unordered │ │ │ ├── stress_1_7_good │ │ │ ├── stress_1_9_good │ │ │ ├── stress_start_stop_1_10_good │ │ │ ├── stress_start_stop_1_11_good │ │ │ ├── stress_start_stop_1_5_good │ │ │ ├── stress_start_stop_1_7_good │ │ │ ├── stress_start_stop_1_9_good │ │ │ └── user_task_span_1_11_good │ │ └── writer.go │ ├── unsafeheader │ │ ├── unsafeheader.go │ │ └── unsafeheader_test.go │ └── xcoff │ │ ├── ar.go │ │ ├── ar_test.go │ │ ├── file.go │ │ ├── file_test.go │ │ ├── testdata │ │ ├── bigar-empty │ │ ├── bigar-ppc64 │ │ ├── gcc-ppc32-aix-dwarf2-exec │ │ ├── gcc-ppc64-aix-dwarf2-exec │ │ ├── hello.c │ │ ├── printbye.c │ │ └── printhello.c │ │ └── xcoff.go └── url │ ├── example_test.go │ ├── url.go │ └── url_test.go ├── main.go ├── main_test.go └── samples ├── 320a5f715aa5724c21013fc14bfe0a10893ce9723ebc25d9ae9f06f5517795d4.zip └── 5cd19717831e5259d535783be33f86ad7e77f8df25cd8f342da4f4f33327d989.zip /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | create: 5 | tags: 6 | - v* 7 | 8 | jobs: 9 | release: 10 | name: Release on GitHub 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Check out code 14 | uses: actions/checkout@v3 15 | 16 | - name: Validates GO releaser config 17 | uses: goreleaser/goreleaser-action@master 18 | with: 19 | args: check 20 | 21 | - name: Create release on GitHub 22 | uses: goreleaser/goreleaser-action@master 23 | with: 24 | args: release --rm-dist 25 | env: 26 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | c2config.txt 3 | test.txt 4 | c2flie.csv 5 | test.py 6 | data 7 | b64.bin -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | builds: 2 | - env: 3 | - CGO_ENABLED=0 4 | goos: 5 | - darwin 6 | - linux 7 | - windows 8 | ignore: 9 | - goos: darwin 10 | goarch: 386 11 | - goos: windows 12 | goarch: arm64 13 | 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 ck00004 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CobaltStrikeParser-go 2 | Golang parser for CobaltStrike Beacon's configuration, reference CobaltStrikeParser project 3 | 4 | CobaltStrike Beacon 配置解析器,参考CobaltStrikeParser项目进行开发 5 | 6 | # 使用 7 | 8 | ``` 9 | go build -o CobaltStrikeParser.exe main.go 10 | 11 | CobaltStrikeParser.exe -u http://127.0.0.1 -o c2configflie.txt -t 10 12 | CobaltStrikeParser.exe -f c2urlflie -o c2configflie.txt -t 10 -br 5 13 | 14 | -u This can be a url (if started with http/s) 15 | -f This can be a file path (if started with http/s) 16 | -o out file 17 | -t timeout. default:30 18 | -br thread,import file valid. default:1 19 | -issave save not decrypted data to file ,Saved in the data directory. default:false 20 | -beaconfile beacon config file path 21 | ``` 22 | 23 | # 使用作为函数调用 24 | 25 | 不要调用 beaconscan.BeaconInitThread 这是多线程模式启动 26 | 27 | beaconscan.Beaconinit(url, fliename, timeout) 28 | 29 | 当flienmae 为""时返回数据返回json格式的数据和错误信息 30 | 31 | 当fliename 不为""时会将json数据写入flienmae中 32 | 33 | 当 IsSave 为true时,会将未解密的beacon保存到当前目录下data文件夹中 34 | 35 | ``` 36 | url := "https://www.google.com" 37 | timeout : = 5 38 | beaconinfo, err := beaconscan.Beaconinit(url, "", timeout,false) 39 | if err != nil { 40 | fmt.Println(err) 41 | } else { 42 | if beaconinfo.IsCobaltStrike { 43 | fmt.Println(beaconscan.StructToJson(beaconinfo)) 44 | } else if beaconinfo.Confidence > 0 { 45 | fmt.Println(url + beaconinfo.ConfidenceInfo) 46 | } else { 47 | fmt.Println(url + "Not CobaltStrike") 48 | } 49 | } 50 | ``` 51 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/ck00004/CobaltStrikeParser-Go 2 | 3 | go 1.17 4 | 5 | require golang.org/x/net v0.7.0 6 | 7 | require ( 8 | github.com/ck00004/uarand v0.0.0-20220919103220-39c675b1721d 9 | github.com/yeka/zip v0.0.0-20180914125537-d046722c6feb 10 | golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect 11 | golang.org/x/text v0.7.0 // indirect 12 | ) 13 | -------------------------------------------------------------------------------- /lib/http/cgi/plan9_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build plan9 6 | // +build plan9 7 | 8 | package cgi 9 | 10 | import ( 11 | "os" 12 | "strconv" 13 | ) 14 | 15 | func isProcessRunning(pid int) bool { 16 | _, err := os.Stat("/proc/" + strconv.Itoa(pid)) 17 | return err == nil 18 | } 19 | -------------------------------------------------------------------------------- /lib/http/cgi/posix_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !plan9 6 | // +build !plan9 7 | 8 | package cgi 9 | 10 | import ( 11 | "os" 12 | "syscall" 13 | ) 14 | 15 | func isProcessRunning(pid int) bool { 16 | p, err := os.FindProcess(pid) 17 | if err != nil { 18 | return false 19 | } 20 | return p.Signal(syscall.Signal(0)) == nil 21 | } 22 | -------------------------------------------------------------------------------- /lib/http/clone.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http 6 | 7 | import ( 8 | "mime/multipart" 9 | "net/textproto" 10 | 11 | "github.com/ck00004/CobaltStrikeParser-Go/lib/url" 12 | ) 13 | 14 | func cloneURLValues(v url.Values) url.Values { 15 | if v == nil { 16 | return nil 17 | } 18 | // http.Header and url.Values have the same representation, so temporarily 19 | // treat it like http.Header, which does have a clone: 20 | return url.Values(Header(v).Clone()) 21 | } 22 | 23 | func cloneURL(u *url.URL) *url.URL { 24 | if u == nil { 25 | return nil 26 | } 27 | u2 := new(url.URL) 28 | *u2 = *u 29 | if u.User != nil { 30 | u2.User = new(url.Userinfo) 31 | *u2.User = *u.User 32 | } 33 | return u2 34 | } 35 | 36 | func cloneMultipartForm(f *multipart.Form) *multipart.Form { 37 | if f == nil { 38 | return nil 39 | } 40 | f2 := &multipart.Form{ 41 | Value: (map[string][]string)(Header(f.Value).Clone()), 42 | } 43 | if f.File != nil { 44 | m := make(map[string][]*multipart.FileHeader) 45 | for k, vv := range f.File { 46 | vv2 := make([]*multipart.FileHeader, len(vv)) 47 | for i, v := range vv { 48 | vv2[i] = cloneMultipartFileHeader(v) 49 | } 50 | m[k] = vv2 51 | } 52 | f2.File = m 53 | } 54 | return f2 55 | } 56 | 57 | func cloneMultipartFileHeader(fh *multipart.FileHeader) *multipart.FileHeader { 58 | if fh == nil { 59 | return nil 60 | } 61 | fh2 := new(multipart.FileHeader) 62 | *fh2 = *fh 63 | fh2.Header = textproto.MIMEHeader(Header(fh.Header).Clone()) 64 | return fh2 65 | } 66 | 67 | // cloneOrMakeHeader invokes Header.Clone but if the 68 | // result is nil, it'll instead make and return a non-nil Header. 69 | func cloneOrMakeHeader(hdr Header) Header { 70 | clone := hdr.Clone() 71 | if clone == nil { 72 | clone = make(Header) 73 | } 74 | return clone 75 | } 76 | -------------------------------------------------------------------------------- /lib/http/cookiejar/dummy_publicsuffix_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cookiejar_test 6 | 7 | import "github.com/ck00004/CobaltStrikeParser-Go/lib/http/cookiejar" 8 | 9 | type dummypsl struct { 10 | List cookiejar.PublicSuffixList 11 | } 12 | 13 | func (dummypsl) PublicSuffix(domain string) string { 14 | return domain 15 | } 16 | 17 | func (dummypsl) String() string { 18 | return "dummy" 19 | } 20 | 21 | var publicsuffix = dummypsl{} 22 | -------------------------------------------------------------------------------- /lib/http/cookiejar/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cookiejar_test 6 | 7 | import ( 8 | "fmt" 9 | "log" 10 | 11 | "github.com/ck00004/CobaltStrikeParser-Go/lib/url" 12 | 13 | "github.com/ck00004/CobaltStrikeParser-Go/lib/http" 14 | "github.com/ck00004/CobaltStrikeParser-Go/lib/http/cookiejar" 15 | "github.com/ck00004/CobaltStrikeParser-Go/lib/http/httptest" 16 | ) 17 | 18 | func ExampleNew() { 19 | // Start a server to give us cookies. 20 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 21 | if cookie, err := r.Cookie("Flavor"); err != nil { 22 | http.SetCookie(w, &http.Cookie{Name: "Flavor", Value: "Chocolate Chip"}) 23 | } else { 24 | cookie.Value = "Oatmeal Raisin" 25 | http.SetCookie(w, cookie) 26 | } 27 | })) 28 | defer ts.Close() 29 | 30 | u, err := url.Parse(ts.URL) 31 | if err != nil { 32 | log.Fatal(err) 33 | } 34 | 35 | // All users of cookiejar should import "golang.org/x/net/publicsuffix" 36 | jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) 37 | if err != nil { 38 | log.Fatal(err) 39 | } 40 | 41 | client := &http.Client{ 42 | Jar: jar, 43 | } 44 | 45 | if _, err = client.Get(u.String()); err != nil { 46 | log.Fatal(err) 47 | } 48 | 49 | fmt.Println("After 1st request:") 50 | for _, cookie := range jar.Cookies(u) { 51 | fmt.Printf(" %s: %s\n", cookie.Name, cookie.Value) 52 | } 53 | 54 | if _, err = client.Get(u.String()); err != nil { 55 | log.Fatal(err) 56 | } 57 | 58 | fmt.Println("After 2nd request:") 59 | for _, cookie := range jar.Cookies(u) { 60 | fmt.Printf(" %s: %s\n", cookie.Name, cookie.Value) 61 | } 62 | // Output: 63 | // After 1st request: 64 | // Flavor: Chocolate Chip 65 | // After 2nd request: 66 | // Flavor: Oatmeal Raisin 67 | } 68 | -------------------------------------------------------------------------------- /lib/http/example_handle_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http_test 6 | 7 | import ( 8 | "fmt" 9 | "log" 10 | "sync" 11 | 12 | "github.com/ck00004/CobaltStrikeParser-Go/lib/http" 13 | ) 14 | 15 | type countHandler struct { 16 | mu sync.Mutex // guards n 17 | n int 18 | } 19 | 20 | func (h *countHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 21 | h.mu.Lock() 22 | defer h.mu.Unlock() 23 | h.n++ 24 | fmt.Fprintf(w, "count is %d\n", h.n) 25 | } 26 | 27 | func ExampleHandle() { 28 | http.Handle("/count", new(countHandler)) 29 | log.Fatal(http.ListenAndServe(":8080", nil)) 30 | } 31 | -------------------------------------------------------------------------------- /lib/http/filetransport_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http 6 | 7 | import ( 8 | "io" 9 | "os" 10 | "path/filepath" 11 | "testing" 12 | ) 13 | 14 | func checker(t *testing.T) func(string, error) { 15 | return func(call string, err error) { 16 | if err == nil { 17 | return 18 | } 19 | t.Fatalf("%s: %v", call, err) 20 | } 21 | } 22 | 23 | func TestFileTransport(t *testing.T) { 24 | check := checker(t) 25 | 26 | dname := t.TempDir() 27 | fname := filepath.Join(dname, "foo.txt") 28 | err := os.WriteFile(fname, []byte("Bar"), 0644) 29 | check("WriteFile", err) 30 | defer os.Remove(fname) 31 | 32 | tr := &Transport{} 33 | tr.RegisterProtocol("file", NewFileTransport(Dir(dname))) 34 | c := &Client{Transport: tr} 35 | 36 | fooURLs := []string{"file:///foo.txt", "file://../foo.txt"} 37 | for _, urlstr := range fooURLs { 38 | res, err := c.Get(urlstr) 39 | check("Get "+urlstr, err) 40 | if res.StatusCode != 200 { 41 | t.Errorf("for %s, StatusCode = %d, want 200", urlstr, res.StatusCode) 42 | } 43 | if res.ContentLength != -1 { 44 | t.Errorf("for %s, ContentLength = %d, want -1", urlstr, res.ContentLength) 45 | } 46 | if res.Body == nil { 47 | t.Fatalf("for %s, nil Body", urlstr) 48 | } 49 | slurp, err := io.ReadAll(res.Body) 50 | res.Body.Close() 51 | check("ReadAll "+urlstr, err) 52 | if string(slurp) != "Bar" { 53 | t.Errorf("for %s, got content %q, want %q", urlstr, string(slurp), "Bar") 54 | } 55 | } 56 | 57 | const badURL = "file://../no-exist.txt" 58 | res, err := c.Get(badURL) 59 | check("Get "+badURL, err) 60 | if res.StatusCode != 404 { 61 | t.Errorf("for %s, StatusCode = %d, want 404", badURL, res.StatusCode) 62 | } 63 | res.Body.Close() 64 | } 65 | -------------------------------------------------------------------------------- /lib/http/httpproxy/export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package httpproxy 6 | 7 | func ExportUseProxy(cfg *Config, host string) bool { 8 | cfg1 := &config{ 9 | Config: *cfg, 10 | } 11 | cfg1.init() 12 | return cfg1.useProxy(host) 13 | } 14 | -------------------------------------------------------------------------------- /lib/http/httpproxy/go19_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.9 6 | // +build go1.9 7 | 8 | package httpproxy_test 9 | 10 | import "testing" 11 | 12 | func init() { 13 | setHelper = func(t *testing.T) { t.Helper() } 14 | } 15 | -------------------------------------------------------------------------------- /lib/http/httptrace/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package httptrace_test 6 | 7 | import ( 8 | "fmt" 9 | "log" 10 | 11 | "github.com/ck00004/CobaltStrikeParser-Go/lib/http/httptrace" 12 | 13 | "github.com/ck00004/CobaltStrikeParser-Go/lib/http" 14 | ) 15 | 16 | func Example() { 17 | req, _ := http.NewRequest("GET", "http://example.com", nil) 18 | trace := &httptrace.ClientTrace{ 19 | GotConn: func(connInfo httptrace.GotConnInfo) { 20 | fmt.Printf("Got Conn: %+v\n", connInfo) 21 | }, 22 | DNSDone: func(dnsInfo httptrace.DNSDoneInfo) { 23 | fmt.Printf("DNS Info: %+v\n", dnsInfo) 24 | }, 25 | } 26 | req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) 27 | _, err := http.DefaultTransport.RoundTrip(req) 28 | if err != nil { 29 | log.Fatal(err) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/http/httputil/httputil.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package httputil provides HTTP utility functions, complementing the 6 | // more common ones in the net/http package. 7 | package httputil 8 | 9 | import ( 10 | "io" 11 | 12 | "github.com/ck00004/CobaltStrikeParser-Go/lib/http/internal" 13 | ) 14 | 15 | // NewChunkedReader returns a new chunkedReader that translates the data read from r 16 | // out of HTTP "chunked" format before returning it. 17 | // The chunkedReader returns io.EOF when the final 0-length chunk is read. 18 | // 19 | // NewChunkedReader is not needed by normal applications. The http package 20 | // automatically decodes chunking when reading response bodies. 21 | func NewChunkedReader(r io.Reader) io.Reader { 22 | return internal.NewChunkedReader(r) 23 | } 24 | 25 | // NewChunkedWriter returns a new chunkedWriter that translates writes into HTTP 26 | // "chunked" format before writing them to w. Closing the returned chunkedWriter 27 | // sends the final 0-length chunk that marks the end of the stream but does 28 | // not send the final CRLF that appears after trailers; trailers and the last 29 | // CRLF must be written separately. 30 | // 31 | // NewChunkedWriter is not needed by normal applications. The http 32 | // package adds chunking automatically if handlers don't set a 33 | // Content-Length header. Using NewChunkedWriter inside a handler 34 | // would result in double chunking or chunking with a Content-Length 35 | // length, both of which are wrong. 36 | func NewChunkedWriter(w io.Writer) io.WriteCloser { 37 | return internal.NewChunkedWriter(w) 38 | } 39 | 40 | // ErrLineTooLong is returned when reading malformed chunked data 41 | // with lines that are too long. 42 | var ErrLineTooLong = internal.ErrLineTooLong 43 | -------------------------------------------------------------------------------- /lib/http/internal/ascii/print.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ascii 6 | 7 | import ( 8 | "strings" 9 | "unicode" 10 | ) 11 | 12 | // EqualFold is strings.EqualFold, ASCII only. It reports whether s and t 13 | // are equal, ASCII-case-insensitively. 14 | func EqualFold(s, t string) bool { 15 | if len(s) != len(t) { 16 | return false 17 | } 18 | for i := 0; i < len(s); i++ { 19 | if lower(s[i]) != lower(t[i]) { 20 | return false 21 | } 22 | } 23 | return true 24 | } 25 | 26 | // lower returns the ASCII lowercase version of b. 27 | func lower(b byte) byte { 28 | if 'A' <= b && b <= 'Z' { 29 | return b + ('a' - 'A') 30 | } 31 | return b 32 | } 33 | 34 | // IsPrint returns whether s is ASCII and printable according to 35 | // https://tools.ietf.org/html/rfc20#section-4.2. 36 | func IsPrint(s string) bool { 37 | for i := 0; i < len(s); i++ { 38 | if s[i] < ' ' || s[i] > '~' { 39 | return false 40 | } 41 | } 42 | return true 43 | } 44 | 45 | // Is returns whether s is ASCII. 46 | func Is(s string) bool { 47 | for i := 0; i < len(s); i++ { 48 | if s[i] > unicode.MaxASCII { 49 | return false 50 | } 51 | } 52 | return true 53 | } 54 | 55 | // ToLower returns the lowercase version of s if s is ASCII and printable. 56 | func ToLower(s string) (lower string, ok bool) { 57 | if !IsPrint(s) { 58 | return "", false 59 | } 60 | return strings.ToLower(s), true 61 | } 62 | -------------------------------------------------------------------------------- /lib/http/internal/ascii/print_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ascii 6 | 7 | import "testing" 8 | 9 | func TestEqualFold(t *testing.T) { 10 | var tests = []struct { 11 | name string 12 | a, b string 13 | want bool 14 | }{ 15 | { 16 | name: "empty", 17 | want: true, 18 | }, 19 | { 20 | name: "simple match", 21 | a: "CHUNKED", 22 | b: "chunked", 23 | want: true, 24 | }, 25 | { 26 | name: "same string", 27 | a: "chunked", 28 | b: "chunked", 29 | want: true, 30 | }, 31 | { 32 | name: "Unicode Kelvin symbol", 33 | a: "chunKed", // This "K" is 'KELVIN SIGN' (\u212A) 34 | b: "chunked", 35 | want: false, 36 | }, 37 | } 38 | for _, tt := range tests { 39 | t.Run(tt.name, func(t *testing.T) { 40 | if got := EqualFold(tt.a, tt.b); got != tt.want { 41 | t.Errorf("AsciiEqualFold(%q,%q): got %v want %v", tt.a, tt.b, got, tt.want) 42 | } 43 | }) 44 | } 45 | } 46 | 47 | func TestIsPrint(t *testing.T) { 48 | var tests = []struct { 49 | name string 50 | in string 51 | want bool 52 | }{ 53 | { 54 | name: "empty", 55 | want: true, 56 | }, 57 | { 58 | name: "ASCII low", 59 | in: "This is a space: ' '", 60 | want: true, 61 | }, 62 | { 63 | name: "ASCII high", 64 | in: "This is a tilde: '~'", 65 | want: true, 66 | }, 67 | { 68 | name: "ASCII low non-print", 69 | in: "This is a unit separator: \x1F", 70 | want: false, 71 | }, 72 | { 73 | name: "Ascii high non-print", 74 | in: "This is a Delete: \x7F", 75 | want: false, 76 | }, 77 | { 78 | name: "Unicode letter", 79 | in: "Today it's 280K outside: it's freezing!", // This "K" is 'KELVIN SIGN' (\u212A) 80 | want: false, 81 | }, 82 | { 83 | name: "Unicode emoji", 84 | in: "Gophers like 🧀", 85 | want: false, 86 | }, 87 | } 88 | for _, tt := range tests { 89 | t.Run(tt.name, func(t *testing.T) { 90 | if got := IsPrint(tt.in); got != tt.want { 91 | t.Errorf("IsASCIIPrint(%q): got %v want %v", tt.in, got, tt.want) 92 | } 93 | }) 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /lib/http/jar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http 6 | 7 | import ( 8 | "github.com/ck00004/CobaltStrikeParser-Go/lib/url" 9 | ) 10 | 11 | // A CookieJar manages storage and use of cookies in HTTP requests. 12 | // 13 | // Implementations of CookieJar must be safe for concurrent use by multiple 14 | // goroutines. 15 | // 16 | // The net/http/cookiejar package provides a CookieJar implementation. 17 | type CookieJar interface { 18 | // SetCookies handles the receipt of the cookies in a reply for the 19 | // given URL. It may or may not choose to save the cookies, depending 20 | // on the jar's policy and implementation. 21 | SetCookies(u *url.URL, cookies []*Cookie) 22 | 23 | // Cookies returns the cookies to send in a request for the given URL. 24 | // It is up to the implementation to honor the standard cookie use 25 | // restrictions such as in RFC 6265. 26 | Cookies(u *url.URL) []*Cookie 27 | } 28 | -------------------------------------------------------------------------------- /lib/http/method.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http 6 | 7 | // Common HTTP methods. 8 | // 9 | // Unless otherwise noted, these are defined in RFC 7231 section 4.3. 10 | const ( 11 | MethodGet = "GET" 12 | MethodHead = "HEAD" 13 | MethodPost = "POST" 14 | MethodPut = "PUT" 15 | MethodPatch = "PATCH" // RFC 5789 16 | MethodDelete = "DELETE" 17 | MethodConnect = "CONNECT" 18 | MethodOptions = "OPTIONS" 19 | MethodTrace = "TRACE" 20 | ) 21 | -------------------------------------------------------------------------------- /lib/http/omithttp2.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build nethttpomithttp2 6 | // +build nethttpomithttp2 7 | 8 | package http 9 | 10 | import ( 11 | "errors" 12 | "sync" 13 | "time" 14 | ) 15 | 16 | func init() { 17 | omitBundledHTTP2 = true 18 | } 19 | 20 | const noHTTP2 = "no bundled HTTP/2" // should never see this 21 | 22 | var http2errRequestCanceled = errors.New("net/http: request canceled") 23 | 24 | var http2goAwayTimeout = 1 * time.Second 25 | 26 | const http2NextProtoTLS = "h2" 27 | 28 | type http2Transport struct { 29 | MaxHeaderListSize uint32 30 | ConnPool interface{} 31 | } 32 | 33 | func (*http2Transport) RoundTrip(*Request) (*Response, error) { panic(noHTTP2) } 34 | func (*http2Transport) CloseIdleConnections() {} 35 | 36 | type http2noDialH2RoundTripper struct{} 37 | 38 | func (http2noDialH2RoundTripper) RoundTrip(*Request) (*Response, error) { panic(noHTTP2) } 39 | 40 | type http2noDialClientConnPool struct { 41 | http2clientConnPool http2clientConnPool 42 | } 43 | 44 | type http2clientConnPool struct { 45 | mu *sync.Mutex 46 | conns map[string][]struct{} 47 | } 48 | 49 | func http2configureTransports(*Transport) (*http2Transport, error) { panic(noHTTP2) } 50 | 51 | func http2isNoCachedConnError(err error) bool { 52 | _, ok := err.(interface{ IsHTTP2NoCachedConnError() }) 53 | return ok 54 | } 55 | 56 | type http2Server struct { 57 | NewWriteScheduler func() http2WriteScheduler 58 | } 59 | 60 | type http2WriteScheduler interface{} 61 | 62 | func http2NewPriorityWriteScheduler(interface{}) http2WriteScheduler { panic(noHTTP2) } 63 | 64 | func http2ConfigureServer(s *Server, conf *http2Server) error { panic(noHTTP2) } 65 | 66 | var http2ErrNoCachedConn = http2noCachedConnError{} 67 | 68 | type http2noCachedConnError struct{} 69 | 70 | func (http2noCachedConnError) IsHTTP2NoCachedConnError() {} 71 | 72 | func (http2noCachedConnError) Error() string { return "http2: no cached connection was available" } 73 | -------------------------------------------------------------------------------- /lib/http/proxy_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http 6 | 7 | import ( 8 | "os" 9 | "testing" 10 | 11 | "github.com/ck00004/CobaltStrikeParser-Go/lib/url" 12 | ) 13 | 14 | // TODO(mattn): 15 | // test ProxyAuth 16 | 17 | var cacheKeysTests = []struct { 18 | proxy string 19 | scheme string 20 | addr string 21 | key string 22 | }{ 23 | {"", "http", "foo.com", "|http|foo.com"}, 24 | {"", "https", "foo.com", "|https|foo.com"}, 25 | {"http://foo.com", "http", "foo.com", "http://foo.com|http|"}, 26 | {"http://foo.com", "https", "foo.com", "http://foo.com|https|foo.com"}, 27 | } 28 | 29 | func TestCacheKeys(t *testing.T) { 30 | for _, tt := range cacheKeysTests { 31 | var proxy *url.URL 32 | if tt.proxy != "" { 33 | u, err := url.Parse(tt.proxy) 34 | if err != nil { 35 | t.Fatal(err) 36 | } 37 | proxy = u 38 | } 39 | cm := connectMethod{proxyURL: proxy, targetScheme: tt.scheme, targetAddr: tt.addr} 40 | if got := cm.key().String(); got != tt.key { 41 | t.Fatalf("{%q, %q, %q} cache key = %q; want %q", tt.proxy, tt.scheme, tt.addr, got, tt.key) 42 | } 43 | } 44 | } 45 | 46 | func ResetProxyEnv() { 47 | for _, v := range []string{"HTTP_PROXY", "http_proxy", "NO_PROXY", "no_proxy", "REQUEST_METHOD"} { 48 | os.Unsetenv(v) 49 | } 50 | ResetCachedEnvironment() 51 | } 52 | -------------------------------------------------------------------------------- /lib/http/roundtrip.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !js || !wasm 6 | // +build !js !wasm 7 | 8 | package http 9 | 10 | // RoundTrip implements the RoundTripper interface. 11 | // 12 | // For higher-level HTTP client support (such as handling of cookies 13 | // and redirects), see Get, Post, and the Client type. 14 | // 15 | // Like the RoundTripper interface, the error types returned 16 | // by RoundTrip are unspecified. 17 | func (t *Transport) RoundTrip(req *Request) (*Response, error) { 18 | return t.roundTrip(req) 19 | } 20 | -------------------------------------------------------------------------------- /lib/http/server_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Server unit tests 6 | 7 | package http 8 | 9 | import ( 10 | "fmt" 11 | "testing" 12 | ) 13 | 14 | func BenchmarkServerMatch(b *testing.B) { 15 | fn := func(w ResponseWriter, r *Request) { 16 | fmt.Fprintf(w, "OK") 17 | } 18 | mux := NewServeMux() 19 | mux.HandleFunc("/", fn) 20 | mux.HandleFunc("/index", fn) 21 | mux.HandleFunc("/home", fn) 22 | mux.HandleFunc("/about", fn) 23 | mux.HandleFunc("/contact", fn) 24 | mux.HandleFunc("/robots.txt", fn) 25 | mux.HandleFunc("/products/", fn) 26 | mux.HandleFunc("/products/1", fn) 27 | mux.HandleFunc("/products/2", fn) 28 | mux.HandleFunc("/products/3", fn) 29 | mux.HandleFunc("/products/3/image.jpg", fn) 30 | mux.HandleFunc("/admin", fn) 31 | mux.HandleFunc("/admin/products/", fn) 32 | mux.HandleFunc("/admin/products/create", fn) 33 | mux.HandleFunc("/admin/products/update", fn) 34 | mux.HandleFunc("/admin/products/delete", fn) 35 | 36 | paths := []string{"/", "/notfound", "/admin/", "/admin/foo", "/contact", "/products", 37 | "/products/", "/products/3/image.jpg"} 38 | b.StartTimer() 39 | for i := 0; i < b.N; i++ { 40 | if h, p := mux.match(paths[i%len(paths)]); h != nil && p == "" { 41 | b.Error("impossible") 42 | } 43 | } 44 | b.StopTimer() 45 | } 46 | -------------------------------------------------------------------------------- /lib/http/testdata/file: -------------------------------------------------------------------------------- 1 | 0123456789 2 | -------------------------------------------------------------------------------- /lib/http/testdata/index.html: -------------------------------------------------------------------------------- 1 | index.html says hello 2 | -------------------------------------------------------------------------------- /lib/http/testdata/style.css: -------------------------------------------------------------------------------- 1 | body {} 2 | -------------------------------------------------------------------------------- /lib/internal/abi/abi_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build goexperiment.regabireflect 6 | // +build goexperiment.regabireflect 7 | 8 | package abi 9 | 10 | const ( 11 | // See abi_generic.go. 12 | 13 | // RAX, RBX, RCX, RDI, RSI, R8, R9, R10, R11. 14 | IntArgRegs = 9 15 | 16 | // X0 -> X14. 17 | FloatArgRegs = 15 18 | 19 | // We use SSE2 registers which support 64-bit float operations. 20 | EffectiveFloatRegSize = 8 21 | ) 22 | -------------------------------------------------------------------------------- /lib/internal/abi/abi_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !goexperiment.regabireflect 6 | // +build !goexperiment.regabireflect 7 | 8 | package abi 9 | 10 | const ( 11 | // ABI-related constants. 12 | // 13 | // In the generic case, these are all zero 14 | // which lets them gracefully degrade to ABI0. 15 | 16 | // IntArgRegs is the number of registers dedicated 17 | // to passing integer argument values. Result registers are identical 18 | // to argument registers, so this number is used for those too. 19 | IntArgRegs = 0 20 | 21 | // FloatArgRegs is the number of registers dedicated 22 | // to passing floating-point argument values. Result registers are 23 | // identical to argument registers, so this number is used for 24 | // those too. 25 | FloatArgRegs = 0 26 | 27 | // EffectiveFloatRegSize describes the width of floating point 28 | // registers on the current platform from the ABI's perspective. 29 | // 30 | // Since Go only supports 32-bit and 64-bit floating point primitives, 31 | // this number should be either 0, 4, or 8. 0 indicates no floating 32 | // point registers for the ABI or that floating point values will be 33 | // passed via the softfloat ABI. 34 | // 35 | // For platforms that support larger floating point register widths, 36 | // such as x87's 80-bit "registers" (not that we support x87 currently), 37 | // use 8. 38 | EffectiveFloatRegSize = 0 39 | ) 40 | -------------------------------------------------------------------------------- /lib/internal/abi/abi_test.s: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | 7 | #ifdef GOARCH_386 8 | #define PTRSIZE 4 9 | #endif 10 | #ifdef GOARCH_arm 11 | #define PTRSIZE 4 12 | #endif 13 | #ifdef GOARCH_mips 14 | #define PTRSIZE 4 15 | #endif 16 | #ifdef GOARCH_mipsle 17 | #define PTRSIZE 4 18 | #endif 19 | #ifndef PTRSIZE 20 | #define PTRSIZE 8 21 | #endif 22 | 23 | TEXT internal∕abi·FuncPCTestFn(SB),NOSPLIT,$0-0 24 | RET 25 | 26 | GLOBL internal∕abi·FuncPCTestFnAddr(SB), NOPTR, $PTRSIZE 27 | DATA internal∕abi·FuncPCTestFnAddr(SB)/PTRSIZE, $internal∕abi·FuncPCTestFn(SB) 28 | -------------------------------------------------------------------------------- /lib/internal/abi/export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package abi 6 | 7 | func FuncPCTestFn() 8 | 9 | var FuncPCTestFnAddr uintptr // address of FuncPCTestFn, directly retrieved from assembly 10 | 11 | //go:noinline 12 | func FuncPCTest() uintptr { 13 | return FuncPCABI0(FuncPCTestFn) 14 | } 15 | -------------------------------------------------------------------------------- /lib/internal/abi/testdata/x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package x 6 | 7 | import "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/abi" 8 | 9 | func Fn0() // defined in assembly 10 | 11 | func Fn1() {} 12 | 13 | var FnExpr func() 14 | 15 | func test() { 16 | _ = abi.FuncPCABI0(Fn0) // line 16, no error 17 | _ = abi.FuncPCABIInternal(Fn0) // line 17, error 18 | _ = abi.FuncPCABI0(Fn1) // line 18, error 19 | _ = abi.FuncPCABIInternal(Fn1) // line 19, no error 20 | _ = abi.FuncPCABI0(FnExpr) // line 20, error 21 | _ = abi.FuncPCABIInternal(FnExpr) // line 21, no error 22 | } 23 | -------------------------------------------------------------------------------- /lib/internal/abi/testdata/x.s: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | TEXT ·Fn0(SB), 0, $0-0 6 | RET 7 | -------------------------------------------------------------------------------- /lib/internal/buildcfg/zbootstrap.go: -------------------------------------------------------------------------------- 1 | // Code generated by go tool dist; DO NOT EDIT. 2 | 3 | package buildcfg 4 | 5 | import "runtime" 6 | 7 | const defaultGO386 = `sse2` 8 | const defaultGOARM = `7` 9 | const defaultGOMIPS = `hardfloat` 10 | const defaultGOMIPS64 = `hardfloat` 11 | const defaultGOPPC64 = `power8` 12 | const defaultGOEXPERIMENT = `` 13 | const defaultGO_EXTLINK_ENABLED = `` 14 | const defaultGO_LDSO = `` 15 | const version = `go1.17.1` 16 | const defaultGOOS = runtime.GOOS 17 | const defaultGOARCH = runtime.GOARCH 18 | -------------------------------------------------------------------------------- /lib/internal/bytealg/compare_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | TEXT ·Compare(SB),NOSPLIT|NOFRAME,$0-28 9 | MOVW a_base+0(FP), R2 10 | MOVW a_len+4(FP), R0 11 | MOVW b_base+12(FP), R3 12 | MOVW b_len+16(FP), R1 13 | ADD $28, R13, R7 14 | B cmpbody<>(SB) 15 | 16 | TEXT runtime·cmpstring(SB),NOSPLIT|NOFRAME,$0-20 17 | MOVW a_base+0(FP), R2 18 | MOVW a_len+4(FP), R0 19 | MOVW b_base+8(FP), R3 20 | MOVW b_len+12(FP), R1 21 | ADD $20, R13, R7 22 | B cmpbody<>(SB) 23 | 24 | // On entry: 25 | // R0 is the length of a 26 | // R1 is the length of b 27 | // R2 points to the start of a 28 | // R3 points to the start of b 29 | // R7 points to return value (-1/0/1 will be written here) 30 | // 31 | // On exit: 32 | // R4, R5, R6 and R8 are clobbered 33 | TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0-0 34 | CMP R2, R3 35 | BEQ samebytes 36 | CMP R0, R1 37 | MOVW R0, R6 38 | MOVW.LT R1, R6 // R6 is min(R0, R1) 39 | 40 | CMP $0, R6 41 | BEQ samebytes 42 | CMP $4, R6 43 | ADD R2, R6 // R2 is current byte in a, R6 is the end of the range to compare 44 | BLT byte_loop // length < 4 45 | AND $3, R2, R8 46 | CMP $0, R8 47 | BNE byte_loop // unaligned a, use byte-wise compare (TODO: try to align a) 48 | aligned_a: 49 | AND $3, R3, R8 50 | CMP $0, R8 51 | BNE byte_loop // unaligned b, use byte-wise compare 52 | AND $0xfffffffc, R6, R8 53 | // length >= 4 54 | chunk4_loop: 55 | MOVW.P 4(R2), R4 56 | MOVW.P 4(R3), R5 57 | CMP R4, R5 58 | BNE cmp 59 | CMP R2, R8 60 | BNE chunk4_loop 61 | CMP R2, R6 62 | BEQ samebytes // all compared bytes were the same; compare lengths 63 | byte_loop: 64 | MOVBU.P 1(R2), R4 65 | MOVBU.P 1(R3), R5 66 | CMP R4, R5 67 | BNE ret 68 | CMP R2, R6 69 | BNE byte_loop 70 | samebytes: 71 | CMP R0, R1 72 | MOVW.LT $1, R0 73 | MOVW.GT $-1, R0 74 | MOVW.EQ $0, R0 75 | MOVW R0, (R7) 76 | RET 77 | ret: 78 | // bytes differed 79 | MOVW.LT $1, R0 80 | MOVW.GT $-1, R0 81 | MOVW R0, (R7) 82 | RET 83 | cmp: 84 | SUB $4, R2, R2 85 | SUB $4, R3, R3 86 | B byte_loop 87 | -------------------------------------------------------------------------------- /lib/internal/bytealg/compare_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !386 && !amd64 && !s390x && !arm && !arm64 && !ppc64 && !ppc64le && !mips && !mipsle && !wasm && !mips64 && !mips64le 6 | // +build !386,!amd64,!s390x,!arm,!arm64,!ppc64,!ppc64le,!mips,!mipsle,!wasm,!mips64,!mips64le 7 | 8 | package bytealg 9 | 10 | import _ "unsafe" // for go:linkname 11 | 12 | func Compare(a, b []byte) int { 13 | l := len(a) 14 | if len(b) < l { 15 | l = len(b) 16 | } 17 | if l == 0 || &a[0] == &b[0] { 18 | goto samebytes 19 | } 20 | for i := 0; i < l; i++ { 21 | c1, c2 := a[i], b[i] 22 | if c1 < c2 { 23 | return -1 24 | } 25 | if c1 > c2 { 26 | return +1 27 | } 28 | } 29 | samebytes: 30 | if len(a) < len(b) { 31 | return -1 32 | } 33 | if len(a) > len(b) { 34 | return +1 35 | } 36 | return 0 37 | } 38 | 39 | //go:linkname runtime_cmpstring runtime.cmpstring 40 | func runtime_cmpstring(a, b string) int { 41 | l := len(a) 42 | if len(b) < l { 43 | l = len(b) 44 | } 45 | for i := 0; i < l; i++ { 46 | c1, c2 := a[i], b[i] 47 | if c1 < c2 { 48 | return -1 49 | } 50 | if c1 > c2 { 51 | return +1 52 | } 53 | } 54 | if len(a) < len(b) { 55 | return -1 56 | } 57 | if len(a) > len(b) { 58 | return +1 59 | } 60 | return 0 61 | } 62 | -------------------------------------------------------------------------------- /lib/internal/bytealg/compare_mips64x.s: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build mips64 || mips64le 6 | // +build mips64 mips64le 7 | 8 | #include "go_asm.h" 9 | #include "textflag.h" 10 | 11 | TEXT ·Compare(SB),NOSPLIT,$0-56 12 | MOVV a_base+0(FP), R3 13 | MOVV b_base+24(FP), R4 14 | MOVV a_len+8(FP), R1 15 | MOVV b_len+32(FP), R2 16 | MOVV $ret+48(FP), R9 17 | JMP cmpbody<>(SB) 18 | 19 | TEXT runtime·cmpstring(SB),NOSPLIT,$0-40 20 | MOVV a_base+0(FP), R3 21 | MOVV b_base+16(FP), R4 22 | MOVV a_len+8(FP), R1 23 | MOVV b_len+24(FP), R2 24 | MOVV $ret+32(FP), R9 25 | JMP cmpbody<>(SB) 26 | 27 | // On entry: 28 | // R1 length of a 29 | // R2 length of b 30 | // R3 points to the start of a 31 | // R4 points to the start of b 32 | // R9 points to the return value (-1/0/1) 33 | TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0 34 | BEQ R3, R4, samebytes // same start of a and b 35 | 36 | SGTU R1, R2, R7 37 | BNE R0, R7, r2_lt_r1 38 | MOVV R1, R10 39 | JMP entry 40 | r2_lt_r1: 41 | MOVV R2, R10 // R10 is min(R1, R2) 42 | entry: 43 | ADDV R3, R10, R8 // R3 start of a, R8 end of a 44 | BEQ R3, R8, samebytes // length is 0 45 | 46 | SRLV $4, R10 // R10 is number of chunks 47 | BEQ R0, R10, byte_loop 48 | 49 | // make sure both a and b are aligned. 50 | OR R3, R4, R11 51 | AND $7, R11 52 | BNE R0, R11, byte_loop 53 | 54 | chunk16_loop: 55 | BEQ R0, R10, byte_loop 56 | MOVV (R3), R6 57 | MOVV (R4), R7 58 | BNE R6, R7, byte_loop 59 | MOVV 8(R3), R13 60 | MOVV 8(R4), R14 61 | ADDV $16, R3 62 | ADDV $16, R4 63 | SUBVU $1, R10 64 | BEQ R13, R14, chunk16_loop 65 | SUBV $8, R3 66 | SUBV $8, R4 67 | 68 | byte_loop: 69 | BEQ R3, R8, samebytes 70 | MOVBU (R3), R6 71 | ADDVU $1, R3 72 | MOVBU (R4), R7 73 | ADDVU $1, R4 74 | BEQ R6, R7, byte_loop 75 | 76 | byte_cmp: 77 | SGTU R6, R7, R8 // R8 = 1 if (R6 > R7) 78 | BNE R0, R8, ret 79 | MOVV $-1, R8 80 | JMP ret 81 | 82 | samebytes: 83 | SGTU R1, R2, R6 84 | SGTU R2, R1, R7 85 | SUBV R7, R6, R8 86 | 87 | ret: 88 | MOVV R8, (R9) 89 | RET 90 | -------------------------------------------------------------------------------- /lib/internal/bytealg/compare_mipsx.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build mips || mipsle 6 | // +build mips mipsle 7 | 8 | #include "go_asm.h" 9 | #include "textflag.h" 10 | 11 | TEXT ·Compare(SB),NOSPLIT,$0-28 12 | MOVW a_base+0(FP), R3 13 | MOVW b_base+12(FP), R4 14 | MOVW a_len+4(FP), R1 15 | MOVW b_len+16(FP), R2 16 | BEQ R3, R4, samebytes 17 | SGTU R1, R2, R7 18 | MOVW R1, R8 19 | CMOVN R7, R2, R8 // R8 is min(R1, R2) 20 | 21 | ADDU R3, R8 // R3 is current byte in a, R8 is last byte in a to compare 22 | loop: 23 | BEQ R3, R8, samebytes 24 | 25 | MOVBU (R3), R6 26 | ADDU $1, R3 27 | MOVBU (R4), R7 28 | ADDU $1, R4 29 | BEQ R6, R7 , loop 30 | 31 | SGTU R6, R7, R8 32 | MOVW $-1, R6 33 | CMOVZ R8, R6, R8 34 | JMP cmp_ret 35 | samebytes: 36 | SGTU R1, R2, R6 37 | SGTU R2, R1, R7 38 | SUBU R7, R6, R8 39 | cmp_ret: 40 | MOVW R8, ret+24(FP) 41 | RET 42 | 43 | TEXT runtime·cmpstring(SB),NOSPLIT,$0-20 44 | MOVW a_base+0(FP), R3 45 | MOVW a_len+4(FP), R1 46 | MOVW b_base+8(FP), R4 47 | MOVW b_len+12(FP), R2 48 | BEQ R3, R4, samebytes 49 | SGTU R1, R2, R7 50 | MOVW R1, R8 51 | CMOVN R7, R2, R8 // R8 is min(R1, R2) 52 | 53 | ADDU R3, R8 // R3 is current byte in a, R8 is last byte in a to compare 54 | loop: 55 | BEQ R3, R8, samebytes // all compared bytes were the same; compare lengths 56 | 57 | MOVBU (R3), R6 58 | ADDU $1, R3 59 | MOVBU (R4), R7 60 | ADDU $1, R4 61 | BEQ R6, R7 , loop 62 | // bytes differed 63 | SGTU R6, R7, R8 64 | MOVW $-1, R6 65 | CMOVZ R8, R6, R8 66 | JMP cmp_ret 67 | samebytes: 68 | SGTU R1, R2, R6 69 | SGTU R2, R1, R7 70 | SUBU R7, R6, R8 71 | cmp_ret: 72 | MOVW R8, ret+16(FP) 73 | RET 74 | -------------------------------------------------------------------------------- /lib/internal/bytealg/compare_native.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build 386 || amd64 || s390x || arm || arm64 || ppc64 || ppc64le || mips || mipsle || wasm || mips64 || mips64le 6 | // +build 386 amd64 s390x arm arm64 ppc64 ppc64le mips mipsle wasm mips64 mips64le 7 | 8 | package bytealg 9 | 10 | import _ "unsafe" // For go:linkname 11 | 12 | //go:noescape 13 | func Compare(a, b []byte) int 14 | 15 | // The declaration below generates ABI wrappers for functions 16 | // implemented in assembly in this package but declared in another 17 | // package. 18 | 19 | //go:linkname abigen_runtime_cmpstring runtime.cmpstring 20 | func abigen_runtime_cmpstring(a, b string) int 21 | -------------------------------------------------------------------------------- /lib/internal/bytealg/compare_s390x.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | TEXT ·Compare(SB),NOSPLIT|NOFRAME,$0-56 9 | MOVD a_base+0(FP), R3 10 | MOVD a_len+8(FP), R4 11 | MOVD b_base+24(FP), R5 12 | MOVD b_len+32(FP), R6 13 | LA ret+48(FP), R7 14 | BR cmpbody<>(SB) 15 | 16 | TEXT runtime·cmpstring(SB),NOSPLIT|NOFRAME,$0-40 17 | MOVD a_base+0(FP), R3 18 | MOVD a_len+8(FP), R4 19 | MOVD b_base+16(FP), R5 20 | MOVD b_len+24(FP), R6 21 | LA ret+32(FP), R7 22 | BR cmpbody<>(SB) 23 | 24 | // input: 25 | // R3 = a 26 | // R4 = alen 27 | // R5 = b 28 | // R6 = blen 29 | // R7 = address of output word (stores -1/0/1 here) 30 | TEXT cmpbody<>(SB),NOSPLIT|NOFRAME,$0-0 31 | CMPBEQ R3, R5, cmplengths 32 | MOVD R4, R8 33 | CMPBLE R4, R6, amin 34 | MOVD R6, R8 35 | amin: 36 | CMPBEQ R8, $0, cmplengths 37 | CMP R8, $256 38 | BLE tail 39 | loop: 40 | CLC $256, 0(R3), 0(R5) 41 | BGT gt 42 | BLT lt 43 | SUB $256, R8 44 | MOVD $256(R3), R3 45 | MOVD $256(R5), R5 46 | CMP R8, $256 47 | BGT loop 48 | tail: 49 | SUB $1, R8 50 | EXRL $cmpbodyclc<>(SB), R8 51 | BGT gt 52 | BLT lt 53 | cmplengths: 54 | CMP R4, R6 55 | BEQ eq 56 | BLT lt 57 | gt: 58 | MOVD $1, 0(R7) 59 | RET 60 | lt: 61 | MOVD $-1, 0(R7) 62 | RET 63 | eq: 64 | MOVD $0, 0(R7) 65 | RET 66 | 67 | TEXT cmpbodyclc<>(SB),NOSPLIT|NOFRAME,$0-0 68 | CLC $1, 0(R3), 0(R5) 69 | RET 70 | -------------------------------------------------------------------------------- /lib/internal/bytealg/compare_wasm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | TEXT ·Compare(SB), NOSPLIT, $0-56 9 | Get SP 10 | I64Load a_base+0(FP) 11 | I64Load a_len+8(FP) 12 | I64Load b_base+24(FP) 13 | I64Load b_len+32(FP) 14 | Call cmpbody<>(SB) 15 | I64Store ret+48(FP) 16 | RET 17 | 18 | TEXT runtime·cmpstring(SB), NOSPLIT, $0-40 19 | Get SP 20 | I64Load a_base+0(FP) 21 | I64Load a_len+8(FP) 22 | I64Load b_base+16(FP) 23 | I64Load b_len+24(FP) 24 | Call cmpbody<>(SB) 25 | I64Store ret+32(FP) 26 | RET 27 | 28 | // params: a, alen, b, blen 29 | // ret: -1/0/1 30 | TEXT cmpbody<>(SB), NOSPLIT, $0-0 31 | // len = min(alen, blen) 32 | Get R1 33 | Get R3 34 | Get R1 35 | Get R3 36 | I64LtU 37 | Select 38 | Set R4 39 | 40 | Get R0 41 | I32WrapI64 42 | Get R2 43 | I32WrapI64 44 | Get R4 45 | I32WrapI64 46 | Call memcmp<>(SB) 47 | I64ExtendI32S 48 | Tee R5 49 | 50 | I64Eqz 51 | If 52 | // check length 53 | Get R1 54 | Get R3 55 | I64Sub 56 | Set R5 57 | End 58 | 59 | I64Const $0 60 | I64Const $-1 61 | I64Const $1 62 | Get R5 63 | I64Const $0 64 | I64LtS 65 | Select 66 | Get R5 67 | I64Eqz 68 | Select 69 | Return 70 | 71 | // compiled with emscripten 72 | // params: a, b, len 73 | // ret: <0/0/>0 74 | TEXT memcmp<>(SB), NOSPLIT, $0-0 75 | Get R2 76 | If $1 77 | Loop 78 | Get R0 79 | I32Load8S $0 80 | Tee R3 81 | Get R1 82 | I32Load8S $0 83 | Tee R4 84 | I32Eq 85 | If 86 | Get R0 87 | I32Const $1 88 | I32Add 89 | Set R0 90 | Get R1 91 | I32Const $1 92 | I32Add 93 | Set R1 94 | I32Const $0 95 | Get R2 96 | I32Const $-1 97 | I32Add 98 | Tee R2 99 | I32Eqz 100 | BrIf $3 101 | Drop 102 | Br $1 103 | End 104 | End 105 | Get R3 106 | I32Const $255 107 | I32And 108 | Get R4 109 | I32Const $255 110 | I32And 111 | I32Sub 112 | Else 113 | I32Const $0 114 | End 115 | Return 116 | -------------------------------------------------------------------------------- /lib/internal/bytealg/count_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | TEXT ·Count(SB),NOSPLIT,$0-20 9 | MOVW b_base+0(FP), R0 10 | MOVW b_len+4(FP), R1 11 | MOVBU c+12(FP), R2 12 | MOVW $ret+16(FP), R7 13 | B countbytebody<>(SB) 14 | 15 | TEXT ·CountString(SB),NOSPLIT,$0-16 16 | MOVW s_base+0(FP), R0 17 | MOVW s_len+4(FP), R1 18 | MOVBU c+8(FP), R2 19 | MOVW $ret+12(FP), R7 20 | B countbytebody<>(SB) 21 | 22 | // Input: 23 | // R0: data 24 | // R1: data length 25 | // R2: byte to find 26 | // R7: address to put result 27 | // 28 | // On exit: 29 | // R4 and R8 are clobbered 30 | TEXT countbytebody<>(SB),NOSPLIT,$0 31 | MOVW $0, R8 // R8 = count of byte to search 32 | CMP $0, R1 33 | B.EQ done // short path to handle 0-byte case 34 | ADD R0, R1 // R1 is the end of the range 35 | byte_loop: 36 | MOVBU.P 1(R0), R4 37 | CMP R4, R2 38 | ADD.EQ $1, R8 39 | CMP R0, R1 40 | B.NE byte_loop 41 | done: 42 | MOVW R8, (R7) 43 | RET 44 | -------------------------------------------------------------------------------- /lib/internal/bytealg/count_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !amd64 && !arm && !arm64 && !ppc64le && !ppc64 && !riscv64 && !s390x 6 | // +build !amd64,!arm,!arm64,!ppc64le,!ppc64,!riscv64,!s390x 7 | 8 | package bytealg 9 | 10 | func Count(b []byte, c byte) int { 11 | n := 0 12 | for _, x := range b { 13 | if x == c { 14 | n++ 15 | } 16 | } 17 | return n 18 | } 19 | 20 | func CountString(s string, c byte) int { 21 | n := 0 22 | for i := 0; i < len(s); i++ { 23 | if s[i] == c { 24 | n++ 25 | } 26 | } 27 | return n 28 | } 29 | -------------------------------------------------------------------------------- /lib/internal/bytealg/count_native.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build amd64 || arm || arm64 || ppc64le || ppc64 || riscv64 || s390x 6 | // +build amd64 arm arm64 ppc64le ppc64 riscv64 s390x 7 | 8 | package bytealg 9 | 10 | //go:noescape 11 | func Count(b []byte, c byte) int 12 | 13 | //go:noescape 14 | func CountString(s string, c byte) int 15 | 16 | // A backup implementation to use by assembly. 17 | func countGeneric(b []byte, c byte) int { 18 | n := 0 19 | for _, x := range b { 20 | if x == c { 21 | n++ 22 | } 23 | } 24 | return n 25 | } 26 | func countGenericString(s string, c byte) int { 27 | n := 0 28 | for i := 0; i < len(s); i++ { 29 | if s[i] == c { 30 | n++ 31 | } 32 | } 33 | return n 34 | } 35 | -------------------------------------------------------------------------------- /lib/internal/bytealg/count_riscv64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | TEXT ·Count(SB),NOSPLIT,$0-40 9 | MOV b_base+0(FP), A1 10 | MOV b_len+8(FP), A2 11 | MOVBU c+24(FP), A3 // byte to count 12 | MOV ZERO, A4 // count 13 | ADD A1, A2 // end 14 | 15 | loop: 16 | BEQ A1, A2, done 17 | MOVBU (A1), A5 18 | ADD $1, A1 19 | BNE A3, A5, loop 20 | ADD $1, A4 21 | JMP loop 22 | 23 | done: 24 | MOV A4, ret+32(FP) 25 | RET 26 | 27 | TEXT ·CountString(SB),NOSPLIT,$0-32 28 | MOV s_base+0(FP), A1 29 | MOV s_len+8(FP), A2 30 | MOVBU c+16(FP), A3 // byte to count 31 | MOV ZERO, A4 // count 32 | ADD A1, A2 // end 33 | 34 | loop: 35 | BEQ A1, A2, done 36 | MOVBU (A1), A5 37 | ADD $1, A1 38 | BNE A3, A5, loop 39 | ADD $1, A4 40 | JMP loop 41 | 42 | done: 43 | MOV A4, ret+24(FP) 44 | RET 45 | -------------------------------------------------------------------------------- /lib/internal/bytealg/equal_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bytealg 6 | 7 | // Equal reports whether a and b 8 | // are the same length and contain the same bytes. 9 | // A nil argument is equivalent to an empty slice. 10 | // 11 | // Equal is equivalent to bytes.Equal. 12 | // It is provided here for convenience, 13 | // because some packages cannot depend on bytes. 14 | func Equal(a, b []byte) bool { 15 | // Neither cmd/compile nor gccgo allocates for these string conversions. 16 | // There is a test for this in package bytes. 17 | return string(a) == string(b) 18 | } 19 | -------------------------------------------------------------------------------- /lib/internal/bytealg/equal_mipsx.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build mips || mipsle 6 | // +build mips mipsle 7 | 8 | #include "go_asm.h" 9 | #include "textflag.h" 10 | 11 | #define REGCTXT R22 12 | 13 | // memequal(a, b unsafe.Pointer, size uintptr) bool 14 | TEXT runtime·memequal(SB),NOSPLIT,$0-13 15 | MOVW a+0(FP), R1 16 | MOVW b+4(FP), R2 17 | BEQ R1, R2, eq 18 | MOVW size+8(FP), R3 19 | ADDU R1, R3, R4 20 | loop: 21 | BNE R1, R4, test 22 | MOVW $1, R1 23 | MOVB R1, ret+12(FP) 24 | RET 25 | test: 26 | MOVBU (R1), R6 27 | ADDU $1, R1 28 | MOVBU (R2), R7 29 | ADDU $1, R2 30 | BEQ R6, R7, loop 31 | 32 | MOVB R0, ret+12(FP) 33 | RET 34 | eq: 35 | MOVW $1, R1 36 | MOVB R1, ret+12(FP) 37 | RET 38 | 39 | // memequal_varlen(a, b unsafe.Pointer) bool 40 | TEXT runtime·memequal_varlen(SB),NOSPLIT,$0-9 41 | MOVW a+0(FP), R1 42 | MOVW b+4(FP), R2 43 | BEQ R1, R2, eq 44 | MOVW 4(REGCTXT), R3 // compiler stores size at offset 4 in the closure 45 | ADDU R1, R3, R4 46 | loop: 47 | BNE R1, R4, test 48 | MOVW $1, R1 49 | MOVB R1, ret+8(FP) 50 | RET 51 | test: 52 | MOVBU (R1), R6 53 | ADDU $1, R1 54 | MOVBU (R2), R7 55 | ADDU $1, R2 56 | BEQ R6, R7, loop 57 | 58 | MOVB R0, ret+8(FP) 59 | RET 60 | eq: 61 | MOVW $1, R1 62 | MOVB R1, ret+8(FP) 63 | RET 64 | -------------------------------------------------------------------------------- /lib/internal/bytealg/equal_native.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bytealg 6 | 7 | import "unsafe" 8 | 9 | // The declarations below generate ABI wrappers for functions 10 | // implemented in assembly in this package but declared in another 11 | // package. 12 | 13 | // The compiler generates calls to runtime.memequal and runtime.memequal_varlen. 14 | // In addition, the runtime calls runtime.memequal explicitly. 15 | // Those functions are implemented in this package. 16 | 17 | //go:linkname abigen_runtime_memequal runtime.memequal 18 | func abigen_runtime_memequal(a, b unsafe.Pointer, size uintptr) bool 19 | 20 | //go:linkname abigen_runtime_memequal_varlen runtime.memequal_varlen 21 | func abigen_runtime_memequal_varlen(a, b unsafe.Pointer) bool 22 | -------------------------------------------------------------------------------- /lib/internal/bytealg/equal_riscv64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | #define CTXT S4 9 | 10 | // func memequal(a, b unsafe.Pointer, size uintptr) bool 11 | TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25 12 | MOV a+0(FP), A1 13 | MOV b+8(FP), A2 14 | BEQ A1, A2, eq 15 | MOV size+16(FP), A3 16 | ADD A1, A3, A4 17 | loop: 18 | BEQ A1, A4, eq 19 | 20 | MOVBU (A1), A6 21 | ADD $1, A1 22 | MOVBU (A2), A7 23 | ADD $1, A2 24 | BEQ A6, A7, loop 25 | 26 | MOVB ZERO, ret+24(FP) 27 | RET 28 | eq: 29 | MOV $1, A1 30 | MOVB A1, ret+24(FP) 31 | RET 32 | 33 | // func memequal_varlen(a, b unsafe.Pointer) bool 34 | TEXT runtime·memequal_varlen(SB),NOSPLIT,$40-17 35 | MOV a+0(FP), A1 36 | MOV b+8(FP), A2 37 | BEQ A1, A2, eq 38 | MOV 8(CTXT), A3 // compiler stores size at offset 8 in the closure 39 | MOV A1, 8(X2) 40 | MOV A2, 16(X2) 41 | MOV A3, 24(X2) 42 | CALL runtime·memequal(SB) 43 | MOVBU 32(X2), A1 44 | MOVB A1, ret+16(FP) 45 | RET 46 | eq: 47 | MOV $1, A1 48 | MOVB A1, ret+16(FP) 49 | RET 50 | -------------------------------------------------------------------------------- /lib/internal/bytealg/equal_s390x.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | // memequal(a, b unsafe.Pointer, size uintptr) bool 9 | TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25 10 | MOVD a+0(FP), R3 11 | MOVD b+8(FP), R5 12 | MOVD size+16(FP), R6 13 | LA ret+24(FP), R7 14 | BR memeqbody<>(SB) 15 | 16 | // memequal_varlen(a, b unsafe.Pointer) bool 17 | TEXT runtime·memequal_varlen(SB),NOSPLIT|NOFRAME,$0-17 18 | MOVD a+0(FP), R3 19 | MOVD b+8(FP), R5 20 | MOVD 8(R12), R6 // compiler stores size at offset 8 in the closure 21 | LA ret+16(FP), R7 22 | BR memeqbody<>(SB) 23 | 24 | // input: 25 | // R3 = a 26 | // R5 = b 27 | // R6 = len 28 | // R7 = address of output byte (stores 0 or 1 here) 29 | // a and b have the same length 30 | TEXT memeqbody<>(SB),NOSPLIT|NOFRAME,$0-0 31 | CMPBEQ R3, R5, equal 32 | loop: 33 | CMPBEQ R6, $0, equal 34 | CMPBLT R6, $32, tiny 35 | CMP R6, $256 36 | BLT tail 37 | CLC $256, 0(R3), 0(R5) 38 | BNE notequal 39 | SUB $256, R6 40 | LA 256(R3), R3 41 | LA 256(R5), R5 42 | BR loop 43 | tail: 44 | SUB $1, R6, R8 45 | EXRL $memeqbodyclc<>(SB), R8 46 | BEQ equal 47 | notequal: 48 | MOVB $0, 0(R7) 49 | RET 50 | equal: 51 | MOVB $1, 0(R7) 52 | RET 53 | tiny: 54 | MOVD $0, R2 55 | CMPBLT R6, $16, lt16 56 | MOVD 0(R3), R8 57 | MOVD 0(R5), R9 58 | CMPBNE R8, R9, notequal 59 | MOVD 8(R3), R8 60 | MOVD 8(R5), R9 61 | CMPBNE R8, R9, notequal 62 | LA 16(R2), R2 63 | SUB $16, R6 64 | lt16: 65 | CMPBLT R6, $8, lt8 66 | MOVD 0(R3)(R2*1), R8 67 | MOVD 0(R5)(R2*1), R9 68 | CMPBNE R8, R9, notequal 69 | LA 8(R2), R2 70 | SUB $8, R6 71 | lt8: 72 | CMPBLT R6, $4, lt4 73 | MOVWZ 0(R3)(R2*1), R8 74 | MOVWZ 0(R5)(R2*1), R9 75 | CMPBNE R8, R9, notequal 76 | LA 4(R2), R2 77 | SUB $4, R6 78 | lt4: 79 | #define CHECK(n) \ 80 | CMPBEQ R6, $n, equal \ 81 | MOVB n(R3)(R2*1), R8 \ 82 | MOVB n(R5)(R2*1), R9 \ 83 | CMPBNE R8, R9, notequal 84 | CHECK(0) 85 | CHECK(1) 86 | CHECK(2) 87 | CHECK(3) 88 | BR equal 89 | 90 | TEXT memeqbodyclc<>(SB),NOSPLIT|NOFRAME,$0-0 91 | CLC $1, 0(R3), 0(R5) 92 | RET 93 | -------------------------------------------------------------------------------- /lib/internal/bytealg/equal_wasm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | // memequal(p, q unsafe.Pointer, size uintptr) bool 9 | TEXT runtime·memequal(SB), NOSPLIT, $0-25 10 | Get SP 11 | I64Load a+0(FP) 12 | I64Load b+8(FP) 13 | I64Load size+16(FP) 14 | Call memeqbody<>(SB) 15 | I64Store8 ret+24(FP) 16 | RET 17 | 18 | // memequal_varlen(a, b unsafe.Pointer) bool 19 | TEXT runtime·memequal_varlen(SB), NOSPLIT, $0-17 20 | Get SP 21 | I64Load a+0(FP) 22 | I64Load b+8(FP) 23 | I64Load 8(CTXT) // compiler stores size at offset 8 in the closure 24 | Call memeqbody<>(SB) 25 | I64Store8 ret+16(FP) 26 | RET 27 | 28 | // params: a, b, len 29 | // ret: 0/1 30 | TEXT memeqbody<>(SB), NOSPLIT, $0-0 31 | Get R0 32 | Get R1 33 | I64Eq 34 | If 35 | I64Const $1 36 | Return 37 | End 38 | 39 | loop: 40 | Loop 41 | Get R2 42 | I64Eqz 43 | If 44 | I64Const $1 45 | Return 46 | End 47 | 48 | Get R0 49 | I32WrapI64 50 | I64Load8U $0 51 | Get R1 52 | I32WrapI64 53 | I64Load8U $0 54 | I64Ne 55 | If 56 | I64Const $0 57 | Return 58 | End 59 | 60 | Get R0 61 | I64Const $1 62 | I64Add 63 | Set R0 64 | 65 | Get R1 66 | I64Const $1 67 | I64Add 68 | Set R1 69 | 70 | Get R2 71 | I64Const $1 72 | I64Sub 73 | Set R2 74 | 75 | Br loop 76 | End 77 | UNDEF 78 | -------------------------------------------------------------------------------- /lib/internal/bytealg/index_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bytealg 6 | 7 | import "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/cpu" 8 | 9 | const MaxBruteForce = 64 10 | 11 | func init() { 12 | if cpu.X86.HasAVX2 { 13 | MaxLen = 63 14 | } else { 15 | MaxLen = 31 16 | } 17 | } 18 | 19 | // Cutover reports the number of failures of IndexByte we should tolerate 20 | // before switching over to Index. 21 | // n is the number of bytes processed so far. 22 | // See the bytes.Index implementation for details. 23 | func Cutover(n int) int { 24 | // 1 error per 8 characters, plus a few slop to start. 25 | return (n + 16) / 8 26 | } 27 | -------------------------------------------------------------------------------- /lib/internal/bytealg/index_arm64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bytealg 6 | 7 | // Empirical data shows that using Index can get better 8 | // performance when len(s) <= 16. 9 | const MaxBruteForce = 16 10 | 11 | func init() { 12 | // Optimize cases where the length of the substring is less than 32 bytes 13 | MaxLen = 32 14 | } 15 | 16 | // Cutover reports the number of failures of IndexByte we should tolerate 17 | // before switching over to Index. 18 | // n is the number of bytes processed so far. 19 | // See the bytes.Index implementation for details. 20 | func Cutover(n int) int { 21 | // 1 error per 16 characters, plus a few slop to start. 22 | return 4 + n>>4 23 | } 24 | -------------------------------------------------------------------------------- /lib/internal/bytealg/index_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !amd64 && !arm64 && !s390x && !ppc64le && !ppc64 6 | // +build !amd64,!arm64,!s390x,!ppc64le,!ppc64 7 | 8 | package bytealg 9 | 10 | const MaxBruteForce = 0 11 | 12 | // Index returns the index of the first instance of b in a, or -1 if b is not present in a. 13 | // Requires 2 <= len(b) <= MaxLen. 14 | func Index(a, b []byte) int { 15 | panic("unimplemented") 16 | } 17 | 18 | // IndexString returns the index of the first instance of b in a, or -1 if b is not present in a. 19 | // Requires 2 <= len(b) <= MaxLen. 20 | func IndexString(a, b string) int { 21 | panic("unimplemented") 22 | } 23 | 24 | // Cutover reports the number of failures of IndexByte we should tolerate 25 | // before switching over to Index. 26 | // n is the number of bytes processed so far. 27 | // See the bytes.Index implementation for details. 28 | func Cutover(n int) int { 29 | panic("unimplemented") 30 | } 31 | -------------------------------------------------------------------------------- /lib/internal/bytealg/index_native.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build amd64 || arm64 || s390x || ppc64le || ppc64 6 | // +build amd64 arm64 s390x ppc64le ppc64 7 | 8 | package bytealg 9 | 10 | //go:noescape 11 | 12 | // Index returns the index of the first instance of b in a, or -1 if b is not present in a. 13 | // Requires 2 <= len(b) <= MaxLen. 14 | func Index(a, b []byte) int 15 | 16 | //go:noescape 17 | 18 | // IndexString returns the index of the first instance of b in a, or -1 if b is not present in a. 19 | // Requires 2 <= len(b) <= MaxLen. 20 | func IndexString(a, b string) int 21 | -------------------------------------------------------------------------------- /lib/internal/bytealg/index_ppc64x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build (aix || linux) && (ppc64 || ppc64le) 6 | // +build aix linux 7 | // +build ppc64 ppc64le 8 | 9 | package bytealg 10 | 11 | import "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/cpu" 12 | 13 | const MaxBruteForce = 16 14 | 15 | var SupportsPower9 = cpu.PPC64.IsPOWER9 16 | 17 | func init() { 18 | MaxLen = 32 19 | } 20 | 21 | // Cutover reports the number of failures of IndexByte we should tolerate 22 | // before switching over to Index. 23 | // n is the number of bytes processed so far. 24 | // See the bytes.Index implementation for details. 25 | func Cutover(n int) int { 26 | // 1 error per 8 characters, plus a few slop to start. 27 | return (n + 16) / 8 28 | } 29 | -------------------------------------------------------------------------------- /lib/internal/bytealg/index_s390x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bytealg 6 | 7 | import "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/cpu" 8 | 9 | const MaxBruteForce = 64 10 | 11 | func init() { 12 | // Note: we're kind of lucky that this flag is available at this point. 13 | // The runtime sets HasVX when processing auxv records, and that happens 14 | // to happen *before* running the init functions of packages that 15 | // the runtime depends on. 16 | // TODO: it would really be nicer for github.com/ck00004/CobaltStrikeParser-Go/lib/internal/cpu to figure out this 17 | // flag by itself. Then we wouldn't need to depend on quirks of 18 | // early startup initialization order. 19 | if cpu.S390X.HasVX { 20 | MaxLen = 64 21 | } 22 | } 23 | 24 | // Cutover reports the number of failures of IndexByte we should tolerate 25 | // before switching over to Index. 26 | // n is the number of bytes processed so far. 27 | // See the bytes.Index implementation for details. 28 | func Cutover(n int) int { 29 | // 1 error per 8 characters, plus a few slop to start. 30 | return (n + 16) / 8 31 | } 32 | -------------------------------------------------------------------------------- /lib/internal/bytealg/indexbyte_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | TEXT ·IndexByte(SB),NOSPLIT,$0-20 9 | MOVL b_base+0(FP), SI 10 | MOVL b_len+4(FP), CX 11 | MOVB c+12(FP), AL 12 | MOVL SI, DI 13 | CLD; REPN; SCASB 14 | JZ 3(PC) 15 | MOVL $-1, ret+16(FP) 16 | RET 17 | SUBL SI, DI 18 | SUBL $1, DI 19 | MOVL DI, ret+16(FP) 20 | RET 21 | 22 | TEXT ·IndexByteString(SB),NOSPLIT,$0-16 23 | MOVL s_base+0(FP), SI 24 | MOVL s_len+4(FP), CX 25 | MOVB c+8(FP), AL 26 | MOVL SI, DI 27 | CLD; REPN; SCASB 28 | JZ 3(PC) 29 | MOVL $-1, ret+12(FP) 30 | RET 31 | SUBL SI, DI 32 | SUBL $1, DI 33 | MOVL DI, ret+12(FP) 34 | RET 35 | -------------------------------------------------------------------------------- /lib/internal/bytealg/indexbyte_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | TEXT ·IndexByte(SB),NOSPLIT,$0-20 9 | MOVW b_base+0(FP), R0 10 | MOVW b_len+4(FP), R1 11 | MOVBU c+12(FP), R2 // byte to find 12 | MOVW $ret+16(FP), R5 13 | B indexbytebody<>(SB) 14 | 15 | TEXT ·IndexByteString(SB),NOSPLIT,$0-16 16 | MOVW s_base+0(FP), R0 17 | MOVW s_len+4(FP), R1 18 | MOVBU c+8(FP), R2 // byte to find 19 | MOVW $ret+12(FP), R5 20 | B indexbytebody<>(SB) 21 | 22 | // input: 23 | // R0: data 24 | // R1: data length 25 | // R2: byte to find 26 | // R5: address to put result 27 | TEXT indexbytebody<>(SB),NOSPLIT,$0-0 28 | MOVW R0, R4 // store base for later 29 | ADD R0, R1 // end 30 | 31 | loop: 32 | CMP R0, R1 33 | B.EQ notfound 34 | MOVBU.P 1(R0), R3 35 | CMP R2, R3 36 | B.NE loop 37 | 38 | SUB $1, R0 // R0 will be one beyond the position we want 39 | SUB R4, R0 // remove base 40 | MOVW R0, (R5) 41 | RET 42 | 43 | notfound: 44 | MOVW $-1, R0 45 | MOVW R0, (R5) 46 | RET 47 | -------------------------------------------------------------------------------- /lib/internal/bytealg/indexbyte_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !386 && !amd64 && !s390x && !arm && !arm64 && !ppc64 && !ppc64le && !mips && !mipsle && !mips64 && !mips64le && !riscv64 && !wasm 6 | // +build !386,!amd64,!s390x,!arm,!arm64,!ppc64,!ppc64le,!mips,!mipsle,!mips64,!mips64le,!riscv64,!wasm 7 | 8 | package bytealg 9 | 10 | func IndexByte(b []byte, c byte) int { 11 | for i, x := range b { 12 | if x == c { 13 | return i 14 | } 15 | } 16 | return -1 17 | } 18 | 19 | func IndexByteString(s string, c byte) int { 20 | for i := 0; i < len(s); i++ { 21 | if s[i] == c { 22 | return i 23 | } 24 | } 25 | return -1 26 | } 27 | -------------------------------------------------------------------------------- /lib/internal/bytealg/indexbyte_mips64x.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build mips64 || mips64le 6 | // +build mips64 mips64le 7 | 8 | #include "go_asm.h" 9 | #include "textflag.h" 10 | 11 | TEXT ·IndexByte(SB),NOSPLIT,$0-40 12 | MOVV b_base+0(FP), R1 13 | MOVV b_len+8(FP), R2 14 | MOVBU c+24(FP), R3 // byte to find 15 | MOVV R1, R4 // store base for later 16 | ADDV R1, R2 // end 17 | ADDV $-1, R1 18 | 19 | loop: 20 | ADDV $1, R1 21 | BEQ R1, R2, notfound 22 | MOVBU (R1), R5 23 | BNE R3, R5, loop 24 | 25 | SUBV R4, R1 // remove base 26 | MOVV R1, ret+32(FP) 27 | RET 28 | 29 | notfound: 30 | MOVV $-1, R1 31 | MOVV R1, ret+32(FP) 32 | RET 33 | 34 | TEXT ·IndexByteString(SB),NOSPLIT,$0-32 35 | MOVV s_base+0(FP), R1 36 | MOVV s_len+8(FP), R2 37 | MOVBU c+16(FP), R3 // byte to find 38 | MOVV R1, R4 // store base for later 39 | ADDV R1, R2 // end 40 | ADDV $-1, R1 41 | 42 | loop: 43 | ADDV $1, R1 44 | BEQ R1, R2, notfound 45 | MOVBU (R1), R5 46 | BNE R3, R5, loop 47 | 48 | SUBV R4, R1 // remove base 49 | MOVV R1, ret+24(FP) 50 | RET 51 | 52 | notfound: 53 | MOVV $-1, R1 54 | MOVV R1, ret+24(FP) 55 | RET 56 | -------------------------------------------------------------------------------- /lib/internal/bytealg/indexbyte_mipsx.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build mips || mipsle 6 | // +build mips mipsle 7 | 8 | #include "go_asm.h" 9 | #include "textflag.h" 10 | 11 | TEXT ·IndexByte(SB),NOSPLIT,$0-20 12 | MOVW b_base+0(FP), R1 13 | MOVW b_len+4(FP), R2 14 | MOVBU c+12(FP), R3 // byte to find 15 | ADDU $1, R1, R4 // store base+1 for later 16 | ADDU R1, R2 // end 17 | 18 | loop: 19 | BEQ R1, R2, notfound 20 | MOVBU (R1), R5 21 | ADDU $1, R1 22 | BNE R3, R5, loop 23 | 24 | SUBU R4, R1 // R1 will be one beyond the position we want so remove (base+1) 25 | MOVW R1, ret+16(FP) 26 | RET 27 | 28 | notfound: 29 | MOVW $-1, R1 30 | MOVW R1, ret+16(FP) 31 | RET 32 | 33 | TEXT ·IndexByteString(SB),NOSPLIT,$0-16 34 | MOVW s_base+0(FP), R1 35 | MOVW s_len+4(FP), R2 36 | MOVBU c+8(FP), R3 // byte to find 37 | ADDU $1, R1, R4 // store base+1 for later 38 | ADDU R1, R2 // end 39 | 40 | loop: 41 | BEQ R1, R2, notfound 42 | MOVBU (R1), R5 43 | ADDU $1, R1 44 | BNE R3, R5, loop 45 | 46 | SUBU R4, R1 // remove (base+1) 47 | MOVW R1, ret+12(FP) 48 | RET 49 | 50 | notfound: 51 | MOVW $-1, R1 52 | MOVW R1, ret+12(FP) 53 | RET 54 | -------------------------------------------------------------------------------- /lib/internal/bytealg/indexbyte_native.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build 386 || amd64 || s390x || arm || arm64 || ppc64 || ppc64le || mips || mipsle || mips64 || mips64le || riscv64 || wasm 6 | // +build 386 amd64 s390x arm arm64 ppc64 ppc64le mips mipsle mips64 mips64le riscv64 wasm 7 | 8 | package bytealg 9 | 10 | //go:noescape 11 | func IndexByte(b []byte, c byte) int 12 | 13 | //go:noescape 14 | func IndexByteString(s string, c byte) int 15 | -------------------------------------------------------------------------------- /lib/internal/bytealg/indexbyte_riscv64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "go_asm.h" 6 | #include "textflag.h" 7 | 8 | TEXT ·IndexByte(SB),NOSPLIT,$0-40 9 | MOV b_base+0(FP), A1 10 | MOV b_len+8(FP), A2 11 | MOVBU c+24(FP), A3 // byte to find 12 | MOV A1, A4 // store base for later 13 | ADD A1, A2 // end 14 | ADD $-1, A1 15 | 16 | loop: 17 | ADD $1, A1 18 | BEQ A1, A2, notfound 19 | MOVBU (A1), A5 20 | BNE A3, A5, loop 21 | 22 | SUB A4, A1 // remove base 23 | MOV A1, ret+32(FP) 24 | RET 25 | 26 | notfound: 27 | MOV $-1, A1 28 | MOV A1, ret+32(FP) 29 | RET 30 | 31 | TEXT ·IndexByteString(SB),NOSPLIT,$0-32 32 | MOV s_base+0(FP), A1 33 | MOV s_len+8(FP), A2 34 | MOVBU c+16(FP), A3 // byte to find 35 | MOV A1, A4 // store base for later 36 | ADD A1, A2 // end 37 | ADD $-1, A1 38 | 39 | loop: 40 | ADD $1, A1 41 | BEQ A1, A2, notfound 42 | MOVBU (A1), A5 43 | BNE A3, A5, loop 44 | 45 | SUB A4, A1 // remove base 46 | MOV A1, ret+24(FP) 47 | RET 48 | 49 | notfound: 50 | MOV $-1, A1 51 | MOV A1, ret+24(FP) 52 | RET 53 | -------------------------------------------------------------------------------- /lib/internal/cfg/cfg.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package cfg holds configuration shared by the Go command and internal/testenv. 6 | // Definitions that don't need to be exposed outside of cmd/go should be in 7 | // cmd/go/internal/cfg instead of this package. 8 | package cfg 9 | 10 | // KnownEnv is a list of environment variables that affect the operation 11 | // of the Go command. 12 | const KnownEnv = ` 13 | AR 14 | CC 15 | CGO_CFLAGS 16 | CGO_CFLAGS_ALLOW 17 | CGO_CFLAGS_DISALLOW 18 | CGO_CPPFLAGS 19 | CGO_CPPFLAGS_ALLOW 20 | CGO_CPPFLAGS_DISALLOW 21 | CGO_CXXFLAGS 22 | CGO_CXXFLAGS_ALLOW 23 | CGO_CXXFLAGS_DISALLOW 24 | CGO_ENABLED 25 | CGO_FFLAGS 26 | CGO_FFLAGS_ALLOW 27 | CGO_FFLAGS_DISALLOW 28 | CGO_LDFLAGS 29 | CGO_LDFLAGS_ALLOW 30 | CGO_LDFLAGS_DISALLOW 31 | CXX 32 | FC 33 | GCCGO 34 | GO111MODULE 35 | GO386 36 | GOARCH 37 | GOARM 38 | GOBIN 39 | GOCACHE 40 | GOENV 41 | GOEXE 42 | GOEXPERIMENT 43 | GOFLAGS 44 | GOGCCFLAGS 45 | GOHOSTARCH 46 | GOHOSTOS 47 | GOINSECURE 48 | GOMIPS 49 | GOMIPS64 50 | GOMODCACHE 51 | GONOPROXY 52 | GONOSUMDB 53 | GOOS 54 | GOPATH 55 | GOPPC64 56 | GOPRIVATE 57 | GOPROXY 58 | GOROOT 59 | GOSUMDB 60 | GOTMPDIR 61 | GOTOOLDIR 62 | GOVCS 63 | GOWASM 64 | GO_EXTLINK_ENABLED 65 | PKG_CONFIG 66 | ` 67 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu.s: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This assembly file exists to allow github.com/ck00004/CobaltStrikeParser-Go/lib/internal/cpu to call 6 | // non-exported runtime functions that use "go:linkname". -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cpu 6 | 7 | const GOARCH = "386" 8 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cpu 6 | 7 | const GOARCH = "amd64" 8 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_arm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cpu 6 | 7 | const CacheLinePadSize = 32 8 | 9 | // arm doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2. 10 | // These are initialized by archauxv() and should not be changed after they are 11 | // initialized. 12 | var HWCap uint 13 | var HWCap2 uint 14 | 15 | // HWCAP/HWCAP2 bits. These are exposed by Linux and FreeBSD. 16 | const ( 17 | hwcap_VFPv4 = 1 << 16 18 | hwcap_IDIVA = 1 << 17 19 | ) 20 | 21 | func doinit() { 22 | options = []option{ 23 | {Name: "vfpv4", Feature: &ARM.HasVFPv4}, 24 | {Name: "idiva", Feature: &ARM.HasIDIVA}, 25 | } 26 | 27 | // HWCAP feature bits 28 | ARM.HasVFPv4 = isSet(HWCap, hwcap_VFPv4) 29 | ARM.HasIDIVA = isSet(HWCap, hwcap_IDIVA) 30 | } 31 | 32 | func isSet(hwc uint, value uint) bool { 33 | return hwc&value != 0 34 | } 35 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_arm64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cpu 6 | 7 | const CacheLinePadSize = 64 8 | 9 | func doinit() { 10 | options = []option{ 11 | {Name: "aes", Feature: &ARM64.HasAES}, 12 | {Name: "pmull", Feature: &ARM64.HasPMULL}, 13 | {Name: "sha1", Feature: &ARM64.HasSHA1}, 14 | {Name: "sha2", Feature: &ARM64.HasSHA2}, 15 | {Name: "crc32", Feature: &ARM64.HasCRC32}, 16 | {Name: "atomics", Feature: &ARM64.HasATOMICS}, 17 | {Name: "cpuid", Feature: &ARM64.HasCPUID}, 18 | {Name: "isNeoverseN1", Feature: &ARM64.IsNeoverseN1}, 19 | {Name: "isZeus", Feature: &ARM64.IsZeus}, 20 | } 21 | 22 | // arm64 uses different ways to detect CPU features at runtime depending on the operating system. 23 | osInit() 24 | } 25 | 26 | func getisar0() uint64 27 | 28 | func getMIDR() uint64 29 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_arm64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | 7 | // func getisar0() uint64 8 | TEXT ·getisar0(SB),NOSPLIT,$0 9 | // get Instruction Set Attributes 0 into R0 10 | MRS ID_AA64ISAR0_EL1, R0 11 | MOVD R0, ret+0(FP) 12 | RET 13 | 14 | // func getMIDR() uint64 15 | TEXT ·getMIDR(SB), NOSPLIT, $0-8 16 | MRS MIDR_EL1, R0 17 | MOVD R0, ret+0(FP) 18 | RET 19 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_arm64_android.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build arm64 6 | // +build arm64 7 | 8 | package cpu 9 | 10 | func osInit() { 11 | hwcapInit("android") 12 | } 13 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_arm64_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build arm64 && darwin && !ios 6 | // +build arm64,darwin,!ios 7 | 8 | package cpu 9 | 10 | func osInit() { 11 | ARM64.HasATOMICS = sysctlEnabled([]byte("hw.optional.armv8_1_atomics\x00")) 12 | ARM64.HasCRC32 = sysctlEnabled([]byte("hw.optional.armv8_crc32\x00")) 13 | 14 | // There are no hw.optional sysctl values for the below features on Mac OS 11.0 15 | // to detect their supported state dynamically. Assume the CPU features that 16 | // Apple Silicon M1 supports to be available as a minimal set of features 17 | // to all Go programs running on darwin/arm64. 18 | ARM64.HasAES = true 19 | ARM64.HasPMULL = true 20 | ARM64.HasSHA1 = true 21 | ARM64.HasSHA2 = true 22 | } 23 | 24 | //go:noescape 25 | func getsysctlbyname(name []byte) (int32, int32) 26 | 27 | func sysctlEnabled(name []byte) bool { 28 | ret, value := getsysctlbyname(name) 29 | if ret < 0 { 30 | return false 31 | } 32 | return value > 0 33 | } 34 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_arm64_freebsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build arm64 6 | // +build arm64 7 | 8 | package cpu 9 | 10 | func osInit() { 11 | // Retrieve info from system register ID_AA64ISAR0_EL1. 12 | isar0 := getisar0() 13 | 14 | // ID_AA64ISAR0_EL1 15 | switch extractBits(isar0, 4, 7) { 16 | case 1: 17 | ARM64.HasAES = true 18 | case 2: 19 | ARM64.HasAES = true 20 | ARM64.HasPMULL = true 21 | } 22 | 23 | switch extractBits(isar0, 8, 11) { 24 | case 1: 25 | ARM64.HasSHA1 = true 26 | } 27 | 28 | switch extractBits(isar0, 12, 15) { 29 | case 1, 2: 30 | ARM64.HasSHA2 = true 31 | } 32 | 33 | switch extractBits(isar0, 16, 19) { 34 | case 1: 35 | ARM64.HasCRC32 = true 36 | } 37 | 38 | switch extractBits(isar0, 20, 23) { 39 | case 2: 40 | ARM64.HasATOMICS = true 41 | } 42 | } 43 | 44 | func extractBits(data uint64, start, end uint) uint { 45 | return (uint)(data>>start) & ((1 << (end - start + 1)) - 1) 46 | } 47 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_arm64_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build arm64 && linux && !android 6 | // +build arm64,linux,!android 7 | 8 | package cpu 9 | 10 | func osInit() { 11 | hwcapInit("linux") 12 | } 13 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_arm64_other.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build arm64 && !linux && !freebsd && !android && (!darwin || ios) 6 | // +build arm64 7 | // +build !linux 8 | // +build !freebsd 9 | // +build !android 10 | // +build !darwin ios 11 | 12 | package cpu 13 | 14 | func osInit() { 15 | // Other operating systems do not support reading HWCap from auxiliary vector, 16 | // reading privileged aarch64 system registers or sysctl in user space to detect 17 | // CPU features at runtime. 18 | } 19 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_mips.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cpu 6 | 7 | const CacheLinePadSize = 32 8 | 9 | func doinit() { 10 | } 11 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_mips64x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build mips64 || mips64le 6 | // +build mips64 mips64le 7 | 8 | package cpu 9 | 10 | const CacheLinePadSize = 32 11 | 12 | // This is initialized by archauxv and should not be changed after it is 13 | // initialized. 14 | var HWCap uint 15 | 16 | // HWCAP bits. These are exposed by the Linux kernel 5.4. 17 | const ( 18 | // CPU features 19 | hwcap_MIPS_MSA = 1 << 1 20 | ) 21 | 22 | func doinit() { 23 | options = []option{ 24 | {Name: "msa", Feature: &MIPS64X.HasMSA}, 25 | } 26 | 27 | // HWCAP feature bits 28 | MIPS64X.HasMSA = isSet(HWCap, hwcap_MIPS_MSA) 29 | } 30 | 31 | func isSet(hwc uint, value uint) bool { 32 | return hwc&value != 0 33 | } 34 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_mipsle.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cpu 6 | 7 | const CacheLinePadSize = 32 8 | 9 | func doinit() { 10 | } 11 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_no_name.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !386 && !amd64 6 | // +build !386,!amd64 7 | 8 | package cpu 9 | 10 | // Name returns the CPU name given by the vendor 11 | // if it can be read directly from memory or by CPU instructions. 12 | // If the CPU name can not be determined an empty string is returned. 13 | // 14 | // Implementations that use the Operating System (e.g. sysctl or /sys/) 15 | // to gather CPU information for display should be placed in internal/sysinfo. 16 | func Name() string { 17 | // "A CPU has no name". 18 | return "" 19 | } 20 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_ppc64x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build ppc64 || ppc64le 6 | // +build ppc64 ppc64le 7 | 8 | package cpu 9 | 10 | const CacheLinePadSize = 128 11 | 12 | func doinit() { 13 | options = []option{ 14 | {Name: "darn", Feature: &PPC64.HasDARN}, 15 | {Name: "scv", Feature: &PPC64.HasSCV}, 16 | {Name: "power9", Feature: &PPC64.IsPOWER9}, 17 | } 18 | 19 | osinit() 20 | } 21 | 22 | func isSet(hwc uint, value uint) bool { 23 | return hwc&value != 0 24 | } 25 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_ppc64x_aix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build ppc64 || ppc64le 6 | // +build ppc64 ppc64le 7 | 8 | package cpu 9 | 10 | const ( 11 | // getsystemcfg constants 12 | _SC_IMPL = 2 13 | _IMPL_POWER9 = 0x20000 14 | ) 15 | 16 | func osinit() { 17 | impl := getsystemcfg(_SC_IMPL) 18 | PPC64.IsPOWER9 = isSet(impl, _IMPL_POWER9) 19 | } 20 | 21 | // getsystemcfg is defined in runtime/os2_aix.go 22 | func getsystemcfg(label uint) uint 23 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_ppc64x_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build ppc64 || ppc64le 6 | // +build ppc64 ppc64le 7 | 8 | package cpu 9 | 10 | // ppc64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2. 11 | // These are initialized by archauxv and should not be changed after they are 12 | // initialized. 13 | var HWCap uint 14 | var HWCap2 uint 15 | 16 | // HWCAP bits. These are exposed by Linux. 17 | const ( 18 | // ISA Level 19 | hwcap2_ARCH_3_00 = 0x00800000 20 | 21 | // CPU features 22 | hwcap2_DARN = 0x00200000 23 | hwcap2_SCV = 0x00100000 24 | ) 25 | 26 | func osinit() { 27 | PPC64.IsPOWER9 = isSet(HWCap2, hwcap2_ARCH_3_00) 28 | PPC64.HasDARN = isSet(HWCap2, hwcap2_DARN) 29 | PPC64.HasSCV = isSet(HWCap2, hwcap2_SCV) 30 | } 31 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_riscv64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cpu 6 | 7 | const CacheLinePadSize = 32 8 | 9 | func doinit() { 10 | } 11 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_s390x_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cpu_test 6 | 7 | import ( 8 | "errors" 9 | . "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/cpu" 10 | "os" 11 | "regexp" 12 | "testing" 13 | ) 14 | 15 | func getFeatureList() ([]string, error) { 16 | cpuinfo, err := os.ReadFile("/proc/cpuinfo") 17 | if err != nil { 18 | return nil, err 19 | } 20 | r := regexp.MustCompile("features\\s*:\\s*(.*)") 21 | b := r.FindSubmatch(cpuinfo) 22 | if len(b) < 2 { 23 | return nil, errors.New("no feature list in /proc/cpuinfo") 24 | } 25 | return regexp.MustCompile("\\s+").Split(string(b[1]), -1), nil 26 | } 27 | 28 | func TestS390XAgainstCPUInfo(t *testing.T) { 29 | // mapping of linux feature strings to S390X fields 30 | mapping := make(map[string]*bool) 31 | for _, option := range Options { 32 | mapping[option.Name] = option.Feature 33 | } 34 | 35 | // these must be true on the machines Go supports 36 | mandatory := make(map[string]bool) 37 | mandatory["zarch"] = false 38 | mandatory["eimm"] = false 39 | mandatory["ldisp"] = false 40 | mandatory["stfle"] = false 41 | 42 | features, err := getFeatureList() 43 | if err != nil { 44 | t.Error(err) 45 | } 46 | for _, feature := range features { 47 | if _, ok := mandatory[feature]; ok { 48 | mandatory[feature] = true 49 | } 50 | if flag, ok := mapping[feature]; ok { 51 | if !*flag { 52 | t.Errorf("feature '%v' not detected", feature) 53 | } 54 | } else { 55 | t.Logf("no entry for '%v'", feature) 56 | } 57 | } 58 | for k, v := range mandatory { 59 | if !v { 60 | t.Errorf("mandatory feature '%v' not detected", k) 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_wasm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cpu 6 | 7 | const CacheLinePadSize = 64 8 | 9 | func doinit() { 10 | } 11 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_x86.s: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build 386 || amd64 6 | // +build 386 amd64 7 | 8 | #include "textflag.h" 9 | 10 | // func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) 11 | TEXT ·cpuid(SB), NOSPLIT, $0-24 12 | MOVL eaxArg+0(FP), AX 13 | MOVL ecxArg+4(FP), CX 14 | CPUID 15 | MOVL AX, eax+8(FP) 16 | MOVL BX, ebx+12(FP) 17 | MOVL CX, ecx+16(FP) 18 | MOVL DX, edx+20(FP) 19 | RET 20 | 21 | // func xgetbv() (eax, edx uint32) 22 | TEXT ·xgetbv(SB),NOSPLIT,$0-8 23 | MOVL $0, CX 24 | XGETBV 25 | MOVL AX, eax+0(FP) 26 | MOVL DX, edx+4(FP) 27 | RET 28 | -------------------------------------------------------------------------------- /lib/internal/cpu/cpu_x86_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build 386 || amd64 6 | // +build 386 amd64 7 | 8 | package cpu_test 9 | 10 | import ( 11 | "os" 12 | "runtime" 13 | "testing" 14 | 15 | . "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/cpu" 16 | ) 17 | 18 | func TestX86ifAVX2hasAVX(t *testing.T) { 19 | if X86.HasAVX2 && !X86.HasAVX { 20 | t.Fatalf("HasAVX expected true when HasAVX2 is true, got false") 21 | } 22 | } 23 | 24 | func TestDisableSSE2(t *testing.T) { 25 | runDebugOptionsTest(t, "TestSSE2DebugOption", "cpu.sse2=off") 26 | } 27 | 28 | func TestSSE2DebugOption(t *testing.T) { 29 | MustHaveDebugOptionsSupport(t) 30 | 31 | if os.Getenv("GODEBUG") != "cpu.sse2=off" { 32 | t.Skipf("skipping test: GODEBUG=cpu.sse2=off not set") 33 | } 34 | 35 | want := runtime.GOARCH != "386" // SSE2 can only be disabled on 386. 36 | if got := X86.HasSSE2; got != want { 37 | t.Errorf("X86.HasSSE2 on %s expected %v, got %v", runtime.GOARCH, want, got) 38 | } 39 | } 40 | 41 | func TestDisableSSE3(t *testing.T) { 42 | runDebugOptionsTest(t, "TestSSE3DebugOption", "cpu.sse3=off") 43 | } 44 | 45 | func TestSSE3DebugOption(t *testing.T) { 46 | MustHaveDebugOptionsSupport(t) 47 | 48 | if os.Getenv("GODEBUG") != "cpu.sse3=off" { 49 | t.Skipf("skipping test: GODEBUG=cpu.sse3=off not set") 50 | } 51 | 52 | want := false 53 | if got := X86.HasSSE3; got != want { 54 | t.Errorf("X86.HasSSE3 expected %v, got %v", want, got) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /lib/internal/cpu/export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cpu 6 | 7 | var ( 8 | Options = options 9 | ) 10 | -------------------------------------------------------------------------------- /lib/internal/execabs/execabs.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package execabs is a drop-in replacement for os/exec 6 | // that requires PATH lookups to find absolute paths. 7 | // That is, execabs.Command("cmd") runs the same PATH lookup 8 | // as exec.Command("cmd"), but if the result is a path 9 | // which is relative, the Run and Start methods will report 10 | // an error instead of running the executable. 11 | package execabs 12 | 13 | import ( 14 | "context" 15 | "fmt" 16 | "os/exec" 17 | "path/filepath" 18 | "reflect" 19 | "unsafe" 20 | ) 21 | 22 | var ErrNotFound = exec.ErrNotFound 23 | 24 | type ( 25 | Cmd = exec.Cmd 26 | Error = exec.Error 27 | ExitError = exec.ExitError 28 | ) 29 | 30 | func relError(file, path string) error { 31 | return fmt.Errorf("%s resolves to executable relative to current directory (.%c%s)", file, filepath.Separator, path) 32 | } 33 | 34 | func LookPath(file string) (string, error) { 35 | path, err := exec.LookPath(file) 36 | if err != nil { 37 | return "", err 38 | } 39 | if filepath.Base(file) == file && !filepath.IsAbs(path) { 40 | return "", relError(file, path) 41 | } 42 | return path, nil 43 | } 44 | 45 | func fixCmd(name string, cmd *exec.Cmd) { 46 | if filepath.Base(name) == name && !filepath.IsAbs(cmd.Path) { 47 | // exec.Command was called with a bare binary name and 48 | // exec.LookPath returned a path which is not absolute. 49 | // Set cmd.lookPathErr and clear cmd.Path so that it 50 | // cannot be run. 51 | lookPathErr := (*error)(unsafe.Pointer(reflect.ValueOf(cmd).Elem().FieldByName("lookPathErr").Addr().Pointer())) 52 | if *lookPathErr == nil { 53 | *lookPathErr = relError(name, cmd.Path) 54 | } 55 | cmd.Path = "" 56 | } 57 | } 58 | 59 | func CommandContext(ctx context.Context, name string, arg ...string) *exec.Cmd { 60 | cmd := exec.CommandContext(ctx, name, arg...) 61 | fixCmd(name, cmd) 62 | return cmd 63 | 64 | } 65 | 66 | func Command(name string, arg ...string) *exec.Cmd { 67 | cmd := exec.Command(name, arg...) 68 | fixCmd(name, cmd) 69 | return cmd 70 | } 71 | -------------------------------------------------------------------------------- /lib/internal/fmtsort/export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package fmtsort 6 | 7 | import "reflect" 8 | 9 | func Compare(a, b reflect.Value) int { 10 | return compare(a, b) 11 | } 12 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_fieldtrack_off.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build !goexperiment.fieldtrack 4 | // +build !goexperiment.fieldtrack 5 | 6 | package goexperiment 7 | 8 | const FieldTrack = false 9 | const FieldTrackInt = 0 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_fieldtrack_on.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build goexperiment.fieldtrack 4 | // +build goexperiment.fieldtrack 5 | 6 | package goexperiment 7 | 8 | const FieldTrack = true 9 | const FieldTrackInt = 1 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_preemptibleloops_off.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build !goexperiment.preemptibleloops 4 | // +build !goexperiment.preemptibleloops 5 | 6 | package goexperiment 7 | 8 | const PreemptibleLoops = false 9 | const PreemptibleLoopsInt = 0 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_preemptibleloops_on.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build goexperiment.preemptibleloops 4 | // +build goexperiment.preemptibleloops 5 | 6 | package goexperiment 7 | 8 | const PreemptibleLoops = true 9 | const PreemptibleLoopsInt = 1 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabi_off.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build !goexperiment.regabi 4 | // +build !goexperiment.regabi 5 | 6 | package goexperiment 7 | 8 | const Regabi = false 9 | const RegabiInt = 0 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabi_on.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build goexperiment.regabi 4 | // +build goexperiment.regabi 5 | 6 | package goexperiment 7 | 8 | const Regabi = true 9 | const RegabiInt = 1 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabiargs_off.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build !goexperiment.regabiargs 4 | // +build !goexperiment.regabiargs 5 | 6 | package goexperiment 7 | 8 | const RegabiArgs = false 9 | const RegabiArgsInt = 0 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabiargs_on.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build goexperiment.regabiargs 4 | // +build goexperiment.regabiargs 5 | 6 | package goexperiment 7 | 8 | const RegabiArgs = true 9 | const RegabiArgsInt = 1 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabidefer_off.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build !goexperiment.regabidefer 4 | // +build !goexperiment.regabidefer 5 | 6 | package goexperiment 7 | 8 | const RegabiDefer = false 9 | const RegabiDeferInt = 0 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabidefer_on.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build goexperiment.regabidefer 4 | // +build goexperiment.regabidefer 5 | 6 | package goexperiment 7 | 8 | const RegabiDefer = true 9 | const RegabiDeferInt = 1 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabig_off.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build !goexperiment.regabig 4 | // +build !goexperiment.regabig 5 | 6 | package goexperiment 7 | 8 | const RegabiG = false 9 | const RegabiGInt = 0 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabig_on.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build goexperiment.regabig 4 | // +build goexperiment.regabig 5 | 6 | package goexperiment 7 | 8 | const RegabiG = true 9 | const RegabiGInt = 1 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabireflect_off.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build !goexperiment.regabireflect 4 | // +build !goexperiment.regabireflect 5 | 6 | package goexperiment 7 | 8 | const RegabiReflect = false 9 | const RegabiReflectInt = 0 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabireflect_on.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build goexperiment.regabireflect 4 | // +build goexperiment.regabireflect 5 | 6 | package goexperiment 7 | 8 | const RegabiReflect = true 9 | const RegabiReflectInt = 1 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabiwrappers_off.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build !goexperiment.regabiwrappers 4 | // +build !goexperiment.regabiwrappers 5 | 6 | package goexperiment 7 | 8 | const RegabiWrappers = false 9 | const RegabiWrappersInt = 0 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_regabiwrappers_on.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build goexperiment.regabiwrappers 4 | // +build goexperiment.regabiwrappers 5 | 6 | package goexperiment 7 | 8 | const RegabiWrappers = true 9 | const RegabiWrappersInt = 1 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_staticlockranking_off.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build !goexperiment.staticlockranking 4 | // +build !goexperiment.staticlockranking 5 | 6 | package goexperiment 7 | 8 | const StaticLockRanking = false 9 | const StaticLockRankingInt = 0 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/exp_staticlockranking_on.go: -------------------------------------------------------------------------------- 1 | // Code generated by mkconsts.go. DO NOT EDIT. 2 | 3 | //go:build goexperiment.staticlockranking 4 | // +build goexperiment.staticlockranking 5 | 6 | package goexperiment 7 | 8 | const StaticLockRanking = true 9 | const StaticLockRankingInt = 1 10 | -------------------------------------------------------------------------------- /lib/internal/goexperiment/mkconsts.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build ignore 6 | // +build ignore 7 | 8 | // mkconsts generates const definition files for each GOEXPERIMENT. 9 | package main 10 | 11 | import ( 12 | "bytes" 13 | "fmt" 14 | "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/goexperiment" 15 | "log" 16 | "os" 17 | "reflect" 18 | "strings" 19 | ) 20 | 21 | func main() { 22 | // Delete existing experiment constant files. 23 | ents, err := os.ReadDir(".") 24 | if err != nil { 25 | log.Fatal(err) 26 | } 27 | for _, ent := range ents { 28 | name := ent.Name() 29 | if !strings.HasPrefix(name, "exp_") { 30 | continue 31 | } 32 | // Check that this is definitely a generated file. 33 | data, err := os.ReadFile(name) 34 | if err != nil { 35 | log.Fatalf("reading %s: %v", name, err) 36 | } 37 | if !bytes.Contains(data, []byte("Code generated by mkconsts")) { 38 | log.Fatalf("%s: expected generated file", name) 39 | } 40 | if err := os.Remove(name); err != nil { 41 | log.Fatal(err) 42 | } 43 | } 44 | 45 | // Generate new experiment constant files. 46 | rt := reflect.TypeOf(&goexperiment.Flags{}).Elem() 47 | for i := 0; i < rt.NumField(); i++ { 48 | f := rt.Field(i).Name 49 | buildTag := "goexperiment." + strings.ToLower(f) 50 | for _, val := range []bool{false, true} { 51 | name := fmt.Sprintf("exp_%s_%s.go", strings.ToLower(f), pick(val, "off", "on")) 52 | data := fmt.Sprintf(`// Code generated by mkconsts.go. DO NOT EDIT. 53 | 54 | //go:build %s%s 55 | // +build %s%s 56 | 57 | package goexperiment 58 | 59 | const %s = %v 60 | const %sInt = %s 61 | `, pick(val, "!", ""), buildTag, pick(val, "!", ""), buildTag, f, val, f, pick(val, "0", "1")) 62 | if err := os.WriteFile(name, []byte(data), 0666); err != nil { 63 | log.Fatalf("writing %s: %v", name, err) 64 | } 65 | } 66 | } 67 | } 68 | 69 | func pick(v bool, f, t string) string { 70 | if v { 71 | return t 72 | } 73 | return f 74 | } 75 | -------------------------------------------------------------------------------- /lib/internal/goroot/gccgo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build gccgo 6 | // +build gccgo 7 | 8 | package goroot 9 | 10 | import ( 11 | "os" 12 | "path/filepath" 13 | ) 14 | 15 | // IsStandardPackage reports whether path is a standard package, 16 | // given goroot and compiler. 17 | func IsStandardPackage(goroot, compiler, path string) bool { 18 | switch compiler { 19 | case "gc": 20 | dir := filepath.Join(goroot, "src", path) 21 | _, err := os.Stat(dir) 22 | return err == nil 23 | case "gccgo": 24 | return stdpkg[path] 25 | default: 26 | panic("unknown compiler " + compiler) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/internal/goversion/goversion.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package goversion 6 | 7 | // Version is the Go 1.x version which is currently 8 | // in development and will eventually get released. 9 | // 10 | // It should be updated at the start of each development cycle to be 11 | // the version of the next Go 1.x release. See golang.org/issue/40705. 12 | const Version = 17 13 | -------------------------------------------------------------------------------- /lib/internal/itoa/itoa.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Simple conversions to avoid depending on strconv. 6 | 7 | package itoa 8 | 9 | // Itoa converts val to a decimal string. 10 | func Itoa(val int) string { 11 | if val < 0 { 12 | return "-" + Uitoa(uint(-val)) 13 | } 14 | return Uitoa(uint(val)) 15 | } 16 | 17 | // Uitoa converts val to a decimal string. 18 | func Uitoa(val uint) string { 19 | if val == 0 { // avoid string allocation 20 | return "0" 21 | } 22 | var buf [20]byte // big enough for 64bit value base 10 23 | i := len(buf) - 1 24 | for val >= 10 { 25 | q := val / 10 26 | buf[i] = byte('0' + val - q*10) 27 | i-- 28 | val = q 29 | } 30 | // val < 10 31 | buf[i] = byte('0' + val) 32 | return string(buf[i:]) 33 | } 34 | -------------------------------------------------------------------------------- /lib/internal/itoa/itoa_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package itoa_test 6 | 7 | import ( 8 | "fmt" 9 | "internal/itoa" 10 | "math" 11 | "testing" 12 | ) 13 | 14 | var ( 15 | minInt64 int64 = math.MinInt64 16 | maxInt64 int64 = math.MaxInt64 17 | maxUint64 uint64 = math.MaxUint64 18 | ) 19 | 20 | func TestItoa(t *testing.T) { 21 | tests := []int{int(minInt64), math.MinInt32, -999, -100, -1, 0, 1, 100, 999, math.MaxInt32, int(maxInt64)} 22 | for _, tt := range tests { 23 | got := itoa.Itoa(tt) 24 | want := fmt.Sprint(tt) 25 | if want != got { 26 | t.Fatalf("Itoa(%d) = %s, want %s", tt, got, want) 27 | } 28 | } 29 | } 30 | 31 | func TestUitoa(t *testing.T) { 32 | tests := []uint{0, 1, 100, 999, math.MaxUint32, uint(maxUint64)} 33 | for _, tt := range tests { 34 | got := itoa.Uitoa(tt) 35 | want := fmt.Sprint(tt) 36 | if want != got { 37 | t.Fatalf("Uitoa(%d) = %s, want %s", tt, got, want) 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/internal/lazyregexp/lazyre.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package lazyregexp is a thin wrapper over regexp, allowing the use of global 6 | // regexp variables without forcing them to be compiled at init. 7 | package lazyregexp 8 | 9 | import ( 10 | "os" 11 | "regexp" 12 | "strings" 13 | "sync" 14 | ) 15 | 16 | // Regexp is a wrapper around regexp.Regexp, where the underlying regexp will be 17 | // compiled the first time it is needed. 18 | type Regexp struct { 19 | str string 20 | once sync.Once 21 | rx *regexp.Regexp 22 | } 23 | 24 | func (r *Regexp) re() *regexp.Regexp { 25 | r.once.Do(r.build) 26 | return r.rx 27 | } 28 | 29 | func (r *Regexp) build() { 30 | r.rx = regexp.MustCompile(r.str) 31 | r.str = "" 32 | } 33 | 34 | func (r *Regexp) FindSubmatch(s []byte) [][]byte { 35 | return r.re().FindSubmatch(s) 36 | } 37 | 38 | func (r *Regexp) FindStringSubmatch(s string) []string { 39 | return r.re().FindStringSubmatch(s) 40 | } 41 | 42 | func (r *Regexp) FindStringSubmatchIndex(s string) []int { 43 | return r.re().FindStringSubmatchIndex(s) 44 | } 45 | 46 | func (r *Regexp) ReplaceAllString(src, repl string) string { 47 | return r.re().ReplaceAllString(src, repl) 48 | } 49 | 50 | func (r *Regexp) FindString(s string) string { 51 | return r.re().FindString(s) 52 | } 53 | 54 | func (r *Regexp) FindAllString(s string, n int) []string { 55 | return r.re().FindAllString(s, n) 56 | } 57 | 58 | func (r *Regexp) MatchString(s string) bool { 59 | return r.re().MatchString(s) 60 | } 61 | 62 | func (r *Regexp) SubexpNames() []string { 63 | return r.re().SubexpNames() 64 | } 65 | 66 | var inTest = len(os.Args) > 0 && strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test") 67 | 68 | // New creates a new lazy regexp, delaying the compiling work until it is first 69 | // needed. If the code is being run as part of tests, the regexp compiling will 70 | // happen immediately. 71 | func New(str string) *Regexp { 72 | lr := &Regexp{str: str} 73 | if inTest { 74 | // In tests, always compile the regexps early. 75 | lr.re() 76 | } 77 | return lr 78 | } 79 | -------------------------------------------------------------------------------- /lib/internal/lazytemplate/lazytemplate.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package lazytemplate is a thin wrapper over text/template, allowing the use 6 | // of global template variables without forcing them to be parsed at init. 7 | package lazytemplate 8 | 9 | import ( 10 | "io" 11 | "os" 12 | "strings" 13 | "sync" 14 | "text/template" 15 | ) 16 | 17 | // Template is a wrapper around text/template.Template, where the underlying 18 | // template will be parsed the first time it is needed. 19 | type Template struct { 20 | name, text string 21 | 22 | once sync.Once 23 | tmpl *template.Template 24 | } 25 | 26 | func (r *Template) tp() *template.Template { 27 | r.once.Do(r.build) 28 | return r.tmpl 29 | } 30 | 31 | func (r *Template) build() { 32 | r.tmpl = template.Must(template.New(r.name).Parse(r.text)) 33 | r.name, r.text = "", "" 34 | } 35 | 36 | func (r *Template) Execute(w io.Writer, data interface{}) error { 37 | return r.tp().Execute(w, data) 38 | } 39 | 40 | var inTest = len(os.Args) > 0 && strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test") 41 | 42 | // New creates a new lazy template, delaying the parsing work until it is first 43 | // needed. If the code is being run as part of tests, the template parsing will 44 | // happen immediately. 45 | func New(name, text string) *Template { 46 | lt := &Template{name: name, text: text} 47 | if inTest { 48 | // In tests, always parse the templates early. 49 | lt.tp() 50 | } 51 | return lt 52 | } 53 | -------------------------------------------------------------------------------- /lib/internal/nettrace/nettrace.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package nettrace contains internal hooks for tracing activity in 6 | // the net package. This package is purely internal for use by the 7 | // net/http/httptrace package and has no stable API exposed to end 8 | // users. 9 | package nettrace 10 | 11 | // TraceKey is a context.Context Value key. Its associated value should 12 | // be a *Trace struct. 13 | type TraceKey struct{} 14 | 15 | // LookupIPAltResolverKey is a context.Context Value key used by tests to 16 | // specify an alternate resolver func. 17 | // It is not exposed to outsider users. (But see issue 12503) 18 | // The value should be the same type as lookupIP: 19 | // func lookupIP(ctx context.Context, host string) ([]IPAddr, error) 20 | type LookupIPAltResolverKey struct{} 21 | 22 | // Trace contains a set of hooks for tracing events within 23 | // the net package. Any specific hook may be nil. 24 | type Trace struct { 25 | // DNSStart is called with the hostname of a DNS lookup 26 | // before it begins. 27 | DNSStart func(name string) 28 | 29 | // DNSDone is called after a DNS lookup completes (or fails). 30 | // The coalesced parameter is whether singleflight de-dupped 31 | // the call. The addrs are of type net.IPAddr but can't 32 | // actually be for circular dependency reasons. 33 | DNSDone func(netIPs []interface{}, coalesced bool, err error) 34 | 35 | // ConnectStart is called before a Dial, excluding Dials made 36 | // during DNS lookups. In the case of DualStack (Happy Eyeballs) 37 | // dialing, this may be called multiple times, from multiple 38 | // goroutines. 39 | ConnectStart func(network, addr string) 40 | 41 | // ConnectStart is called after a Dial with the results, excluding 42 | // Dials made during DNS lookups. It may also be called multiple 43 | // times, like ConnectStart. 44 | ConnectDone func(network, addr string, err error) 45 | } 46 | -------------------------------------------------------------------------------- /lib/internal/obscuretestdata/obscuretestdata.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package obscuretestdata contains functionality used by tests to more easily 6 | // work with testdata that must be obscured primarily due to 7 | // golang.org/issue/34986. 8 | package obscuretestdata 9 | 10 | import ( 11 | "encoding/base64" 12 | "io" 13 | "os" 14 | ) 15 | 16 | // DecodeToTempFile decodes the named file to a temporary location. 17 | // If successful, it returns the path of the decoded file. 18 | // The caller is responsible for ensuring that the temporary file is removed. 19 | func DecodeToTempFile(name string) (path string, err error) { 20 | f, err := os.Open(name) 21 | if err != nil { 22 | return "", err 23 | } 24 | defer f.Close() 25 | 26 | tmp, err := os.CreateTemp("", "obscuretestdata-decoded-") 27 | if err != nil { 28 | return "", err 29 | } 30 | if _, err := io.Copy(tmp, base64.NewDecoder(base64.StdEncoding, f)); err != nil { 31 | tmp.Close() 32 | os.Remove(tmp.Name()) 33 | return "", err 34 | } 35 | if err := tmp.Close(); err != nil { 36 | os.Remove(tmp.Name()) 37 | return "", err 38 | } 39 | return tmp.Name(), nil 40 | } 41 | 42 | // ReadFile reads the named file and returns its decoded contents. 43 | func ReadFile(name string) ([]byte, error) { 44 | f, err := os.Open(name) 45 | if err != nil { 46 | return nil, err 47 | } 48 | defer f.Close() 49 | return io.ReadAll(base64.NewDecoder(base64.StdEncoding, f)) 50 | } 51 | -------------------------------------------------------------------------------- /lib/internal/oserror/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package oserror defines errors values used in the os package. 6 | // 7 | // These types are defined here to permit the syscall package to reference them. 8 | package oserror 9 | 10 | import "errors" 11 | 12 | var ( 13 | ErrInvalid = errors.New("invalid argument") 14 | ErrPermission = errors.New("permission denied") 15 | ErrExist = errors.New("file already exists") 16 | ErrNotExist = errors.New("file does not exist") 17 | ErrClosed = errors.New("file already closed") 18 | ) 19 | -------------------------------------------------------------------------------- /lib/internal/poll/errno_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris 6 | // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | // Do the interface allocations only once for common 13 | // Errno values. 14 | var ( 15 | errEAGAIN error = syscall.EAGAIN 16 | errEINVAL error = syscall.EINVAL 17 | errENOENT error = syscall.ENOENT 18 | ) 19 | 20 | // errnoErr returns common boxed Errno values, to prevent 21 | // allocations at runtime. 22 | func errnoErr(e syscall.Errno) error { 23 | switch e { 24 | case 0: 25 | return nil 26 | case syscall.EAGAIN: 27 | return errEAGAIN 28 | case syscall.EINVAL: 29 | return errEINVAL 30 | case syscall.ENOENT: 31 | return errENOENT 32 | } 33 | return e 34 | } 35 | -------------------------------------------------------------------------------- /lib/internal/poll/errno_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build windows 6 | // +build windows 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | // Do the interface allocations only once for common 13 | // Errno values. 14 | 15 | var ( 16 | errERROR_IO_PENDING error = syscall.Errno(syscall.ERROR_IO_PENDING) 17 | ) 18 | 19 | // ErrnoErr returns common boxed Errno values, to prevent 20 | // allocations at runtime. 21 | func errnoErr(e syscall.Errno) error { 22 | switch e { 23 | case 0: 24 | return nil 25 | case syscall.ERROR_IO_PENDING: 26 | return errERROR_IO_PENDING 27 | } 28 | // TODO: add more here, after collecting data on the common 29 | // error values see on Windows. (perhaps when running 30 | // all.bat?) 31 | return e 32 | } 33 | -------------------------------------------------------------------------------- /lib/internal/poll/error_linux_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll_test 6 | 7 | import ( 8 | "errors" 9 | "os" 10 | "syscall" 11 | 12 | "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll" 13 | ) 14 | 15 | func badStateFile() (*os.File, error) { 16 | if os.Getuid() != 0 { 17 | return nil, errors.New("must be root") 18 | } 19 | // Using OpenFile for a device file is an easy way to make a 20 | // file attached to the runtime-integrated network poller and 21 | // configured in halfway. 22 | return os.OpenFile("/dev/net/tun", os.O_RDWR, 0) 23 | } 24 | 25 | func isBadStateFileError(err error) (string, bool) { 26 | switch err { 27 | case poll.ErrNotPollable, syscall.EBADFD: 28 | return "", true 29 | default: 30 | return "not pollable or file in bad state error", false 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/internal/poll/error_stub_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !linux 6 | // +build !linux 7 | 8 | package poll_test 9 | 10 | import ( 11 | "errors" 12 | "os" 13 | "runtime" 14 | ) 15 | 16 | func badStateFile() (*os.File, error) { 17 | return nil, errors.New("not supported on " + runtime.GOOS) 18 | } 19 | 20 | func isBadStateFileError(err error) (string, bool) { 21 | return "", false 22 | } 23 | -------------------------------------------------------------------------------- /lib/internal/poll/error_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll_test 6 | 7 | import ( 8 | "fmt" 9 | "io/fs" 10 | "net" 11 | "os" 12 | "testing" 13 | "time" 14 | ) 15 | 16 | func TestReadError(t *testing.T) { 17 | t.Run("ErrNotPollable", func(t *testing.T) { 18 | f, err := badStateFile() 19 | if err != nil { 20 | t.Skip(err) 21 | } 22 | defer f.Close() 23 | 24 | // Give scheduler a chance to have two separated 25 | // goroutines: an event poller and an event waiter. 26 | time.Sleep(100 * time.Millisecond) 27 | 28 | var b [1]byte 29 | _, err = f.Read(b[:]) 30 | if perr := parseReadError(err, isBadStateFileError); perr != nil { 31 | t.Fatal(perr) 32 | } 33 | }) 34 | } 35 | 36 | func parseReadError(nestedErr error, verify func(error) (string, bool)) error { 37 | err := nestedErr 38 | if nerr, ok := err.(*net.OpError); ok { 39 | err = nerr.Err 40 | } 41 | if nerr, ok := err.(*fs.PathError); ok { 42 | err = nerr.Err 43 | } 44 | if nerr, ok := err.(*os.SyscallError); ok { 45 | err = nerr.Err 46 | } 47 | if s, ok := verify(err); !ok { 48 | return fmt.Errorf("got %v; want %s", nestedErr, s) 49 | } 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /lib/internal/poll/export_linux_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Export guts for testing on linux. 6 | // Since testing imports os and os imports github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll, 7 | // the github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll tests can not be in package poll. 8 | 9 | package poll 10 | 11 | var ( 12 | GetPipe = getPipe 13 | PutPipe = putPipe 14 | NewPipe = newPipe 15 | DestroyPipe = destroyPipe 16 | ) 17 | 18 | func GetPipeFds(p *SplicePipe) (int, int) { 19 | return p.rfd, p.wfd 20 | } 21 | 22 | type SplicePipe = splicePipe 23 | -------------------------------------------------------------------------------- /lib/internal/poll/export_posix_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows 6 | // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows 7 | 8 | // Export guts for testing on posix. 9 | // Since testing imports os and os imports github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll, 10 | // the github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll tests can not be in package poll. 11 | 12 | package poll 13 | 14 | func (fd *FD) EOFError(n int, err error) error { 15 | return fd.eofError(n, err) 16 | } 17 | -------------------------------------------------------------------------------- /lib/internal/poll/export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Export guts for testing. 6 | // Since testing imports os and os imports github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll, 7 | // the github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll tests can not be in package poll. 8 | 9 | package poll 10 | 11 | var Consume = consume 12 | 13 | type FDMutex struct { 14 | fdMutex 15 | } 16 | 17 | func (mu *FDMutex) Incref() bool { 18 | return mu.incref() 19 | } 20 | 21 | func (mu *FDMutex) IncrefAndClose() bool { 22 | return mu.increfAndClose() 23 | } 24 | 25 | func (mu *FDMutex) Decref() bool { 26 | return mu.decref() 27 | } 28 | 29 | func (mu *FDMutex) RWLock(read bool) bool { 30 | return mu.rwlock(read) 31 | } 32 | 33 | func (mu *FDMutex) RWUnlock(read bool) bool { 34 | return mu.rwunlock(read) 35 | } 36 | -------------------------------------------------------------------------------- /lib/internal/poll/export_windows_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Export guts for testing on windows. 6 | // Since testing imports os and os imports github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll, 7 | // the github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll tests can not be in package poll. 8 | 9 | package poll 10 | 11 | var ( 12 | LogInitFD = &logInitFD 13 | ) 14 | 15 | func (fd *FD) IsPartOfNetpoll() bool { 16 | return fd.pd.runtimeCtx != 0 17 | } 18 | -------------------------------------------------------------------------------- /lib/internal/poll/fcntl_js.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build js && wasm 6 | // +build js,wasm 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | // fcntl not supported on js/wasm 13 | func fcntl(fd int, cmd int, arg int) (int, error) { 14 | return 0, syscall.ENOSYS 15 | } 16 | -------------------------------------------------------------------------------- /lib/internal/poll/fcntl_libc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || darwin || solaris 6 | // +build aix darwin solaris 7 | 8 | package poll 9 | 10 | import _ "unsafe" // for go:linkname 11 | 12 | // Implemented in the syscall package. 13 | //go:linkname fcntl syscall.fcntl 14 | func fcntl(fd int, cmd int, arg int) (int, error) 15 | -------------------------------------------------------------------------------- /lib/internal/poll/fcntl_syscall.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build dragonfly || freebsd || linux || netbsd || openbsd 6 | // +build dragonfly freebsd linux netbsd openbsd 7 | 8 | package poll 9 | 10 | import ( 11 | "syscall" 12 | 13 | "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/syscall/unix" 14 | ) 15 | 16 | func fcntl(fd int, cmd int, arg int) (int, error) { 17 | r, _, e := syscall.Syscall(unix.FcntlSyscall, uintptr(fd), uintptr(cmd), uintptr(arg)) 18 | if e != 0 { 19 | return int(r), syscall.Errno(e) 20 | } 21 | return int(r), nil 22 | } 23 | -------------------------------------------------------------------------------- /lib/internal/poll/fd_fsync_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll 6 | 7 | import "syscall" 8 | 9 | // Fsync invokes SYS_FCNTL with SYS_FULLFSYNC because 10 | // on OS X, SYS_FSYNC doesn't fully flush contents to disk. 11 | // See Issue #26650 as well as the man page for fsync on OS X. 12 | func (fd *FD) Fsync() error { 13 | if err := fd.incref(); err != nil { 14 | return err 15 | } 16 | defer fd.decref() 17 | return ignoringEINTR(func() error { 18 | _, err := fcntl(fd.Sysfd, syscall.F_FULLFSYNC, 0) 19 | return err 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /lib/internal/poll/fd_fsync_posix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris 6 | // +build aix dragonfly freebsd js,wasm linux netbsd openbsd solaris 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | // Fsync wraps syscall.Fsync. 13 | func (fd *FD) Fsync() error { 14 | if err := fd.incref(); err != nil { 15 | return err 16 | } 17 | defer fd.decref() 18 | return ignoringEINTR(func() error { 19 | return syscall.Fsync(fd.Sysfd) 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /lib/internal/poll/fd_fsync_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll 6 | 7 | import "syscall" 8 | 9 | // Fsync wraps syscall.Fsync. 10 | func (fd *FD) Fsync() error { 11 | if err := fd.incref(); err != nil { 12 | return err 13 | } 14 | defer fd.decref() 15 | return syscall.Fsync(fd.Sysfd) 16 | } 17 | -------------------------------------------------------------------------------- /lib/internal/poll/fd_opendir_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll 6 | 7 | import ( 8 | "syscall" 9 | _ "unsafe" // for go:linkname 10 | ) 11 | 12 | // OpenDir returns a pointer to a DIR structure suitable for 13 | // ReadDir. In case of an error, the name of the failed 14 | // syscall is returned along with a syscall.Errno. 15 | func (fd *FD) OpenDir() (uintptr, string, error) { 16 | // fdopendir(3) takes control of the file descriptor, 17 | // so use a dup. 18 | fd2, call, err := fd.Dup() 19 | if err != nil { 20 | return 0, call, err 21 | } 22 | var dir uintptr 23 | for { 24 | dir, err = fdopendir(fd2) 25 | if err != syscall.EINTR { 26 | break 27 | } 28 | } 29 | if err != nil { 30 | syscall.Close(fd2) 31 | return 0, "fdopendir", err 32 | } 33 | return dir, "", nil 34 | } 35 | 36 | // Implemented in syscall/syscall_darwin.go. 37 | //go:linkname fdopendir syscall.fdopendir 38 | func fdopendir(fd int) (dir uintptr, err error) 39 | -------------------------------------------------------------------------------- /lib/internal/poll/fd_posix_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows 6 | // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows 7 | 8 | package poll_test 9 | 10 | import ( 11 | "io" 12 | "testing" 13 | 14 | . "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll" 15 | ) 16 | 17 | var eofErrorTests = []struct { 18 | n int 19 | err error 20 | fd *FD 21 | expected error 22 | }{ 23 | {100, nil, &FD{ZeroReadIsEOF: true}, nil}, 24 | {100, io.EOF, &FD{ZeroReadIsEOF: true}, io.EOF}, 25 | {100, ErrNetClosing, &FD{ZeroReadIsEOF: true}, ErrNetClosing}, 26 | {0, nil, &FD{ZeroReadIsEOF: true}, io.EOF}, 27 | {0, io.EOF, &FD{ZeroReadIsEOF: true}, io.EOF}, 28 | {0, ErrNetClosing, &FD{ZeroReadIsEOF: true}, ErrNetClosing}, 29 | 30 | {100, nil, &FD{ZeroReadIsEOF: false}, nil}, 31 | {100, io.EOF, &FD{ZeroReadIsEOF: false}, io.EOF}, 32 | {100, ErrNetClosing, &FD{ZeroReadIsEOF: false}, ErrNetClosing}, 33 | {0, nil, &FD{ZeroReadIsEOF: false}, nil}, 34 | {0, io.EOF, &FD{ZeroReadIsEOF: false}, io.EOF}, 35 | {0, ErrNetClosing, &FD{ZeroReadIsEOF: false}, ErrNetClosing}, 36 | } 37 | 38 | func TestEOFError(t *testing.T) { 39 | for _, tt := range eofErrorTests { 40 | actual := tt.fd.EOFError(tt.n, tt.err) 41 | if actual != tt.expected { 42 | t.Errorf("eofError(%v, %v, %v): expected %v, actual %v", tt.n, tt.err, tt.fd.ZeroReadIsEOF, tt.expected, actual) 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/internal/poll/fd_writev_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin 6 | // +build darwin 7 | 8 | package poll 9 | 10 | import ( 11 | "syscall" 12 | _ "unsafe" // for go:linkname 13 | ) 14 | 15 | // Implemented in syscall/syscall_darwin.go. 16 | //go:linkname writev syscall.writev 17 | func writev(fd int, iovecs []syscall.Iovec) (uintptr, error) 18 | -------------------------------------------------------------------------------- /lib/internal/poll/fd_writev_illumos.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build illumos 6 | // +build illumos 7 | 8 | package poll 9 | 10 | import ( 11 | "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/syscall/unix" 12 | "syscall" 13 | ) 14 | 15 | func writev(fd int, iovecs []syscall.Iovec) (uintptr, error) { 16 | return unix.Writev(fd, iovecs) 17 | } 18 | -------------------------------------------------------------------------------- /lib/internal/poll/fd_writev_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build dragonfly || freebsd || linux || netbsd || openbsd 6 | // +build dragonfly freebsd linux netbsd openbsd 7 | 8 | package poll 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | func writev(fd int, iovecs []syscall.Iovec) (uintptr, error) { 16 | var ( 17 | r uintptr 18 | e syscall.Errno 19 | ) 20 | for { 21 | r, _, e = syscall.Syscall(syscall.SYS_WRITEV, uintptr(fd), uintptr(unsafe.Pointer(&iovecs[0])), uintptr(len(iovecs))) 22 | if e != syscall.EINTR { 23 | break 24 | } 25 | } 26 | if e != 0 { 27 | return r, e 28 | } 29 | return r, nil 30 | } 31 | -------------------------------------------------------------------------------- /lib/internal/poll/hook_cloexec.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd 6 | // +build dragonfly freebsd illumos linux netbsd openbsd 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | // Accept4Func is used to hook the accept4 call. 13 | var Accept4Func func(int, int) (int, syscall.Sockaddr, error) = syscall.Accept4 14 | -------------------------------------------------------------------------------- /lib/internal/poll/hook_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris 6 | // +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | // CloseFunc is used to hook the close call. 13 | var CloseFunc func(int) error = syscall.Close 14 | 15 | // AcceptFunc is used to hook the accept call. 16 | var AcceptFunc func(int) (int, syscall.Sockaddr, error) = syscall.Accept 17 | -------------------------------------------------------------------------------- /lib/internal/poll/hook_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll 6 | 7 | import "syscall" 8 | 9 | // CloseFunc is used to hook the close call. 10 | var CloseFunc func(syscall.Handle) error = syscall.Closesocket 11 | 12 | // AcceptFunc is used to hook the accept call. 13 | var AcceptFunc func(syscall.Handle, syscall.Handle, *byte, uint32, uint32, uint32, *uint32, *syscall.Overlapped) error = syscall.AcceptEx 14 | 15 | // ConnectExFunc is used to hook the ConnectEx call. 16 | var ConnectExFunc func(syscall.Handle, syscall.Sockaddr, *byte, uint32, *uint32, *syscall.Overlapped) error = syscall.ConnectEx 17 | -------------------------------------------------------------------------------- /lib/internal/poll/iovec_illumos.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build illumos 6 | // +build illumos 7 | 8 | package poll 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | func newIovecWithBase(base *byte) syscall.Iovec { 16 | return syscall.Iovec{Base: (*int8)(unsafe.Pointer(base))} 17 | } 18 | -------------------------------------------------------------------------------- /lib/internal/poll/iovec_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd 6 | // +build darwin dragonfly freebsd linux netbsd openbsd 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | func newIovecWithBase(base *byte) syscall.Iovec { 13 | return syscall.Iovec{Base: base} 14 | } 15 | -------------------------------------------------------------------------------- /lib/internal/poll/read_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll_test 6 | 7 | import ( 8 | "os" 9 | "runtime" 10 | "sync" 11 | "testing" 12 | "time" 13 | ) 14 | 15 | func TestRead(t *testing.T) { 16 | t.Run("SpecialFile", func(t *testing.T) { 17 | var wg sync.WaitGroup 18 | for _, p := range specialFiles() { 19 | for i := 0; i < 4; i++ { 20 | wg.Add(1) 21 | go func(p string) { 22 | defer wg.Done() 23 | for i := 0; i < 100; i++ { 24 | if _, err := os.ReadFile(p); err != nil { 25 | t.Error(err) 26 | return 27 | } 28 | time.Sleep(time.Nanosecond) 29 | } 30 | }(p) 31 | } 32 | } 33 | wg.Wait() 34 | }) 35 | } 36 | 37 | func specialFiles() []string { 38 | var ps []string 39 | switch runtime.GOOS { 40 | case "darwin", "ios", "dragonfly", "freebsd", "netbsd", "openbsd": 41 | ps = []string{ 42 | "/dev/null", 43 | } 44 | case "linux": 45 | ps = []string{ 46 | "/dev/null", 47 | "/proc/stat", 48 | "/sys/devices/system/cpu/online", 49 | } 50 | } 51 | nps := ps[:0] 52 | for _, p := range ps { 53 | f, err := os.Open(p) 54 | if err != nil { 55 | continue 56 | } 57 | f.Close() 58 | nps = append(nps, p) 59 | } 60 | return nps 61 | } 62 | -------------------------------------------------------------------------------- /lib/internal/poll/sendfile_bsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build dragonfly || freebsd 6 | // +build dragonfly freebsd 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | // maxSendfileSize is the largest chunk size we ask the kernel to copy 13 | // at a time. 14 | const maxSendfileSize int = 4 << 20 15 | 16 | // SendFile wraps the sendfile system call. 17 | func SendFile(dstFD *FD, src int, pos, remain int64) (int64, error) { 18 | if err := dstFD.writeLock(); err != nil { 19 | return 0, err 20 | } 21 | defer dstFD.writeUnlock() 22 | if err := dstFD.pd.prepareWrite(dstFD.isFile); err != nil { 23 | return 0, err 24 | } 25 | 26 | dst := dstFD.Sysfd 27 | var written int64 28 | var err error 29 | for remain > 0 { 30 | n := maxSendfileSize 31 | if int64(n) > remain { 32 | n = int(remain) 33 | } 34 | pos1 := pos 35 | n, err1 := syscall.Sendfile(dst, src, &pos1, n) 36 | if n > 0 { 37 | pos += int64(n) 38 | written += int64(n) 39 | remain -= int64(n) 40 | } else if n == 0 && err1 == nil { 41 | break 42 | } 43 | if err1 == syscall.EINTR { 44 | continue 45 | } 46 | if err1 == syscall.EAGAIN { 47 | if err1 = dstFD.pd.waitWrite(dstFD.isFile); err1 == nil { 48 | continue 49 | } 50 | } 51 | if err1 != nil { 52 | // This includes syscall.ENOSYS (no kernel 53 | // support) and syscall.EINVAL (fd types which 54 | // don't implement sendfile) 55 | err = err1 56 | break 57 | } 58 | } 59 | return written, err 60 | } 61 | -------------------------------------------------------------------------------- /lib/internal/poll/sendfile_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll 6 | 7 | import "syscall" 8 | 9 | // maxSendfileSize is the largest chunk size we ask the kernel to copy 10 | // at a time. 11 | const maxSendfileSize int = 4 << 20 12 | 13 | // SendFile wraps the sendfile system call. 14 | func SendFile(dstFD *FD, src int, remain int64) (int64, error) { 15 | if err := dstFD.writeLock(); err != nil { 16 | return 0, err 17 | } 18 | defer dstFD.writeUnlock() 19 | if err := dstFD.pd.prepareWrite(dstFD.isFile); err != nil { 20 | return 0, err 21 | } 22 | 23 | dst := dstFD.Sysfd 24 | var written int64 25 | var err error 26 | for remain > 0 { 27 | n := maxSendfileSize 28 | if int64(n) > remain { 29 | n = int(remain) 30 | } 31 | n, err1 := syscall.Sendfile(dst, src, nil, n) 32 | if n > 0 { 33 | written += int64(n) 34 | remain -= int64(n) 35 | } else if n == 0 && err1 == nil { 36 | break 37 | } 38 | if err1 == syscall.EINTR { 39 | continue 40 | } 41 | if err1 == syscall.EAGAIN { 42 | if err1 = dstFD.pd.waitWrite(dstFD.isFile); err1 == nil { 43 | continue 44 | } 45 | } 46 | if err1 != nil { 47 | // This includes syscall.ENOSYS (no kernel 48 | // support) and syscall.EINVAL (fd types which 49 | // don't implement sendfile) 50 | err = err1 51 | break 52 | } 53 | } 54 | return written, err 55 | } 56 | -------------------------------------------------------------------------------- /lib/internal/poll/sendfile_solaris.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll 6 | 7 | import "syscall" 8 | 9 | // Not strictly needed, but very helpful for debugging, see issue #10221. 10 | //go:cgo_import_dynamic _ _ "libsendfile.so" 11 | //go:cgo_import_dynamic _ _ "libsocket.so" 12 | 13 | // maxSendfileSize is the largest chunk size we ask the kernel to copy 14 | // at a time. 15 | const maxSendfileSize int = 4 << 20 16 | 17 | // SendFile wraps the sendfile system call. 18 | func SendFile(dstFD *FD, src int, pos, remain int64) (int64, error) { 19 | if err := dstFD.writeLock(); err != nil { 20 | return 0, err 21 | } 22 | defer dstFD.writeUnlock() 23 | if err := dstFD.pd.prepareWrite(dstFD.isFile); err != nil { 24 | return 0, err 25 | } 26 | 27 | dst := dstFD.Sysfd 28 | var written int64 29 | var err error 30 | for remain > 0 { 31 | n := maxSendfileSize 32 | if int64(n) > remain { 33 | n = int(remain) 34 | } 35 | pos1 := pos 36 | n, err1 := syscall.Sendfile(dst, src, &pos1, n) 37 | if err1 == syscall.EAGAIN || err1 == syscall.EINTR { 38 | // partial write may have occurred 39 | n = int(pos1 - pos) 40 | } 41 | if n > 0 { 42 | pos += int64(n) 43 | written += int64(n) 44 | remain -= int64(n) 45 | } else if n == 0 && err1 == nil { 46 | break 47 | } 48 | if err1 == syscall.EAGAIN { 49 | if err1 = dstFD.pd.waitWrite(dstFD.isFile); err1 == nil { 50 | continue 51 | } 52 | } 53 | if err1 == syscall.EINTR { 54 | continue 55 | } 56 | if err1 != nil { 57 | // This includes syscall.ENOSYS (no kernel 58 | // support) and syscall.EINVAL (fd types which 59 | // don't implement sendfile) 60 | err = err1 61 | break 62 | } 63 | } 64 | return written, err 65 | } 66 | -------------------------------------------------------------------------------- /lib/internal/poll/sock_cloexec.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This file implements accept for platforms that provide a fast path for 6 | // setting SetNonblock and CloseOnExec. 7 | 8 | //go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd 9 | // +build dragonfly freebsd illumos linux netbsd openbsd 10 | 11 | package poll 12 | 13 | import "syscall" 14 | 15 | // Wrapper around the accept system call that marks the returned file 16 | // descriptor as nonblocking and close-on-exec. 17 | func accept(s int) (int, syscall.Sockaddr, string, error) { 18 | ns, sa, err := Accept4Func(s, syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC) 19 | // On Linux the accept4 system call was introduced in 2.6.28 20 | // kernel and on FreeBSD it was introduced in 10 kernel. If we 21 | // get an ENOSYS error on both Linux and FreeBSD, or EINVAL 22 | // error on Linux, fall back to using accept. 23 | switch err { 24 | case nil: 25 | return ns, sa, "", nil 26 | default: // errors other than the ones listed 27 | return -1, sa, "accept4", err 28 | case syscall.ENOSYS: // syscall missing 29 | case syscall.EINVAL: // some Linux use this instead of ENOSYS 30 | case syscall.EACCES: // some Linux use this instead of ENOSYS 31 | case syscall.EFAULT: // some Linux use this instead of ENOSYS 32 | } 33 | 34 | // See ../syscall/exec_unix.go for description of ForkLock. 35 | // It is probably okay to hold the lock across syscall.Accept 36 | // because we have put fd.sysfd into non-blocking mode. 37 | // However, a call to the File method will put it back into 38 | // blocking mode. We can't take that risk, so no use of ForkLock here. 39 | ns, sa, err = AcceptFunc(s) 40 | if err == nil { 41 | syscall.CloseOnExec(ns) 42 | } 43 | if err != nil { 44 | return -1, nil, "accept", err 45 | } 46 | if err = syscall.SetNonblock(ns, true); err != nil { 47 | CloseFunc(ns) 48 | return -1, nil, "setnonblock", err 49 | } 50 | return ns, sa, "", nil 51 | } 52 | -------------------------------------------------------------------------------- /lib/internal/poll/sockopt.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows 6 | // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | // SetsockoptInt wraps the setsockopt network call with an int argument. 13 | func (fd *FD) SetsockoptInt(level, name, arg int) error { 14 | if err := fd.incref(); err != nil { 15 | return err 16 | } 17 | defer fd.decref() 18 | return syscall.SetsockoptInt(fd.Sysfd, level, name, arg) 19 | } 20 | 21 | // SetsockoptInet4Addr wraps the setsockopt network call with an IPv4 address. 22 | func (fd *FD) SetsockoptInet4Addr(level, name int, arg [4]byte) error { 23 | if err := fd.incref(); err != nil { 24 | return err 25 | } 26 | defer fd.decref() 27 | return syscall.SetsockoptInet4Addr(fd.Sysfd, level, name, arg) 28 | } 29 | 30 | // SetsockoptLinger wraps the setsockopt network call with a Linger argument. 31 | func (fd *FD) SetsockoptLinger(level, name int, l *syscall.Linger) error { 32 | if err := fd.incref(); err != nil { 33 | return err 34 | } 35 | defer fd.decref() 36 | return syscall.SetsockoptLinger(fd.Sysfd, level, name, l) 37 | } 38 | -------------------------------------------------------------------------------- /lib/internal/poll/sockopt_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll 6 | 7 | import "syscall" 8 | 9 | // SetsockoptIPMreqn wraps the setsockopt network call with an IPMreqn argument. 10 | func (fd *FD) SetsockoptIPMreqn(level, name int, mreq *syscall.IPMreqn) error { 11 | if err := fd.incref(); err != nil { 12 | return err 13 | } 14 | defer fd.decref() 15 | return syscall.SetsockoptIPMreqn(fd.Sysfd, level, name, mreq) 16 | } 17 | -------------------------------------------------------------------------------- /lib/internal/poll/sockopt_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris 6 | // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | // SetsockoptByte wraps the setsockopt network call with a byte argument. 13 | func (fd *FD) SetsockoptByte(level, name int, arg byte) error { 14 | if err := fd.incref(); err != nil { 15 | return err 16 | } 17 | defer fd.decref() 18 | return syscall.SetsockoptByte(fd.Sysfd, level, name, arg) 19 | } 20 | -------------------------------------------------------------------------------- /lib/internal/poll/sockopt_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll 6 | 7 | import "syscall" 8 | 9 | // Setsockopt wraps the setsockopt network call. 10 | func (fd *FD) Setsockopt(level, optname int32, optval *byte, optlen int32) error { 11 | if err := fd.incref(); err != nil { 12 | return err 13 | } 14 | defer fd.decref() 15 | return syscall.Setsockopt(fd.Sysfd, level, optname, optval, optlen) 16 | } 17 | 18 | // WSAIoctl wraps the WSAIoctl network call. 19 | func (fd *FD) WSAIoctl(iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *syscall.Overlapped, completionRoutine uintptr) error { 20 | if err := fd.incref(); err != nil { 21 | return err 22 | } 23 | defer fd.decref() 24 | return syscall.WSAIoctl(fd.Sysfd, iocc, inbuf, cbif, outbuf, cbob, cbbr, overlapped, completionRoutine) 25 | } 26 | -------------------------------------------------------------------------------- /lib/internal/poll/sockoptip.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows 6 | // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows 7 | 8 | package poll 9 | 10 | import "syscall" 11 | 12 | // SetsockoptIPMreq wraps the setsockopt network call with an IPMreq argument. 13 | func (fd *FD) SetsockoptIPMreq(level, name int, mreq *syscall.IPMreq) error { 14 | if err := fd.incref(); err != nil { 15 | return err 16 | } 17 | defer fd.decref() 18 | return syscall.SetsockoptIPMreq(fd.Sysfd, level, name, mreq) 19 | } 20 | 21 | // SetsockoptIPv6Mreq wraps the setsockopt network call with an IPv6Mreq argument. 22 | func (fd *FD) SetsockoptIPv6Mreq(level, name int, mreq *syscall.IPv6Mreq) error { 23 | if err := fd.incref(); err != nil { 24 | return err 25 | } 26 | defer fd.decref() 27 | return syscall.SetsockoptIPv6Mreq(fd.Sysfd, level, name, mreq) 28 | } 29 | -------------------------------------------------------------------------------- /lib/internal/poll/strconv.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build plan9 6 | // +build plan9 7 | 8 | package poll 9 | 10 | // stringsHasSuffix is strings.HasSuffix. It reports whether s ends in 11 | // suffix. 12 | func stringsHasSuffix(s, suffix string) bool { 13 | return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix 14 | } 15 | -------------------------------------------------------------------------------- /lib/internal/poll/sys_cloexec.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This file implements accept for platforms that do not provide a fast path for 6 | // setting SetNonblock and CloseOnExec. 7 | 8 | //go:build aix || darwin || (js && wasm) || (solaris && !illumos) 9 | // +build aix darwin js,wasm solaris,!illumos 10 | 11 | package poll 12 | 13 | import ( 14 | "syscall" 15 | ) 16 | 17 | // Wrapper around the accept system call that marks the returned file 18 | // descriptor as nonblocking and close-on-exec. 19 | func accept(s int) (int, syscall.Sockaddr, string, error) { 20 | // See ../syscall/exec_unix.go for description of ForkLock. 21 | // It is probably okay to hold the lock across syscall.Accept 22 | // because we have put fd.sysfd into non-blocking mode. 23 | // However, a call to the File method will put it back into 24 | // blocking mode. We can't take that risk, so no use of ForkLock here. 25 | ns, sa, err := AcceptFunc(s) 26 | if err == nil { 27 | syscall.CloseOnExec(ns) 28 | } 29 | if err != nil { 30 | return -1, nil, "accept", err 31 | } 32 | if err = syscall.SetNonblock(ns, true); err != nil { 33 | CloseFunc(ns) 34 | return -1, nil, "setnonblock", err 35 | } 36 | return ns, sa, "", nil 37 | } 38 | -------------------------------------------------------------------------------- /lib/internal/poll/writev_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package poll_test 6 | 7 | import ( 8 | "reflect" 9 | "testing" 10 | 11 | "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/poll" 12 | ) 13 | 14 | func TestConsume(t *testing.T) { 15 | tests := []struct { 16 | in [][]byte 17 | consume int64 18 | want [][]byte 19 | }{ 20 | { 21 | in: [][]byte{[]byte("foo"), []byte("bar")}, 22 | consume: 0, 23 | want: [][]byte{[]byte("foo"), []byte("bar")}, 24 | }, 25 | { 26 | in: [][]byte{[]byte("foo"), []byte("bar")}, 27 | consume: 2, 28 | want: [][]byte{[]byte("o"), []byte("bar")}, 29 | }, 30 | { 31 | in: [][]byte{[]byte("foo"), []byte("bar")}, 32 | consume: 3, 33 | want: [][]byte{[]byte("bar")}, 34 | }, 35 | { 36 | in: [][]byte{[]byte("foo"), []byte("bar")}, 37 | consume: 4, 38 | want: [][]byte{[]byte("ar")}, 39 | }, 40 | { 41 | in: [][]byte{nil, nil, nil, []byte("bar")}, 42 | consume: 1, 43 | want: [][]byte{[]byte("ar")}, 44 | }, 45 | { 46 | in: [][]byte{nil, nil, nil, []byte("foo")}, 47 | consume: 0, 48 | want: [][]byte{[]byte("foo")}, 49 | }, 50 | { 51 | in: [][]byte{nil, nil, nil}, 52 | consume: 0, 53 | want: [][]byte{}, 54 | }, 55 | } 56 | for i, tt := range tests { 57 | in := tt.in 58 | poll.Consume(&in, tt.consume) 59 | if !reflect.DeepEqual(in, tt.want) { 60 | t.Errorf("%d. after consume(%d) = %+v, want %+v", i, tt.consume, in, tt.want) 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /lib/internal/profile/proto_test.go: -------------------------------------------------------------------------------- 1 | package profile 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | ) 7 | 8 | func TestPackedEncoding(t *testing.T) { 9 | 10 | type testcase struct { 11 | uint64s []uint64 12 | int64s []int64 13 | encoded []byte 14 | } 15 | for i, tc := range []testcase{ 16 | { 17 | []uint64{0, 1, 10, 100, 1000, 10000}, 18 | []int64{1000, 0, 1000}, 19 | []byte{10, 8, 0, 1, 10, 100, 232, 7, 144, 78, 18, 5, 232, 7, 0, 232, 7}, 20 | }, 21 | { 22 | []uint64{10000}, 23 | nil, 24 | []byte{8, 144, 78}, 25 | }, 26 | { 27 | nil, 28 | []int64{-10000}, 29 | []byte{16, 240, 177, 255, 255, 255, 255, 255, 255, 255, 1}, 30 | }, 31 | } { 32 | source := &packedInts{tc.uint64s, tc.int64s} 33 | if got, want := marshal(source), tc.encoded; !reflect.DeepEqual(got, want) { 34 | t.Errorf("failed encode %d, got %v, want %v", i, got, want) 35 | } 36 | 37 | dest := new(packedInts) 38 | if err := unmarshal(tc.encoded, dest); err != nil { 39 | t.Errorf("failed decode %d: %v", i, err) 40 | continue 41 | } 42 | if got, want := dest.uint64s, tc.uint64s; !reflect.DeepEqual(got, want) { 43 | t.Errorf("failed decode uint64s %d, got %v, want %v", i, got, want) 44 | } 45 | if got, want := dest.int64s, tc.int64s; !reflect.DeepEqual(got, want) { 46 | t.Errorf("failed decode int64s %d, got %v, want %v", i, got, want) 47 | } 48 | } 49 | } 50 | 51 | type packedInts struct { 52 | uint64s []uint64 53 | int64s []int64 54 | } 55 | 56 | func (u *packedInts) decoder() []decoder { 57 | return []decoder{ 58 | nil, 59 | func(b *buffer, m message) error { return decodeUint64s(b, &m.(*packedInts).uint64s) }, 60 | func(b *buffer, m message) error { return decodeInt64s(b, &m.(*packedInts).int64s) }, 61 | } 62 | } 63 | 64 | func (u *packedInts) encode(b *buffer) { 65 | encodeUint64s(b, 1, u.uint64s) 66 | encodeInt64s(b, 2, u.int64s) 67 | } 68 | -------------------------------------------------------------------------------- /lib/internal/race/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package race contains helper functions for manually instrumenting code for the race detector. 7 | 8 | The runtime package intentionally exports these functions only in the race build; 9 | this package exports them unconditionally but without the "race" build tag they are no-ops. 10 | */ 11 | package race 12 | -------------------------------------------------------------------------------- /lib/internal/race/norace.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !race 6 | // +build !race 7 | 8 | package race 9 | 10 | import ( 11 | "unsafe" 12 | ) 13 | 14 | const Enabled = false 15 | 16 | func Acquire(addr unsafe.Pointer) { 17 | } 18 | 19 | func Release(addr unsafe.Pointer) { 20 | } 21 | 22 | func ReleaseMerge(addr unsafe.Pointer) { 23 | } 24 | 25 | func Disable() { 26 | } 27 | 28 | func Enable() { 29 | } 30 | 31 | func Read(addr unsafe.Pointer) { 32 | } 33 | 34 | func Write(addr unsafe.Pointer) { 35 | } 36 | 37 | func ReadRange(addr unsafe.Pointer, len int) { 38 | } 39 | 40 | func WriteRange(addr unsafe.Pointer, len int) { 41 | } 42 | 43 | func Errors() int { return 0 } 44 | -------------------------------------------------------------------------------- /lib/internal/race/race.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build race 6 | // +build race 7 | 8 | package race 9 | 10 | import ( 11 | "runtime" 12 | "unsafe" 13 | ) 14 | 15 | const Enabled = true 16 | 17 | func Acquire(addr unsafe.Pointer) { 18 | runtime.RaceAcquire(addr) 19 | } 20 | 21 | func Release(addr unsafe.Pointer) { 22 | runtime.RaceRelease(addr) 23 | } 24 | 25 | func ReleaseMerge(addr unsafe.Pointer) { 26 | runtime.RaceReleaseMerge(addr) 27 | } 28 | 29 | func Disable() { 30 | runtime.RaceDisable() 31 | } 32 | 33 | func Enable() { 34 | runtime.RaceEnable() 35 | } 36 | 37 | func Read(addr unsafe.Pointer) { 38 | runtime.RaceRead(addr) 39 | } 40 | 41 | func Write(addr unsafe.Pointer) { 42 | runtime.RaceWrite(addr) 43 | } 44 | 45 | func ReadRange(addr unsafe.Pointer, len int) { 46 | runtime.RaceReadRange(addr, len) 47 | } 48 | 49 | func WriteRange(addr unsafe.Pointer, len int) { 50 | runtime.RaceWriteRange(addr, len) 51 | } 52 | 53 | func Errors() int { 54 | return runtime.RaceErrors() 55 | } 56 | -------------------------------------------------------------------------------- /lib/internal/reflectlite/asm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Trigger build without complete flag. -------------------------------------------------------------------------------- /lib/internal/syscall/execenv/execenv_default.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !windows 6 | // +build !windows 7 | 8 | package execenv 9 | 10 | import "syscall" 11 | 12 | // Default will return the default environment 13 | // variables based on the process attributes 14 | // provided. 15 | // 16 | // Defaults to syscall.Environ() on all platforms 17 | // other than Windows. 18 | func Default(sys *syscall.SysProcAttr) ([]string, error) { 19 | return syscall.Environ(), nil 20 | } 21 | -------------------------------------------------------------------------------- /lib/internal/syscall/execenv/execenv_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build windows 6 | // +build windows 7 | 8 | package execenv 9 | 10 | import ( 11 | "internal/syscall/windows" 12 | "syscall" 13 | "unicode/utf16" 14 | "unsafe" 15 | ) 16 | 17 | // Default will return the default environment 18 | // variables based on the process attributes 19 | // provided. 20 | // 21 | // If the process attributes contain a token, then 22 | // the environment variables will be sourced from 23 | // the defaults for that user token, otherwise they 24 | // will be sourced from syscall.Environ(). 25 | func Default(sys *syscall.SysProcAttr) (env []string, err error) { 26 | if sys == nil || sys.Token == 0 { 27 | return syscall.Environ(), nil 28 | } 29 | var block *uint16 30 | err = windows.CreateEnvironmentBlock(&block, sys.Token, false) 31 | if err != nil { 32 | return nil, err 33 | } 34 | defer windows.DestroyEnvironmentBlock(block) 35 | blockp := uintptr(unsafe.Pointer(block)) 36 | for { 37 | 38 | // find NUL terminator 39 | end := unsafe.Pointer(blockp) 40 | for *(*uint16)(end) != 0 { 41 | end = unsafe.Pointer(uintptr(end) + 2) 42 | } 43 | 44 | n := (uintptr(end) - uintptr(unsafe.Pointer(blockp))) / 2 45 | if n == 0 { 46 | // environment block ends with empty string 47 | break 48 | } 49 | 50 | entry := (*[(1 << 30) - 1]uint16)(unsafe.Pointer(blockp))[:n:n] 51 | env = append(env, string(utf16.Decode(entry))) 52 | blockp += 2 * (uintptr(len(entry)) + 1) 53 | } 54 | return 55 | } 56 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/asm_aix_ppc64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | 7 | // 8 | // System calls for aix/ppc64 are implemented in syscall/syscall_aix.go 9 | // 10 | 11 | TEXT ·syscall6(SB),NOSPLIT,$0 12 | JMP syscall·syscall6(SB) 13 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/asm_darwin.s: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | 7 | TEXT ·libc_getentropy_trampoline(SB),NOSPLIT,$0-0 8 | JMP libc_getentropy(SB) 9 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/asm_solaris.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | 7 | // System calls for Solaris are implemented in runtime/syscall_solaris.go 8 | 9 | TEXT ·syscall6(SB),NOSPLIT,$0-88 10 | JMP syscall·sysvicall6(SB) 11 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build linux || openbsd || netbsd || dragonfly 6 | // +build linux openbsd netbsd dragonfly 7 | 8 | package unix 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | func Unlinkat(dirfd int, path string, flags int) error { 16 | var p *byte 17 | p, err := syscall.BytePtrFromString(path) 18 | if err != nil { 19 | return err 20 | } 21 | 22 | _, _, errno := syscall.Syscall(unlinkatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags)) 23 | if errno != 0 { 24 | return errno 25 | } 26 | 27 | return nil 28 | } 29 | 30 | func Openat(dirfd int, path string, flags int, perm uint32) (int, error) { 31 | var p *byte 32 | p, err := syscall.BytePtrFromString(path) 33 | if err != nil { 34 | return 0, err 35 | } 36 | 37 | fd, _, errno := syscall.Syscall6(openatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0) 38 | if errno != 0 { 39 | return 0, errno 40 | } 41 | 42 | return int(fd), nil 43 | } 44 | 45 | func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error { 46 | var p *byte 47 | p, err := syscall.BytePtrFromString(path) 48 | if err != nil { 49 | return err 50 | } 51 | 52 | _, _, errno := syscall.Syscall6(fstatatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) 53 | if errno != 0 { 54 | return errno 55 | } 56 | 57 | return nil 58 | 59 | } 60 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_aix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | //go:cgo_import_dynamic libc_fstatat fstatat "libc.a/shr_64.o" 8 | //go:cgo_import_dynamic libc_openat openat "libc.a/shr_64.o" 9 | //go:cgo_import_dynamic libc_unlinkat unlinkat "libc.a/shr_64.o" 10 | 11 | const ( 12 | AT_REMOVEDIR = 0x1 13 | AT_SYMLINK_NOFOLLOW = 0x1 14 | ) 15 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | _ "unsafe" // for linkname 10 | ) 11 | 12 | func Unlinkat(dirfd int, path string, flags int) error { 13 | return unlinkat(dirfd, path, flags) 14 | } 15 | 16 | func Openat(dirfd int, path string, flags int, perm uint32) (int, error) { 17 | return openat(dirfd, path, flags, perm) 18 | } 19 | 20 | func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error { 21 | return fstatat(dirfd, path, stat, flags) 22 | } 23 | 24 | //go:linkname unlinkat syscall.unlinkat 25 | func unlinkat(dirfd int, path string, flags int) error 26 | 27 | //go:linkname openat syscall.openat 28 | func openat(dirfd int, path string, flags int, perm uint32) (int, error) 29 | 30 | //go:linkname fstatat syscall.fstatat 31 | func fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error 32 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_freebsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | const ( 13 | AT_REMOVEDIR = 0x800 14 | AT_SYMLINK_NOFOLLOW = 0x200 15 | ) 16 | 17 | func Unlinkat(dirfd int, path string, flags int) error { 18 | p, err := syscall.BytePtrFromString(path) 19 | if err != nil { 20 | return err 21 | } 22 | 23 | _, _, errno := syscall.Syscall(syscall.SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags)) 24 | if errno != 0 { 25 | return errno 26 | } 27 | 28 | return nil 29 | } 30 | 31 | func Openat(dirfd int, path string, flags int, perm uint32) (int, error) { 32 | p, err := syscall.BytePtrFromString(path) 33 | if err != nil { 34 | return 0, err 35 | } 36 | 37 | fd, _, errno := syscall.Syscall6(syscall.SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0) 38 | if errno != 0 { 39 | return 0, errno 40 | } 41 | 42 | return int(fd), nil 43 | } 44 | 45 | func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error { 46 | return syscall.Fstatat(dirfd, path, stat, flags) 47 | } 48 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_libc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || solaris 6 | // +build aix solaris 7 | 8 | package unix 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | //go:linkname procFstatat libc_fstatat 16 | //go:linkname procOpenat libc_openat 17 | //go:linkname procUnlinkat libc_unlinkat 18 | 19 | var ( 20 | procFstatat, 21 | procOpenat, 22 | procUnlinkat uintptr 23 | ) 24 | 25 | func Unlinkat(dirfd int, path string, flags int) error { 26 | p, err := syscall.BytePtrFromString(path) 27 | if err != nil { 28 | return err 29 | } 30 | 31 | _, _, errno := syscall6(uintptr(unsafe.Pointer(&procUnlinkat)), 3, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), 0, 0, 0) 32 | if errno != 0 { 33 | return errno 34 | } 35 | 36 | return nil 37 | } 38 | 39 | func Openat(dirfd int, path string, flags int, perm uint32) (int, error) { 40 | p, err := syscall.BytePtrFromString(path) 41 | if err != nil { 42 | return 0, err 43 | } 44 | 45 | fd, _, errno := syscall6(uintptr(unsafe.Pointer(&procOpenat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0) 46 | if errno != 0 { 47 | return 0, errno 48 | } 49 | 50 | return int(fd), nil 51 | } 52 | 53 | func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error { 54 | p, err := syscall.BytePtrFromString(path) 55 | if err != nil { 56 | return err 57 | } 58 | 59 | _, _, errno := syscall6(uintptr(unsafe.Pointer(&procFstatat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) 60 | if errno != 0 { 61 | return errno 62 | } 63 | 64 | return nil 65 | } 66 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_solaris.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import "syscall" 8 | 9 | // Implemented as sysvicall6 in runtime/syscall_solaris.go. 10 | func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) 11 | 12 | //go:cgo_import_dynamic libc_fstatat fstatat "libc.so" 13 | //go:cgo_import_dynamic libc_openat openat "libc.so" 14 | //go:cgo_import_dynamic libc_unlinkat unlinkat "libc.so" 15 | 16 | const ( 17 | AT_REMOVEDIR = 0x1 18 | AT_SYMLINK_NOFOLLOW = 0x1000 19 | ) 20 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_sysnum_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | const AT_REMOVEDIR = 0x80 8 | const AT_SYMLINK_NOFOLLOW = 0x0020 9 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_sysnum_dragonfly.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import "syscall" 8 | 9 | const unlinkatTrap uintptr = syscall.SYS_UNLINKAT 10 | const openatTrap uintptr = syscall.SYS_OPENAT 11 | const fstatatTrap uintptr = syscall.SYS_FSTATAT 12 | 13 | const AT_REMOVEDIR = 0x2 14 | const AT_SYMLINK_NOFOLLOW = 0x1 15 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_sysnum_fstatat64_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build arm || mips || mipsle || 386 6 | // +build arm mips mipsle 386 7 | 8 | package unix 9 | 10 | import "syscall" 11 | 12 | const fstatatTrap uintptr = syscall.SYS_FSTATAT64 13 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_sysnum_fstatat_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build arm64 || riscv64 6 | // +build arm64 riscv64 7 | 8 | package unix 9 | 10 | import "syscall" 11 | 12 | const fstatatTrap uintptr = syscall.SYS_FSTATAT 13 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_sysnum_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import "syscall" 8 | 9 | const unlinkatTrap uintptr = syscall.SYS_UNLINKAT 10 | const openatTrap uintptr = syscall.SYS_OPENAT 11 | 12 | const AT_REMOVEDIR = 0x200 13 | const AT_SYMLINK_NOFOLLOW = 0x100 14 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_sysnum_netbsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import "syscall" 8 | 9 | const unlinkatTrap uintptr = syscall.SYS_UNLINKAT 10 | const openatTrap uintptr = syscall.SYS_OPENAT 11 | const fstatatTrap uintptr = syscall.SYS_FSTATAT 12 | 13 | const AT_REMOVEDIR = 0x800 14 | const AT_SYMLINK_NOFOLLOW = 0x200 15 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_sysnum_newfstatat_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build amd64 || mips64 || mips64le || ppc64 || ppc64le || s390x 6 | // +build amd64 mips64 mips64le ppc64 ppc64le s390x 7 | 8 | package unix 9 | 10 | import "syscall" 11 | 12 | const fstatatTrap uintptr = syscall.SYS_NEWFSTATAT 13 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/at_sysnum_openbsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import "syscall" 8 | 9 | const unlinkatTrap uintptr = syscall.SYS_UNLINKAT 10 | const openatTrap uintptr = syscall.SYS_OPENAT 11 | const fstatatTrap uintptr = syscall.SYS_FSTATAT 12 | 13 | const AT_REMOVEDIR = 0x08 14 | const AT_SYMLINK_NOFOLLOW = 0x02 15 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/copy_file_range_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func CopyFileRange(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error) { 13 | r1, _, errno := syscall.Syscall6(copyFileRangeTrap, 14 | uintptr(rfd), 15 | uintptr(unsafe.Pointer(roff)), 16 | uintptr(wfd), 17 | uintptr(unsafe.Pointer(woff)), 18 | uintptr(len), 19 | uintptr(flags), 20 | ) 21 | n = int(r1) 22 | if errno != 0 { 23 | err = errno 24 | } 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/fcntl_linux_32bit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // On 32-bit Linux systems, use SYS_FCNTL64. 6 | // If you change the build tags here, see syscall/flock_linux_32bit.go. 7 | 8 | //go:build (linux && 386) || (linux && arm) || (linux && mips) || (linux && mipsle) 9 | // +build linux,386 linux,arm linux,mips linux,mipsle 10 | 11 | package unix 12 | 13 | import "syscall" 14 | 15 | func init() { 16 | FcntlSyscall = syscall.SYS_FCNTL64 17 | } 18 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/getentropy_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin && !ios 6 | // +build darwin,!ios 7 | 8 | package unix 9 | 10 | import ( 11 | "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/abi" 12 | "syscall" 13 | "unsafe" 14 | ) 15 | 16 | //go:cgo_import_dynamic libc_getentropy getentropy "/usr/lib/libSystem.B.dylib" 17 | 18 | func libc_getentropy_trampoline() 19 | 20 | // GetEntropy calls the macOS getentropy system call. 21 | func GetEntropy(p []byte) error { 22 | _, _, errno := syscall_syscall(abi.FuncPCABI0(libc_getentropy_trampoline), 23 | uintptr(unsafe.Pointer(&p[0])), 24 | uintptr(len(p)), 25 | 0) 26 | if errno != 0 { 27 | return errno 28 | } 29 | return nil 30 | } 31 | 32 | //go:linkname syscall_syscall syscall.syscall 33 | func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) 34 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/getentropy_openbsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | // getentropy(2)'s syscall number, from /usr/src/sys/kern/syscalls.master 13 | const entropyTrap uintptr = 7 14 | 15 | // GetEntropy calls the OpenBSD getentropy system call. 16 | func GetEntropy(p []byte) error { 17 | _, _, errno := syscall.Syscall(entropyTrap, 18 | uintptr(unsafe.Pointer(&p[0])), 19 | uintptr(len(p)), 20 | 0) 21 | if errno != 0 { 22 | return errno 23 | } 24 | return nil 25 | } 26 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/getrandom.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build dragonfly || freebsd || linux 6 | // +build dragonfly freebsd linux 7 | 8 | package unix 9 | 10 | import ( 11 | "sync/atomic" 12 | "syscall" 13 | "unsafe" 14 | ) 15 | 16 | var getrandomUnsupported int32 // atomic 17 | 18 | // GetRandomFlag is a flag supported by the getrandom system call. 19 | type GetRandomFlag uintptr 20 | 21 | // GetRandom calls the getrandom system call. 22 | func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) { 23 | if len(p) == 0 { 24 | return 0, nil 25 | } 26 | if atomic.LoadInt32(&getrandomUnsupported) != 0 { 27 | return 0, syscall.ENOSYS 28 | } 29 | r1, _, errno := syscall.Syscall(getrandomTrap, 30 | uintptr(unsafe.Pointer(&p[0])), 31 | uintptr(len(p)), 32 | uintptr(flags)) 33 | if errno != 0 { 34 | if errno == syscall.ENOSYS { 35 | atomic.StoreInt32(&getrandomUnsupported, 1) 36 | } 37 | return 0, errno 38 | } 39 | return int(r1), nil 40 | } 41 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/getrandom_dragonfly.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | // DragonFlyBSD getrandom system call number. 8 | const getrandomTrap uintptr = 550 9 | 10 | const ( 11 | // GRND_RANDOM is only set for portability purpose, no-op on DragonFlyBSD. 12 | GRND_RANDOM GetRandomFlag = 0x0001 13 | 14 | // GRND_NONBLOCK means return EAGAIN rather than blocking. 15 | GRND_NONBLOCK GetRandomFlag = 0x0002 16 | ) 17 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/getrandom_freebsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | // FreeBSD getrandom system call number. 8 | const getrandomTrap uintptr = 563 9 | 10 | const ( 11 | // GRND_NONBLOCK means return EAGAIN rather than blocking. 12 | GRND_NONBLOCK GetRandomFlag = 0x0001 13 | 14 | // GRND_RANDOM is only set for portability purpose, no-op on FreeBSD. 15 | GRND_RANDOM GetRandomFlag = 0x0002 16 | ) 17 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/getrandom_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | const ( 8 | // GRND_NONBLOCK means return EAGAIN rather than blocking. 9 | GRND_NONBLOCK GetRandomFlag = 0x0001 10 | 11 | // GRND_RANDOM means use the /dev/random pool instead of /dev/urandom. 12 | GRND_RANDOM GetRandomFlag = 0x0002 13 | ) 14 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/getrandom_solaris.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "sync/atomic" 9 | "syscall" 10 | "unsafe" 11 | ) 12 | 13 | //go:cgo_import_dynamic libc_getrandom getrandom "libc.so" 14 | 15 | //go:linkname procGetrandom libc_getrandom 16 | 17 | var procGetrandom uintptr 18 | 19 | var getrandomUnsupported int32 // atomic 20 | 21 | // GetRandomFlag is a flag supported by the getrandom system call. 22 | type GetRandomFlag uintptr 23 | 24 | const ( 25 | // GRND_NONBLOCK means return EAGAIN rather than blocking. 26 | GRND_NONBLOCK GetRandomFlag = 0x0001 27 | 28 | // GRND_RANDOM means use the /dev/random pool instead of /dev/urandom. 29 | GRND_RANDOM GetRandomFlag = 0x0002 30 | ) 31 | 32 | // GetRandom calls the getrandom system call. 33 | func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) { 34 | if len(p) == 0 { 35 | return 0, nil 36 | } 37 | if atomic.LoadInt32(&getrandomUnsupported) != 0 { 38 | return 0, syscall.ENOSYS 39 | } 40 | r1, _, errno := syscall6(uintptr(unsafe.Pointer(&procGetrandom)), 41 | 3, 42 | uintptr(unsafe.Pointer(&p[0])), 43 | uintptr(len(p)), 44 | uintptr(flags), 45 | 0, 0, 0) 46 | if errno != 0 { 47 | if errno == syscall.ENOSYS { 48 | atomic.StoreInt32(&getrandomUnsupported, 1) 49 | } 50 | return 0, errno 51 | } 52 | return int(r1), nil 53 | } 54 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/ioctl_aix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | //go:cgo_import_dynamic libc_ioctl ioctl "libc.a/shr_64.o" 13 | //go:linkname libc_ioctl libc_ioctl 14 | var libc_ioctl uintptr 15 | 16 | // Implemented in syscall/syscall_aix.go. 17 | func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) 18 | 19 | func Ioctl(fd int, cmd int, args uintptr) (err error) { 20 | _, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_ioctl)), 3, uintptr(fd), uintptr(cmd), uintptr(args), 0, 0, 0) 21 | if e1 != 0 { 22 | err = e1 23 | } 24 | return 25 | } 26 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/nonblocking.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build dragonfly || freebsd || linux || netbsd || openbsd 6 | // +build dragonfly freebsd linux netbsd openbsd 7 | 8 | package unix 9 | 10 | import "syscall" 11 | 12 | // FcntlSyscall is the number for the fcntl system call. This is 13 | // usually SYS_FCNTL, but can be overridden to SYS_FCNTL64. 14 | var FcntlSyscall uintptr = syscall.SYS_FCNTL 15 | 16 | func IsNonblock(fd int) (nonblocking bool, err error) { 17 | flag, _, e1 := syscall.Syscall(FcntlSyscall, uintptr(fd), uintptr(syscall.F_GETFL), 0) 18 | if e1 != 0 { 19 | return false, e1 20 | } 21 | return flag&syscall.O_NONBLOCK != 0, nil 22 | } 23 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/nonblocking_js.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build js && wasm 6 | // +build js,wasm 7 | 8 | package unix 9 | 10 | func IsNonblock(fd int) (nonblocking bool, err error) { 11 | return false, nil 12 | } 13 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/nonblocking_libc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aix || darwin || solaris 6 | // +build aix darwin solaris 7 | 8 | package unix 9 | 10 | import ( 11 | "syscall" 12 | _ "unsafe" // for go:linkname 13 | ) 14 | 15 | func IsNonblock(fd int) (nonblocking bool, err error) { 16 | flag, e1 := fcntl(fd, syscall.F_GETFL, 0) 17 | if e1 != nil { 18 | return false, e1 19 | } 20 | return flag&syscall.O_NONBLOCK != 0, nil 21 | } 22 | 23 | // Implemented in the syscall package. 24 | //go:linkname fcntl syscall.fcntl 25 | func fcntl(fd int, cmd int, arg int) (int, error) 26 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/pipe2_illumos.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build illumos 6 | // +build illumos 7 | 8 | package unix 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | //go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so" 16 | 17 | //go:linkname procpipe2 libc_pipe2 18 | 19 | var procpipe2 uintptr 20 | 21 | type _C_int int32 22 | 23 | func Pipe2(p []int, flags int) error { 24 | if len(p) != 2 { 25 | return syscall.EINVAL 26 | } 27 | var pp [2]_C_int 28 | _, _, errno := syscall6(uintptr(unsafe.Pointer(&procpipe2)), 2, uintptr(unsafe.Pointer(&pp)), uintptr(flags), 0, 0, 0, 0) 29 | if errno != 0 { 30 | return errno 31 | } 32 | p[0] = int(pp[0]) 33 | p[1] = int(pp[1]) 34 | return nil 35 | } 36 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/sysnum_linux_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | const ( 8 | getrandomTrap uintptr = 355 9 | copyFileRangeTrap uintptr = 377 10 | ) 11 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/sysnum_linux_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | const ( 8 | getrandomTrap uintptr = 318 9 | copyFileRangeTrap uintptr = 326 10 | ) 11 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/sysnum_linux_arm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | const ( 8 | getrandomTrap uintptr = 384 9 | copyFileRangeTrap uintptr = 391 10 | ) 11 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/sysnum_linux_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build linux && (arm64 || riscv64) 6 | // +build linux 7 | // +build arm64 riscv64 8 | 9 | package unix 10 | 11 | // This file is named "generic" because at a certain point Linux started 12 | // standardizing on system call numbers across architectures. So far this 13 | // means only arm64 and riscv64 use the standard numbers. 14 | 15 | const ( 16 | getrandomTrap uintptr = 278 17 | copyFileRangeTrap uintptr = 285 18 | ) 19 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/sysnum_linux_mips64x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build mips64 || mips64le 6 | // +build mips64 mips64le 7 | 8 | package unix 9 | 10 | const ( 11 | getrandomTrap uintptr = 5313 12 | copyFileRangeTrap uintptr = 5320 13 | ) 14 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/sysnum_linux_mipsx.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build mips || mipsle 6 | // +build mips mipsle 7 | 8 | package unix 9 | 10 | const ( 11 | getrandomTrap uintptr = 4353 12 | copyFileRangeTrap uintptr = 4360 13 | ) 14 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/sysnum_linux_ppc64x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build ppc64 || ppc64le 6 | // +build ppc64 ppc64le 7 | 8 | package unix 9 | 10 | const ( 11 | getrandomTrap uintptr = 359 12 | copyFileRangeTrap uintptr = 379 13 | ) 14 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/sysnum_linux_s390x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | const ( 8 | getrandomTrap uintptr = 349 9 | copyFileRangeTrap uintptr = 375 10 | ) 11 | -------------------------------------------------------------------------------- /lib/internal/syscall/unix/writev_illumos.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build illumos 6 | // +build illumos 7 | 8 | package unix 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | //go:cgo_import_dynamic libc_writev writev "libc.so" 16 | 17 | //go:linkname procwritev libc_writev 18 | 19 | var procwritev uintptr 20 | 21 | func Writev(fd int, iovs []syscall.Iovec) (uintptr, error) { 22 | var p *syscall.Iovec 23 | if len(iovs) > 0 { 24 | p = &iovs[0] 25 | } 26 | n, _, errno := syscall6(uintptr(unsafe.Pointer(&procwritev)), 3, uintptr(fd), uintptr(unsafe.Pointer(p)), uintptr(len(iovs)), 0, 0, 0) 27 | if errno != 0 { 28 | return 0, errno 29 | } 30 | return n, nil 31 | } 32 | -------------------------------------------------------------------------------- /lib/internal/syscall/windows/mksyscall.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build generate 6 | 7 | package windows 8 | 9 | //go:generate go run ../../../syscall/mksyscall_windows.go -output zsyscall_windows.go syscall_windows.go security_windows.go psapi_windows.go symlink_windows.go 10 | -------------------------------------------------------------------------------- /lib/internal/syscall/windows/psapi_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package windows 6 | 7 | type PROCESS_MEMORY_COUNTERS struct { 8 | CB uint32 9 | PageFaultCount uint32 10 | PeakWorkingSetSize uintptr 11 | WorkingSetSize uintptr 12 | QuotaPeakPagedPoolUsage uintptr 13 | QuotaPagedPoolUsage uintptr 14 | QuotaPeakNonPagedPoolUsage uintptr 15 | QuotaNonPagedPoolUsage uintptr 16 | PagefileUsage uintptr 17 | PeakPagefileUsage uintptr 18 | } 19 | 20 | //sys GetProcessMemoryInfo(handle syscall.Handle, memCounters *PROCESS_MEMORY_COUNTERS, cb uint32) (err error) = psapi.GetProcessMemoryInfo 21 | -------------------------------------------------------------------------------- /lib/internal/syscall/windows/registry/export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package registry 8 | 9 | func (k Key) SetValue(name string, valtype uint32, data []byte) error { 10 | return k.setValue(name, valtype, data) 11 | } 12 | -------------------------------------------------------------------------------- /lib/internal/syscall/windows/registry/mksyscall.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build generate 6 | 7 | package registry 8 | 9 | //go:generate go run ../../../../syscall/mksyscall_windows.go -output zsyscall_windows.go syscall.go 10 | -------------------------------------------------------------------------------- /lib/internal/syscall/windows/registry/syscall.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package registry 8 | 9 | import "syscall" 10 | 11 | const ( 12 | _REG_OPTION_NON_VOLATILE = 0 13 | 14 | _REG_CREATED_NEW_KEY = 1 15 | _REG_OPENED_EXISTING_KEY = 2 16 | 17 | _ERROR_NO_MORE_ITEMS syscall.Errno = 259 18 | ) 19 | 20 | func LoadRegLoadMUIString() error { 21 | return procRegLoadMUIStringW.Find() 22 | } 23 | 24 | //sys regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) = advapi32.RegCreateKeyExW 25 | //sys regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) = advapi32.RegDeleteKeyW 26 | //sys regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype uint32, buf *byte, bufsize uint32) (regerrno error) = advapi32.RegSetValueExW 27 | //sys regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) = advapi32.RegEnumValueW 28 | //sys regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) = advapi32.RegDeleteValueW 29 | //sys regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint32, buflenCopied *uint32, flags uint32, dir *uint16) (regerrno error) = advapi32.RegLoadMUIStringW 30 | 31 | //sys expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, err error) = kernel32.ExpandEnvironmentStringsW 32 | -------------------------------------------------------------------------------- /lib/internal/syscall/windows/symlink_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package windows 6 | 7 | import "syscall" 8 | 9 | const ( 10 | ERROR_INVALID_PARAMETER syscall.Errno = 87 11 | 12 | // symlink support for CreateSymbolicLink() starting with Windows 10 (1703, v10.0.14972) 13 | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE = 0x2 14 | 15 | // FileInformationClass values 16 | FileBasicInfo = 0 // FILE_BASIC_INFO 17 | FileStandardInfo = 1 // FILE_STANDARD_INFO 18 | FileNameInfo = 2 // FILE_NAME_INFO 19 | FileStreamInfo = 7 // FILE_STREAM_INFO 20 | FileCompressionInfo = 8 // FILE_COMPRESSION_INFO 21 | FileAttributeTagInfo = 9 // FILE_ATTRIBUTE_TAG_INFO 22 | FileIdBothDirectoryInfo = 0xa // FILE_ID_BOTH_DIR_INFO 23 | FileIdBothDirectoryRestartInfo = 0xb // FILE_ID_BOTH_DIR_INFO 24 | FileRemoteProtocolInfo = 0xd // FILE_REMOTE_PROTOCOL_INFO 25 | FileFullDirectoryInfo = 0xe // FILE_FULL_DIR_INFO 26 | FileFullDirectoryRestartInfo = 0xf // FILE_FULL_DIR_INFO 27 | FileStorageInfo = 0x10 // FILE_STORAGE_INFO 28 | FileAlignmentInfo = 0x11 // FILE_ALIGNMENT_INFO 29 | FileIdInfo = 0x12 // FILE_ID_INFO 30 | FileIdExtdDirectoryInfo = 0x13 // FILE_ID_EXTD_DIR_INFO 31 | FileIdExtdDirectoryRestartInfo = 0x14 // FILE_ID_EXTD_DIR_INFO 32 | ) 33 | 34 | type FILE_ATTRIBUTE_TAG_INFO struct { 35 | FileAttributes uint32 36 | ReparseTag uint32 37 | } 38 | 39 | //sys GetFileInformationByHandleEx(handle syscall.Handle, class uint32, info *byte, bufsize uint32) (err error) 40 | -------------------------------------------------------------------------------- /lib/internal/syscall/windows/sysdll/sysdll.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | // Package sysdll is an internal leaf package that records and reports 8 | // which Windows DLL names are used by Go itself. These DLLs are then 9 | // only loaded from the System32 directory. See Issue 14959. 10 | package sysdll 11 | 12 | // IsSystemDLL reports whether the named dll key (a base name, like 13 | // "foo.dll") is a system DLL which should only be loaded from the 14 | // Windows SYSTEM32 directory. 15 | // 16 | // Filenames are case sensitive, but that doesn't matter because 17 | // the case registered with Add is also the same case used with 18 | // LoadDLL later. 19 | // 20 | // It has no associated mutex and should only be mutated serially 21 | // (currently: during init), and not concurrent with DLL loading. 22 | var IsSystemDLL = map[string]bool{} 23 | 24 | // Add notes that dll is a system32 DLL which should only be loaded 25 | // from the Windows SYSTEM32 directory. It returns its argument back, 26 | // for ease of use in generated code. 27 | func Add(dll string) string { 28 | IsSystemDLL[dll] = true 29 | return dll 30 | } 31 | -------------------------------------------------------------------------------- /lib/internal/sysinfo/sysinfo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package sysinfo implements high level hardware information gathering 6 | // that can be used for debugging or information purposes. 7 | package sysinfo 8 | 9 | import ( 10 | "sync" 11 | 12 | internalcpu "github.com/ck00004/CobaltStrikeParser-Go/lib/internal/cpu" 13 | ) 14 | 15 | type cpuInfo struct { 16 | once sync.Once 17 | name string 18 | } 19 | 20 | var CPU cpuInfo 21 | 22 | func (cpu *cpuInfo) Name() string { 23 | cpu.once.Do(func() { 24 | // Try to get the information from github.com/ck00004/CobaltStrikeParser-Go/lib/internal/cpu. 25 | if name := internalcpu.Name(); name != "" { 26 | cpu.name = name 27 | return 28 | } 29 | // TODO(martisch): use /proc/cpuinfo and /sys/devices/system/cpu/ on Linux as fallback. 30 | }) 31 | return cpu.name 32 | } 33 | -------------------------------------------------------------------------------- /lib/internal/testenv/testenv_cgo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build cgo 6 | // +build cgo 7 | 8 | package testenv 9 | 10 | func init() { 11 | haveCGO = true 12 | } 13 | -------------------------------------------------------------------------------- /lib/internal/testenv/testenv_notwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !windows 6 | // +build !windows 7 | 8 | package testenv 9 | 10 | import ( 11 | "runtime" 12 | ) 13 | 14 | func hasSymlink() (ok bool, reason string) { 15 | switch runtime.GOOS { 16 | case "android", "plan9": 17 | return false, "" 18 | } 19 | 20 | return true, "" 21 | } 22 | -------------------------------------------------------------------------------- /lib/internal/testenv/testenv_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package testenv 6 | 7 | import ( 8 | "os" 9 | "path/filepath" 10 | "sync" 11 | "syscall" 12 | ) 13 | 14 | var symlinkOnce sync.Once 15 | var winSymlinkErr error 16 | 17 | func initWinHasSymlink() { 18 | tmpdir, err := os.MkdirTemp("", "symtest") 19 | if err != nil { 20 | panic("failed to create temp directory: " + err.Error()) 21 | } 22 | defer os.RemoveAll(tmpdir) 23 | 24 | err = os.Symlink("target", filepath.Join(tmpdir, "symlink")) 25 | if err != nil { 26 | err = err.(*os.LinkError).Err 27 | switch err { 28 | case syscall.EWINDOWS, syscall.ERROR_PRIVILEGE_NOT_HELD: 29 | winSymlinkErr = err 30 | } 31 | } 32 | } 33 | 34 | func hasSymlink() (ok bool, reason string) { 35 | symlinkOnce.Do(initWinHasSymlink) 36 | 37 | switch winSymlinkErr { 38 | case nil: 39 | return true, "" 40 | case syscall.EWINDOWS: 41 | return false, ": symlinks are not supported on your version of Windows" 42 | case syscall.ERROR_PRIVILEGE_NOT_HELD: 43 | return false, ": you don't have enough privileges to create symlinks" 44 | } 45 | 46 | return false, "" 47 | } 48 | -------------------------------------------------------------------------------- /lib/internal/testlog/exit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package testlog 6 | 7 | import "sync" 8 | 9 | // PanicOnExit0 reports whether to panic on a call to os.Exit(0). 10 | // This is in the testlog package because, like other definitions in 11 | // package testlog, it is a hook between the testing package and the 12 | // os package. This is used to ensure that an early call to os.Exit(0) 13 | // does not cause a test to pass. 14 | func PanicOnExit0() bool { 15 | panicOnExit0.mu.Lock() 16 | defer panicOnExit0.mu.Unlock() 17 | return panicOnExit0.val 18 | } 19 | 20 | // panicOnExit0 is the flag used for PanicOnExit0. This uses a lock 21 | // because the value can be cleared via a timer call that may race 22 | // with calls to os.Exit 23 | var panicOnExit0 struct { 24 | mu sync.Mutex 25 | val bool 26 | } 27 | 28 | // SetPanicOnExit0 sets panicOnExit0 to v. 29 | func SetPanicOnExit0(v bool) { 30 | panicOnExit0.mu.Lock() 31 | defer panicOnExit0.mu.Unlock() 32 | panicOnExit0.val = v 33 | } 34 | -------------------------------------------------------------------------------- /lib/internal/trace/mkcanned.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2016 The Go Authors. All rights reserved. 3 | # Use of this source code is governed by a BSD-style 4 | # license that can be found in the LICENSE file. 5 | 6 | # mkcanned.bash creates canned traces for the trace test suite using 7 | # the current Go version. 8 | 9 | set -e 10 | 11 | if [ $# != 1 ]; then 12 | echo "usage: $0