Open sihunh opened 2 years ago
file_sig = ['ff d8 ff e0', 'ff d8 ff e8', '89 50 4e 47 0d 0a 1a 0a', '50 4b 03 04', '47 49 46 38 37 61', '47 49 46 38 39 61', '25 50 44 46 2d 31 2e', '4D 5A 90' ]
file_extension = {'ff d8 ff e0':'jpeg', 'ff d8 ff e8':'jpeg', '89 50 4e 47 0d 0a 1a 0a':'png', '50 4b 03 04':'zip', '47 49 46 38 37 61':'gif', '47 49 46 38 39 61':'gif', '25 50 44 46 2d 31 2e':'pdf', '4D 5A 90':'exe' }
ps 2 에서 숨겨진 파일 찾을때 쓸거임
import os from socket import from math import ceil from sig import import itertools import argparse
def hex_group_formatter(iterable): chunks = [iter(iterable)] 4 # (header의 perv_size, size) 청크 4개씩 분할 32byte return ' '.join( ' '.join(format(x, '0>2x') for x in chunk) # 데이터 바꾸는 부분 for chunk in itertools.zip_longest(chunks, fillvalue=0)) # 길이가 다른 자료형이라 zip_logest사용 해서 분할시킴(0x20,0x30,0x40,0x50)...(0,-,-,-) 이런식
def hex_view(filename, chunk_size=16): # 파일 hex값으로 읽어옴 template = ' {:<53}' with open(filename, 'rb') as stream: for chunk_count in itertools.count(0): chunk = stream.read(chunk_size) if not chunk: return yield template.format( hex_group_formatter(chunk) )
def file_output(header_sig): global out_file_cnt out_file_cnt += 1 print('.',file_extension[header_sig],'파일 검출','\t')
def size_rt(bytes): size_result = str(bytes) + 'Byte' if (bytes > 1024): size_result = str(int(ceil(bytes/1024))) + 'KB' elif (bytes > 10242): size_result = str(int(ceil(bytes/(10242)))) + 'MB' elif (bytes > 10243): size_result = str(ceil(bytes/(10243))) + 'GB' elif (bytes > 10244): size_result = str(int(ceil(bytes/(10244)))) + 'TB' return size_result
def stg(): file_name = input('Write file name : ') parser = argparse.ArgumentParser() parser.add_argument('file', nargs='?', default=file_name) args = parser.parse_args()