Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
create readable hex dump of a bitcoin, litecoin, etc wallet.dat
from bsddb.db import *
import sys
import struct
# by Willem Hengeveld <>
# usage: python dumpwallet path_to_your/wallet.dat
# note: you need to have the bsddb package installed
def getcompact(k, i):
b= ord(k[i]) ; i+=1
if b<0xfd:
elif b==0xfd:
b= struct.unpack("<h", k[i:i+2])[0] ; i+=2
elif b==0xfe:
b= struct.unpack("<l", k[i:i+4])[0] ; i+=4
elif b==0xff:
b= struct.unpack("<q", k[i:i+8])[0] ; i+=8
return (b, i)
def decodekey(k):
key.append(k[i:i+l]) ; i += l
if key[0] in ['tx', 'pool', 'version', 'minversion']:
elif i<len(k):
key.append(k[i:i+l]) ; i += l
return key
def decodevalue(k):
while i<len(k):
key.append(k[i:i+l]) ; i += l
return key
# bestblock -> int32, byte, blockhash[len]
# key -> asn1:[01, privkey, =0:[01, [secp256k1, p], [a,b], g, n, 01], =1:pubkey]
def decodekv(k,v):
if key[0] in ['name']:
return "'%s':%s -> %s" % (key[0], key[1], ",".join(map(lambda x:"'%s'"%x, decodevalue(v))))
elif key[0] in ['key', 'ckey', 'defaultkey']:
return "'%s':%s -> %s" % (key[0], ",".join(map(lambda x:x.encode("hex"), key[1:])), ",".join(map(lambda x:x.encode("hex"), decodevalue(v))))
elif key[0] in ['setting']:
return "'%s':%s -> %s" % (key[0], key[1], ",".join(map(lambda x:x.encode("hex"), decodevalue(v))))
return "'%s':%s -> %s" % (key[0], ",".join(map(lambda x:x.encode("hex"), key[1:])), v.encode("hex"))
db = DB()
r=[1], "main", DB_BTREE, DB_RDONLY)
for (k,v) in db.items():
print decodekv(k,v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.