Contacts Db Format

lua-users home
wiki

Plua code to dump records for examination:
-- contacts.lua                                                                                    



-- number of header bytes before the first field

skip = 17



f,n = io.open("db:/ContactsDB-PAdd", "r")



-- just look at one specific record, to make things simpler for investigation

for i = 1,1 do

  print("start")



  -- open the record and get the record length

  l = f:openrec(i)

  if not(l == nil) then

    -- read header

    s = f:read(skip)

    print(string.byte(s, 1))

    print(string.byte(s, 2))

    print(string.byte(s, 3))

    print(string.byte(s, 4))

    print(string.byte(s, 5))

    print(string.byte(s, 6))

    print(string.byte(s, 7))

    print(string.byte(s, 8))

    print(string.byte(s, 9))

    print(string.byte(s, 10))

    print(string.byte(s, 11))

    print(string.byte(s, 12))

    print(string.byte(s, 13))

    print(string.byte(s, 14))

    print(string.byte(s, 15))

    print(string.byte(s, 16))

    print(string.byte(s, 17))    

    print("fields")

    -- read fields in remaining record after header

    s = f:read(l-skip)

    -- fields are all nul-terminated ASCII.  Get them.

    -- This fixed string should be replaced with one that contains 1 S for each field in the header

    t = bin.unpack( "SSSSSSSSSSSSSSSSSSSSS", s)

    -- There seems to be some other byte information after the fields, at least in some cases.

    -- No idea currently what that contains.

    table.foreach(t, print)

  end

  f:closerec()

end

f:close()



Header bytes (Lau-compatible 1-based offset)

Phone labels

Each label has 4 bits, containing a number that tells which label to use: 0 for work, 1 for home, 2 for fax, 3 for other, 4 for email, 5 for main, 6 for pager, 7 for mobile. To read the labels, get the label in the upper bits with "floor(byte / 16)" and the label in the lower bits with "byte - (byte / 16)". To write the labels, "byte = lower + upper * 16".

Address labels

Each label has 4 bits, containing a number that tells which label to use: 0 for work, 1 for home, 2 for other. Read and write the labels as with phone labels.

IM labels

Each label has 4 bits, containing a number that tells which label to use: 0 for IM, 1 for AIM, 2 for MSN, 3 for Yahoo, 4 for AOL ICQ. Read and write the labels as with phone labels.

Confirmation of the above in [HB++ Community forums]


RecentChanges · preferences
edit · history
Last edited October 23, 2007 8:58 pm GMT (diff)