Example #1
0
def load_from_filename(wallet_filename):
    wallet_filename = os.path.abspath(wallet_filename)
    import bsddb3.db
    db_env = bsddb3.db.DBEnv()
    try:
        db_env.open(os.path.dirname(wallet_filename), bsddb3.db.DB_CREATE | bsddb3.db.DB_INIT_MPOOL)
        db = bsddb3.db.DB(db_env)
        db.open(wallet_filename, b"main", bsddb3.db.DB_BTREE, bsddb3.db.DB_RDONLY)
    except UnicodeEncodeError:
        error_exit("the entire path and filename of Bitcoin Core wallets should be entirely ASCII")
    mkey = db.get(b"\x04mkey\x01\x00\x00\x00")
    db.close()
    db_env.close()

    # if not mkey:
    #     raise ValueError("Encrypted master key #1 not found in the Bitcoin Core wallet file.\n"+
    #                      "(is this wallet encrypted? is this a standard Bitcoin Core wallet?)")
        # This is a little fragile because it assumes the encrypted key and salt sizes are
        # 48 and 8 bytes long respectively, which although currently true may not always be
        # (it will loudly fail if this isn't the case; if smarter it could gracefully succeed):
    # self = cls(loading=True)

    encrypted_master_key, salt, method, iter_count = struct.unpack_from(b"< 49p 9p I I", mkey)
    # print encrypted_master_key
    return encrypted_master_key, salt, method, iter_count
Example #2
0
File: db.py Project: Kolumbs/db
 def close(self):
     for index in self.indexes:
         cursor = getattr(index, 'cursor')
         if cursor:
             cursor.close()
         db = getattr(index, 'db')
         db.close()
     for table in self.tables.values():
         if table.cursor:
             table.cursor.close()
         table.close()
     self.env.close()
Example #3
0
 def _read_from_data(self, filename):
   db_env = bsddb3.db.DBEnv()
   try:
     db_env.open(os.path.dirname(filename), bsddb3.db.DB_CREATE | bsddb3.db.DB_INIT_MPOOL)
     db = bsddb3.db.DB(db_env)
     db.open(filename, b"main", bsddb3.db.DB_BTREE, bsddb3.db.DB_RDONLY)
   except UnicodeEncodeError:
     error_exit("the entire path and filename of Bitcoin Core wallets should be entirely ASCII")
   mkey = db.get(b"\x04mkey\x01\x00\x00\x00")
   encrypted_master_key, salt, method, iter_count = struct.unpack_from(b"< 49p 9p I I", mkey)
   db.close()
   db_env.close()
   return encrypted_master_key, salt, method, iter_count
    def iter_db_file(self, db_path):
        zoom = self.get_zoom(db_path) # also checks data in range
        if not zoom:
            return

        db = self.sqlite3.connect(db_path)
        dbc = db.cursor()

        dbc.execute('SELECT x, y, MAX(v), b FROM t GROUP BY x,y;')
        for x, y, version, data in dbc:
            if data:
                coord = [zoom, x, y]
                #~ log('db tile', coord, tile[:20], path)
                #~ log('tile', coord, data)
                yield PixBufTile(coord, data, key=(db_path, coord))

        db.close()
Example #5
0
def finish():
    db.close()
    env.close()
Example #6
0
 def test03_repr_closed_db(self):
     db = hashopen(self.filename)
     db.close()
     rp = repr(db)
     self.assertEquals(rp, "{}")
Example #7
0
def de_DB():
    db.close()
    return
Example #8
0
 def test03_repr_closed_db(self):
     db = hashopen(self.filename)
     db.close()
     rp = repr(db)
     self.assertEquals(rp, "{}")
Example #9
0
def finish():
    db.close()
    env.close()
Example #10
0
  def createDB(self):
    DA_FILE = "./tmp/bpharris_db/sample_db"
    DA_FILE2 = "./tmp/bpharris_db/indexfile"
    #DA_FILE2 = "./index9999"
    DB_SIZE = 100000
    SEED = 10000000
    currentVal = 0
    
    databaseType = self.DBType
    if databaseType == 'indexfile':
      try:
          db = bsddb3.btopen(DA_FILE, "n")
      except:
          print("DB doesn't exist, creating a new one")
          db = bsddb3.btopen(DA_FILE, "c")
      try:
          db2 = bsddb3.hashopen(DA_FILE2, "n")
      except:
          print("DB2 doesn't exist, creating a new one")
          db2 = bsddb3.hashopen(DA_FILE2, "c")
    
    elif databaseType == 'hash':
      try:
          db = bsddb3.hashopen(DA_FILE, "n")
      except:
          print("DB doesn't exist, creating a new one")
          db = bsddb3.hashopen(DA_FILE, "c")
    
    elif databaseType == 'btree':
      try:
          db = bsddb3.btopen(DA_FILE, "n")
      except:
          print("DB doesn't exist, creating a new one")
          db = bsddb3.btopen(DA_FILE, "c")
    
    
    random.seed(SEED)

    for index in range(DB_SIZE):
        krng = 64 + self.get_random()
        key = ""
        for i in range(krng):
            key += str(self.get_random_char())
        vrng = 64 + self.get_random()
        value = ""
        for i in range(vrng):
            value += str(self.get_random_char())
        key = key.encode(encoding='UTF-8')
        value = value.encode(encoding='UTF-8')
        if key not in db:
          db[key] = value
          if databaseType == 'indexfile':
            #If the value already exists in the indexfile --> call customPut to insert duplicate data!
            if value in db2:
              self.customPut(db2,value, key)
            else:
              db2[value] = key
          currentVal += 1
        print("Creating the database: %d%% completed." %((currentVal/DB_SIZE) * 100), end="\r")
        sys.stdout.flush()
    print("Creating the database: 100% completed.")
    try:
        print("Created an %s based database" %(databaseType))
        db.close()
    except Exception as e:
        print (e)
    
    if databaseType == 'indexfile':
      try:
        db2.close()
      except Exception as e:
        print (e)
    
    self.openDatabases()
    
    if(self.createMenu ):
      self.createMenu  = False
      self.mainMenu()
Example #11
0
 def __closeConn__(self, db):
     # close a db file
     db.close()
Example #12
0
with open(wallet_filename, "rb") as wallet_file:
    wallet_file.seek(12)
    if wallet_file.read(
            8) != b"\x62\x31\x05\x00\x09\x00\x00\x00":  # BDB magic, Btree v9
        print(prog + ": error: file is not a Bitcoin Core wallet",
              file=sys.stderr)
        sys.exit(1)

db_env = bsddb3.db.DBEnv()
db_env.open(os.path.dirname(wallet_filename),
            bsddb3.db.DB_CREATE | bsddb3.db.DB_INIT_MPOOL)
db = bsddb3.db.DB(db_env)
db.open(wallet_filename, "main", bsddb3.db.DB_BTREE, bsddb3.db.DB_RDONLY)
mkey = db.get(b"\x04mkey\x01\x00\x00\x00")
db.close()
db_env.close()

if not mkey:
    raise ValueError(
        "Encrypted master key #1 not found in the Bitcoin Core wallet file.\n"
        +
        "(is this wallet encrypted? is this a standard Bitcoin Core wallet?)")

# This is a little fragile because it assumes the encrypted key and salt sizes are
# 48 and 8 bytes long respectively, which although currently true may not always be:
# (it will loudly fail if this isn't the case; if smarter it could gracefully succeed):
encrypted_master_key, salt, method, iter_count = struct.unpack_from(
    "< 49p 9p I I", mkey)
if method != 0:
    print(prog + ": warning: unexpected Bitcoin Core key derivation method",