Created
December 16, 2023 03:45
-
-
Save x1unix/000fadc38ab6b0ff907a4789eb3b01b1 to your computer and use it in GitHub Desktop.
strdump
This file contains 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 ( | |
"bufio" | |
"fmt" | |
"io" | |
"os" | |
_ "unsafe" | |
) | |
//go:linkname appendEscapedRune strconv.appendEscapedRune | |
func appendEscapedRune(buf []byte, r rune, quote byte, ASCIIonly, graphicOnly bool) []byte | |
func main() { | |
buff := make([]byte, 0, 8) | |
defer fmt.Print("\n") | |
r := bufio.NewReader(os.Stdin) | |
for { | |
c, err := r.ReadByte() | |
if err != nil { | |
if err == io.EOF { | |
return | |
} | |
fmt.Fprintln(os.Stderr, "reading standard input:", err) | |
os.Exit(1) | |
} | |
// Reset buffer and quote rune | |
buff = buff[:0] | |
buff = appendEscapedRune(buff, rune(c), 0, false, false) | |
_, _ = os.Stdout.Write(buff) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment