Advertisement
bogolt

print read block number when scanning disk

Nov 26th, 2014
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import binascii
  4. import os
  5. import hashlib
  6. import sys
  7.  
  8. # bytes to read at a time from file (10meg)
  9. readlength=10*1024*1024
  10.  
  11. if len(sys.argv)!=2:
  12.   print "./keyhunter.py <filename>"
  13.   exit()
  14.  
  15. filename = sys.argv[1]
  16.  
  17. f = open(filename)
  18. magic = '\x01\x30\x82\x01\x13\x02\x01\x01\x04\x20'
  19. magiclen = len(magic)
  20.  
  21.  
  22.  
  23. ##### start code from pywallet.py #############
  24. __b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
  25. __b58base = len(__b58chars)
  26.  
  27. def b58encode(v):
  28.   """ encode v, which is a string of bytes, to base58.
  29.  """
  30.  
  31.   long_value = 0L
  32.   for (i, c) in enumerate(v[::-1]):
  33.     long_value += (256**i) * ord(c)
  34.  
  35.   result = ''
  36.   while long_value >= __b58base:
  37.     div, mod = divmod(long_value, __b58base)
  38.     result = __b58chars[mod] + result
  39.     long_value = div
  40.   result = __b58chars[long_value] + result
  41.  
  42.   # Bitcoin does a little leading-zero-compression:
  43.   # leading 0-bytes in the input become leading-1s
  44.   nPad = 0
  45.   for c in v:
  46.     if c == '\0': nPad += 1
  47.     else: break
  48.  
  49.   return (__b58chars[0]*nPad) + result
  50.  
  51. def Hash(data):
  52.   return hashlib.sha256(hashlib.sha256(data).digest()).digest()
  53.  
  54. def EncodeBase58Check(secret):
  55.   hash = Hash(secret)
  56.   return b58encode(secret + hash[0:4])
  57.  
  58. ########## end code from pywallet.py ############
  59.  
  60.  
  61.  
  62. # read through target file
  63. # one block at a time
  64. total_read_mb = 0
  65. while True:
  66.   print total_read_mb
  67.   data = f.read(readlength)
  68.   if not data:
  69.     break
  70.   total_read_mb += 1
  71.  
  72.   # look in this block for keys
  73.   x=0
  74.   while True:
  75.     # find the magic number
  76.     pos=data.find(magic,x)
  77.     #pos=data.find('\13\02\01\01\04\20',0)
  78.     if pos==-1:
  79.       break
  80.     print EncodeBase58Check('\x80'+data[pos+magiclen:pos+magiclen+32])
  81.     x+=(pos+1)
  82.  
  83.   # are we at the end of the file?
  84.   if len(data) < readlength:
  85.     break
  86.  
  87.   # make sure we didn't miss any keys at the end of the block
  88.   f.seek(f.tell()-(32+magiclen))
  89.  
  90. # code grabbed from pywallet.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement