Last active
October 22, 2021 23:13
-
-
Save GGLinnk/0093223e3e6aa50857ce16334d6f2b1a to your computer and use it in GitHub Desktop.
Group Magic Bytes | Python script that group Magic Bytes of files in folder, show retrived bytes and show associated file. This is not the final version!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
from sys import argv, stderr | |
from os import listdir, path | |
import binascii | |
linkPath = path.normpath(argv[1]) | |
if not path.exists(linkPath): | |
print(f"Folder doesn't exists: [{linkPath}]", file=stderr) | |
exit(1) | |
if not path.isdir(linkPath): | |
print(f"Not a folder: [{linkPath}]", file=stderr) | |
exit(1) | |
fileMagiks = {} | |
linkFiles = [f for f in listdir(linkPath) if path.isfile(path.join(linkPath, f))] | |
for f in linkFiles: | |
fb = open(path.join(linkPath, f), "rb") | |
fileMagik = fb.read(4) | |
if fileMagik not in fileMagiks: | |
fileMagiks[fileMagik] = {"refs": []} | |
fileMagiks[fileMagik]["refs"].append(f) | |
fb.close() | |
for fileMagik in fileMagiks: | |
print(f"{fileMagik} : {fileMagiks[fileMagik]['refs']}") | |
#print(f"0x{binascii.hexlify(fileMagik).decode()} : {fileMagik.decode()}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment