-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagic_number.py
More file actions
30 lines (25 loc) · 780 Bytes
/
Copy pathmagic_number.py
File metadata and controls
30 lines (25 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
file_location = sys.argv[1]
formats = {
"jpg" : [b'\xff\xd8\xff\xe0\x00\x10JFIF', b'\xff\xd8\xff\xe1\x14\x0cExif'],
"gif" : [b'GIF89a']
}
#for form, typ in formats.items():
# for i in typ:
# print(i)
with open(file_location, 'rb') as file:
data = file.read(10)
print(data)
print(F"reading metadata: {data}")
for form, typ in formats.items():
print(type(typ))
if form == "gif":
for each in typ:
if each == data[:6]:
print(f"Found format {form}")
else:
if form == "jpg":
for each in typ:
print(each)
if each == data[:10]:
print(f"Found format {form}")