Skip to content

Instantly share code, notes, and snippets.

View grantseltzer's full-sized avatar

grantseltzer grantseltzer

View GitHub Profile
@grantseltzer
grantseltzer / main.go
Last active September 21, 2018 14:57
Empty symbols in Go binaries
package main
import (
"debug/elf"
"fmt"
"log"
"os"
)
func main() {
// 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
}
@grantseltzer
grantseltzer / left.png
Last active April 9, 2019 15:22
grrrrrrrrrrrrrrrrrrrrrrrrr
left.png
@grantseltzer
grantseltzer / right.png
Created April 9, 2019 15:23
rrrrrrrrrrrrrrrrrrrr
right.png
//go:cgo_import_dynamic libc_res_search res_search "/usr/lib/libSystem.B.dylib"
//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))
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)
package switchers
func SwitchFunction(a, b int, c *int) string {
switch *c {
case a:
return "a"
case b:
return "b"
default:
return "c"
package switchers
import "testing"
func TestSwitch(t *testing.T) {
var (
a int
b int
c = &b