Created
May 26, 2020 20:42
-
-
Save Daviey/b5d3d7b1abe0ed647b14297c212c8235 to your computer and use it in GitHub Desktop.
evil cat
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 ( | |
"io" | |
"log" | |
"os" | |
"strings" | |
) | |
func readWrite(src io.Reader, dst io.Writer) { | |
} | |
func errorhandler(err error, fname string) { | |
if _, ok := err.(*os.PathError); ok { | |
log.Fatal("cat: " + fname + ": No such file or directory") | |
} else { | |
// also includes our lies. | |
log.Fatal("cat: " + fname + ": Permission denied") | |
} | |
} | |
func main() { | |
log.SetFlags(0) | |
if len(os.Args) == 1 { | |
_, err := io.Copy(os.Stdout, os.Stdin) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} else { | |
for _, fname := range os.Args[1:] { | |
if !(strings.Contains(fname, "flag") || strings.Contains(fname, "king.txt") || strings.Contains(fname, "user")) { | |
fh, err := os.Open(fname) | |
if err != nil { | |
errorhandler(err, fname) | |
} | |
_, err = io.Copy(os.Stdout, fh) | |
if err != nil { | |
errorhandler(err, fname) | |
} | |
} else { | |
errorhandler(nil, fname) // we are lieing | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment