SHARE
TWEET

hasher.py

finalshare Feb 14th, 2018 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import struct, hashlib, zlib, sys
  2.  
  3. def hexToByteArr(h):
  4.     byte_arr = []
  5.     s = ''
  6.     for c in h:
  7.         s += c
  8.         if (len(s)==2):
  9.             byte_arr.append(s)
  10.             s = ''
  11.            
  12.     return byte_arr
  13.  
  14. if __name__ == '__main__':
  15.     if (len(sys.argv)>=2):
  16.         input_path = sys.argv[1]
  17.         output_path = input_path+'.patched'
  18.         if (len(sys.argv)>=3):
  19.             output_path = sys.argv[2]
  20.            
  21.         f = open(input_path, 'rb').read()
  22.         hex_size = hexToByteArr(struct.pack('<I', len(f)).encode('hex'))
  23.         hex_value = f.encode('hex')
  24.         hex_byte = hexToByteArr(hex_value)
  25.  
  26.         for i in range(len(hex_size)):
  27.             hex_byte[i+32] = hex_size[i]
  28.  
  29.         sha1_data = ''.join(hex_byte[32:]).decode('hex')
  30.         sha1_byte = hexToByteArr(hashlib.sha1(sha1_data).hexdigest())
  31.  
  32.         for i in range(len(sha1_byte)):
  33.             hex_byte[i+12] = sha1_byte[i]
  34.  
  35.         adler32_data = ''.join(hex_byte[12:]).decode('hex')
  36.  
  37.         adler_int = zlib.adler32(adler32_data) % (1<<32)
  38.         adler32_byte = hexToByteArr(struct.pack('<I', adler_int).encode('hex'))
  39.  
  40.         for i in range(len(adler32_byte)):
  41.             hex_byte[i+8] = adler32_byte[i]
  42.  
  43.         patched = ''.join(hex_byte).decode('hex')
  44.  
  45.         f1 = open(output_path, 'wb')
  46.         f1.write(patched)
  47.         f1.close()
  48.         print 'Done'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top