diff --git a/internal/archive/arc.go b/internal/archive/arc.go new file mode 100644 index 0000000..f74517e --- /dev/null +++ b/internal/archive/arc.go @@ -0,0 +1,319 @@ +package archive + +import ( + "bytes" + "io" + "strings" +) + +var arcMethods = map[byte]string{1: "stored", 2: "stored", 3: "packed", 4: "squeezed", 8: "crunched", 9: "squashed"} + +// walkARC reads an ARC archive (SEA's, and PKPAK's methods it shares). +func walkARC(r io.ReaderAt, size int64, fn func(e Entry, open Opener) bool) error { + off := int64(0) + for { + h, err := readAt(r, size, off, 2) + if err != nil { + return nil // the file ends: as good as an end mark + } + if h[0] != 0x1A { + return ErrCorrupt + } + method := h[1] + if method == 0 { + return nil + } + hlen := int64(29) + if method == 1 { + hlen = 25 // the oldest: no unpacked size + } + h, err = readAt(r, size, off, hlen) + if err != nil { + return ErrCorrupt + } + name := cString(h[2:15]) + packed := int64(le32(h[15:])) + mod := dosTime(le16(h[19:]), le16(h[21:])) + want := le16(h[23:]) + orig := packed + if method != 1 { + orig = int64(le32(h[25:])) + } + dataOff := off + hlen + mname, known := arcMethods[method] + if !known { + mname = "method " + string(rune('0'+method%10)) + } + e := Entry{Name: strings.ReplaceAll(name, "\\", "/"), Size: orig, Packed: packed, Method: mname, Modified: mod} + open := func(max int64) ([]byte, error) { + if err := sized(orig, max); err != nil { + return nil, err + } + src, err := readAt(r, size, dataOff, packed) + if err != nil { + return nil, err + } + var out []byte + switch method { + case 1, 2: + out = src + case 3: + out, err = unRLE90(src, orig) + case 4: + var sq []byte + if sq, err = unsqueeze(src, max); err == nil { + out, err = unRLE90(sq, orig) + } + case 8: + if len(src) == 0 || src[0] != 12 { + return nil, ErrCorrupt // the bits it was crunched to: always 12 + } + var lz []byte + if lz, err = unLZW(src[1:], 12, max); err == nil { + out, err = unRLE90(lz, orig) + } + case 9: + out, err = unLZW(src, 13, max) + default: + return nil, ErrMethod + } + if err != nil { + return nil, err + } + if int64(len(out)) != orig { + return nil, ErrCorrupt + } + if crc16(out) != want { + return nil, ErrChecksum + } + return out, nil + } + if !fn(e, open) { + return nil + } + off = dataOff + packed + } +} + +// unRLE90 undoes ARC's run-length coding: 0x90 n repeats the byte before +// it to n times in all, 0x90 0 is a 0x90. +func unRLE90(src []byte, size int64) ([]byte, error) { + out := make([]byte, 0, size) + var last byte + rep := false + for _, c := range src { + switch { + case rep: + if c == 0 { + out = append(out, 0x90) + } else { + for i := 1; i < int(c); i++ { + out = append(out, last) + } + } + rep = false + case c == 0x90: + rep = true + default: + out = append(out, c) + last = c + } + if int64(len(out)) > size { + return nil, ErrCorrupt + } + } + return out, nil +} + +// unsqueeze undoes ARC's squeezing: a Huffman tree (its node count, then +// pairs of children: a leaf is -(byte+1), 256 the end), then the codes, +// low bit first. +func unsqueeze(src []byte, max int64) ([]byte, error) { + if len(src) < 2 { + return nil, ErrCorrupt + } + n := int(le16(src)) + if n > 256 || 2+4*n > len(src) { + return nil, ErrCorrupt + } + if n == 0 { + return nil, nil + } + tree := make([][2]int16, n) + for i := range tree { + tree[i] = [2]int16{int16(le16(src[2+4*i:])), int16(le16(src[4+4*i:]))} + } + var out []byte + node := int16(0) + for _, c := range src[2+4*n:] { + for bit := 0; bit < 8; bit++ { + node = tree[node][c>>bit&1] + if node < 0 { + v := -(int(node) + 1) + if v == 256 { + return out, nil + } + out = append(out, byte(v)) + if int64(len(out)) > max { + return nil, ErrTooBig + } + node = 0 + } else if int(node) >= n { + return nil, ErrCorrupt + } + } + } + return out, nil // no end mark: what there was +} + +// unLZW undoes ARC's crunching and squashing: LZW of 9 bits growing to +// maxbits, code 256 clearing the table, codes low bit first and read in +// groups of their width's bytes, as Unix's compress reads them. +func unLZW(src []byte, maxbits uint, max int64) ([]byte, error) { + const clear, first = 256, 257 + maxmax := 1 << maxbits + prefix := make([]uint16, maxmax) + suffix := make([]byte, maxmax) + for i := 0; i < 256; i++ { + suffix[i] = byte(i) + } + nbits := uint(9) + maxcode := 1<= gsize || free > maxcode { + if free > maxcode { + nbits++ + if nbits >= maxbits { + nbits = maxbits + maxcode = maxmax + } else { + maxcode = 1<= len(src) { + return -1 + } + end := pos + int(nbits) + if end > len(src) { + end = len(src) + } + group = src[pos:end] + pos = end + gbit = 0 + gsize = len(group)*8 - int(nbits-1) + } + code := 0 + for i := uint(0); i < nbits; i++ { + b := gbit + int(i) + if b/8 < len(group) && group[b/8]>>(b%8)&1 != 0 { + code |= 1 << i + } + } + gbit += int(nbits) + return code + } + var out []byte + stack := make([]byte, 0, maxmax) + old := getcode() + if old < 0 { + return nil, nil + } + if old > 255 { + return nil, ErrCorrupt + } + fin := byte(old) + out = append(out, fin) + for { + code := getcode() + if code < 0 { + return out, nil + } + if code == clear { + free = first - 1 + clearFlag = true + if code = getcode(); code < 0 { + return out, nil + } + } + in := code + stack = stack[:0] + if code >= free { + if code > free { + return nil, ErrCorrupt + } + stack = append(stack, fin) + code = old + } + for code >= 256 { + if code >= maxmax || len(stack) >= maxmax { + return nil, ErrCorrupt + } + stack = append(stack, suffix[code]) + code = int(prefix[code]) + } + fin = suffix[code] + stack = append(stack, fin) + for i := len(stack) - 1; i >= 0; i-- { + out = append(out, stack[i]) + } + if int64(len(out)) > max { + return nil, ErrTooBig + } + if free < maxmax { + prefix[free] = uint16(old) + suffix[free] = fin + free++ + } + old = in + } +} + +// arcName is a name as ARC keeps it: 8.3, in capitals. +func arcName(n string) string { + n = strings.ToUpper(n) + if len(n) > 12 { + base, ext, _ := strings.Cut(n, ".") + if len(base) > 8 { + base = base[:8] + } + if len(ext) > 3 { + ext = ext[:3] + } + n = base + if ext != "" { + n += "." + ext + } + } + return n +} + +// writeARC writes files stored (method 2). +func writeARC(w io.Writer, files []File) error { + var b bytes.Buffer + for _, f := range files { + h := make([]byte, 29) + h[0], h[1] = 0x1A, 2 + copy(h[2:14], arcName(f.Name)) + put32(h[15:], uint32(len(f.Data))) + date, tm := dosStamp(f.Modified) + put16(h[19:], date) + put16(h[21:], tm) + put16(h[23:], crc16(f.Data)) + put32(h[25:], uint32(len(f.Data))) + b.Write(h) + b.Write(f.Data) + } + b.Write([]byte{0x1A, 0}) + _, err := w.Write(b.Bytes()) + return err +} diff --git a/internal/archive/archive.go b/internal/archive/archive.go new file mode 100644 index 0000000..50331cd --- /dev/null +++ b/internal/archive/archive.go @@ -0,0 +1,184 @@ +// Package archive reads the archives FidoNet moves mail and files in, in +// Go and without other programs: ZIP, ARC (stored, packed, squeezed, +// crunched and squashed), ARJ (methods 0 to 4) and LHA (-lh0-, -lh4- to +// -lh7-, header levels 0 to 2). It writes ZIP, and ARC, ARJ and LHA +// stored (each format's own "no compression"), which every unpacker +// takes. +// +// Archives come from other systems: every size is checked before memory +// is given to it, every entry against its CRC, and nothing is written to +// disk here. +package archive + +import ( + "bytes" + "errors" + "hash/crc32" + "io" + "strings" + "time" +) + +// Kind is an archive's format. +type Kind string + +// The formats. +const ( + ZIP Kind = "zip" + ARC Kind = "arc" + ARJ Kind = "arj" + LHA Kind = "lha" +) + +// Kinds are the formats read, in the order Detect tries them. +var Kinds = []Kind{ZIP, ARJ, LHA, ARC} + +// Errors. +var ( + ErrFormat = errors.New("not an archive this BBS reads (ZIP, ARC, ARJ, LHA)") + ErrCorrupt = errors.New("the archive is damaged") + ErrChecksum = errors.New("an entry does not match its CRC") + ErrMethod = errors.New("an entry is packed by a method this BBS does not unpack") + ErrTooBig = errors.New("an entry unpacks too big") +) + +// Entry is a file in an archive. +type Entry struct { + Name string // as the archive has it (it may have a path: check it) + Size int64 // unpacked + Packed int64 + Method string // "stored", "crunched", "-lh5-", "method 4"... + Modified time.Time + Dir bool +} + +// Detect is an archive's format by its first bytes ("": none of them). +func Detect(head []byte) Kind { + switch { + case len(head) >= 4 && string(head[:4]) == "PK\x03\x04", len(head) >= 4 && string(head[:4]) == "PK\x05\x06": + return ZIP + case len(head) >= 4 && head[0] == 0x60 && head[1] == 0xEA: + return ARJ + case len(head) >= 7 && head[2] == '-' && head[6] == '-' && (head[3] == 'l') && (head[4] == 'h' || head[4] == 'z'): + return LHA + case len(head) >= 2 && head[0] == 0x1A && head[1] <= 11: + return ARC + } + return "" +} + +// KindByName is the format a file's name says ("": none of them). +func KindByName(name string) Kind { + n := strings.ToLower(name) + switch { + case strings.HasSuffix(n, ".zip"): + return ZIP + case strings.HasSuffix(n, ".arc"): + return ARC + case strings.HasSuffix(n, ".arj"): + return ARJ + case strings.HasSuffix(n, ".lzh"), strings.HasSuffix(n, ".lha"): + return LHA + } + return "" +} + +// Opener unpacks an entry: its contents, checked against its CRC, or an +// error. max is the most it may unpack to (ErrTooBig past it). +type Opener func(max int64) ([]byte, error) + +// Walk calls fn for each entry of the archive in r (size bytes long), in +// order, until fn returns false or the archive ends. +func Walk(r io.ReaderAt, size int64, fn func(e Entry, open Opener) bool) error { + head := make([]byte, 8) + n, _ := r.ReadAt(head, 0) + switch Detect(head[:n]) { + case ZIP: + return walkZIP(r, size, fn) + case ARC: + return walkARC(r, size, fn) + case ARJ: + return walkARJ(r, size, fn) + case LHA: + return walkLHA(r, size, fn) + } + return ErrFormat +} + +// WalkBytes is Walk over an archive in memory. +func WalkBytes(b []byte, fn func(e Entry, open Opener) bool) error { + return Walk(bytes.NewReader(b), int64(len(b)), fn) +} + +// readAt reads exactly n bytes at off, or ErrCorrupt. +func readAt(r io.ReaderAt, size, off, n int64) ([]byte, error) { + if off < 0 || n < 0 || off+n > size { + return nil, ErrCorrupt + } + b := make([]byte, n) + if _, err := r.ReadAt(b, off); err != nil && !(err == io.EOF && off+n == size) { + return nil, ErrCorrupt + } + return b, nil +} + +// dosTime is an MS-DOS date and time (as ARC, ARJ and LHA level 0 and 1 +// keep them), in local time as DOS knew no other. +func dosTime(date, tm uint16) time.Time { + if date == 0 { + return time.Time{} + } + return time.Date(int(date>>9)+1980, time.Month(date>>5&15), int(date&31), + int(tm>>11), int(tm>>5&63), int(tm&31)*2, 0, time.Local) +} + +// dosStamp is a time as DOS's date and time. +func dosStamp(t time.Time) (date, tm uint16) { + if t.Year() < 1980 { + return 1<<5 | 1, 0 // 1980-01-01 + } + return uint16((t.Year()-1980)<<9 | int(t.Month())<<5 | t.Day()), + uint16(t.Hour()<<11 | t.Minute()<<5 | t.Second()/2) +} + +// crc16 is the CRC ARC and LHA keep (CRC-16/ARC: 0xA001 reflected, from 0). +func crc16(b []byte) uint16 { + var c uint16 + for _, x := range b { + c ^= uint16(x) + for i := 0; i < 8; i++ { + if c&1 != 0 { + c = c>>1 ^ 0xA001 + } else { + c >>= 1 + } + } + } + return c +} + +// crc32 is the CRC ARJ keeps (the usual one). +func crc32sum(b []byte) uint32 { return crc32.ChecksumIEEE(b) } + +func le16(b []byte) uint16 { return uint16(b[0]) | uint16(b[1])<<8 } +func le32(b []byte) uint32 { return uint32(le16(b)) | uint32(le16(b[2:]))<<16 } + +func put16(b []byte, v uint16) { b[0], b[1] = byte(v), byte(v>>8) } +func put32(b []byte, v uint32) { put16(b, uint16(v)); put16(b[2:], uint16(v>>16)) } + +// cString is a NUL-ended string's text. +func cString(b []byte) string { + if i := bytes.IndexByte(b, 0); i >= 0 { + b = b[:i] + } + return string(b) +} + +// sized is an Opener's start: refuse what is too big before taking any +// memory for it. +func sized(size, max int64) error { + if size < 0 || size > max { + return ErrTooBig + } + return nil +} diff --git a/internal/archive/archive_test.go b/internal/archive/archive_test.go new file mode 100644 index 0000000..962ee87 --- /dev/null +++ b/internal/archive/archive_test.go @@ -0,0 +1,229 @@ +package archive + +import ( + "bytes" + "errors" + "os" + "path/filepath" + "sort" + "strings" + "testing" + "time" +) + +// The testdata archives were made by the real programs (arc 5.21q, ARJ32 +// 3.10, jlha 0.1.6) from msgs.pkt, small.txt and rle.bin, and an empty +// file. +func originals(t *testing.T) map[string][]byte { + t.Helper() + m := map[string][]byte{"empty.pkt": {}} + for _, n := range []string{"msgs.pkt", "small.txt", "rle.bin"} { + b, err := os.ReadFile(filepath.Join("testdata", n)) + if err != nil { + t.Fatal(err) + } + m[n] = b + } + return m +} + +func TestRead(t *testing.T) { + want := originals(t) + for _, c := range []struct { + file string + kind Kind + names string + methods string + }{ + {"crunch.arc", ARC, "empty.pkt msgs.pkt small.txt", "crunched packed stored"}, + {"squash.arc", ARC, "msgs.pkt small.txt", "packed squashed"}, + {"store.arc", ARC, "rle.bin small.txt", "stored"}, + {"mixed.arc", ARC, "rle.bin sq.bin", "crunched"}, + {"m0.arj", ARJ, "rle.bin small.txt", "stored"}, + {"m1.arj", ARJ, "msgs.pkt rle.bin small.txt", "method 1"}, + {"m2.arj", ARJ, "msgs.pkt rle.bin small.txt", "method 2"}, + {"m3.arj", ARJ, "msgs.pkt rle.bin small.txt", "method 3"}, + {"m4.arj", ARJ, "msgs.pkt rle.bin small.txt", "method 4"}, + {"empty.arj", ARJ, "empty.pkt small.txt", "method 1 stored"}, + {"lh0.lzh", LHA, "rle.bin small.txt", "-lh0-"}, + {"lh5.lzh", LHA, "msgs.pkt rle.bin small.txt", "-lh5-"}, + {"lh5l0.lzh", LHA, "msgs.pkt small.txt", "-lh5-"}, + {"lh5l1.lzh", LHA, "msgs.pkt small.txt", "-lh5-"}, + {"lh6.lzh", LHA, "msgs.pkt rle.bin small.txt", "-lh6-"}, + {"lh7.lzh", LHA, "msgs.pkt rle.bin small.txt", "-lh7-"}, + } { + b, err := os.ReadFile(filepath.Join("testdata", c.file)) + if err != nil { + t.Fatal(err) + } + if k := Detect(b); k != c.kind { + t.Errorf("%s: detected as %q", c.file, k) + } + var names []string + methods := map[string]bool{} + err = WalkBytes(b, func(e Entry, open Opener) bool { + names = append(names, e.Name) + methods[e.Method] = true + data, err := open(1 << 20) + if err != nil { + t.Errorf("%s: %s (%s): %v", c.file, e.Name, e.Method, err) + return true + } + if int64(len(data)) != e.Size { + t.Errorf("%s: %s: %d bytes, the header says %d", c.file, e.Name, len(data), e.Size) + } + if w, ok := want[e.Name]; ok && !bytes.Equal(data, w) { + t.Errorf("%s: %s (%s) unpacks wrong", c.file, e.Name, e.Method) + } + if e.Modified.Year() != time.Now().Year() && e.Modified.Year() < 2020 { + t.Errorf("%s: %s: dated %v", c.file, e.Name, e.Modified) + } + return true + }) + if err != nil { + t.Errorf("%s: %v", c.file, err) + } + sort.Strings(names) + if got := strings.Join(names, " "); got != c.names { + t.Errorf("%s: entries %q, want %q", c.file, got, c.names) + } + var ms []string + for m := range methods { + ms = append(ms, m) + } + sort.Strings(ms) + if got := strings.Join(ms, " "); got != c.methods { + t.Errorf("%s: methods %q, want %q", c.file, got, c.methods) + } + } +} + +// TestWrite: each kind written, then read back. +func TestWrite(t *testing.T) { + want := originals(t) + files := []File{{Name: "msgs.pkt", Data: want["msgs.pkt"], Modified: time.Now()}, + {Name: "small.txt", Data: want["small.txt"], Modified: time.Now()}, + {Name: "empty.pkt", Data: nil, Modified: time.Now()}} + for _, k := range []Kind{ZIP, ARC, ARJ, LHA} { + var b bytes.Buffer + if err := Write(&b, k, "out."+string(k), files); err != nil { + t.Fatalf("%s: %v", k, err) + } + if got := Detect(b.Bytes()); got != k { + t.Errorf("%s: detected as %q", k, got) + } + n := 0 + err := WalkBytes(b.Bytes(), func(e Entry, open Opener) bool { + name := strings.ToLower(e.Name) + data, err := open(1 << 20) + if err != nil || !bytes.Equal(data, want[name]) { + t.Errorf("%s: %s: %v", k, e.Name, err) + } + n++ + return true + }) + if err != nil || n != 3 { + t.Errorf("%s: %d entries, %v", k, n, err) + } + } +} + +// TestHostile: damage, lies about sizes and truncation end in errors, +// never in a panic or a great deal of memory. +func TestHostile(t *testing.T) { + ents, _ := filepath.Glob("testdata/*.*") + for _, p := range ents { + b, _ := os.ReadFile(p) + if Detect(b) == "" { + continue + } + for _, cut := range []int{len(b) / 3, len(b) - 7, 40} { + if cut <= 0 || cut >= len(b) { + continue + } + WalkBytes(b[:cut], func(e Entry, open Opener) bool { open(1 << 20); return true }) + } + for i := 30; i < len(b); i += 97 { // a byte changed here and there + x := append([]byte(nil), b...) + x[i] ^= 0x5A + WalkBytes(x, func(e Entry, open Opener) bool { open(1 << 20); return true }) + } + } + // a size past the limit is refused before anything is unpacked + b, _ := os.ReadFile("testdata/m1.arj") + err := WalkBytes(b, func(e Entry, open Opener) bool { + if e.Name == "msgs.pkt" { + if _, err := open(100); !errors.Is(err, ErrTooBig) { + t.Errorf("a big entry: %v", err) + } + } + return true + }) + if err != nil { + t.Error(err) + } + // a damaged entry fails its CRC + b, _ = os.ReadFile("testdata/store.arc") + b[len(b)-10] ^= 1 + bad := false + WalkBytes(b, func(e Entry, open Opener) bool { + if _, err := open(1 << 20); errors.Is(err, ErrChecksum) { + bad = true + } + return true + }) + if !bad { + t.Error("a damaged entry passed") + } + if err := WalkBytes([]byte("not an archive at all"), func(Entry, Opener) bool { return true }); !errors.Is(err, ErrFormat) { + t.Errorf("text: %v", err) + } +} + +// TestSqueezed: ARC's method 4, which arc 5.21 no longer chooses, from a +// tree made by hand: a is 0, b is 10, the end is 11 (first bit lowest). +func TestSqueezed(t *testing.T) { + sq := []byte{2, 0, // two nodes + 0x9E, 0xFF, 1, 0, // node 0: a (-98), node 1 + 0x9D, 0xFF, 0xFF, 0xFE, // node 1: b (-99), the end (-257) + 0x34} // 0 0 10 11: a a b, the end + var arc []byte + h := make([]byte, 29) + h[0], h[1] = 0x1A, 4 + copy(h[2:], "AAB.TXT") + put32(h[15:], uint32(len(sq))) + put16(h[19:], 0x5B4D) + put16(h[23:], crc16([]byte("aab"))) + put32(h[25:], 3) + arc = append(append(append(arc, h...), sq...), 0x1A, 0) + got := "" + err := WalkBytes(arc, func(e Entry, open Opener) bool { + b, err := open(100) + if err != nil || e.Method != "squeezed" { + t.Errorf("%s: %v", e.Method, err) + } + got = string(b) + return true + }) + if err != nil || got != "aab" { + t.Errorf("%q, %v", got, err) + } +} + +// FuzzWalk: no archive, however made, panics or unpacks past its limit. +func FuzzWalk(f *testing.F) { + ents, _ := filepath.Glob("testdata/*.*") + for _, p := range ents { + if b, _ := os.ReadFile(p); Detect(b) != "" && len(b) < 2000 { + f.Add(b) + } + } + f.Fuzz(func(t *testing.T, b []byte) { + WalkBytes(b, func(e Entry, open Opener) bool { + if data, err := open(1 << 16); err == nil && len(data) > 1<<16 { + t.Fatalf("%d bytes past the limit", len(data)) + } + return true + }) + }) +} diff --git a/internal/archive/arj.go b/internal/archive/arj.go new file mode 100644 index 0000000..e341537 --- /dev/null +++ b/internal/archive/arj.go @@ -0,0 +1,218 @@ +package archive + +import ( + "bytes" + "io" + "strings" +) + +const arjMaxHeader = 2600 // ARJ's own limit on a basic header + +// arjHeader reads the header at off: its basic header, and where what +// follows it (its data) begins; nil at the end of the archive. +func arjHeader(r io.ReaderAt, size, off int64) (h []byte, next int64, err error) { + id, err := readAt(r, size, off, 4) + if err != nil { + return nil, 0, err + } + if id[0] != 0x60 || id[1] != 0xEA { + return nil, 0, ErrCorrupt + } + n := int64(le16(id[2:])) + if n == 0 { + return nil, 0, nil + } + if n < 30 || n > arjMaxHeader { + return nil, 0, ErrCorrupt + } + h, err = readAt(r, size, off+4, n+4) + if err != nil { + return nil, 0, err + } + if crc32sum(h[:n]) != le32(h[n:]) { + return nil, 0, ErrCorrupt + } + pos := off + 4 + n + 4 + for { // the extended headers: skipped + x, err := readAt(r, size, pos, 2) + if err != nil { + return nil, 0, err + } + xn := int64(le16(x)) + pos += 2 + if xn == 0 { + break + } + pos += xn + 4 + } + return h[:n], pos, nil +} + +// walkARJ reads an ARJ archive: methods 0 (stored) to 4. +func walkARJ(r io.ReaderAt, size int64, fn func(e Entry, open Opener) bool) error { + main, off, err := arjHeader(r, size, 0) + if err != nil { + return err + } + if main == nil || main[6] != 2 { + return ErrCorrupt // the first is the archive's own header + } + for { + h, data, err := arjHeader(r, size, off) + if err != nil { + return err + } + if h == nil { + return nil + } + first := int(h[0]) + if first < 30 || first > len(h) { + return ErrCorrupt + } + method := h[5] + ftype := h[6] + stamp := le32(h[8:]) + packed := int64(le32(h[12:])) + orig := int64(le32(h[16:])) + want := le32(h[20:]) + rest := h[first:] + name := cString(rest) + name = strings.ReplaceAll(name, "\\", "/") + e := Entry{Name: name, Size: orig, Packed: packed, Method: "stored", + Modified: dosTime(uint16(stamp>>16), uint16(stamp)), Dir: ftype == 3} + if method != 0 { + e.Method = "method " + string(rune('0'+method)) + } + open := func(max int64) ([]byte, error) { + if err := sized(orig, max); err != nil { + return nil, err + } + if h[4]&1 != 0 { + return nil, ErrMethod // garbled (a password) + } + src, err := readAt(r, size, data, packed) + if err != nil { + return nil, err + } + var out []byte + switch method { + case 0: + if packed != orig { + return nil, ErrCorrupt + } + out = src + case 1, 2, 3: + out, err = unhuf(src, orig, 16) + case 4: + out, err = unarj4(src, orig) + default: + return nil, ErrMethod + } + if err != nil { + return nil, err + } + if crc32sum(out) != want { + return nil, ErrChecksum + } + return out, nil + } + if ftype != 2 && !fn(e, open) { + return nil + } + off = data + packed + } +} + +// unarj4 unpacks ARJ's method 4 ("fastest"): a literal or a match, each +// of lengths and distances in a code of growing widths. +func unarj4(src []byte, size int64) ([]byte, error) { + r := &bitReader{b: src} + // a unary count of more widths from start up to stop, then that many bits + value := func(start, stop uint) int { + plus, pwr := 0, 1< 0 && int64(len(out)) < size; n-- { + if from < 0 { + out = append(out, ' ') + } else { + out = append(out, out[from]) + } + from++ + } + } + return out, nil +} + +// arjBasic is a basic header, its CRC after it. +func arjBasic(method, ftype byte, stamp, packed, orig, crc uint32, name string) []byte { + h := make([]byte, 30) + h[0] = 30 + h[1] = 11 // the version that wrote it: ARJ 2.50's + h[2] = 1 // the version to read it + h[3] = 0 // MS-DOS + h[5] = method + h[6] = ftype + put32(h[8:], stamp) + put32(h[12:], packed) + put32(h[16:], orig) + put32(h[20:], crc) + put16(h[26:], 0x20) // archive + h = append(h, name...) + h = append(h, 0, 0) // the name's end, an empty comment + var b bytes.Buffer + b.Write([]byte{0x60, 0xEA}) + var n [2]byte + put16(n[:], uint16(len(h))) + b.Write(n[:]) + b.Write(h) + var c [4]byte + put32(c[:], crc32sum(h)) + b.Write(c[:]) + b.Write([]byte{0, 0}) // no extended header + return b.Bytes() +} + +// writeARJ writes files stored (method 0) in an archive called name. +func writeARJ(w io.Writer, name string, files []File) error { + var b bytes.Buffer + b.Write(arjBasic(0, 2, 0, 0, 0, 0, name)) + for _, f := range files { + date, tm := dosStamp(f.Modified) + n := f.Name + if len(n) > 500 { + n = n[:500] + } + b.Write(arjBasic(0, 0, uint32(date)<<16|uint32(tm), uint32(len(f.Data)), uint32(len(f.Data)), + crc32sum(f.Data), n)) + b.Write(f.Data) + } + b.Write([]byte{0x60, 0xEA, 0, 0}) + _, err := w.Write(b.Bytes()) + return err +} diff --git a/internal/archive/huf.go b/internal/archive/huf.go new file mode 100644 index 0000000..d2fd26a --- /dev/null +++ b/internal/archive/huf.go @@ -0,0 +1,343 @@ +package archive + +// The static Huffman coding of LHA's -lh4- to -lh7- and ARJ's methods 1 +// to 3 (Haruhiko Okumura's, as both use it): blocks, each with its own +// code tables, of literals and (length, distance) pairs. + +// bitReader reads bits from the first (most significant) down, as LHA and +// ARJ write them; past the end it reads zeros (the output's size, known, +// ends the decoding). +type bitReader struct { + b []byte + pos int + buf uint32 // the next bits, from bit 31 down + n uint // how many of them are good +} + +func (r *bitReader) fill() { + for r.n <= 24 { + var c byte + if r.pos < len(r.b) { + c = r.b[r.pos] + } + r.pos++ + r.buf |= uint32(c) << (24 - r.n) + r.n += 8 + } +} + +// peek is the next 16 bits. +func (r *bitReader) peek() uint16 { + r.fill() + return uint16(r.buf >> 16) +} + +func (r *bitReader) skip(n uint) { + r.fill() + r.buf <<= n + r.n -= n +} + +// bits reads n (at most 16) bits. +func (r *bitReader) bits(n uint) uint16 { + if n == 0 { + return 0 + } + v := r.peek() >> (16 - n) + r.skip(n) + return v +} + +// overrun reports whether far more was read than there is: a corrupt +// stream decoding zeros. +func (r *bitReader) overrun() bool { return r.pos > len(r.b)+8 } + +const ( + hufThreshold = 3 + hufMaxMatch = 256 + hufNC = 255 + hufMaxMatch + 2 - hufThreshold // 510: literals and lengths + hufCBit = 9 + hufNT = 16 + 3 // the code lengths' code + hufTBit = 5 + hufMaxNP = 0x11 +) + +// huf decodes one stream. +type huf struct { + r bitReader + np int // positions' codes: the dictionary's bits + 1 + pbit uint // bits that say how many there are + blocksize int + cLen [hufNC]byte + ptLen [hufNT + hufMaxNP]byte + cTable [4096]uint16 + ptTable [256]uint16 + left [2*hufNC - 1]uint16 + right [2*hufNC - 1]uint16 +} + +// makeTable builds a decoding table of tablebits from code lengths, with +// a tree beside it for codes longer than that; false if the lengths do +// not make a code. +func (h *huf) makeTable(nchar int, bitlen []byte, tablebits uint, table []uint16) bool { + var count [17]uint32 + var start, weight [18]uint32 + for i := 0; i < nchar; i++ { + if bitlen[i] > 16 { + return false + } + count[bitlen[i]]++ + } + for i := 1; i <= 16; i++ { + start[i+1] = start[i] + count[i]<<(16-i) + } + if start[17] != 1<<16 { + return false + } + jut := 16 - tablebits + for i := uint(1); i <= tablebits; i++ { + start[i] >>= jut + weight[i] = 1 << (tablebits - i) + } + for i := tablebits + 1; i <= 16; i++ { + weight[i] = 1 << (16 - i) + } + if i := start[tablebits+1] >> jut; i != 1<<16>>jut { + for k := uint32(1) << tablebits; i < k; i++ { + table[i] = 0 + } + } + avail := nchar + mask := uint32(1) << (15 - tablebits) + for ch := 0; ch < nchar; ch++ { + l := uint(bitlen[ch]) + if l == 0 { + continue + } + next := start[l] + weight[l] + if l <= tablebits { + if next > 1<>jut] + for i := l - tablebits; i != 0; i-- { + if *p == 0 { + if avail >= len(h.left) { + return false + } + h.left[avail], h.right[avail] = 0, 0 + *p = uint16(avail) + avail++ + } + if int(*p) >= len(h.left) { + return false + } + if k&mask != 0 { + p = &h.right[*p] + } else { + p = &h.left[*p] + } + k <<= 1 + } + *p = uint16(ch) + } + start[l] = next + } + return true +} + +// readPtLen reads the lengths of a pt code: nn codes, nbit bits for how +// many; after the special'th (if any) a 2-bit count of zeros. +func (h *huf) readPtLen(nn int, nbit uint, special int) bool { + n := int(h.r.bits(nbit)) + if n == 0 { + c := h.r.bits(nbit) + for i := 0; i < nn; i++ { + h.ptLen[i] = 0 + } + for i := range h.ptTable { + h.ptTable[i] = c + } + return true + } + if n > nn { + return false + } + i := 0 + for i < n { + c := int(h.r.peek() >> 13) + if c == 7 { + for mask := uint16(1) << 12; mask&h.r.peek() != 0; mask >>= 1 { + c++ + if c > 16 { + return false + } + } + } + if c < 7 { + h.r.skip(3) + } else { + h.r.skip(uint(c - 3)) + } + h.ptLen[i] = byte(c) + i++ + if i == special { + for z := int(h.r.bits(2)); z > 0 && i < nn; z-- { + h.ptLen[i] = 0 + i++ + } + } + } + for ; i < nn; i++ { + h.ptLen[i] = 0 + } + return h.makeTable(nn, h.ptLen[:], 8, h.ptTable[:]) +} + +// readCLen reads the literals' and lengths' code lengths. +func (h *huf) readCLen() bool { + n := int(h.r.bits(hufCBit)) + if n == 0 { + c := h.r.bits(hufCBit) + for i := range h.cLen { + h.cLen[i] = 0 + } + for i := range h.cTable { + h.cTable[i] = c + } + return true + } + if n > hufNC { + return false + } + i := 0 + for i < n { + c := int(h.ptTable[h.r.peek()>>8]) + if c >= hufNT { + for mask := uint16(1) << 7; c >= hufNT; mask >>= 1 { + if mask == 0 || c >= len(h.left) { + return false + } + if h.r.peek()&mask != 0 { + c = int(h.right[c]) + } else { + c = int(h.left[c]) + } + } + } + h.r.skip(uint(h.ptLen[c])) + if c <= 2 { + switch c { + case 0: + c = 1 + case 1: + c = int(h.r.bits(4)) + 3 + default: + c = int(h.r.bits(hufCBit)) + 20 + } + for ; c > 0 && i < hufNC; c-- { + h.cLen[i] = 0 + i++ + } + } else { + h.cLen[i] = byte(c - 2) + i++ + } + } + for ; i < hufNC; i++ { + h.cLen[i] = 0 + } + return h.makeTable(hufNC, h.cLen[:], 12, h.cTable[:]) +} + +// decodeC is the next literal (below 256) or length code; -1 if the +// stream is broken. +func (h *huf) decodeC() int { + if h.blocksize == 0 { + h.blocksize = int(h.r.bits(16)) + if !h.readPtLen(hufNT, hufTBit, 3) || !h.readCLen() || !h.readPtLen(h.np, h.pbit, -1) { + return -1 + } + } + h.blocksize-- + j := int(h.cTable[h.r.peek()>>4]) + if j >= hufNC { + for mask := uint16(1) << 3; j >= hufNC; mask >>= 1 { + if mask == 0 || j >= len(h.left) { + return -1 + } + if h.r.peek()&mask != 0 { + j = int(h.right[j]) + } else { + j = int(h.left[j]) + } + } + } + h.r.skip(uint(h.cLen[j])) + return j +} + +// decodeP is the next distance (less one); -1 if the stream is broken. +func (h *huf) decodeP() int { + j := int(h.ptTable[h.r.peek()>>8]) + if j >= h.np { + for mask := uint16(1) << 7; j >= h.np; mask >>= 1 { + if mask == 0 || j >= len(h.left) { + return -1 + } + if h.r.peek()&mask != 0 { + j = int(h.right[j]) + } else { + j = int(h.left[j]) + } + } + } + h.r.skip(uint(h.ptLen[j])) + if j != 0 { + j = 1<<(j-1) + int(h.r.bits(uint(j-1))) + } + return j +} + +// unhuf unpacks size bytes coded so, with distances of up to dicbit bits. +// Before the start the dictionary is spaces, as LHA's is. +func unhuf(src []byte, size int64, dicbit uint) ([]byte, error) { + h := &huf{r: bitReader{b: src}, np: int(dicbit) + 1, pbit: 4} + if dicbit > 13 { + h.pbit = 5 + } + out := make([]byte, 0, size) + for int64(len(out)) < size { + if h.r.overrun() { + return nil, ErrCorrupt + } + c := h.decodeC() + switch { + case c < 0: + return nil, ErrCorrupt + case c < 256: + out = append(out, byte(c)) + default: + n := c - 256 + hufThreshold + p := h.decodeP() + if p < 0 { + return nil, ErrCorrupt + } + from := len(out) - p - 1 + for ; n > 0 && int64(len(out)) < size; n-- { + if from < 0 { + out = append(out, ' ') + } else { + out = append(out, out[from]) + } + from++ + } + } + } + return out, nil +} diff --git a/internal/archive/lha.go b/internal/archive/lha.go new file mode 100644 index 0000000..4dd8693 --- /dev/null +++ b/internal/archive/lha.go @@ -0,0 +1,183 @@ +package archive + +import ( + "bytes" + "io" + "strings" + "time" +) + +// lhaDicbit is each LHA method's dictionary's bits (0: stored). +var lhaDicbit = map[string]uint{"-lh0-": 0, "-lz4-": 0, "-lhd-": 0, "-lh4-": 12, "-lh5-": 13, "-lh6-": 15, "-lh7-": 16} + +// walkLHA reads an LHA (LZH) archive: headers of levels 0, 1 and 2. +func walkLHA(r io.ReaderAt, size int64, fn func(e Entry, open Opener) bool) error { + off := int64(0) + for off < size { + first, err := readAt(r, size, off, 1) + if err != nil || first[0] == 0 { + return nil // the end (a 0, or the file ends) + } + base, err := readAt(r, size, off, 22) + if err != nil { + return ErrCorrupt + } + method := string(base[2:7]) + packed := int64(le32(base[7:])) + orig := int64(le32(base[11:])) + level := base[20] + var name, dir string + var mod time.Time + var headerLen int64 // to the data + var want uint16 + switch level { + case 0, 1: + hsize := int64(base[0]) + h, err := readAt(r, size, off, hsize+2) + if err != nil || hsize < 22 { + return ErrCorrupt + } + var sum byte + for _, c := range h[2:] { + sum += c + } + if sum != h[1] { + return ErrCorrupt + } + mod = dosTime(le16(h[17:]), le16(h[15:])) + nl := int64(h[21]) + if 22+nl+2 > hsize+2 { + return ErrCorrupt + } + name = string(h[22 : 22+nl]) + want = le16(h[22+nl:]) + headerLen = hsize + 2 + if level == 1 { + // the extended headers, whose size the packed size counts + next := int64(le16(h[hsize:])) + for next != 0 { + x, err := readAt(r, size, off+headerLen, next) + if err != nil || next < 3 { + return ErrCorrupt + } + name, dir = lhaExt(x[:next-2], name, dir) + headerLen += next + packed -= next + next = int64(le16(x[next-2:])) + } + } + case 2: + total := int64(le16(base[0:])) + h, err := readAt(r, size, off, total) + if err != nil || total < 26 { + return ErrCorrupt + } + mod = time.Unix(int64(le32(h[15:])), 0) + want = le16(h[21:]) + pos := int64(24) + next := int64(le16(h[pos:])) + pos += 2 + for next != 0 { + if next < 3 || pos+next > total { + return ErrCorrupt + } + x := h[pos : pos+next] + name, dir = lhaExt(x[:next-2], name, dir) + pos += next + next = int64(le16(x[next-2:])) + } + headerLen = total + default: + return ErrMethod + } + if packed < 0 || orig < 0 { + return ErrCorrupt + } + if dir != "" { + name = dir + "/" + name + } + name = strings.ReplaceAll(name, "\\", "/") + dataOff := off + headerLen + dicbit, known := lhaDicbit[method] + e := Entry{Name: name, Size: orig, Packed: packed, Method: method, Modified: mod, Dir: method == "-lhd-"} + open := func(max int64) ([]byte, error) { + if err := sized(orig, max); err != nil { + return nil, err + } + if !known { + return nil, ErrMethod + } + src, err := readAt(r, size, dataOff, packed) + if err != nil { + return nil, err + } + var out []byte + if dicbit == 0 { + if packed != orig { + return nil, ErrCorrupt + } + out = src + } else if out, err = unhuf(src, orig, dicbit); err != nil { + return nil, err + } + if crc16(out) != want { + return nil, ErrChecksum + } + return out, nil + } + if !fn(e, open) { + return nil + } + off = dataOff + packed + } + return nil +} + +// lhaExt reads an extended header: the file's name, its directory. +func lhaExt(x []byte, name, dir string) (string, string) { + if len(x) == 0 { + return name, dir + } + switch x[0] { + case 0x01: + name = string(x[1:]) + case 0x02: + dir = strings.Trim(strings.ReplaceAll(string(x[1:]), "\xff", "/"), "/") + } + return name, dir +} + +// writeLHA writes files stored (-lh0-), with level 0 headers. +func writeLHA(w io.Writer, files []File) error { + var b bytes.Buffer + for _, f := range files { + name := []byte(f.Name) + if len(name) > 200 { + name = name[:200] + } + hsize := 22 + len(name) + h := make([]byte, hsize+2) + h[0] = byte(hsize) + copy(h[2:], "-lh0-") + put32(h[7:], uint32(len(f.Data))) + put32(h[11:], uint32(len(f.Data))) + date, tm := dosStamp(f.Modified) + put16(h[15:], tm) + put16(h[17:], date) + h[19] = 0x20 // archive + h[20] = 0 // level 0 + h[21] = byte(len(name)) + copy(h[22:], name) + put16(h[22+len(name):], crc16(f.Data)) + var sum byte + for _, c := range h[2:] { + sum += c + } + h[1] = sum + b.Write(h) + b.Write(f.Data) + } + b.WriteByte(0) + _, err := w.Write(b.Bytes()) + return err +} diff --git a/internal/archive/testdata/crunch.arc b/internal/archive/testdata/crunch.arc new file mode 100644 index 0000000..2c363e2 Binary files /dev/null and b/internal/archive/testdata/crunch.arc differ diff --git a/internal/archive/testdata/empty.arj b/internal/archive/testdata/empty.arj new file mode 100644 index 0000000..6fd510d Binary files /dev/null and b/internal/archive/testdata/empty.arj differ diff --git a/internal/archive/testdata/lh0.lzh b/internal/archive/testdata/lh0.lzh new file mode 100644 index 0000000..9f9976d Binary files /dev/null and b/internal/archive/testdata/lh0.lzh differ diff --git a/internal/archive/testdata/lh5.lzh b/internal/archive/testdata/lh5.lzh new file mode 100644 index 0000000..b816991 Binary files /dev/null and b/internal/archive/testdata/lh5.lzh differ diff --git a/internal/archive/testdata/lh5l0.lzh b/internal/archive/testdata/lh5l0.lzh new file mode 100644 index 0000000..9722fc3 Binary files /dev/null and b/internal/archive/testdata/lh5l0.lzh differ diff --git a/internal/archive/testdata/lh5l1.lzh b/internal/archive/testdata/lh5l1.lzh new file mode 100644 index 0000000..5662f1f Binary files /dev/null and b/internal/archive/testdata/lh5l1.lzh differ diff --git a/internal/archive/testdata/lh6.lzh b/internal/archive/testdata/lh6.lzh new file mode 100644 index 0000000..a9ef123 Binary files /dev/null and b/internal/archive/testdata/lh6.lzh differ diff --git a/internal/archive/testdata/lh7.lzh b/internal/archive/testdata/lh7.lzh new file mode 100644 index 0000000..073c36c Binary files /dev/null and b/internal/archive/testdata/lh7.lzh differ diff --git a/internal/archive/testdata/m0.arj b/internal/archive/testdata/m0.arj new file mode 100644 index 0000000..c0633f9 Binary files /dev/null and b/internal/archive/testdata/m0.arj differ diff --git a/internal/archive/testdata/m1.arj b/internal/archive/testdata/m1.arj new file mode 100644 index 0000000..d3530b3 Binary files /dev/null and b/internal/archive/testdata/m1.arj differ diff --git a/internal/archive/testdata/m2.arj b/internal/archive/testdata/m2.arj new file mode 100644 index 0000000..50630c4 Binary files /dev/null and b/internal/archive/testdata/m2.arj differ diff --git a/internal/archive/testdata/m3.arj b/internal/archive/testdata/m3.arj new file mode 100644 index 0000000..5509531 Binary files /dev/null and b/internal/archive/testdata/m3.arj differ diff --git a/internal/archive/testdata/m4.arj b/internal/archive/testdata/m4.arj new file mode 100644 index 0000000..75230a5 Binary files /dev/null and b/internal/archive/testdata/m4.arj differ diff --git a/internal/archive/testdata/mixed.arc b/internal/archive/testdata/mixed.arc new file mode 100644 index 0000000..e93036d Binary files /dev/null and b/internal/archive/testdata/mixed.arc differ diff --git a/internal/archive/testdata/msgs.pkt b/internal/archive/testdata/msgs.pkt new file mode 100644 index 0000000..3db542a --- /dev/null +++ b/internal/archive/testdata/msgs.pkt @@ -0,0 +1,16 @@ +AREA:FSX_GEN MSGID: 21:1/100 00000000 Line 0 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000001 Line 1 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000002 Line 2 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000003 Line 3 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000004 Line 4 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000005 Line 5 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000006 Line 6 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000007 Line 7 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000008 Line 8 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000009 Line 9 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000000a Line 10 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000000b Line 11 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000000c Line 12 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000000d Line 13 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000000e Line 14 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000000f Line 15 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000010 Line 16 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000011 Line 17 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000012 Line 18 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000013 Line 19 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000014 Line 20 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000015 Line 21 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000016 Line 22 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000017 Line 23 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000018 Line 24 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000019 Line 25 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000001a Line 26 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000001b Line 27 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000001c Line 28 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000001d Line 29 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000001e Line 30 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000001f Line 31 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000020 Line 32 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000021 Line 33 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000022 Line 34 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000023 Line 35 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000024 Line 36 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000025 Line 37 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000026 Line 38 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000027 Line 39 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000028 Line 40 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000029 Line 41 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000002a Line 42 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000002b Line 43 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000002c Line 44 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000002d Line 45 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000002e Line 46 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000002f Line 47 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000030 Line 48 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000031 Line 49 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000032 Line 50 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000033 Line 51 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000034 Line 52 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000035 Line 53 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000036 Line 54 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000037 Line 55 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000038 Line 56 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000039 Line 57 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000003a Line 58 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000003b Line 59 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000003c Line 60 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000003d Line 61 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000003e Line 62 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000003f Line 63 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000040 Line 64 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000041 Line 65 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000042 Line 66 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000043 Line 67 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000044 Line 68 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000045 Line 69 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000046 Line 70 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000047 Line 71 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000048 Line 72 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000049 Line 73 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000004a Line 74 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000004b Line 75 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000004c Line 76 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000004d Line 77 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000004e Line 78 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000004f Line 79 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000050 Line 80 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000051 Line 81 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000052 Line 82 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000053 Line 83 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000054 Line 84 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000055 Line 85 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000056 Line 86 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000057 Line 87 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000058 Line 88 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000059 Line 89 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000005a Line 90 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000005b Line 91 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000005c Line 92 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000005d Line 93 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000005e Line 94 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000005f Line 95 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000060 Line 96 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000061 Line 97 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000062 Line 98 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000063 Line 99 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000064 Line 100 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000065 Line 101 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000066 Line 102 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000067 Line 103 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000068 Line 104 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000069 Line 105 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000006a Line 106 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000006b Line 107 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000006c Line 108 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000006d Line 109 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000006e Line 110 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000006f Line 111 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000070 Line 112 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000071 Line 113 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000072 Line 114 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000073 Line 115 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000074 Line 116 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000075 Line 117 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000076 Line 118 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000077 Line 119 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000078 Line 120 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000079 Line 121 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000007a Line 122 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000007b Line 123 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000007c Line 124 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000007d Line 125 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000007e Line 126 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000007f Line 127 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000080 Line 128 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000081 Line 129 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000082 Line 130 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000083 Line 131 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000084 Line 132 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000085 Line 133 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000086 Line 134 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000087 Line 135 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000088 Line 136 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000089 Line 137 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000008a Line 138 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000008b Line 139 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000008c Line 140 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000008d Line 141 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000008e Line 142 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000008f Line 143 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000090 Line 144 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000091 Line 145 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000092 Line 146 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000093 Line 147 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000094 Line 148 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000095 Line 149 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000096 Line 150 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000097 Line 151 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000098 Line 152 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000099 Line 153 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000009a Line 154 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000009b Line 155 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000009c Line 156 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000009d Line 157 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000009e Line 158 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000009f Line 159 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000a0 Line 160 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000a1 Line 161 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000a2 Line 162 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000a3 Line 163 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000a4 Line 164 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000a5 Line 165 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000a6 Line 166 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000a7 Line 167 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000a8 Line 168 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000a9 Line 169 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000aa Line 170 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ab Line 171 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ac Line 172 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ad Line 173 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ae Line 174 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000af Line 175 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000b0 Line 176 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000b1 Line 177 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000b2 Line 178 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000b3 Line 179 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000b4 Line 180 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000b5 Line 181 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000b6 Line 182 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000b7 Line 183 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000b8 Line 184 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000b9 Line 185 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ba Line 186 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000bb Line 187 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000bc Line 188 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000bd Line 189 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000be Line 190 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000bf Line 191 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000c0 Line 192 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000c1 Line 193 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000c2 Line 194 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000c3 Line 195 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000c4 Line 196 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000c5 Line 197 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000c6 Line 198 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000c7 Line 199 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000c8 Line 200 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000c9 Line 201 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ca Line 202 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000cb Line 203 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000cc Line 204 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000cd Line 205 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ce Line 206 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000cf Line 207 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000d0 Line 208 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000d1 Line 209 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000d2 Line 210 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000d3 Line 211 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000d4 Line 212 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000d5 Line 213 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000d6 Line 214 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000d7 Line 215 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000d8 Line 216 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000d9 Line 217 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000da Line 218 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000db Line 219 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000dc Line 220 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000dd Line 221 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000de Line 222 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000df Line 223 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000e0 Line 224 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000e1 Line 225 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000e2 Line 226 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000e3 Line 227 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000e4 Line 228 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000e5 Line 229 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000e6 Line 230 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000e7 Line 231 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000e8 Line 232 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000e9 Line 233 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ea Line 234 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000eb Line 235 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ec Line 236 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ed Line 237 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ee Line 238 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ef Line 239 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000f0 Line 240 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000f1 Line 241 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000f2 Line 242 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000f3 Line 243 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000f4 Line 244 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000f5 Line 245 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000f6 Line 246 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000f7 Line 247 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000f8 Line 248 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000f9 Line 249 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000fa Line 250 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000fb Line 251 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000fc Line 252 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000fd Line 253 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000fe Line 254 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 000000ff Line 255 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000100 Line 256 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000101 Line 257 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000102 Line 258 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000103 Line 259 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000104 Line 260 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000105 Line 261 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000106 Line 262 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000107 Line 263 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000108 Line 264 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000109 Line 265 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000010a Line 266 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000010b Line 267 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000010c Line 268 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000010d Line 269 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000010e Line 270 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000010f Line 271 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000110 Line 272 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000111 Line 273 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000112 Line 274 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000113 Line 275 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000114 Line 276 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000115 Line 277 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000116 Line 278 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000117 Line 279 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000118 Line 280 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000119 Line 281 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000011a Line 282 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000011b Line 283 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000011c Line 284 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000011d Line 285 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000011e Line 286 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000011f Line 287 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000120 Line 288 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000121 Line 289 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000122 Line 290 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000123 Line 291 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000124 Line 292 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000125 Line 293 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000126 Line 294 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000127 Line 295 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000128 Line 296 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 00000129 Line 297 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000012a Line 298 of a message, hello hello hello world. AREA:FSX_GEN MSGID: 21:1/100 0000012b Line 299 of a message, hello hello hello world. ¥MÊ%0»m,ÞÖ#{.Ù?rËqD”ÖI<�\4`¾1 iþÚ îè¹™\|)™ý¯å“%<ÖT¯Mú×' ®³þé#/Šò!žä‘ű ìµV;üo“B~ËÈþ)UåÍŽFÜŽÔ·ÂvM*ZMvwø]†�JÖ½£@éÈËÌÉ5öÍa"jáS8®4M3º $jÀL�±ºò>;ùîõ÷Ÿ+I4¯‡õR i¹K ˜.…»U¶r¨rczÍtfü¶�ñ„c°ä²º)p4tðd¬h÷õ°+=Æfô[Þª,ÊíÍ+QWAMîJò³OC +4GÞcl€l•{¦„ÖCµê×BM á]LXHò=¦÷6a�2ç â¦f�çô~„gåFÕ>Èâ¡%{Û%l›>O»I�Fïp0ËùSrRÜέ×d¶£/» ­êá Ä©— 9u5+‡‹\ŠBØ„ÏLý§-Ž]Ù%‰-…*q"‡>è­Õ‰Bz8R†\gŸœi”ä[б € aó}ä6ÝýÉ�nu¯eGϱB$‚ÜS+Ã�|–ë^P‰ä†º¨¥}žo¶]«Ã*óŽf.‡-IÌÉ ™›w+OǦýL‘JÛGu+D¸5Àç }ú‡é#/!ò�&‡xivëüÃ'õ“e'K©‚›Döø‰2oú”’íîî––�‰¾‚…eà~_}xN�`§!Ê€}v3í4óvå¿–w=ac&¾[å…6³o¼®Hh‚h§Ñ¾^Ÿ'hý÷ Ð3ÊO.SËŠÑ‘�ÕŸ¶ÔÕ ºdÈÏhÞPØ:.ϺëSBHË-½WJ²‘RW"7Äûeš@÷¡Æ,RqÏdò]oÌPÄ·?L~b¥<Çéœ×�ÙǼäà[ úîxäê[òÌ6"A·Ü».âB* (ÁE !8cCû“Tq!³�Q¥ŒéI‚õj†y£¾e]ÎRާÀV‡:¸ç5�ɾ‡À¼J¸©)âuZ—�ž qL”ÝÕºCút µ›6¶rÓšDh»óQD|Læ1 JŠÍ‡³ãüT Ï_yQ5dHÓfÔYž ™ôÀßî)çYs5…v?«†ˆß‡—o+V…xgQ§bǨzÂðñ ßw�lÈ'WJ 96R°HF"!ºf!Ä6~ih9,“ô3C2h–£¬Ø… +³ƒ�¼¤ó“Óß2±ðn.“Wßg“²û0û^ý±…Q‘mvÿT8)û5§¶0ÍÊ,Ø ¾i›†ÛWÂwë@²§Oæ¥Víàƒv@«ìybˆšOO~§²Rx§`„4T4dÄMKš˜ÞŒd76�iÆíÌßq—í HƒÏ|Ü×uu\?èÝ …2Ö|ÌP€Ø÷é +Ñ]§Çú6€oRf²3éhó½¯Òék^È>¶�ŒÃÌ&Ö×´‡7r›ÍpÈìlTB#bðsJ´Óï–@ðµuˆÀ�Ú_ö�·}š¤õøÛ+¹N›Å+¦G°k$–€3Iw_ç±NjÎU.˜eým(à;<‡ÖwGòü÷ïIû~ÿTR¤ïþ—î¿ÚÖ&\¸ +©0÷øImÔ@­0»®òk‘ޯ؀”•µüΪ‹°hü<©b¢™A,ÌÏÌ™7aóÀK*lêY3\×3¼Gž„š^×£ +Üþ<×Ïä"ÆOóÓ4*ñlMÚ>-o>Bñ �|æ_»J+–ÿë‚(ÇŸŸTù¡¼àðUJ;¹SÕôÅ狪•�ªMžÛ~ÀÆÀw瑤†‰ØP“HKŒÿ±+øÃfwžÊîi‚Åë,µ wË„¤ôg`lb/\”¹·ÎL~ü¿6¾í)O¡°� +0høm…�Ú1äC‚­f\Á*½êù Ë=.ƒ£w-É]åQ½xqXƒ´„÷3J¢e˜á5ñ¥¾ƒÇ?¿öÂVázIïcPp'¿Gä1Å &ç­¥wô;»I©q\çJàLˆÖÒ~O Š—«U…û7¢é÷:Nlô’=ƒgºÝ…zy1Ç”ÔS–Iâ®Gâ’_¸ÞÑo�\F\uYd(,ýŒYiFb�g!б«�ü.ÑôDˆ_»S¾¶ä$=¶}¤Ã•7ýä D +|-r]U4Ÿ€ 1c… ízã4³0[‹?îü�8>>ÏFttKìËT Ç×ʹ­Í{«ß¤Í¦K´Øº7_#¦Ýf +sG×Ë舋3€>Þy“9œ±U=‰+îKá?C–ГŒ|,“èqÅg»ë›ôðž|ªq`ÄÊ´Sz¥¦ûŠ‘n— Q"²áÆáµ7sOÕ¬´Gg�0ó‰AÓ4Ò<þËLÕ�8Âçê“´•´ÈĤÿÂã™^›JßÁv-©¥|¦hÚ ƒþ™ŸßÜÇí·³ç"u2Ñ¿ÍN`×ùÍá¯/W¹¢»&ŸY8–¯×P”j`Ó]6´Ò�›Ë2dYþˆIeÒ>JP63&WûïÜ¥Iyµ�Vˆ2 ²bæÅ +pÊázrQX¡é›Ö�ý"|ÇqÓžÌø |,XW·Â_”ʹ:«Å«Î!?س}Æaï‘°yߎ ®O{B/dŠAâïzQ¼´nÏÀj˜óhtçC…á¼~Îl@>.ŠÅJŸÇ,Zv¤`7"¹˜b!Ÿ-s“@Ì�¶ÎíC�Z»³Ó ìÍ´2]•:ŠpÏRÜe›OŸ[tþ‚Þ²9’}8£k°,ÕÉq�.²Ùâ®çiÛAú`…YSx…V·±Ò/gŸFEù÷y{ãD³™DH{ª<ÙVOìÏi:”¸ùi�›d8žå9R¦ãï¹”V$ïø*©‡7úÞúa¤·.’€}(F ÊJ—¼_V4ž§Â^¶£u¼E½�z6ÎnýØÿP™)HtSFâÍ-áõao¾ÙI‘$×­ àZTÁ—â²dð+¥ëÛOÍ)©˜×¼öF™¯`qå+K¾Õ¸{áÊ…:t\g9q�0`€útês9)Ð%áD:4ëÈWbó/F¿Ïy¾më™=EÚ,g:µV»®‚>z¾¶ú´3¶§9|‚µbä +á: +ù8%„^L”ÂI€‰ã ¯Mù÷&]ÈóQåÉu&¸¨nŸClV¸ï©ïƵ «÷ªt +ëJI‹Ä‹ †¶G0fÚ2¹�yH$›®¹}³Ï«¬¥ö¼|x²MEièÏäÊšV!Iš��®%a([›´ï¶Û"ø£Y�ƒ T‰y +oÌåf�2d{B(%®E`Š¥l¤§ øÏ¬YÔ,«ý̃í ¢ Ô¨P/ OkI.·¹Ø°N©u„ôžè޹ŒC�ó3¹MtÍ.D>h]„»LZR³|âÿm°Çël¥ 7!ͳtÀÑÀr€ +†Þ{vµh¦ÙŽ˜ÿnPôˆE™�-©øR£çlk¸à]ÞG˜ 9MDšM´1VíË.Ô­Ë«xgEvÜ5���������������������������������������������������������������������������������������������������� \ No newline at end of file diff --git a/internal/archive/testdata/rle.bin b/internal/archive/testdata/rle.bin new file mode 100644 index 0000000..a0ee14c --- /dev/null +++ b/internal/archive/testdata/rle.bin @@ -0,0 +1 @@ +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB�������xyz \ No newline at end of file diff --git a/internal/archive/testdata/small.txt b/internal/archive/testdata/small.txt new file mode 100644 index 0000000..0302f82 --- /dev/null +++ b/internal/archive/testdata/small.txt @@ -0,0 +1,2 @@ +FILE_ID.DIZ text +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA diff --git a/internal/archive/testdata/sq.bin b/internal/archive/testdata/sq.bin new file mode 100644 index 0000000..7e8e3ad --- /dev/null +++ b/internal/archive/testdata/sq.bin @@ -0,0 +1 @@ +abbaadbabbabadcaabaababcbaabcaabacdbababcaacbaacaccaabbddabcdaabcbadadaaaaaaabacbcaabcababbabadabddacabbbabcabdbbabbabcbaaaaacbaaacaadaaaacacaabbcaabbabddabaaaaaabbaaaabaabacaaaadcaaacbabcbbbabcbaabbbadaaababaacabaaabbbaabbaaabdabbabaababaaabaabbaaaaacacbaacaaccabbbaababcaaaababbaabaabcaaccaaabbadbaaacaabaacccbacaaccbacbabaaabccaaabaaabaadaaaaacdbbabdbaabaccbbbabadacacbaacaaadcbbdadddabaaabaabaababbaadbaaaacbaccaaaaabdcaaacaddcacdaabbcaacaaabbbaaaaccacacaaaaaaacbabbaaaaaaababaaaaaaaababbacabaaaabbcbabcabdaaabacbaabaaaaababbacaaaadadaadbccaaabacbbcdbcabababbacbbaaaacaabababdaacaaccaacabacbabacaacbbbbaabbadbabacbacaaabaabbcaaabaabaaabadacbaabbcbbdbbaabaddaaaabadbbabbcaaacaabbadacbbcabbcabcbbadaaaaacaaabaaaaccaababbaabcdcbbaabacacbdaadadabbcbaacaadacaaabbbcaddaacaaaaabcaaaacdaaaabbbaaaaaaaaaabbbaaabaadaabaaadbdaabbabcacaabbbbccaacabbbbababaababbbbabbbbaaaddbaaadbadabbbbababaaaacabaabacbbbbaaaaaaacaaabaabcbadaaabccaaacaaabababcdbaabababbacbabbacacabbabaacaacaaccadacaabdbababbbadcbaababbaaccbaaabbaaacbaacbdbaababdaaacabdaaababaabadaaacabbaaccbcdababacadacaabcaaaacaaacabaaaababcaabaaaaacbaaaadabaacaababaaacaacaacabaaaaabababaaabaaaaacaaaaaabbaaaaaaaddaaaaaaaabaadabacbaacacdaaabaacabaaaabaabbaaabaaabaaaabbdaadcaacadabaaacbbaaaacaabababbcdaacbcbacbadaacaaaacbaaacabbcbdbbaaaaabcacaacbbbaaabccbadbcaaadcbbaaaaaacdaabaaaacbaabaadbabaaaaaacbbabcdbacdbcaaabaaccabacaadaaaaaaccbbabacbcbaabbacaacbacaaabaaabbaaaaacadbbbaacbabbaaacaaaaaaaaaabdabacdbbadbbcaaadbaadcaabdaadaadaabaabbabaaabaaaaaaababcaaaaadaaaaaaccbaacdbaaaaaabbaacaaaaadaccabadcbaaabbabaaaaaccaacabaaaaaaadacabbcaaaaabcaabaaaaaabbadccbaabcccabccabaaaaaaabadcdaabbcdccbbaabbaaaabacbaacaaaacaaababaabaaacacadbbaaabbbaaaacbcdaaabaaabadccbaaadaabacaaaaaaaababaaaaaadaaaababbabbcabccdaabaaaaaaabbaaaaaaadbabababaaaaacbaaabcacaababaacaaaaaaaaaaaaaadbadaaaaaaaabdaabcaaababbccabaabbaaabacaacbadbcbaaccaaacaaabaabcaabaacacabbabbcaaabbaaabbaaabbabababbcbdacbcaaaaaabbababbaaaaaaaabccabbbabaaaabcbcaaacaaaaabaabadaabcabbaaaabaaaadbbdabaaaaaaabaadaaaaaaaabbdababacbccdaaabbabddaaaadaabaacabdaaacaaaacaaaaaabbabbbaaaabbbdaaadcbaacaaadabdacbabadbadaabaaabbaddbbabcaaacaccdbaaaabbaabaadbabbabbaaccdbcbbbaaabacabaaccaacaaaddbacaaacaaaaadcbcbaaaaaaaaaaaababaaaaaabaaabaacbabaabcbabbababaaaaacbcaaabaabdabaaacbaaabacaabaacbabaaabacaabbacdaaaabacbababcbbabdbdabaacdbbadaabbbcaaaabaaababcabaabaadbaabaaadabbaabababaabbaaabbadacbbaaaaaabaaaaaaaaaaaabaabcbabaaacabadaacbacaaaaaaccaaabaabaadcababbbbacaaababdaaaaaabaaccabbacbbbaaabbbbdaaaaabaaabaaababcbbaaaabadbaaababcbababbbaaabcaaabbaaaaabbacaaacaaacbadbbabaaaacaaaaaaaaaababbbaaaaaabaaaabbabcbabdbabbabacaacabbaadbbaabaabaaabaaaaaacabdcaaaaabaabbcadaaabaacaaacacaabbaabaabaaaababbcbbabaababcbaaaabadaabbabcaaaabaaaabbacabaaaababaaacabababababaaaaaabadbaaadabbaaacaabccaadbaabaaadacbababcabcaaaabbbabaaaabbbadaabdbcbacaacbdaaabadabcadaaaaabcbaaababdaababaabaaaaaaadaacacaabdaabacacbabbaabbaccadacacbacaaaaaaadadbbcaaaaabdaabacbaadaaabaaadcabacbcbaababbaaacaabaaaaacabbaadabaaaacbacaaaacaaccaaacbacaaaababadbaababaaaabaaababcaabcaaaabacacadabaaaabcbaabacaabadbbbaadcabaacaaabaacaabaaabddbaababbacabacabbbaacbaabcaabbabaabbdcacbaaacabdaacaabdbbaaaacccaaaaadababaabacadabaabbaaabbabbcbabdabbbaccbaccaacbacacaabaacababdbaaadabaabbaaabacbbaaaaaabadcbacaababbaacbaaaaabaadbaacaaaaaaaacabcaabbbbaacbabaababaacccabaaaabbaaadacadbbcbadaaaaaaaccaabaabdacabacaaaaaadbadabadabbababcaabaabaaadbaabaaaaabcacdbbccaddaccacaacbaaaabaaccbbaccaaacdbbbabbcaababaaadbccabaabbcabcabbabaacbaaabdcababbabdbaccaccbbbaabaabbaaddacaccbaabaabcbcccaaacaabbacabaadabaaacaabdbacaaaabaacbaabacabbaacbcabbbdacaaabaaababcaaaabcaaabaadacaaacdacaaaababbabccaaaaabaadabbaaaabaaadbadcabacbadabaabbaaaccadacacabdababcadaaaaabaaaacbbbbdaabddbaaaaccddcaabaacabacbaaadaacaaacbcdaadbaaacdacdabbaaaaaaaaaacabbbabacdcabdaaaaacbaabbaacbabbbaaaaabbaabbaaaabcbbbcabaaabbbaabbdacbcaabbbbbaaabaabbabcababbaabacaabcbbbadaadabaabaaaaacbbbcaacababaabaaabdbabcaaabdabaaaababcacdacaacaacaaaaacbbabaabbadbddcbbabaaababcbaaacaaabbdadaaaacabaaabaaacaaaddbab \ No newline at end of file diff --git a/internal/archive/testdata/squash.arc b/internal/archive/testdata/squash.arc new file mode 100644 index 0000000..d7b2b5c Binary files /dev/null and b/internal/archive/testdata/squash.arc differ diff --git a/internal/archive/testdata/store.arc b/internal/archive/testdata/store.arc new file mode 100644 index 0000000..ead594e Binary files /dev/null and b/internal/archive/testdata/store.arc differ diff --git a/internal/archive/write.go b/internal/archive/write.go new file mode 100644 index 0000000..f320962 --- /dev/null +++ b/internal/archive/write.go @@ -0,0 +1,46 @@ +package archive + +import ( + "archive/zip" + "bytes" + "io" + "time" +) + +// File is a file to put in an archive. +type File struct { + Name string + Data []byte + Modified time.Time +} + +// Write writes files as an archive of the kind (called name, which ARJ +// keeps): ZIP deflated, the others stored. +func Write(w io.Writer, kind Kind, name string, files []File) error { + switch kind { + case ZIP: + var b bytes.Buffer + zw := zip.NewWriter(&b) + for _, f := range files { + fw, err := zw.CreateHeader(&zip.FileHeader{Name: f.Name, Method: zip.Deflate, Modified: f.Modified}) + if err != nil { + return err + } + if _, err := fw.Write(f.Data); err != nil { + return err + } + } + if err := zw.Close(); err != nil { + return err + } + _, err := w.Write(b.Bytes()) + return err + case ARC: + return writeARC(w, files) + case ARJ: + return writeARJ(w, name, files) + case LHA: + return writeLHA(w, files) + } + return ErrFormat +} diff --git a/internal/archive/zip.go b/internal/archive/zip.go new file mode 100644 index 0000000..0444b73 --- /dev/null +++ b/internal/archive/zip.go @@ -0,0 +1,46 @@ +package archive + +import ( + "archive/zip" + "bytes" + "io" + "strings" +) + +func walkZIP(r io.ReaderAt, size int64, fn func(e Entry, open Opener) bool) error { + z, err := zip.NewReader(r, size) + if err != nil { + return ErrFormat + } + for _, f := range z.File { + method := "deflated" + if f.Method == zip.Store { + method = "stored" + } + e := Entry{Name: f.Name, Size: int64(f.UncompressedSize64), Packed: int64(f.CompressedSize64), + Method: method, Modified: f.Modified, Dir: strings.HasSuffix(f.Name, "/")} + open := func(max int64) ([]byte, error) { + if err := sized(e.Size, max); err != nil { + return nil, err + } + rc, err := f.Open() + if err != nil { + return nil, ErrMethod + } + defer rc.Close() + var b bytes.Buffer + n, err := io.Copy(&b, io.LimitReader(rc, max+1)) + if n > max { + return nil, ErrTooBig + } + if err != nil { + return nil, ErrChecksum // archive/zip checks the CRC as it ends + } + return b.Bytes(), nil + } + if !fn(e, open) { + return nil + } + } + return nil +} diff --git a/internal/fido/binkd_test.go b/internal/fido/binkd_test.go index 7752372..74309d9 100644 --- a/internal/fido/binkd_test.go +++ b/internal/fido/binkd_test.go @@ -13,6 +13,7 @@ import ( "testing" "time" + "github.com/Neo-Desktop/bbs-sec/internal/archive" "github.com/Neo-Desktop/bbs-sec/internal/bbs" "github.com/Neo-Desktop/bbs-sec/internal/ftn" "github.com/Neo-Desktop/bbs-sec/internal/store" @@ -170,7 +171,7 @@ node 21:1/200@fidonet %s secret b := bbs.New(bbs.Defaults(), st, nil) b.Log.SetOutput(lb) link := &Link{Name: "hub", Addr: mustAddr("21:1/100"), Host: hubAddr, Password: "secret", - Echoes: "TEST", Route: true, Zip: true} + Echoes: "TEST", Route: true, Packer: archive.ZIP} f, err := New(b, Settings{Addrs: []ftn.Addr{mustAddr("21:1/200")}, System: "Our BBS", Sysop: "Alice", Origin: "Our BBS", Dir: filepath.Join(dir, "fido"), Links: []*Link{link}}) if err != nil { diff --git a/internal/fido/fido.go b/internal/fido/fido.go index c1fa0bf..009b252 100644 --- a/internal/fido/fido.go +++ b/internal/fido/fido.go @@ -14,6 +14,7 @@ import ( "syscall" "time" + "github.com/Neo-Desktop/bbs-sec/internal/archive" "github.com/Neo-Desktop/bbs-sec/internal/bbs" "github.com/Neo-Desktop/bbs-sec/internal/ftn" "github.com/Neo-Desktop/bbs-sec/internal/news" @@ -37,13 +38,13 @@ type Settings struct { type Link struct { Name string Addr ftn.Addr - Host string // host:port to call it ("": it calls us) - Password string // binkp session password - PlainOK bool // the password may be sent in the clear (no CRAM-MD5) - PktPassword string // packets' password ("": not checked, none sent) - Echoes string // wildmat of the echo tags exchanged - Route bool // netmail for nodes that are not links goes here - Zip bool // bundles: ZIP (ARCmail), else bare packets + Host string // host:port to call it ("": it calls us) + Password string // binkp session password + PlainOK bool // the password may be sent in the clear (no CRAM-MD5) + PktPassword string // packets' password ("": not checked, none sent) + Echoes string // wildmat of the echo tags exchanged + Route bool // netmail for nodes that are not links goes here + Packer archive.Kind // bundles' format (ARCmail): ZIP, ARC, ARJ, LHA ("": bare packets) Poll time.Duration AKA ftn.Addr // ours to use with it (zero: by its zone) } diff --git a/internal/fido/fido_test.go b/internal/fido/fido_test.go index c0edb2a..5e778bc 100644 --- a/internal/fido/fido_test.go +++ b/internal/fido/fido_test.go @@ -3,15 +3,18 @@ package fido import ( "bytes" "context" + "fmt" "log" "net" "os" + "os/exec" "path/filepath" "strings" "sync" "testing" "time" + "github.com/Neo-Desktop/bbs-sec/internal/archive" "github.com/Neo-Desktop/bbs-sec/internal/bbs" "github.com/Neo-Desktop/bbs-sec/internal/ftn" "github.com/Neo-Desktop/bbs-sec/internal/store" @@ -127,11 +130,11 @@ func (s *system) messages(t *testing.T) []*store.Message { func TestEchomailAndNetmail(t *testing.T) { // hub 21:1/100 with nodes 21:1/200 and 21:1/300; 200 calls the hub, // the hub calls 300 - hubTo200 := &Link{Name: "n200", Addr: mustAddr("21:1/200"), Password: "pw200", Echoes: "*", Zip: true} + hubTo200 := &Link{Name: "n200", Addr: mustAddr("21:1/200"), Password: "pw200", Echoes: "*", Packer: archive.ZIP} hubTo300 := &Link{Name: "n300", Addr: mustAddr("21:1/300"), Password: "pw300", Echoes: "*"} hub := newSystem(t, "21:1/100", hubTo200, hubTo300) n200 := newSystem(t, "21:1/200", &Link{Name: "hub", Addr: mustAddr("21:1/100"), Host: hub.host, - Password: "pw200", Echoes: "*", Zip: true, Route: true}) + Password: "pw200", Echoes: "*", Packer: archive.ZIP, Route: true}) n300 := newSystem(t, "21:1/300", &Link{Name: "hub", Addr: mustAddr("21:1/100"), Password: "pw300", Echoes: "TEST"}) hubTo300.Host = n300.host @@ -361,3 +364,96 @@ func TestGateway(t *testing.T) { t.Fatalf("%+v", em) } } + +// TestBundles: echomail in ARC, ARJ and LHA bundles (stored, as written +// here) is tossed like ZIP's; the bundle is named as ARCmail is, +// whatever is in it. +func TestBundles(t *testing.T) { + for _, k := range []archive.Kind{archive.ARC, archive.ARJ, archive.LHA} { + t.Run(string(k), func(t *testing.T) { + hub := newSystem(t, "21:1/100", &Link{Name: "n200", Addr: mustAddr("21:1/200"), Password: "pw", Echoes: "*"}) + n200 := newSystem(t, "21:1/200", &Link{Name: "hub", Addr: mustAddr("21:1/100"), Host: hub.host, + Password: "pw", Echoes: "*", Packer: k}) + n200.f.ScanAll() + if _, err := n200.node(t, "alice").Post(n200.area, "All", "In "+string(k), []string{"Packed"}, 0); err != nil { + t.Fatal(err) + } + if n, err := n200.f.Scan(n200.f.S.Links[0]); err != nil || n != 1 { + t.Fatalf("scan: %d, %v", n, err) + } + var bundles []string + ents, _ := os.ReadDir(n200.f.outbound(n200.f.S.Links[0])) + for _, e := range ents { + if !strings.HasPrefix(e.Name(), ".") { + bundles = append(bundles, e.Name()) + } + } + if len(bundles) != 1 || !bundleName.MatchString(bundles[0]) { + t.Fatalf("outbound: %v", bundles) + } + b, _ := os.ReadFile(filepath.Join(n200.f.outbound(n200.f.S.Links[0]), bundles[0])) + if archive.Detect(b) != k { + t.Fatalf("the bundle is %q", archive.Detect(b)) + } + n200.call(t, n200.f.S.Links[0], hub) + if hm := hub.messages(t); len(hm) != 1 || hm[0].Subject != "In "+string(k) { + t.Fatalf("hub has %+v", hm) + } + }) + } +} + +// TestRealBundles: bundles packed by the real programs (arc crunching, +// ARJ's methods 1 and 4, LHA's -lh5-), where they are installed. +func TestRealBundles(t *testing.T) { + for _, c := range []struct { + prog string + args []string // then the bundle and the packet + }{ + {"arc", []string{"a"}}, + {"arj", []string{"a", "-m1", "-y"}}, + {"arj", []string{"a", "-m4", "-y"}}, + {"jlha", []string{"ao5q"}}, + } { + t.Run(c.prog+strings.Join(c.args, ""), func(t *testing.T) { + if _, err := exec.LookPath(c.prog); err != nil { + t.Skipf("no %s", c.prog) + } + hub := newSystem(t, "21:1/100", &Link{Name: "n200", Addr: mustAddr("21:1/200"), Password: "pw", Echoes: "*"}) + n200 := newSystem(t, "21:1/200", &Link{Name: "hub", Addr: mustAddr("21:1/100"), Password: "pw", Echoes: "*"}) + n200.f.ScanAll() + for i := 0; i < 20; i++ { // enough text to be worth packing + n200.node(t, "alice").Post(n200.area, "All", fmt.Sprintf("Message %d", i), []string{strings.Repeat("Hello, hub. ", 40)}, 0) + } + if n, err := n200.f.Scan(n200.f.S.Links[0]); err != nil || n != 20 { + t.Fatalf("scan: %d, %v", n, err) + } + out := n200.f.outbound(n200.f.S.Links[0]) + pkts, _ := filepath.Glob(filepath.Join(out, "*.pkt")) + if len(pkts) != 1 { + t.Fatalf("packets: %v", pkts) + } + bundle := filepath.Join(hub.f.inbound(hub.f.S.Links[0]), "0000abcd.mo1") + tmp := filepath.Join(t.TempDir(), "b."+c.prog) + cmd := exec.Command(c.prog, append(c.args, tmp, filepath.Base(pkts[0]))...) + cmd.Dir = out + cmd.Env = append(os.Environ(), "JAVA_TOOL_OPTIONS=") + if b, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("%s: %v\n%s", c.prog, err, b) + } + if _, err := os.Stat(tmp); err != nil { // arj adds .arj, jlha may add .lzh + m, _ := filepath.Glob(tmp + ".*") + if len(m) != 1 { + t.Fatalf("no bundle made") + } + tmp = m[0] + } + b, _ := os.ReadFile(tmp) + os.WriteFile(bundle, b, 0600) + st, err := hub.f.Toss(hub.f.S.Links[0]) + if err != nil || st.Echomail != 20 { + t.Fatalf("tossed %v, %v (%s bundle)", st, err, archive.Detect(b)) + } + }) + } +} diff --git a/internal/fido/scan.go b/internal/fido/scan.go index 6d71f7d..0b69fdd 100644 --- a/internal/fido/scan.go +++ b/internal/fido/scan.go @@ -1,10 +1,8 @@ package fido import ( - "archive/zip" "bytes" "fmt" - "io" "os" "path/filepath" "sort" @@ -12,6 +10,7 @@ import ( "time" "unicode/utf8" + "github.com/Neo-Desktop/bbs-sec/internal/archive" "github.com/Neo-Desktop/bbs-sec/internal/ftn" "github.com/Neo-Desktop/bbs-sec/internal/store" ) @@ -306,18 +305,12 @@ func (f *Fido) writeOutbound(l *Link, msgs []*ftn.Message) error { } data := pkt.Bytes() file := name + ".pkt" - if l.Zip { - var z bytes.Buffer - zw := zip.NewWriter(&z) - w, err := zw.CreateHeader(&zip.FileHeader{Name: file, Method: zip.Deflate, Modified: time.Now()}) - if err != nil { + if l.Packer != "" { + var b bytes.Buffer + if err := archive.Write(&b, l.Packer, name, []archive.File{{Name: file, Data: data, Modified: time.Now()}}); err != nil { return err } - io.Copy(w, bytes.NewReader(data)) - if err := zw.Close(); err != nil { - return err - } - data = z.Bytes() + data = b.Bytes() ext := days[time.Now().Weekday()] for c := 0; ; c++ { file = fmt.Sprintf("%s.%s%c", name, ext, "0123456789abcdefghijklmnopqrstuvwxyz"[c%36]) diff --git a/internal/fido/toss.go b/internal/fido/toss.go index ada6a20..ea910ba 100644 --- a/internal/fido/toss.go +++ b/internal/fido/toss.go @@ -1,7 +1,6 @@ package fido import ( - "archive/zip" "bytes" "errors" "fmt" @@ -11,6 +10,7 @@ import ( "regexp" "strings" + "github.com/Neo-Desktop/bbs-sec/internal/archive" "github.com/Neo-Desktop/bbs-sec/internal/bbs" "github.com/Neo-Desktop/bbs-sec/internal/ftn" "github.com/Neo-Desktop/bbs-sec/internal/news" @@ -95,38 +95,54 @@ func (f *Fido) tossFile(l *Link, path string, st *TossStats) error { } func (f *Fido) tossBundle(l *Link, path string, st *TossStats) error { - z, err := zip.OpenReader(path) + fh, err := os.Open(path) if err != nil { - if fi, e := os.Stat(path); e == nil && fi.Size() == 0 { - return nil // an empty bundle: some mailers leave them - } - return fmt.Errorf("not a ZIP bundle (ARC, ARJ, LHA are not unpacked here): %v", err) + return err } - defer z.Close() - if len(z.File) > maxBundleFiles { - return errors.New("too many files in the bundle") + defer fh.Close() + fi, err := fh.Stat() + if err != nil { + return err } - var total uint64 - for _, zf := range z.File { - if !strings.HasSuffix(strings.ToLower(zf.Name), ".pkt") || strings.ContainsAny(zf.Name, "/\\") { - f.B.Log.Printf("fido: %s: %s in the bundle is not a packet: skipped", l.Name, zf.Name) - continue + if fi.Size() == 0 { + return nil // an empty bundle: some mailers leave them + } + head := make([]byte, 8) + n, _ := fh.ReadAt(head, 0) + if archive.Detect(head[:n]) == "" { + return errors.New("not a bundle: not ZIP, ARC, ARJ or LHA") + } + var total int64 + count := 0 + var werr error + err = archive.Walk(fh, fi.Size(), func(e archive.Entry, open archive.Opener) bool { + if count++; count > maxBundleFiles { + werr = errors.New("too many files in the bundle") + return false } - total += zf.UncompressedSize64 - if zf.UncompressedSize64 > maxPacket || total > maxBundleUnpack { - return errors.New("the bundle unpacks too big") + if !strings.HasSuffix(strings.ToLower(e.Name), ".pkt") || strings.ContainsAny(e.Name, "/\\") { + f.B.Log.Printf("fido: %s: %s in the bundle is not a packet: skipped", l.Name, e.Name) + return true } - r, err := zf.Open() + if total += e.Size; e.Size > maxPacket || total > maxBundleUnpack { + werr = errors.New("the bundle unpacks too big") + return false + } + data, err := open(maxPacket) if err != nil { - return err + werr = fmt.Errorf("%s: %w", e.Name, err) + return false } - err = f.tossPacket(l, io.LimitReader(r, maxPacket), st) - r.Close() - if err != nil { - return fmt.Errorf("%s: %w", zf.Name, err) + if err := f.tossPacket(l, bytes.NewReader(data), st); err != nil { + werr = fmt.Errorf("%s: %w", e.Name, err) + return false } + return true + }) + if werr != nil { + return werr } - return nil + return err } // tossPacket takes a packet from a link: from its address, to ours, with diff --git a/internal/files/archive.go b/internal/files/archive.go index 9507c12..17842e8 100644 --- a/internal/files/archive.go +++ b/internal/files/archive.go @@ -2,7 +2,7 @@ package files import ( "archive/tar" - "archive/zip" + "bytes" "compress/gzip" "errors" "io" @@ -16,11 +16,12 @@ import ( "golang.org/x/text/encoding/charmap" + "github.com/Neo-Desktop/bbs-sec/internal/archive" "github.com/Neo-Desktop/bbs-sec/internal/store" ) // ErrNotArchive: the file is not an archive the BBS looks into. -var ErrNotArchive = errors.New("not an archive the BBS can look into (ZIP, tar, tar.gz)") +var ErrNotArchive = errors.New("not an archive the BBS can look into (ZIP, ARC, ARJ, LHA, tar, tar.gz)") // Entry is a file in an archive. type Entry struct { @@ -36,12 +37,14 @@ const MaxEntries = 2000 // maxDIZ is the most of a FILE_ID.DIZ read. const maxDIZ = 4096 -// archiveKind is how a file of that name is read: "zip", "tar", "tgz" or "". +// archiveKind is how a file of that name is read: "zip", "arc", "arj", +// "lha", "tar", "tgz" or "". func archiveKind(name string) string { n := strings.ToLower(name) + if k := archive.KindByName(n); k != "" { + return string(k) + } switch { - case strings.HasSuffix(n, ".zip"): - return "zip" case strings.HasSuffix(n, ".tar"): return "tar" case strings.HasSuffix(n, ".tar.gz"), strings.HasSuffix(n, ".tgz"): @@ -57,28 +60,31 @@ func IsArchive(name string) bool { return archiveKind(name) != "" } // reader of its contents, until fn says stop or MaxEntries. func walk(p, name string, fn func(e Entry, open func() (io.Reader, error)) bool) error { switch archiveKind(name) { - case "zip": - z, err := zip.OpenReader(p) + case "zip", "arc", "arj", "lha": + in, err := os.Open(p) if err != nil { - return ErrNotArchive + return err } - defer z.Close() - for i, f := range z.File { - if i >= MaxEntries { - break + defer in.Close() + fi, err := in.Stat() + if err != nil { + return err + } + i := 0 + err = archive.Walk(in, fi.Size(), func(e archive.Entry, open archive.Opener) bool { + if i++; i > MaxEntries { + return false } - e := Entry{Name: f.Name, Size: int64(f.UncompressedSize64), Modified: f.Modified, - Dir: strings.HasSuffix(f.Name, "/")} - open := func() (io.Reader, error) { - r, err := f.Open() + return fn(Entry{Name: e.Name, Size: e.Size, Modified: e.Modified, Dir: e.Dir}, func() (io.Reader, error) { + b, err := open(maxDIZ * 4) if err != nil { return nil, err } - return r, nil - } - if !fn(e, open) { - break - } + return bytes.NewReader(b), nil + }) + }) + if err != nil && i == 0 { + return ErrNotArchive } return nil case "tar", "tgz": diff --git a/internal/files/archive_test.go b/internal/files/archive_test.go index cf852fe..10743be 100644 --- a/internal/files/archive_test.go +++ b/internal/files/archive_test.go @@ -9,6 +9,8 @@ import ( "strings" "testing" "time" + + "github.com/Neo-Desktop/bbs-sec/internal/archive" ) func zipOf(t *testing.T, files map[string][]byte) []byte { @@ -96,3 +98,33 @@ func TestDIZAndListing(t *testing.T) { t.Error(ErrNotArchive) } } + +// TestOldArchives: an LHA's and an ARJ's FILE_ID.DIZ, and their listings, +// as a ZIP's. +func TestOldArchives(t *testing.T) { + s, alice, _, a := setup(t, 1<<20, 0) + when := time.Date(1995, 3, 4, 10, 0, 0, 0, time.Local) + for _, k := range []archive.Kind{archive.LHA, archive.ARJ, archive.ARC} { + var b bytes.Buffer + archive.Write(&b, k, "game."+string(k), []archive.File{ + {Name: "FILE_ID.DIZ", Data: []byte("Lord v4.00\r\nA door game\r\n"), Modified: when}, + {Name: "lord.exe", Data: bytes.Repeat([]byte{2}, 500), Modified: when}}) + name := "lord." + map[archive.Kind]string{archive.LHA: "lzh", archive.ARJ: "arj", archive.ARC: "arc"}[k] + up, err := s.Upload(alice, a, name, "") + if err != nil { + t.Fatal(err) + } + up.Write(b.Bytes()) + f, err := up.Commit() + if err != nil { + t.Fatal(err) + } + if f.Description != "Lord v4.00" || f.LongDesc != "Lord v4.00\nA door game" { + t.Errorf("%s: %q, %q", k, f.Description, f.LongDesc) + } + es, err := s.Listing(f) + if err != nil || len(es) != 2 || !strings.EqualFold(es[1].Name, "lord.exe") || es[1].Size != 500 || es[1].Modified.Year() != 1995 { + t.Errorf("%s: listing %+v %v", k, es, err) + } + } +} diff --git a/internal/server/fidoconfig.go b/internal/server/fidoconfig.go index 42b2e6a..8a838d6 100644 --- a/internal/server/fidoconfig.go +++ b/internal/server/fidoconfig.go @@ -6,6 +6,7 @@ import ( "net" "strings" + "github.com/Neo-Desktop/bbs-sec/internal/archive" "github.com/Neo-Desktop/bbs-sec/internal/config" "github.com/Neo-Desktop/bbs-sec/internal/fido" "github.com/Neo-Desktop/bbs-sec/internal/ftn" @@ -144,11 +145,13 @@ func link(s *config.Section) (*fido.Link, error) { return nil, err } switch p := strings.ToLower(s.String("packer", "zip")); p { - case "zip": - l.Zip = true + case "zip", "arc", "arj", "lha": + l.Packer = archive.Kind(p) + case "lzh": + l.Packer = archive.LHA case "none": default: - return nil, fmt.Errorf("packer: %q is not zip or none", p) + return nil, fmt.Errorf("packer: %q is not zip, arc, arj, lha or none", p) } if l.Poll, err = s.Seconds("poll", 0, 0, 7*86400); err != nil { return nil, err diff --git a/internal/server/fidoconfig_test.go b/internal/server/fidoconfig_test.go index a2aad15..ade75c6 100644 --- a/internal/server/fidoconfig_test.go +++ b/internal/server/fidoconfig_test.go @@ -6,6 +6,8 @@ import ( "strings" "testing" "time" + + "github.com/Neo-Desktop/bbs-sec/internal/archive" ) func TestFidoConfig(t *testing.T) { @@ -38,10 +40,10 @@ packer = none t.Fatalf("%+v %+v", f, c.Binkp) } hub := f.Links[0] - if hub.Host != "hub.example:24554" || !hub.Zip || !hub.Route || hub.Poll != time.Hour || hub.PktPassword != "PKT" { + if hub.Host != "hub.example:24554" || hub.Packer != archive.ZIP || !hub.Route || hub.Poll != time.Hour || hub.PktPassword != "PKT" { t.Fatalf("%+v", hub) } - if f.Links[1].Zip || !strings.Contains(strings.Join(c.Warnings, "\n"), "[link other] has no password") { + if f.Links[1].Packer != "" || !strings.Contains(strings.Join(c.Warnings, "\n"), "[link other] has no password") { t.Fatalf("%+v %v", f.Links[1], c.Warnings) } for body, want := range map[string]string{ diff --git a/internal/store/lhafile-0.3.1-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl b/internal/store/lhafile-0.3.1-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl new file mode 100644 index 0000000..839fc02 Binary files /dev/null and b/internal/store/lhafile-0.3.1-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl differ