示例#1
0
func (mc *mysqlConn) DumpBinlog(filename string, position uint32) (driver.Rows, error) {
	ServerId := uint32(1) // Must be non-zero to avoid getting EOF packet
	flags := uint16(0)

	e := mc.writeCommandPacket(COM_BINLOG_DUMP, position, flags, ServerId, filename)
	if e != nil {
		return nil, e
	}

	for {
		pkt, e := mc.readPacket()
		if e != nil {
			return nil, e
		} else if pkt[0] == 254 { // EOF packet
			break
		}
		if pkt[0] == 0 {
			var header EventHeader
			if e := header.Read(pkt[1:]); e != nil {
				return nil, e
			}
			header.Print()
			fmt.Printf("Event Data:\n%s\n\n", hex.Dump(pkt[20:]))
		} else {
			fmt.Printf("Unknown packet:\n%s\n\n", hex.Dump(pkt))
		}
	}

	return nil, nil
}
示例#2
0
func TestPattern_Encode(t *testing.T) {
	for _, f := range []string{
		"pattern_1.splice",
		"pattern_2.splice",
		"pattern_3.splice",
		"pattern_4.splice",
		"pattern_5.splice",
	} {
		raw, err := ioutil.ReadFile(path.Join("fixtures", f))
		if err != nil {
			t.Fatalf("unable to read %s, %v", f, err)
		}

		decoded, err := Decode(bytes.NewBuffer(raw))
		if err != nil {
			t.Fatalf("unable to decode %s, %v", f, err)
		}

		encoded := bytes.NewBuffer([]byte{})
		if err := decoded.Encode(encoded); err != nil {
			t.Fatalf("unable to encode %s, %v", f, err)
		}

		rawEncoded := encoded.Bytes()
		if !bytes.HasPrefix(raw, rawEncoded) {
			t.Errorf(
				"encoded did not match raw for %s.\nExpected:\n\n%s\n\nActual:\n\n%s",
				f,
				hex.Dump(raw),
				hex.Dump(rawEncoded),
			)
		}
	}
}
示例#3
0
// Write implements io.Writer.
func (w SecureWriter) Write(buf []byte) (int, error) {
	if uint64(len(buf)) > maxMessageSize {
		return 0, fmt.Errorf("input is too large. Got %d bytes, max: %d", len(buf), maxMessageSize)
	}

	// Create a nonce.
	nonce, err := NewNonce()
	if err != nil {
		return 0, err
	}
	debugf("Write: nonce\n%s\n", hex.Dump(nonce[:]))

	// Encrypt the message with the nonce prefix.
	sealed := box.SealAfterPrecomputation(nonce[:], buf, nonce, w.key)

	debugf("Write: sealed %d bytes\n%s\n", len(sealed), hex.Dump(sealed))

	// Write a fixed header indicating how long the message is.
	header := uint64(len(sealed))
	headerSize := binary.Size(header)
	if err := binary.Write(w.w, binary.BigEndian, header); err != nil {
		return headerSize, err
	}

	// Write the message.
	messageSize, err := w.w.Write(sealed)

	// Return the size of the header and the message.
	return headerSize + messageSize, err
}
func (h *Hexer) FmtAt(offset, n int64) string {

	grab := int64(16)

	_, err := h.Seek(offset, 0)
	if err != nil {
		return ""
	}
	leftover := n % grab
	var buf = make([]byte, n+leftover)
	_, err = h.Read(buf)

	if err != nil {
		return ""
	}

	st := ""
	i := int64(0)
	for i = int64(0); i < int64(n/grab); i++ {
		stT := hex.Dump(buf[i*grab : i*grab+16])
		os := fmt.Sprintf("%08x", offset+i*grab)
		stT = strings.Replace(stT, "00000000", os, 1)
		st = st + stT
	}
	if leftover > 0 {
		stT := hex.Dump(buf[n-leftover : n])
		os := fmt.Sprintf("%08x", offset+n-leftover)
		stT = strings.Replace(stT, "00000000", os, 1)
		st = st + stT
	}
	return st
}
示例#5
0
func TestDecodeEncodePattern(t *testing.T) {
	tData := []string{
		"pattern_1.splice",
		"pattern_2.splice",
		"pattern_3.splice",
	}

	for _, exp := range tData {
		expected, err := ioutil.ReadFile(path.Join("fixtures", exp))
		decoded := Pattern{}
		err = Unmarshal(expected, &decoded)
		if err != nil {
			t.Fatal(err)
		}

		actual, err := Marshal(decoded)

		if !bytes.Equal(actual, expected) {
			t.Errorf("%s was incorrectly encoded", exp)
			t.Log("Expected\n" + hex.Dump(expected))
			t.Log("Got\n" + hex.Dump(actual))
			t.Logf("First diff at index %#x", firstDiff(actual, expected))
		}

	}

}
示例#6
0
func Pipe(local net.Conn, remote net.Conn) {
	local_chan := chanFromConn(local)
	remote_chan := chanFromConn(remote)
	for {
		select {
		case b1 := <-local_chan:
			if b1 == nil {
				return
			}
			out_str := fmt.Sprintf("id: %09d,%v,LOCAL>>>>>\n%s%s\n", access_id, time.Now(), hex.Dump(b1), hex.EncodeToString(b1))
			fmt.Print(out_str)
			if access_log != nil {
				access_log.Print(out_str)
			}
			remote.Write(b1)

		case b2 := <-remote_chan:
			if b2 == nil {
				return
			}
			out_str := fmt.Sprintf("id: %09d,%v,REMOTE<<<<<\n%s%s\n", access_id, time.Now(), hex.Dump(b2), hex.EncodeToString(b2))
			fmt.Print(out_str)
			if access_log != nil {
				access_log.Print(out_str)
			}
			local.Write(b2)
		}
	}
}
示例#7
0
func TestVoidUnionSetters(t *testing.T) {
	t.Parallel()
	want := mustEncodeTestMessage(t, "VoidUnion", "(b = void)", []byte{
		0, 0, 0, 0, 2, 0, 0, 0,
		0, 0, 0, 0, 1, 0, 0, 0,
		1, 0, 0, 0, 0, 0, 0, 0,
	})

	msg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatal(err)
	}
	voidUnion, err := air.NewRootVoidUnion(seg)
	if err != nil {
		t.Fatal(err)
	}
	voidUnion.SetB()

	act, err := msg.Marshal()
	if err != nil {
		t.Fatal("msg.Marshal():", err)
	}
	if !bytes.Equal(act, want) {
		t.Errorf("msg.Marshal() =\n%s\n; want:\n%s", hex.Dump(act), hex.Dump(want))
	}
}
示例#8
0
文件: iter.go 项目: tbytes/goIPP
func (i *iterator) GetNextN(it int) ([]byte, bool) {
	if i.dBug {
		i.deBug()
	}
	if i.mark+it < i.markEnd {
		markIn := i.mark
		i.mark += it
		i.bRemaining -= it

		fmt.Println(hex.Dump(i.srcIn[markIn:i.mark]))

		return i.srcIn[markIn:i.mark], true
	} else {
		if i.mark+it > i.markEnd {
			log.Println("i exceeds markEnd")
			return nil, false
		} else if i.mark+it == i.markEnd {
			markIn := i.mark
			i.mark += it
			i.bRemaining -= it

			fmt.Println(hex.Dump(i.srcIn[markIn:i.mark]))

			return i.srcIn[markIn:i.mark], true
		}
	}
	return nil, false
}
示例#9
0
文件: uat.go 项目: cyoung/adsbtest
func main() {
	ee, _ := hex.DecodeString("0dd90007150b3908050b39c51243b0b80005800021bcc09082102d53cc00082efc1e012d43cc000000000100000fd9000f1300120813000fc46743b25400158000213d1ed082102cb9526ade833b9ee34eb34a04fdb4a1c6d96586a8")
	fmt.Printf("a\n%s\n\n", hex.Dump(ee))
	eee := doRS(ee[:72])
	fmt.Printf("b\n%s\n\n", hex.Dump(eee))
	return
	testMessage := "31db57800c92ae60148006745f105011a02c31c9832db2cf4e5a832df0c2fcb7cb4833d70c342d4810d9336008b3b0cf5f5e741e00002d0eaac08210000000ff0c51b92000000000efd304011a1518011b0300c5aba371de58c598c33d2658c372631b8e58c430434ab658c5aba371de581e00002d0eaac08210000000ff0c51b72000000000efd304011a1518011b0300c5aba371de58c598c33d2658c372631b8e58c430434ab658c5aba371de582180067403503455014a02c15cd832df0c35cda8015543e0c35c30d4b520c704cd803312830cefc30801cf0cb481234b8013f2813310cb4ca079c114c30cb8c30c30f5e7402180067403503455014a02ca092832df0c35cda8015543e0c36c30d0b520c704cd803312830c6f370c60073c32da048d2e004fca04cc432d3781e704530c30db1c31c7d79d2180067403503455014a02c83d4832df0c35cda8015543e0cf5c30ccb520c704cd803312830def370ca0073c32d2048d2e004fca04cc432d3181e704530c37cb1c31dfd79d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
	f, err := decodeDumpFmt(testMessage)
	fmt.Printf("%s\n", hex.Dump(f))
	if err != nil {
		panic(err)
	}
	p := createPacket(f)

	fmt.Printf("%d\n", len(p))

	fOut, err := os.Create("uat.bin")
	if err != nil {
		panic(err)
	}
	defer fOut.Close()
	outByte := iqFileOut(p)
	fmt.Printf("len=%d\n", len(outByte))
	fmt.Printf("%s\n", hex.Dump(outByte))
	for i := 0; i < 10000; i++ {
		fOut.Write(outByte)
	}
}
示例#10
0
func TestFilterEncode(t *testing.T) {
	for _, i := range encode_filters {
		p, err := CompileFilter(i.filter_str)
		if err != nil {
			t.Errorf("Problem compiling %s - %s\n", i.filter_str, err)
		}
		fBytes, error := hex.DecodeString(i.filter_encoded)
		if error != nil {
			t.Errorf("Error decoding byte string: %s\n", i.filter_encoded)
		}
		if !bytes.Equal(p.Bytes(), fBytes) {
			l := len(fBytes)
			pBytes := p.Bytes()
			if l > len(pBytes) {
				l = len(pBytes)
			}
			for i := 0; i < l; i++ {
				if pBytes[i] != fBytes[i] {
					l = i
					break
				}
			}
			t.Errorf("Filter does not match ref bytes (first difference at byte %d) %s\n\n%s\n%s",
				l, i.filter_str, hex.Dump(p.Bytes()), hex.Dump(fBytes))
		}
	}
}
示例#11
0
func TestBinaryMarshaling(t *testing.T) {
	paths := []string{
		"pattern_1.splice",
		"pattern_2.splice",
		"pattern_3.splice",
		"pattern_4.splice",
		"pattern_5.splice"}

	for _, fp := range paths {
		b, err := ioutil.ReadFile(path.Join("sequences", fp))
		if err != nil {
			t.Fatalf("something went wrong decoding %s - %v", fp, err)
		}
		p := &Pattern{}
		if err := p.UnmarshalBinary(b); err != nil {
			t.Fatalf("something went wrong decoding %s - %v", fp, err)
		}
		b2, err := p.MarshalBinary()
		if err != nil {
			t.Fatalf("something went wrong decoding %s - %v", fp, err)
		}
		if !bytes.Equal(b[:len(b2)], b2) {
			t.Logf("failed")
			fmt.Println(fp)
			fmt.Println(hex.Dump(b))
			fmt.Println("---")
			fmt.Println(hex.Dump(b2))
			fmt.Println()
			t.Fatalf("%s wasn't decoded as expect.", fp)
		}
	}
}
示例#12
0
func TestPattern(t *testing.T) {
	fbuf, err := ioutil.ReadFile("fixtures/pattern_1.splice")
	if err != nil {
		t.Fatal(err)
	}

	buf := bytes.NewBuffer(fbuf)
	p, err := DecodeReader(buf)
	if err != nil {
		t.Fatal(err)
	}

	wbuf := bytes.NewBuffer([]byte{})
	_, err = p.WriteTo(wbuf)
	if err != nil {
		t.Fatal(err)
	}

	if d := bytes.Compare(fbuf, wbuf.Bytes()); d != 0 {
		t.Errorf("Difference between what was read and what was written: %d", d)
		t.Log("original\n", hex.Dump(fbuf))
		t.Log("new\n", hex.Dump(wbuf.Bytes()))

	}

}
func forward_tap_to_phys(phys_conn *net.UDPConn, tap_conn *TapConn, peer_addr *net.UDPAddr, key []byte, chan_disc_peer chan net.UDPAddr) {
	/* Raw tap frame received */
	frame := make([]byte, TAP_MTU+14)
	/* Encapsulated frame and error */
	var enc_frame []byte
	var invalid error = nil
	/* Discovered peer */
	var disc_peer_addr net.UDPAddr

	/* Initialize our HMAC-SHA256 hash context */
	hmac_h := hmac.New(sha256.New, key)

	/* If a peer was specified, fill in our discovered peer information */
	if peer_addr != nil {
		disc_peer_addr.IP = peer_addr.IP
		disc_peer_addr.Port = peer_addr.Port
	} else {
		/* Otherwise, wait for the forward_phys_to_tap() goroutine to discover a peer */
		disc_peer_addr = <-chan_disc_peer
	}

	log.Printf("Starting tap->phys forwarding with peer %s:%d...\n", disc_peer_addr.IP, disc_peer_addr.Port)

	for {
		/* Read a raw frame from our tap device */
		n, err := tap_conn.Read(frame)
		if err != nil {
			log.Fatalf("Error reading from tap device!: %s\n", err)
		}

		if DEBUG == 2 {
			log.Println("<- tap  | Plaintext frame to peer:")
			log.Println("\n" + hex.Dump(frame[0:n]))
		}

		/* Encapsulate the frame */
		enc_frame, invalid = encap_frame(frame[0:n], hmac_h)

		/* Skip it if it's invalid */
		if invalid != nil {
			if DEBUG >= 1 {
				log.Printf("-> phys | Frame discarded! Size: %d, Reason: %s\n", n, invalid.Error())
				log.Println("\n" + hex.Dump(frame[0:n]))
			}
			continue
		}

		if DEBUG == 2 {
			log.Println("-> phys | Encapsulated frame to peer:")
			log.Println("\n" + hex.Dump(enc_frame))
		}

		/* Send the encapsulated frame to our peer through UDP */
		_, err = phys_conn.WriteToUDP(enc_frame, &disc_peer_addr)
		if err != nil {
			log.Fatalf("Error writing to UDP socket!: %s\n", err)
		}
	}
}
示例#14
0
func compare(t *testing.T, src, dst []byte) {
	if bytes.Equal(src, dst) {
		return
	}
	t.Log(hex.Dump(src))
	t.Log(hex.Dump(dst))
	t.Fatal("invalid output")
}
示例#15
0
文件: do.go 项目: cznic/dns
func hdump(emitId func(), name string, r *pcat.Record) {
	emitId()
	fmt.Printf("#--%s\n#--Query\n%s#--Reply\n%s\n",
		name,
		hex.Dump(r.Query),
		hex.Dump(r.Reply),
	)
}
示例#16
0
func TestKISS(t *testing.T) {
	v := aprs.ParseFrame(christmasMsg)
	bc := EncodeAPRSCommand(v)
	t.Logf("Command:\n" + hex.Dump(bc))

	br := EncodeAPRSResponse(v)
	t.Logf("Response:\n" + hex.Dump(br))
}
示例#17
0
func TestBind(t *testing.T) {
	tx := []byte{
		0x00, 0x00, 0x00, 0x2A, 0x00, 0x00, 0x00, 0x02,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
		0x73, 0x6D, 0x70, 0x70, 0x63, 0x6C, 0x69, 0x65,
		0x6E, 0x74, 0x31, 0x00, 0x70, 0x61, 0x73, 0x73,
		0x77, 0x6F, 0x72, 0x64, 0x00, 0x00, 0x34, 0x00,
		0x00, 0x00,
	}
	pdu := NewBindTransmitter()
	f := pdu.Fields()
	f.Set(pdufield.SystemID, "smppclient1")
	f.Set(pdufield.Password, "password")
	f.Set(pdufield.InterfaceVersion, 0x34)
	pdu.Header().Seq = 1
	var b bytes.Buffer
	if err := pdu.SerializeTo(&b); err != nil {
		t.Fatal(err)
	}
	l := uint32(b.Len())
	if l != pdu.Header().Len {
		t.Fatalf("unexpected len: want %d, have %d", l, pdu.Header().Len)
	}
	if !bytes.Equal(tx, b.Bytes()) {
		t.Fatalf("unexpected bytes:\nwant:\n%s\nhave:\n%s",
			hex.Dump(tx), hex.Dump(b.Bytes()))
	}
	pdu, err := Decode(&b)
	if err != nil {
		t.Fatal(err)
	}
	h := pdu.Header()
	if h.ID != BindTransmitterID {
		t.Fatalf("unexpected ID: want %d, have %d",
			BindTransmitterID, h.ID)
	}
	if h.Seq != 1 {
		t.Fatalf("unexpected Seq: want 1, have %d", h.Seq)
	}
	test := []struct {
		n pdufield.Name
		v string
	}{
		{pdufield.SystemID, "smppclient1"},
		{pdufield.Password, "password"},
		{pdufield.InterfaceVersion, strconv.Itoa(0x34)},
	}
	for _, el := range test {
		f := pdu.Fields()[el.n]
		if f == nil {
			t.Fatalf("missing field: %s", el.n)
		}
		if f.String() != el.v {
			t.Fatalf("unexpected value for %q: want %q, have %q",
				el.n, el.v, f.String())
		}
	}
}
示例#18
0
func TestDataVersioningAvoidsUnnecessaryTruncation(t *testing.T) {
	t.Parallel()
	in := mustEncodeTestMessage(t, "VerTwoDataTwoPtr", "(val = 9, duo = 8, ptr1 = (val = 77), ptr2 = (val = 55))", []byte{
		0, 0, 0, 0, 7, 0, 0, 0,
		0, 0, 0, 0, 2, 0, 2, 0,
		9, 0, 0, 0, 0, 0, 0, 0,
		8, 0, 0, 0, 0, 0, 0, 0,
		4, 0, 0, 0, 1, 0, 0, 0,
		4, 0, 0, 0, 1, 0, 0, 0,
		77, 0, 0, 0, 0, 0, 0, 0,
		55, 0, 0, 0, 0, 0, 0, 0,
	})
	want := mustEncodeTestMessage(t, "Wrap2x2", "(mightNotBeReallyEmpty = (val = 9, duo = 8, ptr1 = (val = 77), ptr2 = (val = 55)))", []byte{
		0, 0, 0, 0, 8, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 1, 0,
		0, 0, 0, 0, 2, 0, 2, 0,
		9, 0, 0, 0, 0, 0, 0, 0,
		8, 0, 0, 0, 0, 0, 0, 0,
		4, 0, 0, 0, 1, 0, 0, 0,
		4, 0, 0, 0, 1, 0, 0, 0,
		77, 0, 0, 0, 0, 0, 0, 0,
		55, 0, 0, 0, 0, 0, 0, 0,
	})

	msg, err := capnp.Unmarshal(in)
	if err != nil {
		t.Fatal("Unmarshal:", err)
	}

	// Read in the message as if it's an old client (less fields in schema).
	oldRoot, err := air.ReadRootVerEmpty(msg)
	if err != nil {
		t.Fatal("ReadRootVerEmpty:", err)
	}

	// Store the larger message into another segment.
	freshMsg, freshSeg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatal("NewMessage:", err)
	}
	wrapEmpty, err := air.NewRootWrapEmpty(freshSeg)
	if err != nil {
		t.Fatal("NewRootWrapEmpty:", err)
	}
	if err := wrapEmpty.SetMightNotBeReallyEmpty(oldRoot); err != nil {
		t.Fatal("SetMightNotBeReallyEmpty:", err)
	}

	// Verify that it matches the expected serialization.
	out, err := freshMsg.Marshal()
	if err != nil {
		t.Fatal("Marshal:", err)
	}
	if !bytes.Equal(out, want) {
		t.Errorf("After copy, data is:\n%s\nwant:\n%s", hex.Dump(out), hex.Dump(want))
	}
}
示例#19
0
func handler(w http.ResponseWriter, r *http.Request) {
	u, err := url.Parse(r.FormValue("url"))
	if err != nil {
		serve(w, r, &Result{Err: err.Error()})
		return
	}
	hostname := u.Host
	if hostname == "" {
		serve(w, r, &Result{Err: "Can't get Hostname"})
		return
	}

	path := u.Path
	if path == "" {
		path = "/"
	}
	if u.RawQuery != "" {
		path = fmt.Sprintf("%s?%s", u.Path, u.RawQuery)
	}
	fmt.Println(hostname)
	fmt.Println(path)
	endpoint := r.FormValue("endpoint")

	var dstip net.IP
	if endpoint == "" {
		endpoint = hostname
	}
	ipstr := r.FormValue("ip")
	if ipstr == "" {
		dstaddrs, err := net.LookupIP(endpoint)
		if err != nil {
			serve(w, r, &Result{Err: err.Error()})
			return
		}
		dstip = dstaddrs[0].To4()
	} else {
		dstip = net.ParseIP(ipstr)
	}
	fmt.Println(dstip)
	if dstip == nil {
		serve(w, r, &Result{Err: "ip error"})
		return
	}
	c_fullpayload := make(chan int)
	req, _ := http.NewRequest("GET", fmt.Sprintf("http://%s%s", dstip.String(), path), nil)
	req.Host = hostname
	go getfullbodysize(c_fullpayload, req)
	pkt_count, payload_size, fullpayload, err := initcwndcheck.Detectinitcwnd(hostname, path, dstip)
	fullpayloadsize := <-c_fullpayload
	if err != nil {
		serve(w, r, &Result{pkt_count, payload_size, fullpayloadsize, hex.Dump(fullpayload), err.Error(), dstip.String()})
	} else {
		serve(w, r, &Result{pkt_count, payload_size, fullpayloadsize, hex.Dump(fullpayload), "", dstip.String()})
	}

}
示例#20
0
func TestPack(t *testing.T) {
	for _, test := range compressionTests {
		orig := make([]byte, len(test.original))
		copy(orig, test.original)
		compressed := Pack(nil, orig)
		if !bytes.Equal(compressed, test.compressed) {
			t.Errorf("Pack(nil,\n%s\n) =\n%s\n; want\n%s", hex.Dump(test.original), hex.Dump(compressed), hex.Dump(test.compressed))
		}
	}
}
示例#21
0
func (e *TableMapEvent) Dump(w io.Writer) {
	fmt.Fprintf(w, "TableID: %d\n", e.TableID)
	fmt.Fprintf(w, "Flags: %d\n", e.Flags)
	fmt.Fprintf(w, "Schema: %s\n", e.Schema)
	fmt.Fprintf(w, "Table: %s\n", e.Table)
	fmt.Fprintf(w, "Column count: %d\n", e.ColumnCount)
	fmt.Fprintf(w, "Column type: \n%s", hex.Dump(e.ColumnType))
	fmt.Fprintf(w, "NULL bitmap: \n%s", hex.Dump(e.NullBitmap))
	fmt.Fprintln(w)
}
示例#22
0
func TestNTLMOWFv1(t *testing.T) {
	hash := ntlmHash("Password")
	val := [21]byte{
		0xa4, 0xf4, 0x9c, 0x40, 0x65, 0x10, 0xbd, 0xca, 0xb6, 0x82, 0x4e, 0xe7, 0xc3, 0x0f, 0xd8, 0x52,
		0, 0, 0, 0, 0,
	}
	if hash != val {
		t.Errorf("got:\n%sexpected:\n%s", hex.Dump(hash[:]), hex.Dump(val[:]))
	}
}
示例#23
0
func Fuzz(data []byte) int {
	// Regenerate the length, or we'll most commonly exit quickly due to an
	// unexpected eof which is unintestering.
	if len(data) > 8 {
		binary.BigEndian.PutUint32(data[4:], uint32(len(data))-8)
	}

	// Setup a rawConnection we'll use to parse the message.
	c := rawConnection{
		cr:     &countingReader{Reader: bytes.NewReader(data)},
		closed: make(chan struct{}),
		pool: sync.Pool{
			New: func() interface{} {
				return make([]byte, BlockSize)
			},
		},
	}

	// Attempt to parse the message.
	hdr, msg, err := c.readMessage()
	if err != nil {
		return 0
	}

	// If parsing worked, attempt to encode it again.
	newBs, err := msg.AppendXDR(nil)
	if err != nil {
		panic("not encodable")
	}

	// Create an appriate header for the re-encoding.
	newMsg := make([]byte, 8)
	binary.BigEndian.PutUint32(newMsg, encodeHeader(hdr))
	binary.BigEndian.PutUint32(newMsg[4:], uint32(len(newBs)))
	newMsg = append(newMsg, newBs...)

	// Use the rawConnection to parse the re-encoding.
	c.cr = &countingReader{Reader: bytes.NewReader(newMsg)}
	hdr2, msg2, err := c.readMessage()
	if err != nil {
		fmt.Println("Initial:\n" + hex.Dump(data))
		fmt.Println("New:\n" + hex.Dump(newMsg))
		panic("not parseable after re-encode: " + err.Error())
	}

	// Make sure the data is the same as it was before.
	if hdr != hdr2 {
		panic("headers differ")
	}
	if !reflect.DeepEqual(msg, msg2) {
		panic("contents differ")
	}

	return 1
}
示例#24
0
func TestLMOWFv1(t *testing.T) {
	hash := lmHash("Password")
	val := [21]byte{
		0xe5, 0x2c, 0xac, 0x67, 0x41, 0x9a, 0x9a, 0x22,
		0x4a, 0x3b, 0x10, 0x8f, 0x3f, 0xa6, 0xcb, 0x6d,
		0, 0, 0, 0, 0,
	}
	if hash != val {
		t.Errorf("got:\n%sexpected:\n%s", hex.Dump(hash[:]), hex.Dump(val[:]))
	}
}
示例#25
0
func TestUnpack(t *testing.T) {
	for _, test := range compressionTests {
		compressed := make([]byte, len(test.compressed))
		copy(compressed, test.compressed)
		orig, err := Unpack(nil, compressed)
		if err != nil {
			t.Errorf("%s: Unpack(nil,\n%s\n) error: %v", test.name, hex.Dump(test.compressed), err)
		} else if !bytes.Equal(orig, test.original) {
			t.Errorf("%s: Unpack(nil,\n%s\n) =\n%s\n; want\n%s", test.name, hex.Dump(test.compressed), hex.Dump(orig), hex.Dump(test.original))
		}
	}
}
func TestWriteVCF(t *testing.T) {
	msg := getMessage(t)

	writer := bytes.NewBufferString("")
	writeMessageVCF(writer, msg)

	expected := hex.Dump([]byte(vcf[0:len(vcf)]))
	got := hex.Dump([]byte(writer.String()))
	if expected != got {
		t.Error("Expected\n", expected, "\nGot\n", got)
	}
}
示例#27
0
func TestCompressSeveralConcat(t *testing.T) {
	assert := assert.New(t)
	// SELECT repeat("a", 50)
	before := `
01 00 00 01 01 25 00 00    02 03 64 65 66 00 00 00    .....%....def...
0f 72 65 70 65 61 74 28    22 61 22 2c 20 35 30 29    .repeat("a", 50)
00 0c 08 00 32 00 00 00    fd 01 00 1f 00 00 05 00    ....2...........
00 03 fe 00 00 02 00 33    00 00 04 32 61 61 61 61    .......3...2aaaa
61 61 61 61 61 61 61 61    61 61 61 61 61 61 61 61    aaaaaaaaaaaaaaaa
61 61 61 61 61 61 61 61    61 61 61 61 61 61 61 61    aaaaaaaaaaaaaaaa
61 61 61 61 61 61 61 61    61 61 61 61 61 61 05 00    aaaaaaaaaaaaaa..
00 05 fe 00 00 02 00                                  .......
2e 00 00 00 03 73 65 6c    65 63 74 20 22 30 31 32    .....select "012
33 34 35 36 37 38 39 30    31 32 33 34 35 36 37 38    3456789012345678
39 30 31 32 33 34 35 36    37 38 39 30 31 32 33 34    9012345678901234
35 22                                                 5"
09 00 00 00 03 53 45 4c 45 43 54 20 31                ....SELECT 1
`
	after := `
4a 00 00 01 77 00 00 78    9c 63 64 60 60 64 54 65    J...w..x.cd..dTe
60 60 62 4e 49 4d 63 60    60 e0 2f 4a 2d 48 4d 2c    ..bNIMc.../J-HM,
d1 50 4a 54 d2 51 30 35    d0 64 e0 e1 60 30 02 8a    .PJT.Q05.d...0..
ff 65 64 90 67 60 60 65    60 60 fe 07 54 cc 60 cc    .ed.g..e....T...
c0 c0 62 94 48 32 00 ea    67 05 eb 07 00 8d f9 1c    ..b.H2..g.......
64                                                    d
22 00 00 00 32 00 00 78    9c d3 63 60 60 60 2e 4e    "...2..x..c....N
cd 49 4d 2e 51 50 32 30    34 32 36 31 35 33 b7 b0    .IM.QP20426153..
c4 cd 52 02 00 0c d1 0a    6c                         ..R.....l
0d 00 00 00 00 00 00 09    00 00 00 03 53 45 4c 45    ............SELE
43 54 20 31                                           CT 1
`
	_, _ = before, after

	buf := bytes.NewBufferString("")
	buf.Write(DecodeDump(after))

	r := NewCompressedReader(buf)
	b, err := ioutil.ReadAll(r)
	fmt.Println(hex.Dump(b))
	fmt.Println(hex.Dump(DecodeDump(after)))
	fmt.Println(hex.Dump(buf.Bytes()))
	assert.NoError(err)
	assert.EqualValues(DecodeDump(before), b)

	// write and read again
	w := NewCompressedWriter(buf)
	_, err = w.Write(DecodeDump(before))
	assert.NoError(err)
	b, err = ioutil.ReadAll(r)
	assert.NoError(err)
	assert.EqualValues(DecodeDump(before), b)
}
示例#28
0
func TestAfproto(t *testing.T) {
	if testing.Short() {
		return
	}

	var afp AfprotoFrame
	var msg = []byte("He\x85\x59\x85llo!")
	var test_buf []byte
	var rx_buf []byte

	test_buf = afp.Serialize(msg)

	/* Test length of test_buf */
	if len(test_buf) != 16 {
		t.Log(len(test_buf))
		t.Log(test_buf)
		t.Log(hex.Dump(test_buf))
		t.Log(string(test_buf))
		t.Fail()
	}

	rx_buf = afp.Extract(test_buf)

	/* Did extraction fail? */
	if rx_buf == nil {
		t.Error("Extract Failure")
	}

	if len(rx_buf) != len(msg) {
		t.Log(len(rx_buf))
		t.Log(rx_buf)
		t.Log(hex.Dump(rx_buf))
		t.Log(string(rx_buf))
		t.Fail()
	}

	/* create a failure */
	rx_buf = afp.Extract([]byte("\x33\x33\x33\x33\x33\x33\x33"))
	if rx_buf != nil {
		t.Log(rx_buf)
		t.Log(hex.Dump(rx_buf))
		t.Error("nil expected, incorrect return value for malformed packet")
	}

	/* create another failure */
	rx_buf = afp.Extract([]byte(""))
	if rx_buf != nil {
		t.Log(rx_buf)
		t.Log(hex.Dump(rx_buf))
		t.Error("nil expected, incorrect return value for malformed packet")
	}
}
示例#29
0
func TestNTLMv1Response(t *testing.T) {
	challenge := [8]byte{
		0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
	}
	nt := ntResponse(challenge, "Password")
	val := [24]byte{
		0x67, 0xc4, 0x30, 0x11, 0xf3, 0x02, 0x98, 0xa2, 0xad, 0x35, 0xec, 0xe6, 0x4f, 0x16, 0x33, 0x1c,
		0x44, 0xbd, 0xbe, 0xd9, 0x27, 0x84, 0x1f, 0x94,
	}
	if nt != val {
		t.Errorf("got:\n%sexpected:\n%s", hex.Dump(nt[:]), hex.Dump(val[:]))
	}
}
示例#30
0
func TestLMv1Response(t *testing.T) {
	challenge := [8]byte{
		0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
	}
	nt := lmResponse(challenge, "Password")
	val := [24]byte{
		0x98, 0xde, 0xf7, 0xb8, 0x7f, 0x88, 0xaa, 0x5d, 0xaf, 0xe2, 0xdf, 0x77, 0x96, 0x88, 0xa1, 0x72,
		0xde, 0xf1, 0x1c, 0x7d, 0x5c, 0xcd, 0xef, 0x13,
	}
	if nt != val {
		t.Errorf("got:\n%sexpected:\n%s", hex.Dump(nt[:]), hex.Dump(val[:]))
	}
}