Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using 'with' to open file #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions keyhunter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

filename = sys.argv[1]

f = open(filename)

magic = '\x01\x30\x82\x01\x13\x02\x01\x01\x04\x20'
magiclen = len(magic)

Expand Down Expand Up @@ -58,32 +58,33 @@ def EncodeBase58Check(secret):
########## end code from pywallet.py ############


with open(filename, 'r') as f:

# read through target file
# one block at a time
while True:
data = f.read(readlength)
if not data:
break

# look in this block for keys
x=0
# read through target file
# one block at a time
while True:
# find the magic number
pos=data.find(magic,x)
#pos=data.find('\13\02\01\01\04\20',0)
if pos==-1:
data = f.read(readlength)
if not data:
break
print EncodeBase58Check('\x80'+data[pos+magiclen:pos+magiclen+32])
x+=(pos+1)

# look in this block for keys
x=0
while True:
# find the magic number
pos=data.find(magic,x)
#pos=data.find('\13\02\01\01\04\20',0)
if pos==-1:
break
print EncodeBase58Check('\x80'+data[pos+magiclen:pos+magiclen+32])
x+=(pos+1)

# are we at the end of the file?
if len(data) < readlength:
break
# are we at the end of the file?
if len(data) < readlength:
break

# make sure we didn't miss any keys at the end of the block
f.seek(f.tell()-(32+magiclen))
# make sure we didn't miss any keys at the end of the block
f.seek(f.tell()-(32+magiclen))

# code grabbed from pywallet.py