This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"debug/elf" | |
"fmt" | |
"log" | |
"os" | |
) | |
func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This defeats the purpose of io.Writer | |
func WriteAsciiArtToFile(path string) error { | |
f, err := os.Open(path) | |
if err != nil { | |
return err | |
} | |
artBytes := makeSomeArt() | |
_, err = f.Write(artBytes) | |
return err | |
} |



This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//go:cgo_import_dynamic libc_res_search res_search "/usr/lib/libSystem.B.dylib" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//go:nosplit | |
//go:cgo_unsafe_args | |
func res_search(dname *byte, class int32, rtype int32, answer *byte, anslen int32) (int32, int32) { | |
args := struct { | |
dname *byte | |
class, rtype int32 | |
answer *byte | |
anslen, retSize, retErr int32 | |
}{dname, class, rtype, answer, anslen, 0, 0} | |
libcCall(unsafe.Pointer(funcPC(res_search_trampoline)), unsafe.Pointer(&args)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEXT runtime·res_search_trampoline(SB),NOSPLIT,$0 | |
PUSHQ BP | |
MOVQ SP, BP | |
MOVQ DI, BX // move DI into BX to preserve struct addr | |
MOVL 24(BX), R8 // arg 5 anslen | |
MOVQ 16(BX), CX // arg 4 answer | |
MOVL 12(BX), DX // arg 3 type | |
MOVL 8(BX), SI // arg 2 class | |
MOVQ 0(BX), DI // arg 1 name | |
CALL libc_res_search(SB) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package switchers | |
func SwitchFunction(a, b int, c *int) string { | |
switch *c { | |
case a: | |
return "a" | |
case b: | |
return "b" | |
default: | |
return "c" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package switchers | |
import "testing" | |
func TestSwitch(t *testing.T) { | |
var ( | |
a int | |
b int | |
c = &b |