SHARE
TWEET

Untitled

a guest Mar 3rd, 2018 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import sys
  3. import struct
  4.  
  5. argc = len(sys.argv)
  6.  
  7. if argc != 3:
  8.     script = os.path.basename(__file__)
  9.     sys.exit("usage: {} <filename> <value>".format(script))
  10.  
  11.  
  12. filename = sys.argv[1]
  13. value = int(sys.argv[2], 0)
  14.  
  15. if value < 0 or value > 0xff:
  16.     sys.exit("value must be in the range [0, 0xff]")
  17.  
  18. with open(filename, "r+b") as file:
  19.  
  20.     # Determine the size of the file
  21.     file.seek(0, os.SEEK_END)
  22.     size = file.tell()
  23.  
  24.     address = 0
  25.     while address < size:
  26.  
  27.         # Read the next byte
  28.         file.seek(address)
  29.         byte = struct.unpack("B", file.read(1))[0]
  30.  
  31.         # Check for a match
  32.         if byte == value:
  33.             print hex(address)
  34.  
  35.         address += 1
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