From d9ffc3e573d20460707b956bb7bb51fadc5a5f2b Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Sat, 14 Jun 2025 14:24:35 +0200 Subject: [PATCH] Debug prints --- fmp/fmp_debug.go | 4 ++++ fmp/fmp_file.go | 2 +- fmp/fmp_sector.go | 24 ++++-------------------- fmp/fmp_table.go | 8 ++++---- fmp/fmp_type.go | 11 +++++------ 5 files changed, 18 insertions(+), 31 deletions(-) diff --git a/fmp/fmp_debug.go b/fmp/fmp_debug.go index fa52b04..6b93a0d 100644 --- a/fmp/fmp_debug.go +++ b/fmp/fmp_debug.go @@ -5,6 +5,10 @@ import ( "os" ) +func debug(str string, args ...interface{}) { + fmt.Printf(str+"\n", args...) +} + func (f *FmpFile) ToDebugFile(fname string) { f_sectors, err := os.Create(fname + ".sectors") if err != nil { diff --git a/fmp/fmp_file.go b/fmp/fmp_file.go index f42e97e..cbccc0c 100644 --- a/fmp/fmp_file.go +++ b/fmp/fmp_file.go @@ -100,7 +100,7 @@ func (ctx *FmpFile) readHeader() error { } func (ctx *FmpFile) readSector() (*FmpSector, error) { - println("---------- Reading sector", ctx.currentSectorID) + debug("---------- Reading sector %d", ctx.currentSectorID) buf := make([]byte, sectorHeaderSize) n, err := ctx.stream.Read(buf) diff --git a/fmp/fmp_sector.go b/fmp/fmp_sector.go index b284c01..68648a0 100644 --- a/fmp/fmp_sector.go +++ b/fmp/fmp_sector.go @@ -2,7 +2,6 @@ package fmp import ( "encoding/hex" - "fmt" "io" ) @@ -19,22 +18,20 @@ func (sect *FmpSector) readChunks() error { chunk, err := sect.readChunk(sect.Payload) if chunk == nil { - fmt.Printf("0x%02x (pos %v, unknown)\n", sect.Payload[0], pos) + debug("0x%02x (pos %v, unknown)\n", sect.Payload[0], pos) } else { - fmt.Printf("0x%02x (pos %v, type %v)\n", sect.Payload[0], pos, int(chunk.Type)) + debug("0x%02x (pos %v, type %v)\n", sect.Payload[0], pos, int(chunk.Type)) } if err == io.EOF { - println("break1") break } if err != nil { - println(hex.EncodeToString(sect.Payload)) - println("break2") + debug("chunk error at sector %d", sect.ID) + debug(hex.EncodeToString(sect.Payload)) return err } if chunk == nil { - println("break3") break } if chunk.Length == 0 { @@ -92,14 +89,6 @@ func (sect *FmpSector) processChunks(dict *FmpDict, currentPath *[]uint64) error case FMP_CHUNK_NOOP: // noop } - - if chunk.Delayed { - if len(*currentPath) == 0 { - println("warning: delayed pop without path") - } else { - *currentPath = (*currentPath)[:len(*currentPath)-1] - } - } } return nil } @@ -112,11 +101,6 @@ func (sect *FmpSector) readChunk(payload []byte) (*FmpChunk, error) { chunk := &FmpChunk{} chunkCode := payload[0] - if (chunkCode & 0xC0) == 0xC0 { - chunkCode &= 0x3F - chunk.Delayed = true - } - switch chunkCode { case 0x00: chunk.Length = 2 diff --git a/fmp/fmp_table.go b/fmp/fmp_table.go index 85994f5..2e6f290 100644 --- a/fmp/fmp_table.go +++ b/fmp/fmp_table.go @@ -7,19 +7,19 @@ func (ctx *FmpFile) Tables() []*FmpTable { if key != 3 { continue } - println("Found a 3") + debug("Found a 3") for key, ent = range *ent.Children { if key != 16 { continue } - println("Found a 3.16") + debug("Found a 3.16") for key, ent = range *ent.Children { if key != 5 { continue } - println("Found a 3.16.5") + debug("Found a 3.16.5") for tablePath := range *ent.Children { if key >= 128 { @@ -27,7 +27,7 @@ func (ctx *FmpFile) Tables() []*FmpTable { } // Found a table! - println("Found a table at 3.16.5.", tablePath) + debug("Found a table at 3.16.5.%d", tablePath) } } } diff --git a/fmp/fmp_type.go b/fmp/fmp_type.go index a4d6fc1..714f681 100644 --- a/fmp/fmp_type.go +++ b/fmp/fmp_type.go @@ -32,12 +32,11 @@ type FmpSector struct { } type FmpChunk struct { - Type FmpChunkType - Length uint64 - Key uint64 // If Type == FMP_CHUNK_SHORT_KEY_VALUE or FMP_CHUNK_LONG_KEY_VALUE - Index uint64 // Segment index, if Type == FMP_CHUNK_SEGMENTED_DATA - Value []byte - Delayed bool + Type FmpChunkType + Length uint64 + Key uint64 // If Type == FMP_CHUNK_SHORT_KEY_VALUE or FMP_CHUNK_LONG_KEY_VALUE + Index uint64 // Segment index, if Type == FMP_CHUNK_SEGMENTED_DATA + Value []byte } type FmpDict map[uint64]*FmpDictEntry