Skip to content

Commit 61cf149

Browse files
committed
Fix offset logging, add README notes
1 parent a46caa4 commit 61cf149

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ bitcoind importprivkey 5KXXXXXXXXXXXX
2020
bitcoind getbalance
2121
```
2222

23+
## Features and Limitations
24+
* Supports both pre-2012 and post-2012 wallet keys.
25+
* Supports logging to a file.
26+
* Cannot find encrypted wallets.
27+
2328
DONATIONS --> 1YAyBtCwvZqNF9umZTUmfQ6vvLQRTG9qG

keyhunter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# bytes to read at a time from file (10 MiB)
1515
READ_BLOCK_SIZE = 10 * 1024 * 1024
1616

17+
# magic bytes reference: https://bitcointalk.org/index.php?topic=2745783.msg28084524#msg28084524
1718
MAGIC_BYTES_LIST = [
1819
bytes.fromhex("01308201130201010420"), # old, <2012
1920
bytes.fromhex("01d63081d30201010420"), # new, >2012
@@ -80,8 +81,9 @@ def find_keys(filename: str | Path) -> set[str]:
8081
key_data = b"\x80" + block_bytes[key_offset : key_offset + 32] # noqa: E203
8182
priv_key_wif = encode_base58_check(key_data)
8283
keys.add(priv_key_wif)
84+
global_offset = f.tell() - len(block_bytes) + key_offset
8385
logger.info(
84-
f"Found key at offset {key_offset:,} = 0x{key_offset:02x} "
86+
f"Found key at offset {global_offset:,} = 0x{global_offset:_x} "
8587
f"(using magic bytes {magic_bytes.hex()}): {priv_key_wif}"
8688
)
8789
pos += 1
@@ -132,6 +134,7 @@ def main_keyhunter(haystack_filename: str | Path, log_path: Optional[str | Path]
132134

133135
keys = find_keys(haystack_filename)
134136

137+
keys = sorted(list(keys))
135138
logger.info(f"Found {len(keys)} keys: {keys}")
136139

137140
if len(keys) > 0:

0 commit comments

Comments
 (0)