Skip to content

Instantly share code, notes, and snippets.

@achow101
Created February 20, 2018 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achow101/7f7143e6c3d3fdc034d3470e72823e9d to your computer and use it in GitHub Desktop.
Save achow101/7f7143e6c3d3fdc034d3470e72823e9d to your computer and use it in GitHub Desktop.
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