1

I was trying to write a program that would grab the ascii or binary behind a .jpeg and find for example the "JFIFHH" to verify thats its really a JPEG the simple script i wrote was

    test = open('test.jpeg', 'rb')

data = test.read()
print(data)

if 'JFIFHH' in data :
    print('FOUND')

elif 'JFIFHH' not in data :     
  print('not found')

It always prints not found even if its there. so i found out it wasn't the binary it printed but something else, so how can i make this work???

BluePython
  • 17
  • 4

1 Answers1

0

This isn't the proper pattern to look for in the first place. I checked a JPEG file and it contained JFIF but not JFIFHH...

As this answer states you should look for FF D8 start & FF D9 end byte sequences, like this (Python 2/3 compatible code):

with open("test.jpeg","rb") as f:
    contents = f.read()
    if contents.startswith(b"\xff\xd8") and contents.endswith(b"\xff\xd9"):
        print("it's a jpeg")
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219