You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.4 KiB

package main
import (
"net"
"flag"
"os"
"os/signal"
"syscall"
"fmt"
"image/color"
log "github.com/sirupsen/logrus"
)
var targetAddr string
var imgPath string
var goProc int
var socketCount int
var startx int
var starty int
var partTotal int
var partCount int
var partBegin int
func main() {
flag.StringVar(&targetAddr, "addr", "151.217.177.136:1234", "address of target tcp")
flag.StringVar(&imgPath, "img", "", "path to image")
flag.IntVar(&goProc, "proc", 1, "count of procs (go routines)")
flag.IntVar(&socketCount, "sockets", 1, "count of sockets to target")
flag.IntVar(&startx, "start-x", 0, "move at x")
flag.IntVar(&starty, "start-y", 0, "move at y")
flag.IntVar(&partTotal, "part-total", 1, "total count of parts")
flag.IntVar(&partCount, "part-count", 1, "showed parts")
flag.IntVar(&partBegin, "part-begin", 0, "beginning at part x")
flag.Parse()
log.Infof("starting for %s with %d proc(s) | move by (%d,%d) | %d parts of %d begin at %d", targetAddr, goProc, startx, starty, partCount, partTotal, partBegin)
var pixelmatrix [][][4]uint32
// get matrix
if imgPath != "" {
pixelmatrix = getImage(imgPath)
}else{
pixelmatrix = getColor(color.RGBA{0xcc, 0xff, 0x33, 0xff}, 1024, 1024)
}
// transform
pixelmatrix, sx, sy := getPart(pixelmatrix, partCount, partTotal, partBegin)
startx += sx
starty += sy
for s := 0; s < socketCount; s++ {
pm, sx, sy := getPart(pixelmatrix, 1, socketCount, s)
sx += startx
sy += starty
conn := createSocket(pm, sx, sy)
defer conn.Close()
}
// Wait for INT/TERM
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
log.Println("received", sig)
}
func createSocket(pixelmatrix [][][4]uint32, xstart, ystart int) net.Conn {
// connection(s)
conn, err := net.Dial("tcp", targetAddr)
if err != nil {
log.Fatalf("not able to create connection: %s", err)
}
// start painting
for s := 0; s < goProc; s++ {
go paint(conn, pixelmatrix, xstart, ystart)
}
return conn
}
func paint(conn net.Conn, pixelmatrix [][][4]uint32, xstart, ystart int) {
var prerender [][]byte
for x, row := range pixelmatrix {
for y, pixel := range row {
if pixel[3] != 0 {
msg := fmt.Sprintf("PX %d %d %02x%02x%02x\n", xstart+x, ystart+y, pixel[0], pixel[1], pixel[2])
prerender = append(prerender, []byte(msg))
}
}
}
for {
for _, data := range prerender {
conn.Write(data)
}
}
}