This commit is contained in:
Neale Pickett 2018-07-24 23:53:06 +00:00
parent a860c7f069
commit d06ca08456
5 changed files with 84 additions and 84 deletions

View File

@ -14,8 +14,8 @@ package gapstring
import ( import (
"bytes" "bytes"
"fmt"
"encoding/binary" "encoding/binary"
"fmt"
"strings" "strings"
"unicode/utf16" "unicode/utf16"
) )
@ -198,7 +198,7 @@ func (g GapString) Bytes(fill ...byte) []byte {
// Fill in gap // Fill in gap
if len(fill) > 0 { if len(fill) > 0 {
for i := 0; i < c.gap; i += 1 { for i := 0; i < c.gap; i += 1 {
ret[pos] = fill[pos % len(fill)] ret[pos] = fill[pos%len(fill)]
pos += 1 pos += 1
} }
} }
@ -243,9 +243,9 @@ func (g GapString) HexString() string {
// There's probably a faster way to do this. Do we care? // There's probably a faster way to do this. Do we care?
fmt.Fprintf(out, "%02x", c) fmt.Fprintf(out, "%02x", c)
} }
if i + 1 < glen { if i+1 < glen {
out.WriteRune(' ') out.WriteRune(' ')
if i % 8 == 7 { if i%8 == 7 {
out.WriteRune(' ') out.WriteRune(' ')
} }
} }
@ -298,7 +298,7 @@ func (g GapString) Hexdump() string {
glen := g.Length() glen := g.Length()
pos := 0 pos := 0
prev := []byte{} prev := []byte{}
for ; pos < glen; { for pos < glen {
// Check for repeats // Check for repeats
end := pos + 16 end := pos + 16
if end > glen { if end > glen {
@ -307,7 +307,7 @@ func (g GapString) Hexdump() string {
cur := g.Slice(pos, end) cur := g.Slice(pos, end)
curBytes := cur.Bytes() curBytes := cur.Bytes()
if 0 == bytes.Compare(prev, curBytes) { if 0 == bytes.Compare(prev, curBytes) {
if ! skipping { if !skipping {
fmt.Fprintln(out, "*") fmt.Fprintln(out, "*")
skipping = true skipping = true
} }
@ -361,4 +361,3 @@ func (g GapString) Utf16LE(gap string) string {
func (g GapString) Utf16BE(gap string) string { func (g GapString) Utf16BE(gap string) string {
return g.Utf16(binary.BigEndian, gap) return g.Utf16(binary.BigEndian, gap)
} }

View File

@ -19,7 +19,7 @@ func TestChunk(t *testing.T) {
c = chunk{data: []byte("moo")} c = chunk{data: []byte("moo")}
assertEqual(t, "byte chunk", c.length(), 3) assertEqual(t, "byte chunk", c.length(), 3)
assertEqual(t, "byte slice", string(c.slice(1,3).data), "oo") assertEqual(t, "byte slice", string(c.slice(1, 3).data), "oo")
} }
func TestGapString(t *testing.T) { func TestGapString(t *testing.T) {

View File

@ -10,11 +10,11 @@ package netshovel
import ( import (
"flag" "flag"
"log"
"github.com/google/gopacket" "github.com/google/gopacket"
"github.com/google/gopacket/layers" "github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap" "github.com/google/gopacket/pcap"
"github.com/google/gopacket/tcpassembly" "github.com/google/gopacket/tcpassembly"
"log"
) )
// Mainloop to handle dispatching of PCAP files from command line // Mainloop to handle dispatching of PCAP files from command line

View File

@ -4,9 +4,9 @@ import (
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/dirtbags/netshovel/gapstring"
"strings" "strings"
"time" "time"
"github.com/dirtbags/netshovel/gapstring"
) )
// Error returned by convenience methods that are unable to get enough data // Error returned by convenience methods that are unable to get enough data
@ -14,6 +14,7 @@ type ShortError struct {
Wanted int // How many bytes you needed Wanted int // How many bytes you needed
Available int // How many bytes were available Available int // How many bytes were available
} }
func (e *ShortError) Error() string { func (e *ShortError) Error() string {
return fmt.Sprintf("Short read: wanted %d of %d available", e.wanted, e.available) return fmt.Sprintf("Short read: wanted %d of %d available", e.wanted, e.available)
} }
@ -21,6 +22,7 @@ func (e *ShortError) Error() string {
// Error returned by convenience methods that are unable to operate on gaps in data // Error returned by convenience methods that are unable to operate on gaps in data
type MissingError struct { type MissingError struct {
} }
func (e *MissingError) Error() string { func (e *MissingError) Error() string {
return "Operation on missing bytes" return "Operation on missing bytes"
} }
@ -81,7 +83,7 @@ func (pkt *Packet) Describe() string {
pkt.Description, pkt.Description,
) )
for _, f := range(pkt.Fields) { for _, f := range pkt.Fields {
fmt.Fprintf(out, " %s: %s\n", f.key, f.value) fmt.Fprintf(out, " %s: %s\n", f.key, f.value)
} }
fmt.Fprint(out, pkt.Payload.Hexdump()) fmt.Fprint(out, pkt.Payload.Hexdump())
@ -248,4 +250,3 @@ func (pkt *Packet) Uint8(name string) (uint8, error) {
} }
return value.(uint8), err return value.(uint8), err
} }

View File

@ -2,14 +2,14 @@ package netshovel
import ( import (
"fmt" "fmt"
"io"
"os"
"net/url"
"strings"
"time"
"github.com/dirtbags/netshovel/gapstring" "github.com/dirtbags/netshovel/gapstring"
"github.com/google/gopacket" "github.com/google/gopacket"
"github.com/google/gopacket/tcpassembly" "github.com/google/gopacket/tcpassembly"
"io"
"net/url"
"os"
"strings"
"time"
) )
// A File and the path where it lives // A File and the path where it lives
@ -99,8 +99,8 @@ func (stream *Stream) Read(length int) (Utterance, error) {
ret = stream.pending ret = stream.pending
stream.pending.Data = gapstring.GapString{} stream.pending.Data = gapstring.GapString{}
} else { } else {
r, more := <- stream.conversation r, more := <-stream.conversation
if ! more { if !more {
err = io.EOF err = io.EOF
} }
ret = r ret = r
@ -111,8 +111,8 @@ func (stream *Stream) Read(length int) (Utterance, error) {
// Pull in utterances until we have enough data. // Pull in utterances until we have enough data.
// .When will always be the timestamp on the last received utterance // .When will always be the timestamp on the last received utterance
for stream.pending.Data.Length() < length { for stream.pending.Data.Length() < length {
u, more := <- stream.conversation u, more := <-stream.conversation
if ! more { if !more {
break break
} }
stream.pending.Data = stream.pending.Data.Append(u.Data) stream.pending.Data = stream.pending.Data.Append(u.Data)