Files
bambu-nfc/mifare/mifare.go
T
s1d3sw1ped b38f7f643b Add bambu-nfc dump parse, Key-A HKDF, and spool merge.
Parse filanfc-dump/v1 zip/JSON, Bambu 1K images, and merge stickers by tray UID. dump and mifare packages stay importable for a later common library.
2026-08-23 15:23:11 -05:00

37 lines
938 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package mifare holds MIFARE Classic 1K layout helpers with no brand-specific memory map.
package mifare
import "fmt"
const (
Sectors = 16
Blocks = 64
BlockSize = 16
SectorSize = 64
Size1K = 1024
)
// SectorOf returns the sector index for a block number (063).
func SectorOf(block int) int {
return block / 4
}
// BlockRange returns the half-open block range [first, last) for a sector.
func BlockRange(sector int) (first, last int) {
first = sector * 4
last = first + 4
return first, last
}
// SectorBytes returns the 64-byte slice for sector (015) from a 1K image.
func SectorBytes(image []byte, sector int) ([]byte, error) {
if len(image) != Size1K {
return nil, fmt.Errorf("image size: want %d got %d", Size1K, len(image))
}
if sector < 0 || sector >= Sectors {
return nil, fmt.Errorf("sector %d out of range", sector)
}
off := sector * SectorSize
return image[off : off+SectorSize], nil
}