Documentation
¶
Overview ¶
Package absdb reads ComponentAce Absolute Database (.abs) files.
The binary format is reverse-engineered from real .abs files and the C++ header files shipped with the Absolute Database SDK.
Index ¶
- Constants
- Variables
- type BTreeEntry
- type BTreePageHeader
- type BaseFieldType
- type BlobRef
- type Column
- type CryptoAlgorithm
- type CryptoHeader
- type DiskPageHeader
- type FieldType
- type File
- func (db *File) Close() error
- func (db *File) CryptoHeader() *CryptoHeader
- func (db *File) Encrypted() bool
- func (db *File) OpenIndex() (*IndexReader, error)
- func (db *File) OpenTable() (*Reader, error)
- func (db *File) PageCount() int
- func (db *File) PageSize() int
- func (db *File) ReadBlob(ref BlobRef) ([]byte, error)
- func (db *File) ReadPage(n int) (Page, error)
- func (db *File) ScanPages() ([]PageSummary, error)
- func (db *File) Schema() (*TableSchema, error)
- func (db *File) VerifyPassword(password string) bool
- func (db *File) Version() float64
- type IndexInfo
- type IndexReader
- func (ir *IndexReader) FindByPrimaryKey(key int32) (dataPageNo int32, itemNo uint16, err error)
- func (ir *IndexReader) FindByStringKey(value string) (dataPageNo int32, itemNo uint16, err error)
- func (ir *IndexReader) Indexes() []IndexInfo
- func (ir *IndexReader) PrimaryKeyIndex() (*indexRoot, error)
- func (ir *IndexReader) ScanIndex(rootPageNo int) ([]BTreeEntry, error)
- func (ir *IndexReader) SecondaryIndexes() []IndexInfo
- type Page
- type PageSummary
- type Reader
- type Record
- func (rec Record) Blob(col int) ([]byte, error)
- func (rec Record) BlobRef(col int) BlobRef
- func (rec Record) Bool(col int) bool
- func (rec Record) Bytes(col int) []byte
- func (rec Record) Float(col int) float64
- func (rec Record) Int(col int) int32
- func (rec Record) Int64(col int) int64
- func (rec Record) IsNull(col int) bool
- func (rec Record) Memo(col int) (string, error)
- func (rec Record) String(col int) string
- func (rec Record) Time(col int) time.Time
- func (rec Record) Uint32(col int) uint32
- type TableSchema
Constants ¶
const ( PageTypeSystemDir = 2 // System directory PageTypeFileHdr = 3 // File header (page 0) PageTypeSchema = 8 // Schema metadata (zlib-compressed column defs) PageTypeData = 10 // Data page (row storage) PageTypeIndex = 12 // B-tree index page )
Page type constants from the TABSDiskPageHeader.PageType field.
const (
// PageTypeBlob is the page type for BLOB data storage.
PageTypeBlob = 11
)
Variables ¶
var ( ErrNotABS = errors.New("absdb: not an Absolute Database file") ErrTruncated = errors.New("absdb: file is truncated") ErrPageOutOfRange = errors.New("absdb: page number out of range") )
var ( ErrBlobNotFound = fmt.Errorf("absdb: BLOB data not found") ErrBlobTrunc = fmt.Errorf("absdb: BLOB data truncated") )
var ( ErrNoIndex = errors.New("absdb: no index found") ErrKeyNotFound = errors.New("absdb: key not found") )
var ( ErrNoData = errors.New("absdb: no data pages found") ErrNoMoreRows = errors.New("absdb: no more rows") )
var ( ErrNoSchema = errors.New("absdb: no schema page found") ErrBadSchema = errors.New("absdb: malformed schema data") ErrCompression = errors.New("absdb: decompression failed") )
var ErrUnsupportedCipher = errors.New("absdb: unsupported encryption algorithm")
ErrUnsupportedCipher indicates an unsupported encryption algorithm.
var ErrWrongPassword = errors.New("absdb: incorrect password")
ErrWrongPassword indicates the provided password does not match.
var Magic = [16]byte{
'A', 'B', 'S', '0', 'L', 'U', 'T', 'E',
'D', 'A', 'T', 'A', 'B', 'A', 'S', 'E',
}
Magic is the 16-byte file signature: "ABS0LUTEDATABASE" (note: zero, not letter O).
Functions ¶
This section is empty.
Types ¶
type BTreeEntry ¶
type BTreeEntry struct {
Key []byte // key bytes (KeyPrefixSize bytes)
PageNo int32 // referenced page number
ItemNo uint16 // referenced item number within the page
}
BTreeEntry is a single entry in an index page.
func (BTreeEntry) RecordID ¶
func (e BTreeEntry) RecordID() (int32, uint16)
RecordID returns the entry's reference as a (PageNo, ItemNo) pair.
type BTreePageHeader ¶
type BTreePageHeader struct {
IsRoot bool
IsLeaf bool
LeftPageNo int32 // left sibling page (-1 = none)
RightPageNo int32 // right sibling page (-1 = none)
HasKeys bool
HasSuffixes bool
KeyPrefixSize uint16 // key size per entry (short key)
EntryCount uint16 // number of entries on this page
PagePrefixSize uint16 // page-level prefix size
}
BTreePageHeader is the on-disk header at the start of every index page body.
type BaseFieldType ¶
type BaseFieldType byte
BaseFieldType represents the low-level storage type (TABSBaseFieldType).
const ( BftUnknown BaseFieldType = 0 BftChar BaseFieldType = 1 BftWideChar BaseFieldType = 2 BftVarchar BaseFieldType = 3 BftWideVarchar BaseFieldType = 4 BftInt8 BaseFieldType = 5 BftInt16 BaseFieldType = 6 BftInt32 BaseFieldType = 7 BftInt64 BaseFieldType = 8 BftUint8 BaseFieldType = 9 BftUint16 BaseFieldType = 10 BftUint32 BaseFieldType = 11 BftSingle BaseFieldType = 12 BftDouble BaseFieldType = 13 BftExtended BaseFieldType = 14 BftDate BaseFieldType = 15 BftTime BaseFieldType = 16 BftDateTime BaseFieldType = 17 BftBlob BaseFieldType = 18 BftClob BaseFieldType = 19 BftWideClob BaseFieldType = 20 BftLogical BaseFieldType = 21 BftCurrency BaseFieldType = 22 BftBytes BaseFieldType = 23 BftVarBytes BaseFieldType = 24 )
type BlobRef ¶
type BlobRef struct {
PageNo int32 // page number where BLOB data starts
ItemNo uint16 // item number within the page (usually 0)
}
BlobRef is a reference to BLOB data stored in a record field.
type Column ¶
type Column struct {
Name string // column name
ID uint32 // internal column ID
BaseType BaseFieldType // low-level storage type
FieldType FieldType // high-level field type
Size uint32 // max size for variable-length types (string length, etc.)
Position int // 0-based position in the column list
}
Column describes a single column in a table.
type CryptoAlgorithm ¶
type CryptoAlgorithm byte
CryptoAlgorithm identifies the encryption algorithm (TABSCryptoAlgorithm).
const ( CryptoRijndael128 CryptoAlgorithm = 0 CryptoRijndael256 CryptoAlgorithm = 1 CryptoDESSingle CryptoAlgorithm = 2 CryptoDESTriple CryptoAlgorithm = 3 CryptoBlowfish CryptoAlgorithm = 4 CryptoTwofish128 CryptoAlgorithm = 5 CryptoTwofish256 CryptoAlgorithm = 6 CryptoSquare CryptoAlgorithm = 7 )
type CryptoHeader ¶
type CryptoHeader struct {
HeaderSize int16
Algorithm CryptoAlgorithm
Mode byte
ControlBlock [controlBlockSize]byte
ControlCRC uint32
}
CryptoHeader holds the parsed TABSCryptoHeader from page 0.
type DiskPageHeader ¶
type DiskPageHeader struct {
State int32 // page state
PageType uint16 // page type (see PageType* constants)
NextPageNo int32 // next page in chain (-1 = none)
CRC32 uint32 // CRC32 checksum
CRCType byte
HashType byte
CipherType byte
MACType byte
ObjectID int32 // table/object this page belongs to (-1 = system)
RecPageNo int32 // record ID: page number
RecItemNo uint16 // record ID: item number within page
}
DiskPageHeader is the 40-byte TABSDiskPageHeader found at offset 0x17C in every page.
type FieldType ¶
type FieldType byte
FieldType represents the high-level field type (TABSAdvancedFieldType).
const ( FieldUnknown FieldType = 0 FieldChar FieldType = 1 FieldString FieldType = 2 FieldWideChar FieldType = 3 FieldWideString FieldType = 4 FieldShortInt FieldType = 5 FieldSmallInt FieldType = 6 FieldInteger FieldType = 7 FieldLargeInt FieldType = 8 FieldByte FieldType = 9 FieldWord FieldType = 10 FieldCardinal FieldType = 11 FieldAutoInc FieldType = 12 FieldAutoIncInt8 FieldType = 13 FieldAutoIncInt16 FieldType = 14 FieldAutoIncInt32 FieldType = 15 FieldAutoIncInt64 FieldType = 16 FieldAutoIncUint8 FieldType = 17 FieldAutoIncUint16 FieldType = 18 FieldAutoIncUint32 FieldType = 19 FieldSingle FieldType = 20 FieldDouble FieldType = 21 FieldExtended FieldType = 22 FieldBoolean FieldType = 23 FieldCurrency FieldType = 24 FieldDate FieldType = 25 FieldTime FieldType = 26 FieldDateTime FieldType = 27 FieldTimeStamp FieldType = 28 FieldBytes FieldType = 29 FieldVarBytes FieldType = 30 FieldBLOB FieldType = 31 FieldGraphic FieldType = 32 FieldMemo FieldType = 33 FieldFmtMemo FieldType = 34 FieldWideMemo FieldType = 35 FieldGUID FieldType = 36 )
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents an opened Absolute Database file.
func OpenWithPassword ¶
OpenWithPassword opens an encrypted Absolute Database file. If the file is not encrypted, the password is ignored. Returns ErrWrongPassword if the password doesn't match.
func (*File) CryptoHeader ¶
func (db *File) CryptoHeader() *CryptoHeader
CryptoHeader returns the parsed crypto header, or nil if the file is not encrypted.
func (*File) OpenIndex ¶
func (db *File) OpenIndex() (*IndexReader, error)
OpenIndex creates an IndexReader by scanning all index pages.
func (*File) ReadBlob ¶
ReadBlob reads the BLOB data for the given reference from the database. Returns the raw (decompressed) bytes. For Memo fields, convert to string.
func (*File) ScanPages ¶
func (db *File) ScanPages() ([]PageSummary, error)
ScanPages reads all pages and returns their disk page headers.
func (*File) Schema ¶
func (db *File) Schema() (*TableSchema, error)
Schema reads and parses the table schema from the database file. For single-table databases, this returns the schema of the only table.
func (*File) VerifyPassword ¶
VerifyPassword checks whether the given password is correct for this encrypted database. It decrypts the ControlBlock and compares its CRC32 with the stored value.
type IndexInfo ¶
type IndexInfo struct {
RootPageNo int // root page of the B-tree
KeySize int // key size in bytes
EntryCount int // total entries (for root-only trees)
IsInternal bool // true for system indexes (RecordPage, BlobPage)
}
IndexInfo describes a discovered index.
type IndexReader ¶
type IndexReader struct {
// contains filtered or unexported fields
}
IndexReader provides index-based lookups on a table.
func (*IndexReader) FindByPrimaryKey ¶
func (ir *IndexReader) FindByPrimaryKey(key int32) (dataPageNo int32, itemNo uint16, err error)
FindByPrimaryKey looks up a record by its primary key (AutoInc/RecNo value). Returns the data page number and item number, or ErrKeyNotFound.
func (*IndexReader) FindByStringKey ¶
func (ir *IndexReader) FindByStringKey(value string) (dataPageNo int32, itemNo uint16, err error)
FindByStringKey searches a secondary string index for the given value. Uses the first secondary index found with matching key size.
func (*IndexReader) Indexes ¶
func (ir *IndexReader) Indexes() []IndexInfo
Indexes returns information about all discovered indexes.
func (*IndexReader) PrimaryKeyIndex ¶
func (ir *IndexReader) PrimaryKeyIndex() (*indexRoot, error)
PrimaryKeyIndex returns the root page info for the primary key index. The primary key index has 5-byte keys (1 null flag + 4-byte int32).
func (*IndexReader) ScanIndex ¶
func (ir *IndexReader) ScanIndex(rootPageNo int) ([]BTreeEntry, error)
ScanIndex reads all entries from the specified index root page, following the B-tree leaf chain for multi-page indexes.
func (*IndexReader) SecondaryIndexes ¶
func (ir *IndexReader) SecondaryIndexes() []IndexInfo
SecondaryIndexes returns root pages for non-system, non-primary indexes.
type Page ¶
type Page struct {
Number int
Data []byte
Header *DiskPageHeader // nil if no ABSP marker found
}
Page represents a single page read from the database file.
type PageSummary ¶
type PageSummary struct {
Number int
Empty bool
Header *DiskPageHeader
}
PageSummary is a lightweight summary of a scanned page.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader iterates over data records in a table.
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record represents a single data record.
func (Record) Blob ¶
Blob reads the BLOB data for the given column from the database. Returns the raw bytes. Returns nil for NULL BLOBs.
func (Record) Memo ¶
Memo reads a Memo (text BLOB) column and returns it as a string. Returns empty string for NULL values.
type TableSchema ¶
type TableSchema struct {
Columns []Column
}
TableSchema holds the parsed schema for one table.