-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
woo! It's a command line tool and it will tell you if you've got an o…
…bfuscated zip or tar file!
- Loading branch information
Catherine Oborski
committed
Sep 7, 2024
1 parent
1546500
commit d094164
Showing
3 changed files
with
50 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |