woo! It's a command line tool and it will tell you if you've got an obfuscated zip or tar file!
This commit is contained in:
parent
15465006e8
commit
d094164c84
3 changed files with 50 additions and 16 deletions
7
app.py
Normal file
7
app.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from typer import Typer
|
||||
import identify_file_type
|
||||
|
||||
app = Typer()
|
||||
VERSION = "0.1.0-alpha"
|
||||
|
||||
app.add_typer(identify_file_type.app, name="identify_file_type")
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
from typer import Typer, Argument
|
||||
from rich import print, console
|
||||
from log import create_rich_logger
|
||||
from pprint import pprint
|
||||
import argparse
|
||||
import pathlib
|
||||
import shutil
|
||||
import tempfile
|
||||
import zipfile
|
||||
import magic
|
||||
|
||||
app = Typer()
|
||||
logger = create_rich_logger()
|
||||
|
||||
|
||||
@app.command()
|
||||
def identify(files: list[str] = Argument(..., help="File paths to identify")):
|
||||
"""Identifies the file type of provided files with incorrect extensions."""
|
||||
for file_path in files:
|
||||
try:
|
||||
with open(file_path, "rb") as f:
|
||||
file_type = magic.from_buffer(f.read(2048))
|
||||
|
||||
if file_type.startswith("ZIP archive"):
|
||||
with zipfile.ZipFile(file_path, "r") as z:
|
||||
print(f"{file_path}: ZIP archive containing:")
|
||||
for member in z.namelist():
|
||||
Text.print(f" - {member}")
|
||||
elif file_type.startswith("TAR archive"):
|
||||
with tarfile.open(file_path, "r") as tar:
|
||||
print(f"{file_path}: TAR archive containing:")
|
||||
for member in tar.getmembers():
|
||||
print(f" - {member.name}")
|
||||
else:
|
||||
print(f"{file_path}: {file_type}")
|
||||
|
||||
except FileNotFoundError:
|
||||
log.error(f"Error: File not found: {file_path}")
|
||||
|
||||
print(f"[bold green]Identified file type: {file_type}[/bold green]")
|
||||
19
main.py
19
main.py
|
|
@ -1,25 +1,12 @@
|
|||
from typer import Typer, Argument
|
||||
from rich import print, console
|
||||
from pprint import pprint
|
||||
import argparse
|
||||
import pathlib
|
||||
import shutil
|
||||
import tempfile
|
||||
import zipfile
|
||||
from typer import Typer
|
||||
from log import create_rich_logger
|
||||
import identify_file_type
|
||||
|
||||
app = Typer()
|
||||
VERSION = "0.1.0-alpha"
|
||||
logger = create_rich_logger()
|
||||
|
||||
|
||||
@app.command()
|
||||
def identify(files: list[str] = Argument(..., help="File paths to identify")):
|
||||
"""Identifies the file type of provided files with incorrect extensions."""
|
||||
# ... (file identification logic)
|
||||
|
||||
print("[bold green]Identified file type:[/bold green]")
|
||||
|
||||
app.add_typer(identify_file_type.app, name="identify_file_type")
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
|
|
|
|||
Loading…
Reference in a new issue