You can't dump a corrupt wallet to json as it won't have the correct format.
I quickly wrote a small Python script for parsing a wallet and dumping the private keys from it (run with Python 2):
import sys
import struct
from bsddb.db import *
from hashlib import sha256
# Dumps the private keys from a wallet.dat file.
# Inspired by pywallet.
# Credits: https://bitcoin.stackexchange.com/questions/13681/opening-wallet-dat-in-python-using-bsddb3
B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
if not len(sys.argv) == 2:
print("Usage: %s <wallet_file>" % sys.argv[2])
sys.exit(1)
def read_size(buffer, offset):
size = ord(buffer[offset])
offset += 1
if size == 0xfd:
size = struct.unpack_from("<H", buffer, offset)[0]
offset += 2
if size == 0xfe:
size = struct.unpack_from("<I", buffer, offset)[0]
offset += 4
if size == 0xff:
size = struct.unpack_from("<Q", buffer, offset)[0]
offset += 8
return offset, size
def read_string(buffer, offset):
offset, string_len = read_size(buffer, offset)
return offset + string_len, buffer[offset: offset + string_len]
def b58_encode(d):
out = ""
p = 0
x = 0
while ord(d[0]) == 0:
out += "1"
d = d[1:]
for i, v in enumerate(d[::-1]):
x += ord(v)*(256**i)
while x > 58**(p+1):
p += 1
while p >= 0:
a, x = divmod(x, 58**p)
out += B58[a]
p -= 1
return out
def b58check_encode(d):
checksum = sha256(sha256(d).digest()).digest()[:4]
return b58_encode(d + checksum)
db = DB()
db.open(sys.argv[1], "main", DB_BTREE, DB_RDONLY)
items = db.items()
for item in items:
k, v = item
koff, voff = 0, 0
koff, item_type = read_string(k, koff)
if item_type == "key":
koff, pubkey = read_string(k, koff)
voff, privkey = read_string(v, voff)
if len(privkey) == 279:
secret = privkey[9:9+32]
else:
secret = privkey[8:8+32]
if pubkey[0] != "\x04":
secret += "\x01"
print(b58check_encode("\x80" + secret))
db.close()
It's very simple, and outputs a bunch of WIF private keys (you can paste them into Electrum's Sweep dialog for example, but if there's many of them, it's going to take a while to check their balances, so be patient.
NOTE: the method of working with the database used here is different from pywallet's. It may work better on corrupted wallets.
A pip install of the bsddb may be required.
You might also be able to get bitcointools to turn a private key from one of the mentioned scripts and convert it to an address to scan for a balance on blockchain.info's API.
The user jackjack here wrote pywallet (you can search for it on githum and it should appear under the name jackjack-jj/pywallet).
What drive was the file on before it became corrupted? Was it in amongst other files or on its own on the drive - can you get that drive professionally recovered, have you?
Thanks for the response, my client doesn't have the original drive where the wallet was not corrupted.
How do you know this is your exact wallet.dat? Do you just think it's for bitcoin or had you put it on a specific drive to back it up which it got corrupted on. Do you have any backups of the corrupted wallet also as in if you did a full system backup at the time that you still have a copy of?