from util import unhex from tls97 import tls from util import assert_status from struct import pack, unpack from binascii import hexlify, unhexlify from blobs import db_write_enable from flash import flush_changes from sid import * class UserStorage(): def __init__(self, dbid, name): self.dbid=dbid self.name=name self.users=[] def __repr__(self): return '' % (self.dbid, repr(self.name), repr(self.users)) class User(): def __init__(self, dbid, identity): self.dbid=dbid self.identity=identity self.fingers=[] def __repr__(self): return '' % (self.dbid, repr(self.identity), repr(self.fingers)) def subtype_to_string(s): if s < 0xf5 or s > 0xfe: return 'Unknown' return 'WINBIO_FINGER_UNSPECIFIED_POS_%02d' % (s - 0xf5 + 1) def parse_user_storage(rsp): assert_status(rsp[:2]) rsp=rsp[2:] hdr, rsp = rsp[:8], rsp[8:] recid, usercnt, namesz, unknwn = unpack(' 0: raise Exception('Junk at the end of the storage info response: %s' % rsp.hex()) storage=UserStorage(recid, name) while len(usrtab) > 0: rec, usrtab = usrtab[:4], usrtab[4:] urid, valsz = unpack(' 0: raise Exception('Junk at the end of the user info response: %s' % rsp.hex()) identity = parse_identity(identity) user=User(recid, identity) while len(fingertab) > 0: rec, fingertab = fingertab[:8], fingertab[8:] frid, subtype, stgid, valsz = unpack('' % ( self.dbid, self.type, self.storage, repr(self.value), repr(self.children) ) class Db(): def get_user_storage(self, dbid=0, name=''): name=name.encode() if len(name) > 0: name += b'\0' return parse_user_storage(tls.cmd(pack('