-
-
Save achow101/7f7143e6c3d3fdc034d3470e72823e9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import binascii | |
import os | |
import array | |
header = [0xd6,0x30,0x81,0xD3,0x02,0x01,0x01,0x04,0x20] | |
header_ptr = 0 | |
privkeys = [] | |
with open("/home/andy/.bitcoin/regtest/wallets/unencrypted_7_orig", "rb") as f: | |
read_bytes = f.read() | |
in_privkey = False | |
cur_privkey = [] | |
print("Reading 1024 bytes at a time") | |
for b in read_bytes: | |
if in_privkey and len(cur_privkey) < 32: | |
cur_privkey.append(b) | |
continue | |
elif len(cur_privkey) == 32: | |
pk = array.array('B', cur_privkey).tostring() | |
privkeys.append(pk) | |
print("Found a private key " + str(len(privkeys))) | |
cur_privkey.clear() | |
in_privkey = False | |
continue | |
if b == header[header_ptr]: | |
header_ptr += 1 | |
if header_ptr == len(header): | |
# We're now at a private key | |
in_privkey = True | |
header_ptr = 0 | |
else: | |
header_ptr = 0 | |
print("Checking log files now") | |
privkey_found = False | |
for filename in os.listdir("/home/andy/.bitcoin/regtest/wallets/database"): | |
with open("/home/andy/.bitcoin/regtest/wallets/database/" + filename, "rb") as f: | |
read_bytes = f.read() | |
for privkey in privkeys: | |
if privkey in read_bytes: | |
privkey_found = True | |
print("Private key in bytes " + str(binascii.hexlify(privkey))) | |
if not privkey_found: | |
print("No Privkeys found") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment