Example #1
0
func shouldHaveSameContentAs(actual interface{}, expected ...interface{}) string {
	if len(expected) != 1 {
		return "shouldHaveSameContentAs must have only one expected value"
	}
	actualIn, err := os.Open(actual.(string))
	if err != nil {
		return err.Error()
	}
	defer actualIn.Close()
	expectedIn, err := os.Open(expected[0].(string))
	if err != nil {
		return err.Error()
	}
	defer expectedIn.Close()

	actualPipeIn, actualPipeOut := io.Pipe()
	actualScanner := bufio.NewScanner(actualPipeIn)
	actualDumper := hex.Dumper(actualPipeOut)
	go func() {
		io.Copy(actualDumper, actualIn)
		actualDumper.Close()
		actualPipeOut.Close()
	}()

	expectedPipeIn, expectedPipeOut := io.Pipe()
	expectedScanner := bufio.NewScanner(expectedPipeIn)
	expectedDumper := hex.Dumper(expectedPipeOut)
	go func() {
		io.Copy(expectedDumper, expectedIn)
		expectedDumper.Close()
		expectedPipeOut.Close()
	}()

	for {
		actualNext := actualScanner.Scan()
		expectedNext := expectedScanner.Scan()
		if expectedNext && !actualNext {
			return fmt.Sprintf("%v and %v differ: extra Line %s", actual, expected[0], expectedScanner.Text())
		}
		if !expectedNext && actualNext {
			return fmt.Sprintf("%v and %v differ: extra Line %s", actual, expected[0], actualScanner.Text())
		}
		if actualScanner.Text() != expectedScanner.Text() {
			return fmt.Sprintf("%v and %v differ: %s != %s", actual, expected[0], actualScanner.Text(), expectedScanner.Text())
		}
		if !actualNext || !expectedNext {
			break
		}
	}

	return ""
}
Example #2
0
File: dump.go Project: sstallion/go
func dump(args ...string) error {
	var w io.WriteCloser

	if len(args) == 0 {
		w = hex.Dumper(os.Stdout)
	} else {
		var err error

		w, err = os.Create(args[0])
		if err != nil {
			return err
		}
	}
	defer w.Close()

	d, err := openDevice()
	if err != nil {
		return err
	}
	defer d.Close()

	if dumpCount == 0 {
		dumpCount = eeprom.MaxBytes - dumpStart
	}
	data := make([]byte, dumpCount)
	if err := d.Read(uint16(dumpStart), data); err != nil {
		d.Reset()
		return err
	}
	_, err = w.Write(data)
	return err
}
Example #3
0
func layout(g *gocui.Gui) error {
	maxX, _ := g.Size()

	if v, err := g.SetView("legend", maxX-23, 0, maxX-1, 5); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}
		fmt.Fprintln(v, "KEYBINDINGS")
		fmt.Fprintln(v, "↑ ↓: Seek input")
		fmt.Fprintln(v, "A: Enable autoscroll")
		fmt.Fprintln(v, "^C: Exit")
	}

	if v, err := g.SetView("stdin", 0, 0, 80, 35); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}
		if _, err := g.SetCurrentView("stdin"); err != nil {
			return err
		}
		dumper := hex.Dumper(v)
		if _, err := io.Copy(dumper, os.Stdin); err != nil {
			return err
		}
		v.Wrap = true
	}

	return nil
}
Example #4
0
File: hex.go Project: sheik/golang
func main() {
	if len(os.Args) < 2 {
		fmt.Println("you must supply a file name")
		os.Exit(1)
	}

	fp, err := os.Open(os.Args[1])
	if err != nil {
		panic(err)
	}

	reader := bufio.NewReader(fp)
	w := hex.Dumper(os.Stdout)

	buf := make([]byte, 1024)
	for {
		n, err := reader.Read(buf)
		if err != nil && err != io.EOF {
			panic(err)
		}
		if n == 0 {
			break
		}
		w.Write(buf[:n])
	}
}
Example #5
0
// WriteTo writes Go source code to w that contains the recorded traffic.
func (r *recordingConn) WriteTo(w io.Writer) (int64, error) {
	// TLS always starts with a client to server flow.
	clientToServer := true
	var written int64
	for i, flow := range r.flows {
		source, dest := "client", "server"
		if !clientToServer {
			source, dest = dest, source
		}
		n, err := fmt.Fprintf(w, ">>> Flow %d (%s to %s)\n", i+1, source, dest)
		written += int64(n)
		if err != nil {
			return written, err
		}
		dumper := hex.Dumper(w)
		n, err = dumper.Write(flow)
		written += int64(n)
		if err != nil {
			return written, err
		}
		err = dumper.Close()
		if err != nil {
			return written, err
		}
		clientToServer = !clientToServer
	}
	return written, nil
}
Example #6
0
func Sender(interval int, logfile *LogFile, peers []LoadPeer) {
	lm := LoadMessage{Interval: uint16(interval)}
	lm.ProbeInit()

	for {
		var buffer bytes.Buffer
		time.Sleep(time.Duration(lm.Interval) * time.Second)

		lm.Probe()
		if err := lm.Encode(&buffer); err != nil {
			log.Fatal("encode error:", err)
		}

		fmt.Println()
		if *f_verbose > 1 {
			fmt.Printf("Local LoadMessage, size=%d\n", buffer.Len())
			hex.Dumper(os.Stdout).Write(buffer.Bytes())
			fmt.Println()
		}
		lm.Dump(os.Stdout)
		if logfile != nil {
			logfile.WriteMessage(buffer.Bytes())
		}

		for _, peer := range peers {
			peer.conn.Write(buffer.Bytes())
		}
		lm.ProbeRotate()
	}
}
Example #7
0
func DumpLogFile(filename string) {
	var lm LoadMessage

	logfile, err := OpenLogFile(filename, MODE_READ)
	if err != nil {
		fmt.Println("Error open log file:", err)
		return
	}

	for {
		ts, buffer, err := logfile.ReadMessage()
		if err != nil {
			break
		}
		t := FromTimestamp(ts).Format("20060102-150405")
		err = lm.Decode(bytes.NewReader(buffer))
		if err != nil {
			fmt.Println("Error decode packet:", err)
			break
		}

		fmt.Println()
		if *f_verbose > 1 {
			fmt.Printf("Read LoadMessage, local time %s, size=%d\n", t, len(buffer))
			hex.Dumper(os.Stdout).Write(buffer)
			fmt.Println()
		}
		lm.Dump(os.Stdout)
	}

	if err != nil && err != io.EOF {
		fmt.Println(err)
	}
}
Example #8
0
func (hd *hexDumper) Flush() error {
	// Default to Stdout if not specified.
	var writer = hd.Writer
	if writer == nil {
		writer = os.Stdout
	}

	// Dump the hex dump with the optional prefix.
	if hd.Len() > 0 {
		buf := &bytes.Buffer{}
		dumper := hex.Dumper(buf)
		hd.WriteTo(dumper)
		dumper.Close()
		hd.Reset()

		hd.mu.Lock()
		defer hd.mu.Unlock()

		scanner := bufio.NewScanner(buf)
		for scanner.Scan() {
			if _, err := writer.Write([]byte(hd.Prefix)); err != nil {
				return err
			} else if _, err := writer.Write(scanner.Bytes()); err != nil {
				return err
			} else if _, err := writer.Write([]byte("\n")); err != nil {
				return err
			}
		}
	}
	return nil
}
Example #9
0
func (c *hexDump) dump(b []byte) {
	if !c.quiet {
		hd := hex.Dumper(c.out)
		hd.Write(b)
		hd.Close()
		c.out.Write([]byte("\n"))
	}
}
Example #10
0
func logConnection(c net.Conn) net.Conn {
	w := hex.Dumper(os.Stdout)
	r := io.TeeReader(c, w)
	return &loggedConnection{
		Conn:   c,
		reader: r,
	}
}
Example #11
0
func debug(d io.Reader) {
	dumper := hex.Dumper(os.Stdout)
	bs, err := ioutil.ReadAll(d)
	if err != nil {
		log.Fatal(err)
	}
	dumper.Write(bs)
	dumper.Close()
}
Example #12
0
File: main.go Project: qmsk/onewire
func hexdump(buf []byte) {
	dumper := hex.Dumper(os.Stdout)

	if _, err := dumper.Write(buf); err != nil {
		panic(err)
	}

	dumper.Close()
}
Example #13
0
func dumpFile() {
	data, err := ioutil.ReadFile("hex.go")
	if err != nil {
		log.Fatalf("failed reading file: %s", err)
	}
	dumper := hex.Dumper(os.Stdout)
	defer dumper.Close()
	log.Println("dumping hex.go to stdout")
	dumper.Write(data)
}
Example #14
0
File: dasm.go Project: 8l/e8
func dumpDataSeg(start uint32, b []byte) {
	n := len(b)
	fmt.Println("[data] // %08x - %08x, %d bytes\n",
		start, start+uint32(n), n,
	)

	dumper := hex.Dumper(os.Stdout)
	dumper.Write(b)
	dumper.Close()
	fmt.Println()
}
Example #15
0
func (sys *System) Dump(writer io.Writer, name string) error {
	fmt.Fprintf(writer, "%v\n%s\n\n", time.Now(), name)
	fmt.Fprintf(writer, "PC: 0x%X, SP: 0x%X, I: 0x%X\n\n", sys.pc, sys.sp, sys.i)

	for i, v := range sys.v {
		fmt.Fprintf(writer, "V%d: 0x%X\n", i, v)
	}

	stackDumper := hex.Dumper(writer)
	defer stackDumper.Close()

	fmt.Fprintln(writer)
	if err := binary.Write(stackDumper, binary.BigEndian, sys.stack[:]); err != nil {
		return err
	}

	memoryDumper := hex.Dumper(writer)
	defer memoryDumper.Close()

	fmt.Fprintln(writer)
	if _, err := memoryDumper.Write(sys.memory[:]); err != nil {
		return err
	}

	for y := 0; y < 32; y++ {
		fmt.Fprintln(writer)
		for x := 0; x < 64; x++ {
			if sys.video[y*64+x] != 0 {
				fmt.Fprint(writer, "#")
			} else {
				fmt.Fprint(writer, ".")
			}
		}
	}

	return nil
}
Example #16
0
func sendMessage(w http.ResponseWriter, r *http.Request) {
	src := r.FormValue("src")
	dest := r.FormValue("dest")
	text := r.FormValue("msg")
	if radio == nil {
		http.Error(w, "No radio", 500)
		return
	}

	if text != "" {
		d := hex.Dumper(os.Stdout)
		defer d.Close()
		mw := io.MultiWriter(d, radio)

		_, err := mw.Write([]byte{0xc0, 0x00})
		if err != nil {
			http.Error(w, err.Error(), 500)
			log.Printf("Error writing command: %v", err)
			return
		}

		msg := aprs.Frame{
			Source: aprs.AddressFromString(src),
			Dest:   aprs.AddressFromString(dest),
			Path: []aprs.Address{
				aprs.AddressFromString("WIDE2-2")},
			Body: aprs.Info(text),
		}

		body := ax25.EncodeAPRSCommand(msg)
		_, err = mw.Write(body)
		if err != nil {
			http.Error(w, err.Error(), 500)
			log.Printf("Error writing command: %v", err)
			return
		}

		_, err = mw.Write([]byte{0xc0})
		if err != nil {
			http.Error(w, err.Error(), 500)
			log.Printf("Error finishing command: %v", err)
			return
		}

		fmt.Fprintf(w, "Message sent")
	} else {
		http.Error(w, "No message", 400)
	}
}
Example #17
0
func main() {
	flag.Parse()
	var f *os.File
	if readFromStdin() {
		f = os.Stdin
	} else {
		var err error
		f, err = os.Open(*infile)
		if err != nil {
			log.Fatal("Failed to open ", *infile)
		}
	}
	dumper := hex.Dumper(os.Stdout)
	io.Copy(dumper, f)
	f.Close()
}
Example #18
0
// WriteTo writes Go source code to w that contains the recorded traffic.
func (r *recordingConn) WriteTo(w io.Writer) {
	// TLS always starts with a client to server flow.
	clientToServer := true

	for i, flow := range r.flows {
		source, dest := "client", "server"
		if !clientToServer {
			source, dest = dest, source
		}
		fmt.Fprintf(w, ">>> Flow %d (%s to %s)\n", i+1, source, dest)
		dumper := hex.Dumper(w)
		dumper.Write(flow)
		dumper.Close()
		clientToServer = !clientToServer
	}
}
Example #19
0
// WriteTo writes hex dumps to w that contains the recorded traffic.
func (r *recordingConn) WriteTo(w io.Writer) {
	fmt.Fprintf(w, ">>> runner is %s, shim is %s\n", r.local, r.peer)
	for i, flow := range r.flows {
		switch flow.flowType {
		case readFlow:
			fmt.Fprintf(w, ">>> Flow %d (%s to %s)\n", i+1, r.peer, r.local)
		case writeFlow:
			fmt.Fprintf(w, ">>> Flow %d (%s to %s)\n", i+1, r.local, r.peer)
		case specialFlow:
			fmt.Fprintf(w, ">>> Flow %d %q\n", i+1, flow.message)
		}

		if flow.data != nil {
			dumper := hex.Dumper(w)
			dumper.Write(flow.data)
			dumper.Close()
		}
	}
}
Example #20
0
func TestClientInit(t *testing.T) {
	hdump := hex.Dumper(os.Stdout)

	pr, pw := io.Pipe()
	go func(w io.Writer) {
		time.Sleep(2 * time.Second)
		WriteMessage(w, &ProtocolMessage{Num: 0, Type: MsgTypeGreeting & MsgTypeServerMask, Data: &MsgServerGreeting{Hash([]byte("testing"))}})
		time.Sleep(2 * time.Second)
		WriteMessage(w, &ProtocolMessage{Num: 1, Type: MsgTypeAuthenticate & MsgTypeServerMask})
		time.Sleep(2 * time.Second)
		WriteMessage(w, &ProtocolMessage{Num: 2, Type: MsgTypeGoodbye & MsgTypeServerMask})
	}(pw)

	c := FauxServer{hdump, pr}
	client := NewClient(c, "account name", Hash([]byte("password")))
	time.Sleep(1 * time.Second)
	client.Close(true)

	hdump.Close()
	_ = client
}
Example #21
0
func ExampleDumper() {
	lines := []string{
		"Go is an open source programming language.",
		"\n",
		"We encourage all Go users to subscribe to golang-announce.",
	}

	stdoutDumper := hex.Dumper(os.Stdout)

	defer stdoutDumper.Close()

	for _, line := range lines {
		stdoutDumper.Write([]byte(line))
	}

	// Output:
	// 00000000  47 6f 20 69 73 20 61 6e  20 6f 70 65 6e 20 73 6f  |Go is an open so|
	// 00000010  75 72 63 65 20 70 72 6f  67 72 61 6d 6d 69 6e 67  |urce programming|
	// 00000020  20 6c 61 6e 67 75 61 67  65 2e 0a 57 65 20 65 6e  | language..We en|
	// 00000030  63 6f 75 72 61 67 65 20  61 6c 6c 20 47 6f 20 75  |courage all Go u|
	// 00000040  73 65 72 73 20 74 6f 20  73 75 62 73 63 72 69 62  |sers to subscrib|
	// 00000050  65 20 74 6f 20 67 6f 6c  61 6e 67 2d 61 6e 6e 6f  |e to golang-anno|
	// 00000060  75 6e 63 65 2e                                    |unce.|
}
Example #22
0
func main() {
	f, err := os.Open(os.Args[1])
	handle(err)
	defer f.Close()

	r, err := dfgen.NewReader(bufio.NewReaderSize(f, 0x10000))
	handle(err)

	n, err := r.ReadLong()
	handle(err)
	fmt.Println("Year:", n)

	length, err := r.ReadLong()
	handle(err)
	fmt.Println("\nUnk2:\nLength", length)
	for i := 0; i < int(length); i++ {
		n, err = r.ReadLong() // are these ALWAYS the first N natural numbers?
		handle(err)
		fmt.Println(i, n)
	}

	length, err = r.ReadLong() // is this ALWAYS the same as the previous length?
	handle(err)
	fmt.Println("\nUnk3:\nLength", length)
	for i := 0; i < int(length); i++ {
		n, err = r.ReadLong()
		handle(err)
		fmt.Println(i, n)
	}

	b, err := r.ReadByte() // is this ALWAYS 1?
	handle(err)
	fmt.Println("Unk4:", b)

	s, err := r.ReadShort() // is this ALWAYS 2?
	handle(err)
	fmt.Println("Unk5:", s)

	s, err = r.ReadShort() // is this ALWAYS 2?
	handle(err)
	fmt.Println("Unk6:", s)

	length, err = r.ReadLong() // is this ALWAYS 10?
	handle(err)
	fmt.Println("\nUnk7:\nLength", length)
	for i := 0; i < int(length); i++ {
		n, err = r.ReadLong()
		handle(err)
		fmt.Println(i, n)
	}

	s, err = r.ReadShort() // is this ALWAYS 2?
	handle(err)
	fmt.Println("Unk8:", s)

	x := hex.Dumper(os.Stdout)
	defer x.Close()

	_, err = io.Copy(x, r.R)
	handle(err)
}
Example #23
0
func displayIncoming(r io.Reader, prefix string) {
	indent := ""
	out := func(f string, args ...interface{}) {
		fmt.Printf("%s%s"+f+"\n", append([]interface{}{prefix, indent}, args...)...)
	}

	ur := binproto.NewSimpleUnitReader(r)

	for {
		ut, data, err := ur.ReadUnit()
		switch err {
		case nil:
		case io.EOF:
			return
		default:
			fmt.Fprintf(os.Stderr, "could not read next unit: %s\n", err)
			os.Exit(1)
		}

		switch ut {
		case binproto.UTNil:
			out("Nil")
		case binproto.UTRequest:
			out("Request %d", data.(uint16))
		case binproto.UTAnswer:
			out("Answer %d", data.(uint16))
		case binproto.UTEvent:
			out("Event %d", data.(uint16))
		case binproto.UTBin:
			out("Bin %s", strconv.Quote(string(data.([]byte))))
		case binproto.UTNumber:
			out("Num %d", data.(int64))
		case binproto.UTList:
			out("List")
			indent += " "
		case binproto.UTTextKVMap:
			out("TextKVMap")
			indent += " "
		case binproto.UTIdKVMap:
			out("IdKVMap")
			indent += " "
		case binproto.UTUKey:
			out("UKey %d", data.(byte))
		case binproto.UTBinStream:
			out("Binstream")
			dumper := hex.Dumper(os.Stdout)
			if _, err := io.Copy(dumper, data.(*binproto.BinstreamReader)); err != nil {
				dumper.Close()
				fmt.Fprintf(os.Stderr, "error while dumping binstream: %s\n", err)
				os.Exit(1)
			}
			if err := dumper.Close(); err != nil {
				fmt.Fprintf(os.Stderr, "error while dumping binstream: %s\n", err)
				os.Exit(1)
			}
		case binproto.UTTerm:
			out("Term")
			indent = dedent(indent)
		}
	}
}
Example #24
0
func dump(data []byte) {
	dumper := hex.Dumper(os.Stdout)
	io.Copy(dumper, bytes.NewReader(data))
	dumper.Close()
}
Example #25
0
func writeHexChunk(p []byte) {
	dumper := hex.Dumper(out.Out)
	dumper.Write(p)
	dumper.Close()
}
Example #26
0
func main() {
	f, err := os.Open(os.Args[1])
	handle(err)
	defer f.Close()

	r, err := dfgen.NewReader(bufio.NewReaderSize(f, 0x10000))
	handle(err)

	s, err := r.ReadShort()
	handle(err)
	fmt.Println("Unk1:", s)

	n, err := r.ReadLong()
	handle(err)
	fmt.Println("Unk2:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk3:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk4:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk5:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk6:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk7:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk8:", int32(n))

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk9:", int32(n))

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk10:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk11:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk12:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk13:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk14:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk15:", int32(n))

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk16:", int32(n))

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk17:", int32(n))

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk18:", int32(n))

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk19:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk20:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk21:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk22:", int32(n))

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk23:", int32(n))

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk24:", int32(n))

	has_name, err := r.ReadByte()
	handle(err)
	if has_name > 1 {
		panic("has_name ∉ {0, 1}")
	}
	if has_name == 1 {
		NameStruct(r)
	}

	b, err := r.ReadByte()
	handle(err)
	fmt.Println("Unk25:", b)

	s, err = r.ReadShort()
	handle(err)
	fmt.Println("Unk26:", s)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk27:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk28:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk29:", n)

	str, err := r.ReadString()
	handle(err)
	fmt.Println("World name:", str)

	for _, kind := range []string{"MATERIAL", "ITEM", "CREATURE", "INTERACTION"} {
		listListLength, err := r.ReadLong()
		handle(err)
		fmt.Println(kind, "raws:", listListLength)

		for i := 0; i < int(listListLength); i++ {
			listLength, err := r.ReadLong()
			handle(err)

			for j := 0; j < int(listLength); j++ {
				str, err = r.ReadString()
				handle(err)

				fmt.Println(i, j, str)
			}
		}
	}

	var stInorganic, stPlant, stBody, stBodyGloss, stCreature, stItem, stBuilding, stEntity, stWord, stSymbol, stTranslation, stColor, stShape, stColorPattern, stReaction, stMaterialTemplate, stTissueTemplate, stBodyDetailPlan, stCreatureVariation, stInteraction []string

	for _, t := range []struct {
		name string
		list *[]string
	}{
		{"INORGANIC", &stInorganic},
		{"PLANT", &stPlant},
		{"BODY", &stBody},
		{"BODYGLOSS", &stBodyGloss},
		{"CREATURE", &stCreature},
		{"ITEM", &stItem},
		{"BUILDING", &stBuilding},
		{"ENTITY", &stEntity},
		{"WORD", &stWord},
		{"SYMBOL", &stSymbol},
		{"TRANSLATION", &stTranslation},
		{"COLOR", &stColor},
		{"SHAPE", &stShape},
		{"COLOR_PATTERN", &stColorPattern},
		{"REACTION", &stReaction},
		{"MATERIAL_TEMPLATE", &stMaterialTemplate},
		{"TISSUE_TEMPLATE", &stTissueTemplate},
		{"BODY_DETAIL_PLAN", &stBodyDetailPlan},
		{"CREATURE_VARIATION", &stCreatureVariation},
		{"INTERACTION", &stInteraction},
	} {
		listLength, err := r.ReadLong()
		handle(err)
		fmt.Println(t.name, "string table:", listLength)

		*t.list = make([]string, listLength)

		for i := 0; i < int(listLength); i++ {
			str, err = r.ReadString()
			handle(err)

			(*t.list)[i] = str

			fmt.Println(i, str)
		}
	}

	listLength, err := r.ReadLong()
	handle(err)
	fmt.Println("Unk30:", listLength, "records")
	for i := 0; i < int(listLength); i++ {
		j, err := r.ReadLong()
		handle(err)

		k, err := r.ReadLong()
		handle(err)

		fmt.Println(i, j, k)
	}

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk31:", n)

	listLength, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk32:", listLength, "records")
	unk32Length := int(listLength)
	for i := 0; i < int(listLength); i++ {
		n, err = r.ReadLong()
		fmt.Println(i, n)
	}

	listLength, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk33:", listLength, "records")
	for i := 0; i < int(listLength); i++ {
		n, err = r.ReadLong()
		fmt.Println(i, n)
	}

	listLength, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk34:", listLength, "records")
	for i := 0; i < int(listLength); i++ {
		n, err = r.ReadLong()
		fmt.Println(i, n)
	}

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk35:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk36:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk37:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk38:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk39:", n)

	listLength, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk40:", listLength, "records")
	for i := 0; i < int(listLength); i++ {
		n, err = r.ReadLong()
		fmt.Println(i, n)
	}

	listLength, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk41:", listLength, "records")
	for i := 0; i < int(listLength); i++ {
		n, err = r.ReadLong()
		fmt.Println(i, n)
	}
	unk41Length := int(listLength)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk42:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk43:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk44:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk45:", n)

	n, err = r.ReadLong()
	handle(err)
	fmt.Println("Unk46:", n)

	for i := 0; i < unk41Length; i++ {
		for j := 0; j < 3; j++ {
			s, err = r.ReadShort()
			handle(err)
			fmt.Println(i, "Unk47a:", j, int16(s))
		}

		s, err = r.ReadShort()
		handle(err)
		fmt.Println(i, "Unk47b:", s)

		listLength, err = r.ReadLong()
		handle(err)
		fmt.Println(i, "Unk47c:", listLength, "records")
		for j := 0; j < int(listLength); j++ {
			for k := 0; k < 3; k++ {
				s, err = r.ReadShort()
				handle(err)
				fmt.Println(i, "Unk47c:", j, k, s)
			}
		}

		s, err = r.ReadShort()
		handle(err)
		fmt.Println(i, "Unk47d:", s)

		for j := 0; j < 3; j++ {
			n, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk47e:", j, int32(n))
		}

		for j := 0; j < 3; j++ {
			s, err = r.ReadShort()
			handle(err)
			fmt.Println(i, "Unk47f:", j, int16(s))
		}

		for j := 0; j < 3; j++ {
			s, err = r.ReadShort()
			handle(err)
			fmt.Println(i, "Unk47g:", j, int16(s))
		}

		b, err = r.ReadByte()
		handle(err)
		fmt.Println(i, "Unk47h:", b)

		for j := 0; j < 9; j++ {
			s, err = r.ReadShort()
			handle(err)
			fmt.Println(i, "Unk47i:", j, int16(s))
		}

		for j := 0; j < 3; j++ {
			n, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk47j:", j, int32(n))
		}

		for j := 0; j < 3; j++ {
			s, err = r.ReadShort()
			handle(err)
			fmt.Println(i, "Unk47k:", j, int16(s))
		}

		for j := 0; j < 3; j++ {
			n, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk47l:", j, int32(n))
		}

		for j := 0; j < 11; j++ {
			s, err = r.ReadShort()
			handle(err)
			fmt.Println(i, "Unk47m:", j, int16(s))
		}

		str, err = r.ReadString()
		handle(err)
		fmt.Println(i, "Unk47n:", str)
	}

	for i := 0; i < unk32Length; i++ {
		s, err = r.ReadShort()
		handle(err)
		fmt.Println(i, "Unk48a:", s)

		n, err = r.ReadLong()
		handle(err)
		fmt.Println(i, "Unk48b:", n)

		str, err = r.ReadString()
		handle(err)
		fmt.Println(i, "Unk48c:", str)

		s, err = r.ReadShort()
		handle(err)
		fmt.Println(i, "Unk48d:", s)

		s, err = r.ReadShort()
		handle(err)
		fmt.Println(i, "Unk48e:", s)

		n, err = r.ReadLong()
		handle(err)
		fmt.Println(i, "Unk48f:", n)

		s, err = r.ReadShort()
		handle(err)
		fmt.Println(i, "Unk48g:", s)

		has_name, err := r.ReadByte()
		handle(err)
		if has_name > 1 {
			panic("has_name ∉ {0, 1}")
		}
		if has_name == 1 {
			NameStruct(r)
		}

		s, err = r.ReadShort()
		handle(err)
		fmt.Println(i, "Creature type:", s)
		fmt.Println("(", stCreature[s], ")")

		n, err = r.ReadLong()
		handle(err)
		fmt.Println(i, "Unk48h:", n)

		for j := 0; j < 19; j++ {
			listLength, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk48i", j, "a:", listLength, "records")
			for k := 0; k < int(listLength); k++ {
				s, err = r.ReadShort()
				handle(err)
				fmt.Println(i, "Unk48i", j, "a:", k, s)
			}

			listLength, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk48i", j, "b:", listLength, "records")
			for k := 0; k < int(listLength); k++ {
				n, err = r.ReadLong()
				handle(err)
				fmt.Println(i, "Unk48i", j, "b:", k, n)
			}
		}

		for j := 0; j < 12; j++ {
			listLength, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk48j", j, "a:", listLength, "records")
			for k := 0; k < int(listLength); k++ {
				n, err = r.ReadLong()
				handle(err)
				fmt.Println(i, "Unk48j", j, "a:", k, n)
			}

			listLength, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk48j", j, "b:", listLength, "records")
			for k := 0; k < int(listLength); k++ {
				s, err = r.ReadShort()
				handle(err)
				fmt.Println(i, "Unk48j", j, "b:", k, s)
			}
		}

		for j := 0; j < 2; j++ {
			listLength, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk48k", j, "a:", listLength, "records")
			for k := 0; k < int(listLength); k++ {
				s, err = r.ReadShort()
				handle(err)
				fmt.Println(i, "Unk48k", j, "a:", k, s)
			}

			listLength, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk48k", j, "b:", listLength, "records")
			for k := 0; k < int(listLength); k++ {
				n, err = r.ReadLong()
				handle(err)
				fmt.Println(i, "Unk48k", j, "b:", k, n)
			}
		}

		n, err = r.ReadLong()
		handle(err)
		fmt.Println(i, "Unk48l:", n)

		for j := 0; j < 9; j++ {
			listLength, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk48m", j, "a:", listLength, "records")
			for k := 0; k < int(listLength); k++ {
				s, err = r.ReadShort()
				handle(err)
				fmt.Println(i, "Unk48m", j, "a:", k, s)
			}

			listLength, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk48m", j, "b:", listLength, "records")
			for k := 0; k < int(listLength); k++ {
				n, err = r.ReadLong()
				handle(err)
				fmt.Println(i, "Unk48m", j, "b:", k, n)
			}
		}

		for j := 0; j < 3; j++ {
			s, err = r.ReadShort()
			handle(err)
			fmt.Println(i, "Unk48n", j, "a:", int16(s))

			n, err = r.ReadLong()
			handle(err)
			fmt.Println(i, "Unk48n", j, "b:", n)
		}
		break
	}

	x := hex.Dumper(os.Stdout)
	defer x.Close()

	_, err = io.Copy(x, r.R)
	handle(err)
}
Example #27
0
// dump can be useful for debugging.
func dump(w io.Writer, b []byte) {
	h := hex.Dumper(w)
	h.Write(b)
	h.Close()
}