mirror of
https://github.com/garraflavatra/go-fmp.git
synced 2025-06-28 04:25:11 +00:00
Debug prints
This commit is contained in:
@ -5,6 +5,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func debug(str string, args ...interface{}) {
|
||||||
|
fmt.Printf(str+"\n", args...)
|
||||||
|
}
|
||||||
|
|
||||||
func (f *FmpFile) ToDebugFile(fname string) {
|
func (f *FmpFile) ToDebugFile(fname string) {
|
||||||
f_sectors, err := os.Create(fname + ".sectors")
|
f_sectors, err := os.Create(fname + ".sectors")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -100,7 +100,7 @@ func (ctx *FmpFile) readHeader() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *FmpFile) readSector() (*FmpSector, error) {
|
func (ctx *FmpFile) readSector() (*FmpSector, error) {
|
||||||
println("---------- Reading sector", ctx.currentSectorID)
|
debug("---------- Reading sector %d", ctx.currentSectorID)
|
||||||
buf := make([]byte, sectorHeaderSize)
|
buf := make([]byte, sectorHeaderSize)
|
||||||
n, err := ctx.stream.Read(buf)
|
n, err := ctx.stream.Read(buf)
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package fmp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,22 +18,20 @@ func (sect *FmpSector) readChunks() error {
|
|||||||
|
|
||||||
chunk, err := sect.readChunk(sect.Payload)
|
chunk, err := sect.readChunk(sect.Payload)
|
||||||
if chunk == nil {
|
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 {
|
} 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 {
|
if err == io.EOF {
|
||||||
println("break1")
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println(hex.EncodeToString(sect.Payload))
|
debug("chunk error at sector %d", sect.ID)
|
||||||
println("break2")
|
debug(hex.EncodeToString(sect.Payload))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if chunk == nil {
|
if chunk == nil {
|
||||||
println("break3")
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if chunk.Length == 0 {
|
if chunk.Length == 0 {
|
||||||
@ -92,14 +89,6 @@ func (sect *FmpSector) processChunks(dict *FmpDict, currentPath *[]uint64) error
|
|||||||
case FMP_CHUNK_NOOP:
|
case FMP_CHUNK_NOOP:
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
|
||||||
if chunk.Delayed {
|
|
||||||
if len(*currentPath) == 0 {
|
|
||||||
println("warning: delayed pop without path")
|
|
||||||
} else {
|
|
||||||
*currentPath = (*currentPath)[:len(*currentPath)-1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -112,11 +101,6 @@ func (sect *FmpSector) readChunk(payload []byte) (*FmpChunk, error) {
|
|||||||
chunk := &FmpChunk{}
|
chunk := &FmpChunk{}
|
||||||
chunkCode := payload[0]
|
chunkCode := payload[0]
|
||||||
|
|
||||||
if (chunkCode & 0xC0) == 0xC0 {
|
|
||||||
chunkCode &= 0x3F
|
|
||||||
chunk.Delayed = true
|
|
||||||
}
|
|
||||||
|
|
||||||
switch chunkCode {
|
switch chunkCode {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
chunk.Length = 2
|
chunk.Length = 2
|
||||||
|
@ -7,19 +7,19 @@ func (ctx *FmpFile) Tables() []*FmpTable {
|
|||||||
if key != 3 {
|
if key != 3 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
println("Found a 3")
|
debug("Found a 3")
|
||||||
|
|
||||||
for key, ent = range *ent.Children {
|
for key, ent = range *ent.Children {
|
||||||
if key != 16 {
|
if key != 16 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
println("Found a 3.16")
|
debug("Found a 3.16")
|
||||||
|
|
||||||
for key, ent = range *ent.Children {
|
for key, ent = range *ent.Children {
|
||||||
if key != 5 {
|
if key != 5 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
println("Found a 3.16.5")
|
debug("Found a 3.16.5")
|
||||||
|
|
||||||
for tablePath := range *ent.Children {
|
for tablePath := range *ent.Children {
|
||||||
if key >= 128 {
|
if key >= 128 {
|
||||||
@ -27,7 +27,7 @@ func (ctx *FmpFile) Tables() []*FmpTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Found a table!
|
// Found a table!
|
||||||
println("Found a table at 3.16.5.", tablePath)
|
debug("Found a table at 3.16.5.%d", tablePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,11 @@ type FmpSector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FmpChunk struct {
|
type FmpChunk struct {
|
||||||
Type FmpChunkType
|
Type FmpChunkType
|
||||||
Length uint64
|
Length uint64
|
||||||
Key uint64 // If Type == FMP_CHUNK_SHORT_KEY_VALUE or FMP_CHUNK_LONG_KEY_VALUE
|
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
|
Index uint64 // Segment index, if Type == FMP_CHUNK_SEGMENTED_DATA
|
||||||
Value []byte
|
Value []byte
|
||||||
Delayed bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type FmpDict map[uint64]*FmpDictEntry
|
type FmpDict map[uint64]*FmpDictEntry
|
||||||
|
Reference in New Issue
Block a user