import os
'''
Explainations:
root: path of the image folder
image_list: path of each image
images: name of each image
dirs: =images
target_info_seg: information segments that always occur in screenshots but rarely occur in photos
pri_iden_mark: primitiveness identification marks, which can be used to judge whether a screenshot is original or not
process_time: record the number of times the image is processed
If you want to test on your own data, just change the root is fine.
'''
root = './MyData/Screenshot-wechat-unprocessed/'
image_list = []
images = []
dirs = os.listdir(root)
target_info_seg = [
b'(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a',
b'\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P',
b'(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n',
b'(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00',
b'\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14',
b'\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@',
b'\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00',
b'(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a',
b'$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$'
]
pri_iden_mark = [
b'\xff\xe0', b'\xff\xe1', b'\xff\xe2', b'\xff\xe3',
b'\xff\xe4', b'\xff\xe5', b'\xff\xe6', b'\xff\xe7',
b'\xff\xe8', b'\xff\xe9', b'\xff\xea', b'\xff\xeb',
b'\xff\xec', b'\xff\xed', b'\xff\xee', b'\xff\xef'
]
process_time = 0
''' create the image name list and the image path list '''
for image in dirs:
images.append(image)
tmp = os.path.join(root+image)
image_list.append(tmp)
''' read the binary data of each image '''
for i in range(len(image_list)):
image_path = image_list[i]
with open(image_path, "rb") as file:
jpg_bin = file.read()
''' print module '''
print('\033[0;31;40mNo:\033[0m', i + 1, '\033[0;31;40m---\033[0m',
images[i], '\n')
''' judgement module1: screenshot/photo '''
''' determine whether every segment is contained in the binary data '''
for j in range(len(target_info_seg)):
if jpg_bin.find(target_info_seg[j]) == -1:
flag = 'p'
break
elif j == len(target_info_seg)-2:
# print('Found segment', j, 'at position', jpg_bin.find(target_info_seg[j]))
flag = 's'
break
''' Photoshop-processed target information section judgement '''
if jpg_bin.find(target_info_seg[8]) != -1:
flag = 's'
''' print result: photo/screenshot '''
if flag == 's':
print('\033[0;31;36mScreenshot\033[0m')
elif flag == 'p':
print('\033[0;31;36mPhoto\033[0m\n')
''' judgement module2: processed/unprocessed '''
if flag == 's':
for k in range(len(pri_iden_mark)):
if jpg_bin.find(pri_iden_mark[k]) != -1:
process_time += 1
if process_time > 1:
print('\033[0;31;40mImprimitive\033[0m\n')
break
elif k == len(pri_iden_mark)-1:
print('Primitive\n')
break
process_time = 0